@zyro-sec/schema 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.
- package/AGENTS.md +95 -0
- package/package.json +9 -15
- 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/script/pack.ts
ADDED
package/src/agent.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export * as Agent from "./agent.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { ephemeral, inventory } from "./event.js"
|
|
5
|
+
import { optional } from "./schema.js"
|
|
6
|
+
import { Model } from "./model.js"
|
|
7
|
+
import { Permission } from "./permission.js"
|
|
8
|
+
import { Provider } from "./provider.js"
|
|
9
|
+
import { PositiveInt, statics } from "./schema.js"
|
|
10
|
+
|
|
11
|
+
const Updated = ephemeral({ type: "agent.updated", schema: {} })
|
|
12
|
+
|
|
13
|
+
export const ID = Schema.String.pipe(Schema.brand("Agent.ID"), Schema.annotate({ identifier: "Agent.ID" }))
|
|
14
|
+
export type ID = typeof ID.Type
|
|
15
|
+
|
|
16
|
+
export const Name = Schema.String.pipe(Schema.brand("Agent.Name"))
|
|
17
|
+
export type Name = typeof Name.Type
|
|
18
|
+
|
|
19
|
+
export const Color = Schema.String.annotate({ identifier: "Agent.Color" })
|
|
20
|
+
export type Color = typeof Color.Type
|
|
21
|
+
|
|
22
|
+
export interface Info extends Schema.Schema.Type<typeof Info> {}
|
|
23
|
+
export const Info = Schema.Struct({
|
|
24
|
+
id: ID,
|
|
25
|
+
name: Name,
|
|
26
|
+
model: Model.Ref.pipe(optional),
|
|
27
|
+
request: Provider.Request,
|
|
28
|
+
system: Schema.String.pipe(optional),
|
|
29
|
+
/**
|
|
30
|
+
* Added to the default prompt while the agent is selected, without replacing it like `system`. A string is
|
|
31
|
+
* introduced as this agent's instructions, and core tells the model when they stop applying. `{ selected, unselected }`
|
|
32
|
+
* sends both texts exactly as written: `selected` while the agent is selected, `unselected` once when the session
|
|
33
|
+
* switches away.
|
|
34
|
+
*/
|
|
35
|
+
instructions: Schema.Union([Schema.String, Schema.Struct({ selected: Schema.String, unselected: Schema.String })]).pipe(
|
|
36
|
+
optional,
|
|
37
|
+
),
|
|
38
|
+
description: Schema.String.pipe(optional),
|
|
39
|
+
mode: Schema.Literals(["subagent", "primary", "all"]),
|
|
40
|
+
hidden: Schema.Boolean,
|
|
41
|
+
color: Color.pipe(optional),
|
|
42
|
+
steps: PositiveInt.pipe(optional),
|
|
43
|
+
permissions: Permission.Ruleset,
|
|
44
|
+
})
|
|
45
|
+
.annotate({ identifier: "Agent.Info" })
|
|
46
|
+
.pipe(
|
|
47
|
+
statics(() => ({
|
|
48
|
+
default: (id: ID) =>
|
|
49
|
+
({
|
|
50
|
+
id,
|
|
51
|
+
name: Name.make(id),
|
|
52
|
+
request: { settings: {}, headers: {}, body: {} },
|
|
53
|
+
mode: "primary",
|
|
54
|
+
hidden: false,
|
|
55
|
+
permissions: [
|
|
56
|
+
{ action: "*", resource: "*", effect: "allow" },
|
|
57
|
+
{ action: "read", resource: "*.env", effect: "ask" },
|
|
58
|
+
{ action: "read", resource: "*.env.*", effect: "ask" },
|
|
59
|
+
{ action: "read", resource: "*.env.example", effect: "allow" },
|
|
60
|
+
],
|
|
61
|
+
}) satisfies Info,
|
|
62
|
+
})),
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
export const Event = {
|
|
66
|
+
Updated,
|
|
67
|
+
Definitions: inventory(Updated),
|
|
68
|
+
}
|
package/src/artifact.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export * as Artifact from "./artifact.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { ephemeral, inventory } from "./event.js"
|
|
5
|
+
import { ascending } from "./identifier.js"
|
|
6
|
+
import { optional, statics } from "./schema.js"
|
|
7
|
+
import { SessionID } from "./session-id.js"
|
|
8
|
+
|
|
9
|
+
export const ID = Schema.String.check(Schema.isStartingWith("art_")).pipe(
|
|
10
|
+
Schema.brand("Artifact.ID"),
|
|
11
|
+
Schema.annotate({ identifier: "Artifact.ID" }),
|
|
12
|
+
statics((schema) => ({
|
|
13
|
+
create: () => schema.make("art_" + ascending()),
|
|
14
|
+
})),
|
|
15
|
+
)
|
|
16
|
+
export type ID = typeof ID.Type
|
|
17
|
+
|
|
18
|
+
export const ProviderID = Schema.Trim.check(Schema.isNonEmpty()).pipe(
|
|
19
|
+
Schema.brand("Artifact.ProviderID"),
|
|
20
|
+
Schema.annotate({ identifier: "Artifact.ProviderID" }),
|
|
21
|
+
)
|
|
22
|
+
export type ProviderID = typeof ProviderID.Type
|
|
23
|
+
|
|
24
|
+
export const Capability = Schema.Literals(["static", "server-code", "sqlite", "durable-objects"]).annotate({
|
|
25
|
+
identifier: "Artifact.Capability",
|
|
26
|
+
})
|
|
27
|
+
export type Capability = typeof Capability.Type
|
|
28
|
+
|
|
29
|
+
export interface Provider extends Schema.Schema.Type<typeof Provider> {}
|
|
30
|
+
export const Provider = Schema.Struct({
|
|
31
|
+
id: ProviderID,
|
|
32
|
+
name: Schema.String,
|
|
33
|
+
capabilities: Schema.Array(Capability),
|
|
34
|
+
default: Schema.Boolean,
|
|
35
|
+
}).annotate({ identifier: "Artifact.Provider" })
|
|
36
|
+
|
|
37
|
+
export interface Time extends Schema.Schema.Type<typeof Time> {}
|
|
38
|
+
export const Time = Schema.Struct({
|
|
39
|
+
created: Schema.Finite,
|
|
40
|
+
updated: Schema.Finite,
|
|
41
|
+
}).annotate({ identifier: "Artifact.Time" })
|
|
42
|
+
|
|
43
|
+
export interface Info extends Schema.Schema.Type<typeof Info> {}
|
|
44
|
+
export const Info = Schema.Struct({
|
|
45
|
+
id: ID,
|
|
46
|
+
provider: ProviderID,
|
|
47
|
+
sessionID: SessionID.pipe(optional),
|
|
48
|
+
title: Schema.String,
|
|
49
|
+
entry: Schema.String,
|
|
50
|
+
url: Schema.String,
|
|
51
|
+
time: Time,
|
|
52
|
+
}).annotate({ identifier: "Artifact.Info" })
|
|
53
|
+
|
|
54
|
+
export interface Content extends Schema.Schema.Type<typeof Content> {}
|
|
55
|
+
export const Content = Schema.Struct({
|
|
56
|
+
info: Info,
|
|
57
|
+
files: Schema.Record(Schema.String, Schema.String),
|
|
58
|
+
}).annotate({ identifier: "Artifact.Content" })
|
|
59
|
+
|
|
60
|
+
export interface CreateInput extends Schema.Schema.Type<typeof CreateInput> {}
|
|
61
|
+
export const CreateInput = Schema.Struct({
|
|
62
|
+
title: Schema.String,
|
|
63
|
+
files: Schema.Record(Schema.String, Schema.String),
|
|
64
|
+
entry: Schema.String.pipe(optional),
|
|
65
|
+
provider: ProviderID.pipe(optional),
|
|
66
|
+
sessionID: SessionID.pipe(optional),
|
|
67
|
+
}).annotate({ identifier: "Artifact.CreateInput" })
|
|
68
|
+
|
|
69
|
+
export interface UpdateInput extends Schema.Schema.Type<typeof UpdateInput> {}
|
|
70
|
+
export const UpdateInput = Schema.Struct({
|
|
71
|
+
title: Schema.String.pipe(optional),
|
|
72
|
+
files: Schema.Record(Schema.String, Schema.String),
|
|
73
|
+
entry: Schema.String.pipe(optional),
|
|
74
|
+
sessionID: SessionID.pipe(optional),
|
|
75
|
+
}).annotate({ identifier: "Artifact.UpdateInput" })
|
|
76
|
+
|
|
77
|
+
const Updated = ephemeral({
|
|
78
|
+
type: "artifact.updated",
|
|
79
|
+
schema: {},
|
|
80
|
+
})
|
|
81
|
+
export const Event = { Updated, Definitions: inventory(Updated) }
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
export * as Automation from "./automation.js"
|
|
2
|
+
|
|
3
|
+
import { Duration, Option, Schema } from "effect"
|
|
4
|
+
import { Agent } from "./agent.js"
|
|
5
|
+
import { ascending } from "./identifier.js"
|
|
6
|
+
import { ProjectID } from "./project-id.js"
|
|
7
|
+
import { DateTimeUtcFromMillis, NonNegativeInt, optional, statics } from "./schema.js"
|
|
8
|
+
import { SessionID } from "./session-id.js"
|
|
9
|
+
|
|
10
|
+
export const ID = Schema.String.check(Schema.isStartingWith("aut_")).pipe(
|
|
11
|
+
Schema.brand("Automation.ID"),
|
|
12
|
+
Schema.annotate({ identifier: "Automation.ID" }),
|
|
13
|
+
statics((schema) => ({
|
|
14
|
+
create: () => schema.make("aut_" + ascending()),
|
|
15
|
+
})),
|
|
16
|
+
)
|
|
17
|
+
export type ID = typeof ID.Type
|
|
18
|
+
|
|
19
|
+
const decodeDuration = Schema.decodeUnknownOption(Schema.DurationFromString)
|
|
20
|
+
|
|
21
|
+
/** Milliseconds in a duration string, or `None` when it is not one. */
|
|
22
|
+
export const durationMillis = (value: string) => decodeDuration(value).pipe(Option.map(Duration.toMillis))
|
|
23
|
+
|
|
24
|
+
/** A duration such as "90 seconds", "5 minutes" or "2 hours". The service validates it, since clients cannot run a custom check. */
|
|
25
|
+
export const DurationString = Schema.String.annotate({
|
|
26
|
+
identifier: "Automation.Duration",
|
|
27
|
+
description: 'A duration such as "90 seconds", "5 minutes" or "2 hours".',
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
const zone = {
|
|
31
|
+
tz: Schema.String.pipe(optional).annotate({
|
|
32
|
+
description: "IANA time zone. Defaults to the configured timezone, then the server's local zone.",
|
|
33
|
+
}),
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Runs once: at an instant with an offset, a wall-clock time in `tz` such as "2026-10-27T09:00", or "in 10 minutes". */
|
|
37
|
+
export const At = Schema.Struct({
|
|
38
|
+
type: Schema.tag("at"),
|
|
39
|
+
at: Schema.String.annotate({
|
|
40
|
+
description: 'An instant with an offset, a wall-clock time in tz such as "2026-10-27T09:00", or "in 10 minutes".',
|
|
41
|
+
}),
|
|
42
|
+
...zone,
|
|
43
|
+
}).annotate({ identifier: "Automation.Trigger.At" })
|
|
44
|
+
export interface At extends Schema.Schema.Type<typeof At> {}
|
|
45
|
+
export const Every = Schema.Struct({ type: Schema.tag("every"), every: DurationString, ...zone }).annotate({
|
|
46
|
+
identifier: "Automation.Trigger.Every",
|
|
47
|
+
})
|
|
48
|
+
export interface Every extends Schema.Schema.Type<typeof Every> {}
|
|
49
|
+
export const Cron = Schema.Struct({ type: Schema.tag("cron"), cron: Schema.String, ...zone }).annotate({
|
|
50
|
+
identifier: "Automation.Trigger.Cron",
|
|
51
|
+
})
|
|
52
|
+
export interface Cron extends Schema.Schema.Type<typeof Cron> {}
|
|
53
|
+
|
|
54
|
+
export const Event = Schema.Struct({
|
|
55
|
+
type: Schema.tag("event"),
|
|
56
|
+
server: Schema.NonEmptyString,
|
|
57
|
+
event: Schema.NonEmptyString,
|
|
58
|
+
args: Schema.Record(Schema.String, Schema.Json).pipe(optional),
|
|
59
|
+
}).annotate({ identifier: "Automation.Trigger.Event" })
|
|
60
|
+
export interface Event extends Schema.Schema.Type<typeof Event> {}
|
|
61
|
+
|
|
62
|
+
export const Trigger = Schema.Union([At, Every, Cron, Event]).pipe(
|
|
63
|
+
Schema.toTaggedUnion("type"),
|
|
64
|
+
Schema.annotate({ identifier: "Automation.Trigger" }),
|
|
65
|
+
)
|
|
66
|
+
export type Trigger = typeof Trigger.Type
|
|
67
|
+
|
|
68
|
+
/** Declares a variant field absent, so `{ session, subagent }` fails instead of silently dropping one. */
|
|
69
|
+
const absent = Schema.optionalKey(Schema.Never)
|
|
70
|
+
|
|
71
|
+
/** Where a prompt action goes: an existing Session, or a new child of the creating Session with an agent on every run. */
|
|
72
|
+
export const Target = Schema.Union([
|
|
73
|
+
Schema.Struct({ session: SessionID, subagent: absent }),
|
|
74
|
+
Schema.Struct({ subagent: Agent.ID, session: absent }),
|
|
75
|
+
]).annotate({ identifier: "Automation.Target" })
|
|
76
|
+
export type Target = typeof Target.Type
|
|
77
|
+
|
|
78
|
+
/** The child Session a `{ subagent }` run starts, derived from the run so a retry adopts it instead of starting another. */
|
|
79
|
+
export const runSessionID = (id: ID, run: number) => SessionID.make(`ses_${id}_${run}`)
|
|
80
|
+
|
|
81
|
+
/** Whether a Session is a `{ subagent }` run's child, which finishes without reporting to or waking its parent. */
|
|
82
|
+
export const isRunSession = (sessionID: SessionID) => sessionID.startsWith("ses_aut_")
|
|
83
|
+
|
|
84
|
+
export const PromptAction = Schema.Struct({ type: Schema.tag("prompt"), prompt: Schema.String, to: Target }).annotate({
|
|
85
|
+
identifier: "Automation.Action.Prompt",
|
|
86
|
+
})
|
|
87
|
+
export interface PromptAction extends Schema.Schema.Type<typeof PromptAction> {}
|
|
88
|
+
|
|
89
|
+
/** Code can hand off one prompt, but cannot choose a Session by id. Reject unknown keys rather than dropping a target. */
|
|
90
|
+
export const CodeResult = Schema.Struct({
|
|
91
|
+
state: Schema.Json.pipe(optional),
|
|
92
|
+
done: Schema.Boolean.pipe(optional),
|
|
93
|
+
send: Schema.Struct({
|
|
94
|
+
prompt: Schema.String.check(Schema.isPattern(/\S/)),
|
|
95
|
+
to: Schema.Struct({ subagent: Agent.ID.check(Schema.isPattern(/\S/)) }).pipe(optional),
|
|
96
|
+
}).pipe(optional),
|
|
97
|
+
}).annotate({ identifier: "Automation.CodeResult" })
|
|
98
|
+
export interface CodeResult extends Schema.Schema.Type<typeof CodeResult> {}
|
|
99
|
+
// Code Mode represents a program that returns nothing as JSON null.
|
|
100
|
+
export const decodeCodeResult = Schema.decodeUnknownResult(Schema.NullOr(CodeResult), { onExcessProperty: "error" })
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Runs `code` in a confined Code Mode runtime with no model call and no `fetch`. Tools called statically as
|
|
104
|
+
* `tools.<path>(...)` are extracted from the AST and authorized at creation. The program receives
|
|
105
|
+
* `input = { state, now, runs, args, event? }` and returns nothing or a `CodeResult`.
|
|
106
|
+
*/
|
|
107
|
+
export const CodeAction = Schema.Struct({
|
|
108
|
+
type: Schema.tag("code"),
|
|
109
|
+
code: Schema.String,
|
|
110
|
+
args: Schema.Json.pipe(optional),
|
|
111
|
+
}).annotate({ identifier: "Automation.Action.Code" })
|
|
112
|
+
export interface CodeAction extends Schema.Schema.Type<typeof CodeAction> {}
|
|
113
|
+
|
|
114
|
+
const shellFields = { type: Schema.tag("shell"), command: Schema.NonEmptyString }
|
|
115
|
+
|
|
116
|
+
export const ShellAction = Schema.Struct(shellFields).annotate({ identifier: "Automation.Action.Shell" })
|
|
117
|
+
export interface ShellAction extends Schema.Schema.Type<typeof ShellAction> {}
|
|
118
|
+
|
|
119
|
+
export const Action = Schema.Union([PromptAction, CodeAction, ShellAction]).pipe(
|
|
120
|
+
Schema.toTaggedUnion("type"),
|
|
121
|
+
Schema.annotate({ identifier: "Automation.Action" }),
|
|
122
|
+
)
|
|
123
|
+
export type Action = typeof Action.Type
|
|
124
|
+
|
|
125
|
+
export const Status = Schema.Literals(["active", "paused", "done"]).annotate({ identifier: "Automation.Status" })
|
|
126
|
+
export type Status = typeof Status.Type
|
|
127
|
+
|
|
128
|
+
export const Outcome = Schema.Literals(["fired", "late", "skipped", "disabled", "failed", "expired"]).annotate({
|
|
129
|
+
identifier: "Automation.Outcome",
|
|
130
|
+
})
|
|
131
|
+
export type Outcome = typeof Outcome.Type
|
|
132
|
+
|
|
133
|
+
export const Info = Schema.Struct({
|
|
134
|
+
id: ID,
|
|
135
|
+
name: Schema.String,
|
|
136
|
+
projectID: ProjectID,
|
|
137
|
+
/** The Session that created it, if any. Deleting that Session does not delete the automation. */
|
|
138
|
+
sessionID: SessionID.pipe(optional),
|
|
139
|
+
directory: Schema.String,
|
|
140
|
+
trigger: Trigger,
|
|
141
|
+
tz: Schema.String,
|
|
142
|
+
action: Action,
|
|
143
|
+
expires: DateTimeUtcFromMillis.pipe(optional),
|
|
144
|
+
status: Status,
|
|
145
|
+
nextDueAt: DateTimeUtcFromMillis.pipe(optional),
|
|
146
|
+
runCount: NonNegativeInt,
|
|
147
|
+
lastRunAt: DateTimeUtcFromMillis.pipe(optional),
|
|
148
|
+
lastOutcome: Outcome.pipe(optional),
|
|
149
|
+
lastOutput: Schema.String.pipe(optional),
|
|
150
|
+
state: Schema.Json.pipe(optional),
|
|
151
|
+
time: Schema.Struct({ created: DateTimeUtcFromMillis, updated: DateTimeUtcFromMillis }),
|
|
152
|
+
}).annotate({ identifier: "Automation.Info" })
|
|
153
|
+
export interface Info extends Schema.Schema.Type<typeof Info> {}
|
|
154
|
+
|
|
155
|
+
export const PromptActionInput = Schema.Struct({
|
|
156
|
+
type: Schema.tag("prompt"),
|
|
157
|
+
prompt: Schema.String.check(Schema.isMinLength(1)).annotate({
|
|
158
|
+
description: "The message the target Session receives, with enough context to act on it without this conversation.",
|
|
159
|
+
}),
|
|
160
|
+
to: Target.pipe(optional).annotate({
|
|
161
|
+
description:
|
|
162
|
+
'Where the prompt goes: { session: "ses_..." }, or { subagent: "<agent>" } to start a new child of the creating Session with that agent each run. Defaults to the creating Session.',
|
|
163
|
+
}),
|
|
164
|
+
}).annotate({ identifier: "Automation.PromptActionInput" })
|
|
165
|
+
export interface PromptActionInput extends Schema.Schema.Type<typeof PromptActionInput> {}
|
|
166
|
+
|
|
167
|
+
export const CodeActionInput = Schema.Struct({
|
|
168
|
+
type: Schema.tag("code"),
|
|
169
|
+
code: Schema.String.check(Schema.isMinLength(1)).annotate({
|
|
170
|
+
description: [
|
|
171
|
+
"Code Mode JavaScript run on each trigger with no model (32 KB output cap).",
|
|
172
|
+
'Call tools statically as tools.<ns>.<tool>(...) or tools["ns-name"].tool(...); each is authorized once at creation to run unattended.',
|
|
173
|
+
"A shell command still running at its timeout is stopped and the call throws; it never moves to the background.",
|
|
174
|
+
"Receives input = { state, now, runs, args } (also globals): state starts null, now is epoch ms, runs counts earlier runs.",
|
|
175
|
+
"Event triggers also receive input.event = { id, timestamp, data }; data follows the event type's payloadSchema.",
|
|
176
|
+
"Return nothing, or { state?, done?, send? }. JSON state is kept for the next run; done: true stops. lastOutput shows the delivery target and any logs.",
|
|
177
|
+
"Return at most one send per run. { send: { prompt } } steers the creating session; { send: { prompt, to: { subagent } } } starts a permitted child that does not report back. No session IDs. Omit send to stay quiet. A rejected send commits neither state nor done.",
|
|
178
|
+
'Example code string: if (runs < 2) return; return { done: true, send: { prompt: "Three checks elapsed. Review the build." } }',
|
|
179
|
+
].join(" "),
|
|
180
|
+
}),
|
|
181
|
+
args: Schema.Json.pipe(optional).annotate({ description: "JSON passed to every run as input.args." }),
|
|
182
|
+
}).annotate({ identifier: "Automation.CodeActionInput" })
|
|
183
|
+
export interface CodeActionInput extends Schema.Schema.Type<typeof CodeActionInput> {}
|
|
184
|
+
|
|
185
|
+
export const ShellActionInput = Schema.Struct({
|
|
186
|
+
...shellFields,
|
|
187
|
+
command: shellFields.command.annotate({
|
|
188
|
+
description: "The fixed shell command to run on each trigger without a model.",
|
|
189
|
+
}),
|
|
190
|
+
}).annotate({ identifier: "Automation.ShellActionInput" })
|
|
191
|
+
export interface ShellActionInput extends Schema.Schema.Type<typeof ShellActionInput> {}
|
|
192
|
+
|
|
193
|
+
export const ActionInput = Schema.Union([PromptActionInput, CodeActionInput, ShellActionInput]).pipe(
|
|
194
|
+
Schema.toTaggedUnion("type"),
|
|
195
|
+
Schema.annotate({ identifier: "Automation.ActionInput" }),
|
|
196
|
+
)
|
|
197
|
+
export type ActionInput = typeof ActionInput.Type
|
|
198
|
+
|
|
199
|
+
/** An automation as callers describe it: a name, when it runs, what it does, and when it stops. */
|
|
200
|
+
export const Request = Schema.Struct({
|
|
201
|
+
name: Schema.String.check(Schema.isMinLength(1)).annotate({ description: "A short label shown in lists." }),
|
|
202
|
+
trigger: Trigger.annotate({
|
|
203
|
+
description:
|
|
204
|
+
'When it runs: { type: "at", at: "in 20 minutes" | "2026-10-27T09:00" }, { type: "every", every: "1 hour" } or { type: "cron", cron: "0 9 * * 1-5" }, each with an optional tz. Or { type: "event", server, event, args? } for a connected MCP server advertising push delivery.',
|
|
205
|
+
}),
|
|
206
|
+
action: ActionInput.annotate({
|
|
207
|
+
description:
|
|
208
|
+
'What it does: { type: "prompt", prompt, to? } sends a prompt; { type: "code", code, args? } runs Code Mode; { type: "shell", command } runs a fixed shell command.',
|
|
209
|
+
}),
|
|
210
|
+
expires: Schema.String.pipe(optional).annotate({
|
|
211
|
+
description: 'When it stops for good: an instant, a wall-clock time in tz, or "in 8 hours".',
|
|
212
|
+
}),
|
|
213
|
+
}).annotate({ identifier: "Automation.Request" })
|
|
214
|
+
export interface Request extends Schema.Schema.Type<typeof Request> {}
|
|
215
|
+
|
|
216
|
+
export const CreateInput = Schema.Struct({
|
|
217
|
+
// A creating Session supplies the directory, default recipient, and authority for code or child actions.
|
|
218
|
+
sessionID: SessionID.pipe(optional),
|
|
219
|
+
directory: Schema.String.annotate({
|
|
220
|
+
description: "Where it runs when there is no Session. Defaults to the server user's home folder.",
|
|
221
|
+
}).pipe(optional),
|
|
222
|
+
...Request.fields,
|
|
223
|
+
}).annotate({ identifier: "Automation.CreateInput" })
|
|
224
|
+
export interface CreateInput extends Schema.Schema.Type<typeof CreateInput> {}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export * as BlobStore from "./blob-store.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { descending } from "./identifier.js"
|
|
5
|
+
import { statics } from "./schema.js"
|
|
6
|
+
|
|
7
|
+
// Strict, because the server names files after it.
|
|
8
|
+
export const ID = Schema.String.check(Schema.isPattern(/^blob_[0-9a-f]{12}[0-9A-Za-z]{14}$/u)).pipe(
|
|
9
|
+
Schema.brand("Blob.ID"),
|
|
10
|
+
Schema.annotate({
|
|
11
|
+
identifier: "Blob.ID",
|
|
12
|
+
description: "A stored blob, such as a generated video, which outlives the job that made it",
|
|
13
|
+
}),
|
|
14
|
+
statics((schema) => ({
|
|
15
|
+
create: () => schema.make("blob_" + descending()),
|
|
16
|
+
})),
|
|
17
|
+
)
|
|
18
|
+
export type ID = typeof ID.Type
|
|
19
|
+
|
|
20
|
+
export interface Info extends Schema.Schema.Type<typeof Info> {}
|
|
21
|
+
export const Info = Schema.Struct({
|
|
22
|
+
id: ID,
|
|
23
|
+
mime: Schema.String,
|
|
24
|
+
bytes: Schema.Finite,
|
|
25
|
+
}).annotate({ identifier: "Blob.Info" })
|
package/src/command.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export * as Command from "./command.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { ephemeral, inventory } from "./event.js"
|
|
5
|
+
import { optional } from "./schema.js"
|
|
6
|
+
|
|
7
|
+
const Updated = ephemeral({ type: "command.updated", schema: {} })
|
|
8
|
+
|
|
9
|
+
export interface Info extends Schema.Schema.Type<typeof Info> {}
|
|
10
|
+
export const Info = Schema.Struct({
|
|
11
|
+
name: Schema.String,
|
|
12
|
+
description: Schema.String.pipe(optional),
|
|
13
|
+
}).annotate({ identifier: "Command.Info" })
|
|
14
|
+
|
|
15
|
+
export const Event = {
|
|
16
|
+
Updated,
|
|
17
|
+
Definitions: inventory(Updated),
|
|
18
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export * as ConfigAgent from "./agent.js"
|
|
2
|
+
|
|
3
|
+
import { Effect, Schema } from "effect"
|
|
4
|
+
import { Permission } from "../permission.js"
|
|
5
|
+
import { optional, PositiveInt } from "../schema.js"
|
|
6
|
+
import { ConfigModel } from "./model.js"
|
|
7
|
+
import { ConfigProvider } from "./provider.js"
|
|
8
|
+
|
|
9
|
+
export const Color = Schema.String.check(Schema.isPattern(/^#[0-9a-fA-F]{6}$/u))
|
|
10
|
+
|
|
11
|
+
export class Info extends Schema.Class<Info>("Config.Agent")({
|
|
12
|
+
model: ConfigModel.Selection.pipe(optional),
|
|
13
|
+
request: ConfigProvider.Request.pipe(optional),
|
|
14
|
+
system: Schema.String.pipe(optional),
|
|
15
|
+
description: Schema.String.pipe(optional),
|
|
16
|
+
mode: Schema.Literals(["subagent", "primary", "all"]).pipe(optional),
|
|
17
|
+
hidden: Schema.Boolean.pipe(optional),
|
|
18
|
+
// An unsupported color, such as a V1 theme name, should not drop the whole agent.
|
|
19
|
+
color: Color.pipe(
|
|
20
|
+
Schema.catchDecoding(() => Effect.succeedNone),
|
|
21
|
+
optional,
|
|
22
|
+
),
|
|
23
|
+
steps: PositiveInt.pipe(optional),
|
|
24
|
+
disabled: Schema.Boolean.pipe(optional),
|
|
25
|
+
permissions: Permission.Ruleset.pipe(optional),
|
|
26
|
+
}) {}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * as ConfigCommand from "./command.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { optional } from "../schema.js"
|
|
5
|
+
import { ConfigModel } from "./model.js"
|
|
6
|
+
|
|
7
|
+
export class Info extends Schema.Class<Info>("Config.Command")({
|
|
8
|
+
template: Schema.String,
|
|
9
|
+
description: Schema.String.pipe(optional),
|
|
10
|
+
agent: Schema.String.pipe(optional),
|
|
11
|
+
model: ConfigModel.Selection.pipe(optional),
|
|
12
|
+
subagent: Schema.Boolean.pipe(optional),
|
|
13
|
+
subtask: Schema.Boolean.annotate({ description: "Deprecated alias for subagent." }).pipe(optional),
|
|
14
|
+
}) {}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export * as ConfigCompaction from "./compaction.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { NonNegativeInt, optional } from "../schema.js"
|
|
5
|
+
|
|
6
|
+
export class Keep extends Schema.Class<Keep>("Config.Compaction.Keep")({
|
|
7
|
+
tokens: NonNegativeInt.pipe(optional),
|
|
8
|
+
}) {}
|
|
9
|
+
|
|
10
|
+
/** A share of the model's window such as "20%" or "12.5%", from 1% up to but not including 100%. */
|
|
11
|
+
export const Percent = Schema.String.check(Schema.isPattern(/^([1-9]\d?(\.\d+)?)%$/u)).annotate({
|
|
12
|
+
identifier: "Config.Compaction.Percent",
|
|
13
|
+
})
|
|
14
|
+
export type Percent = typeof Percent.Type
|
|
15
|
+
|
|
16
|
+
export class Info extends Schema.Class<Info>("Config.Compaction")({
|
|
17
|
+
auto: Schema.Boolean.pipe(optional),
|
|
18
|
+
background: Schema.Boolean.pipe(optional).annotate({
|
|
19
|
+
description:
|
|
20
|
+
"Write the summary in the background as the session nears automatic compaction, so it does not wait for one (default: true). A summary that is never used still costs tokens.",
|
|
21
|
+
}),
|
|
22
|
+
keep: Keep.pipe(optional),
|
|
23
|
+
buffer: Schema.Union([Percent, NonNegativeInt]).pipe(optional).annotate({
|
|
24
|
+
description:
|
|
25
|
+
'Room kept free below the model\'s context window before automatic compaction, as a share of the window from "1%" to "99%", such as "20%" to compact at 80% full. A token count is also accepted.',
|
|
26
|
+
}),
|
|
27
|
+
}) {}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export * as ConfigExperimental from "./experimental.js"
|
|
2
|
+
|
|
3
|
+
import { Record, Schema } from "effect"
|
|
4
|
+
import { NonNegativeInt, optional } from "../schema.js"
|
|
5
|
+
import { ConfigFlag } from "./flag.js"
|
|
6
|
+
import { ConfigModel } from "./model.js"
|
|
7
|
+
import { ConfigPolicy } from "./policy.js"
|
|
8
|
+
|
|
9
|
+
export class Info extends Schema.Class<Info>("ConfigExperimental.Info")({
|
|
10
|
+
portable_shell_scanner: Schema.Boolean.pipe(optional).annotate({
|
|
11
|
+
description: "Deprecated: the built-in shell permission scanner is now always enabled.",
|
|
12
|
+
}),
|
|
13
|
+
codemode_vm: Schema.Boolean.pipe(optional).annotate({
|
|
14
|
+
description: "Deprecated: ignored because Code Mode always runs on the VM.",
|
|
15
|
+
}),
|
|
16
|
+
all_flags: Schema.Boolean.pipe(optional).annotate({
|
|
17
|
+
description:
|
|
18
|
+
"Enable all flags except opt-in-only flags on any build channel, like OPENCODE_FLAGS=all. Per-flag config settings take precedence over all_flags; false leaves the build defaults in effect.",
|
|
19
|
+
}),
|
|
20
|
+
...Record.map(ConfigFlag.registry, (description, key) =>
|
|
21
|
+
Schema.Boolean.pipe(optional).annotate({
|
|
22
|
+
description:
|
|
23
|
+
ConfigFlag.optInOnly.has(key) || ConfigFlag.localOnly.has(key)
|
|
24
|
+
? description
|
|
25
|
+
: `${description} Defaults to on in local and dev builds and off in releases.`,
|
|
26
|
+
}),
|
|
27
|
+
),
|
|
28
|
+
video_generate: Schema.Union([
|
|
29
|
+
Schema.Boolean,
|
|
30
|
+
Schema.Struct({
|
|
31
|
+
model: ConfigModel.Selection.pipe(optional).annotate({
|
|
32
|
+
description:
|
|
33
|
+
"Default model for the generate_video tool when the agent doesn't choose one, as providerID/modelID. Falls back to automatic selection when it isn't available.",
|
|
34
|
+
}),
|
|
35
|
+
}),
|
|
36
|
+
])
|
|
37
|
+
.pipe(optional)
|
|
38
|
+
.annotate({
|
|
39
|
+
description:
|
|
40
|
+
"Settings for the generate_video tool, which is offered while a connected provider has a video model.",
|
|
41
|
+
}),
|
|
42
|
+
part_rows: Schema.Boolean.pipe(optional).annotate({
|
|
43
|
+
description:
|
|
44
|
+
"Write each assistant part as its own session_part row instead of rewriting the whole message on every event. Defaults to true; set false to fall back to whole-message writes.",
|
|
45
|
+
}),
|
|
46
|
+
image_generate: Schema.Union([
|
|
47
|
+
Schema.Boolean,
|
|
48
|
+
Schema.Struct({
|
|
49
|
+
model: ConfigModel.Selection.pipe(optional).annotate({
|
|
50
|
+
description:
|
|
51
|
+
"Default model for the generate_image tool when the agent doesn't choose one, as providerID/modelID. Falls back to automatic selection when it isn't available.",
|
|
52
|
+
}),
|
|
53
|
+
}),
|
|
54
|
+
])
|
|
55
|
+
.pipe(optional)
|
|
56
|
+
.annotate({
|
|
57
|
+
description:
|
|
58
|
+
"Settings for the generate_image tool, which is offered while a connected provider has an image model.",
|
|
59
|
+
}),
|
|
60
|
+
subagent_depth: NonNegativeInt.pipe(optional).annotate({
|
|
61
|
+
description: "Maximum subagent nesting depth. Defaults to 1.",
|
|
62
|
+
}),
|
|
63
|
+
location_idle_timeout: Schema.Union([Schema.DurationFromString, Schema.Literal(false)])
|
|
64
|
+
.pipe(optional)
|
|
65
|
+
.annotate({
|
|
66
|
+
description:
|
|
67
|
+
'How long a location can go without session activity before its services are unloaded. Running sessions and background jobs keep a location loaded. Set to false to never unload (default: "60 minutes")',
|
|
68
|
+
}),
|
|
69
|
+
policies: ConfigPolicy.Info.pipe(Schema.Array, optional).annotate({
|
|
70
|
+
description: "Deprecated: use top-level policies. Ordered policies controlling access to configured resources",
|
|
71
|
+
}),
|
|
72
|
+
}) {}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export * as ConfigFlag from "./flag.js"
|
|
2
|
+
|
|
3
|
+
/** The `OPENCODE_FLAGS` entry that enables all flags except opt-in-only flags, as in `all,-media_blob`. */
|
|
4
|
+
export const wildcard = "all"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Flags default to on in local and dev builds and off in releases, except for `optInOnly` flags, which must be
|
|
8
|
+
* named explicitly in `experimental.<key>` or `OPENCODE_FLAGS`. Read a flag with Core's `Flag.enabled("<key>")`.
|
|
9
|
+
*/
|
|
10
|
+
export const registry = {
|
|
11
|
+
todo: "Enable the experimental todowrite tool. Off by default in every build, including local and dev; opt in with OPENCODE_FLAGS=todo or experimental.todo: true.",
|
|
12
|
+
media_blob: "Store new session media once in a deduplicated blob table instead of inline in every message row.",
|
|
13
|
+
artifacts: "Enable experimental artifacts backed by pluggable providers.",
|
|
14
|
+
console_watches:
|
|
15
|
+
"Watch Slack threads, GitHub pull requests, issues, commits and Actions runs, and the workspace's MCP servers' events through OpenCode Console, and wake sessions when they change.",
|
|
16
|
+
recommended_api: "Use each model's recommended API from models.dev instead of the first API it lists.",
|
|
17
|
+
model_speeds:
|
|
18
|
+
"Offer a model's faster and slower service tiers (fast, flex…) as speeds of that model: one entry in the model picker with a speed selector, instead of a separate entry per tier such as gpt-5.5-fast.",
|
|
19
|
+
full_codemode: "Enable the full Code Mode work in progress.",
|
|
20
|
+
machines: "Let a tool path name a machine, as in gpu:/work/train.py, and act on that machine's files and processes.",
|
|
21
|
+
home_memory:
|
|
22
|
+
"Give sessions in the home folder a persistent memory/, docs/ and scripts/ workspace the agent can use freely, tidied by a daily maintenance session that reads the day's home-folder conversations.",
|
|
23
|
+
project_overlay:
|
|
24
|
+
"Load a personal config dir for each project from ~/.config/opencode/project/<project-id>/, read like an extra .opencode dir that ranks above the repo's own, and let home memory keep the skills it builds for the user there.",
|
|
25
|
+
opencode_api:
|
|
26
|
+
'Let Code Mode scripts call the OpenCode HTTP API with fetch("opencode:///api/..."), in-process and already signed in, with no permission checks. Only in local and dev builds, and off there until you opt in with OPENCODE_FLAGS=opencode_api or experimental.opencode_api: true.',
|
|
27
|
+
mcp_skills:
|
|
28
|
+
"Load skills from MCP servers that offer them (the io.modelcontextprotocol/skills extension), named <server>:<skill>. A server that offers skills no longer has its instructions included.",
|
|
29
|
+
compaction_jobs:
|
|
30
|
+
"List a session's subagents, with their session IDs, and its running background jobs in its compaction checkpoints, so the agent can still continue or account for them after compacting.",
|
|
31
|
+
sqlite_fts:
|
|
32
|
+
"Build an SQLite full-text index of session titles and message text in the background, and enable the opencode.session.search and opencode.session.read tools. The index covers every session in the database and starts while any loaded location enables it; SQLite keeps it current from then on, also after this is turned off.",
|
|
33
|
+
} as const satisfies Record<string, string>
|
|
34
|
+
export type Key = keyof typeof registry
|
|
35
|
+
|
|
36
|
+
export const optInOnly: ReadonlySet<Key> = new Set(["todo", "opencode_api"])
|
|
37
|
+
|
|
38
|
+
/** Flags that stay off outside local and dev builds, whatever `OPENCODE_FLAGS` or config say. */
|
|
39
|
+
export const localOnly: ReadonlySet<Key> = new Set(["opencode_api"])
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * as ConfigFormatter from "./formatter.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { optional } from "../schema.js"
|
|
5
|
+
|
|
6
|
+
export class Entry extends Schema.Class<Entry>("Config.Formatter.Entry")({
|
|
7
|
+
disabled: Schema.Boolean.pipe(optional),
|
|
8
|
+
command: Schema.String.pipe(Schema.Array, optional),
|
|
9
|
+
environment: Schema.Record(Schema.String, Schema.String).pipe(optional),
|
|
10
|
+
extensions: Schema.String.pipe(Schema.Array, optional),
|
|
11
|
+
}) {}
|
|
12
|
+
|
|
13
|
+
export const Info = Schema.Union([Schema.Boolean, Schema.Record(Schema.String, Entry)])
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export * as ConfigLSP from "./lsp.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { optional } from "../schema.js"
|
|
5
|
+
|
|
6
|
+
export const Disabled = Schema.Struct({
|
|
7
|
+
disabled: Schema.Literal(true),
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
export class Server extends Schema.Class<Server>("Config.LSP.Server")({
|
|
11
|
+
command: Schema.String.pipe(Schema.Array),
|
|
12
|
+
extensions: Schema.String.pipe(Schema.Array, optional),
|
|
13
|
+
disabled: Schema.Boolean.pipe(optional),
|
|
14
|
+
env: Schema.Record(Schema.String, Schema.String).pipe(optional),
|
|
15
|
+
initialization: Schema.Record(Schema.String, Schema.Unknown).pipe(optional),
|
|
16
|
+
}) {}
|
|
17
|
+
|
|
18
|
+
export const Entry = Schema.Union([Disabled, Server])
|
|
19
|
+
export const Info = Schema.Union([Schema.Boolean, Schema.Record(Schema.String, Entry)])
|