@zyro-sec/schema 1.0.0 → 1.0.2
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 +9 -11
- 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/src/vcs.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export * as Vcs from "./vcs.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { NonNegativeInt, optional } from "./schema.js"
|
|
5
|
+
|
|
6
|
+
export const Branch = Schema.Struct({
|
|
7
|
+
current: optional(Schema.String),
|
|
8
|
+
default: optional(Schema.String),
|
|
9
|
+
}).annotate({ identifier: "Vcs.Branch" })
|
|
10
|
+
export interface Branch extends Schema.Schema.Type<typeof Branch> {}
|
|
11
|
+
|
|
12
|
+
export const Info = Schema.Struct({
|
|
13
|
+
provider: optional(Schema.String),
|
|
14
|
+
branch: Branch,
|
|
15
|
+
}).annotate({ identifier: "Vcs.Info" })
|
|
16
|
+
export interface Info extends Schema.Schema.Type<typeof Info> {}
|
|
17
|
+
|
|
18
|
+
export const BranchList = Schema.Array(Schema.String).annotate({ identifier: "Vcs.BranchList" })
|
|
19
|
+
export type BranchList = typeof BranchList.Type
|
|
20
|
+
|
|
21
|
+
export const Base = Schema.Struct({
|
|
22
|
+
name: Schema.String,
|
|
23
|
+
ref: Schema.String,
|
|
24
|
+
source: Schema.Literals(["reflog", "default"]),
|
|
25
|
+
}).annotate({ identifier: "Vcs.Base" })
|
|
26
|
+
export interface Base extends Schema.Schema.Type<typeof Base> {}
|
|
27
|
+
|
|
28
|
+
export const Mode = Schema.Literals(["working", "branch", "committed"]).annotate({ identifier: "Vcs.Mode" })
|
|
29
|
+
export type Mode = typeof Mode.Type
|
|
30
|
+
|
|
31
|
+
/** How a diff lists untracked files: one by one, or each untracked folder as one `dir/` entry. */
|
|
32
|
+
export const Untracked = Schema.Literals(["files", "folders"]).annotate({ identifier: "Vcs.Untracked" })
|
|
33
|
+
export type Untracked = typeof Untracked.Type
|
|
34
|
+
|
|
35
|
+
export const FileStatus = Schema.Struct({
|
|
36
|
+
file: Schema.String,
|
|
37
|
+
additions: NonNegativeInt,
|
|
38
|
+
deletions: NonNegativeInt,
|
|
39
|
+
status: Schema.Literals(["added", "deleted", "modified"]),
|
|
40
|
+
}).annotate({ identifier: "Vcs.FileStatus" })
|
|
41
|
+
export interface FileStatus extends Schema.Schema.Type<typeof FileStatus> {}
|
package/src/websearch.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export * as WebSearch from "./websearch.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { ephemeral, inventory } from "./event.js"
|
|
5
|
+
import { optional } from "./schema.js"
|
|
6
|
+
|
|
7
|
+
export const ID = Schema.String.pipe(Schema.brand("WebSearch.ID"), Schema.annotate({ identifier: "WebSearch.ID" }))
|
|
8
|
+
export type ID = typeof ID.Type
|
|
9
|
+
|
|
10
|
+
export interface Provider extends Schema.Schema.Type<typeof Provider> {}
|
|
11
|
+
export const Provider = Schema.Struct({
|
|
12
|
+
id: ID,
|
|
13
|
+
name: Schema.String,
|
|
14
|
+
}).annotate({ identifier: "WebSearch.Provider" })
|
|
15
|
+
|
|
16
|
+
export interface Input extends Schema.Schema.Type<typeof Input> {}
|
|
17
|
+
export const Input = Schema.Struct({
|
|
18
|
+
query: Schema.String,
|
|
19
|
+
providerID: ID.pipe(optional),
|
|
20
|
+
}).annotate({ identifier: "WebSearch.Input" })
|
|
21
|
+
export type ProviderInput = Pick<Input, "query">
|
|
22
|
+
|
|
23
|
+
export interface Result extends Schema.Schema.Type<typeof Result> {}
|
|
24
|
+
export const Result = Schema.Struct({
|
|
25
|
+
url: Schema.String,
|
|
26
|
+
title: Schema.String.pipe(optional),
|
|
27
|
+
content: Schema.String.pipe(optional),
|
|
28
|
+
time: Schema.Struct({
|
|
29
|
+
published: Schema.Finite.pipe(optional).annotate({
|
|
30
|
+
description: "Publication time in milliseconds since the Unix epoch",
|
|
31
|
+
}),
|
|
32
|
+
}),
|
|
33
|
+
}).annotate({ identifier: "WebSearch.Result" })
|
|
34
|
+
|
|
35
|
+
export class Response extends Schema.Class<Response>("WebSearch.Response")({
|
|
36
|
+
providerID: ID,
|
|
37
|
+
results: Schema.Array(Result),
|
|
38
|
+
}) {}
|
|
39
|
+
|
|
40
|
+
const Updated = ephemeral({
|
|
41
|
+
type: "websearch.updated",
|
|
42
|
+
schema: {},
|
|
43
|
+
})
|
|
44
|
+
export const Event = { Updated, Definitions: inventory(Updated) }
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export * as WorkspaceEvent from "./workspace-event.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { Event } from "./event.js"
|
|
5
|
+
import { WorkspaceID } from "./workspace-id.js"
|
|
6
|
+
|
|
7
|
+
export const ConnectionStatus = Schema.Struct({
|
|
8
|
+
workspaceID: WorkspaceID,
|
|
9
|
+
status: Schema.Literals(["connected", "connecting", "disconnected", "error"]),
|
|
10
|
+
}).annotate({ identifier: "WorkspaceEvent.ConnectionStatus" })
|
|
11
|
+
export interface ConnectionStatus extends Schema.Schema.Type<typeof ConnectionStatus> {}
|
|
12
|
+
|
|
13
|
+
export const Ready = Event.ephemeral({
|
|
14
|
+
type: "workspace.ready",
|
|
15
|
+
schema: {
|
|
16
|
+
name: Schema.String,
|
|
17
|
+
},
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
export const Failed = Event.ephemeral({
|
|
21
|
+
type: "workspace.failed",
|
|
22
|
+
schema: {
|
|
23
|
+
message: Schema.String,
|
|
24
|
+
},
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
export const Status = Event.ephemeral({
|
|
28
|
+
type: "workspace.status",
|
|
29
|
+
schema: ConnectionStatus.fields,
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
export const Definitions = Event.inventory(Ready, Failed, Status)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Schema } from "effect"
|
|
2
|
+
import { ascending } from "./identifier.js"
|
|
3
|
+
import { statics } from "./schema.js"
|
|
4
|
+
|
|
5
|
+
export const WorkspaceID = Schema.String.check(Schema.isStartingWith("wrk")).pipe(
|
|
6
|
+
Schema.brand("Workspace.ID"),
|
|
7
|
+
Schema.annotate({ identifier: "Workspace.ID" }),
|
|
8
|
+
statics((schema) => {
|
|
9
|
+
const create = () => schema.make("wrk_" + ascending())
|
|
10
|
+
return {
|
|
11
|
+
ascending: (id?: string) => {
|
|
12
|
+
if (!id) return create()
|
|
13
|
+
return schema.make(id)
|
|
14
|
+
},
|
|
15
|
+
create,
|
|
16
|
+
}
|
|
17
|
+
}),
|
|
18
|
+
)
|
|
19
|
+
export type WorkspaceID = typeof WorkspaceID.Type
|
package/src/workspace.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export * as Workspace from "./workspace.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { WorkspaceEvent } from "./workspace-event.js"
|
|
5
|
+
import { WorkspaceID } from "./workspace-id.js"
|
|
6
|
+
|
|
7
|
+
export const ID = WorkspaceID
|
|
8
|
+
export type ID = WorkspaceID
|
|
9
|
+
|
|
10
|
+
export const DestroyResult = Schema.Struct({
|
|
11
|
+
destroyed: Schema.Boolean.annotate({
|
|
12
|
+
description: "True when this request transitioned the workspace from existing to destroyed.",
|
|
13
|
+
}),
|
|
14
|
+
}).annotate({
|
|
15
|
+
identifier: "WorkspaceDestroyResult",
|
|
16
|
+
description: "Reports whether this request destroyed an existing workspace.",
|
|
17
|
+
})
|
|
18
|
+
export interface DestroyResult extends Schema.Schema.Type<typeof DestroyResult> {}
|
|
19
|
+
|
|
20
|
+
export const Event = WorkspaceEvent
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export * as WorktreeEvent from "./worktree-event.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { optional } from "./schema.js"
|
|
5
|
+
import { Event } from "./event.js"
|
|
6
|
+
|
|
7
|
+
export const Ready = Event.ephemeral({
|
|
8
|
+
type: "worktree.ready",
|
|
9
|
+
schema: {
|
|
10
|
+
name: Schema.String,
|
|
11
|
+
branch: optional(Schema.String),
|
|
12
|
+
},
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
export const Failed = Event.ephemeral({
|
|
16
|
+
type: "worktree.failed",
|
|
17
|
+
schema: {
|
|
18
|
+
message: Schema.String,
|
|
19
|
+
},
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
export const Definitions = Event.inventory(Ready, Failed)
|
package/src/worktree.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
export * as Worktree from "./worktree.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { durable, ephemeral, inventory } from "./event.js"
|
|
5
|
+
import { AbsolutePath, optional } from "./schema.js"
|
|
6
|
+
import { Project } from "./project.js"
|
|
7
|
+
|
|
8
|
+
export const StrategyID = Schema.Trim.pipe(Schema.check(Schema.isNonEmpty()), Schema.brand("Worktree.StrategyID"))
|
|
9
|
+
export type StrategyID = typeof StrategyID.Type
|
|
10
|
+
|
|
11
|
+
export const CreateInput = Schema.Struct({
|
|
12
|
+
projectID: Project.ID,
|
|
13
|
+
from: optional(AbsolutePath),
|
|
14
|
+
branch: optional(Schema.Trim.pipe(Schema.check(Schema.isNonEmpty()))),
|
|
15
|
+
directory: optional(AbsolutePath).annotate({
|
|
16
|
+
description:
|
|
17
|
+
"Parent directory for the new worktree. Uses the project's canonical configuration, then defaults to the server's data directory under worktree/<first six project ID characters>.",
|
|
18
|
+
}),
|
|
19
|
+
name: optional(Schema.String),
|
|
20
|
+
}).annotate({ identifier: "Worktree.CreateInput" })
|
|
21
|
+
export interface CreateInput extends Schema.Schema.Type<typeof CreateInput> {}
|
|
22
|
+
|
|
23
|
+
export const RemoveInput = Schema.Struct({
|
|
24
|
+
projectID: Project.ID,
|
|
25
|
+
directory: AbsolutePath,
|
|
26
|
+
force: Schema.Boolean,
|
|
27
|
+
}).annotate({ identifier: "Worktree.RemoveInput" })
|
|
28
|
+
export interface RemoveInput extends Schema.Schema.Type<typeof RemoveInput> {}
|
|
29
|
+
|
|
30
|
+
export const Info = Schema.Struct({
|
|
31
|
+
directory: AbsolutePath,
|
|
32
|
+
}).annotate({ identifier: "Worktree.Info" })
|
|
33
|
+
export interface Info extends Schema.Schema.Type<typeof Info> {}
|
|
34
|
+
|
|
35
|
+
export const Directory = Schema.Struct({
|
|
36
|
+
directory: AbsolutePath,
|
|
37
|
+
strategy: optional(Schema.String),
|
|
38
|
+
}).annotate({ identifier: "Worktree.Directory" })
|
|
39
|
+
export interface Directory extends Schema.Schema.Type<typeof Directory> {}
|
|
40
|
+
|
|
41
|
+
export const ListEntry = Schema.Struct({
|
|
42
|
+
directory: AbsolutePath,
|
|
43
|
+
type: Schema.Literals(["root", "worktree"]),
|
|
44
|
+
}).annotate({ identifier: "Worktree.ListEntry" })
|
|
45
|
+
export interface ListEntry extends Schema.Schema.Type<typeof ListEntry> {}
|
|
46
|
+
|
|
47
|
+
export class OperationError extends Schema.TaggedError<OperationError>()("Worktree.OperationError", {
|
|
48
|
+
message: Schema.String,
|
|
49
|
+
forceRequired: optional(Schema.Boolean),
|
|
50
|
+
}) {}
|
|
51
|
+
|
|
52
|
+
export const List = Schema.Array(Directory).annotate({ identifier: "Worktree.List" })
|
|
53
|
+
export type List = typeof List.Type
|
|
54
|
+
|
|
55
|
+
const Updated = ephemeral({
|
|
56
|
+
type: "worktree.updated",
|
|
57
|
+
schema: { projectID: Project.ID },
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
const Resolved = durable({
|
|
61
|
+
type: "worktree.resolved",
|
|
62
|
+
durable: { aggregate: "projectID", version: 1 },
|
|
63
|
+
schema: {
|
|
64
|
+
projectID: Project.ID,
|
|
65
|
+
directory: AbsolutePath,
|
|
66
|
+
previous: Project.ID,
|
|
67
|
+
adopted: optional(Schema.Array(Project.ID)),
|
|
68
|
+
},
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
export const Event = { Updated, Resolved, Definitions: inventory(Updated, Resolved) }
|
|
72
|
+
|
|
73
|
+
export function adopt(
|
|
74
|
+
session: { readonly projectID: string; readonly directory: string; readonly workspaceID?: string },
|
|
75
|
+
event: {
|
|
76
|
+
readonly projectID: string
|
|
77
|
+
readonly directory: string
|
|
78
|
+
readonly previous: string
|
|
79
|
+
readonly adopted?: ReadonlyArray<string>
|
|
80
|
+
},
|
|
81
|
+
) {
|
|
82
|
+
if (session.workspaceID) return
|
|
83
|
+
if (
|
|
84
|
+
session.projectID !== event.previous &&
|
|
85
|
+
session.projectID !== Project.ID.global &&
|
|
86
|
+
!event.adopted?.includes(session.projectID)
|
|
87
|
+
)
|
|
88
|
+
return
|
|
89
|
+
if (session.projectID === event.projectID) return
|
|
90
|
+
const normalize = (value: string) =>
|
|
91
|
+
value
|
|
92
|
+
.replaceAll("\\", "/")
|
|
93
|
+
.split("/")
|
|
94
|
+
.reduce((result, segment) => {
|
|
95
|
+
if (!segment || segment === ".") return result
|
|
96
|
+
if (segment === "..") return result.slice(0, result.lastIndexOf("/"))
|
|
97
|
+
return `${result}/${segment}`
|
|
98
|
+
}, "")
|
|
99
|
+
const directory = normalize(session.directory)
|
|
100
|
+
const root = normalize(event.directory)
|
|
101
|
+
const windows = /^\/[a-z]:/i.test(root)
|
|
102
|
+
const key = windows ? directory.toLowerCase() : directory
|
|
103
|
+
const parent = windows ? root.toLowerCase() : root
|
|
104
|
+
if (key !== parent && !key.startsWith(parent + "/")) return
|
|
105
|
+
return {
|
|
106
|
+
projectID: event.projectID,
|
|
107
|
+
subpath: key === parent ? undefined : directory.slice(root.length + 1),
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
})
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
})
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
})
|
|
@@ -0,0 +1,194 @@
|
|
|
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
|
+
})
|