@zyro-sec/schema 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/AGENTS.md +95 -95
  2. package/package.json +1 -1
  3. package/script/build.ts +9 -9
  4. package/script/config-schema.ts +86 -86
  5. package/script/config-v1.json +1311 -1311
  6. package/script/pack.ts +5 -5
  7. package/src/agent.ts +68 -68
  8. package/src/artifact.ts +81 -81
  9. package/src/automation.ts +224 -224
  10. package/src/blob-store.ts +25 -25
  11. package/src/command.ts +18 -18
  12. package/src/config/agent.ts +26 -26
  13. package/src/config/command.ts +14 -14
  14. package/src/config/compaction.ts +27 -27
  15. package/src/config/experimental.ts +72 -72
  16. package/src/config/flag.ts +39 -39
  17. package/src/config/formatter.ts +13 -13
  18. package/src/config/lsp.ts +19 -19
  19. package/src/config/mcp.ts +22 -22
  20. package/src/config/media.ts +15 -15
  21. package/src/config/model.ts +37 -37
  22. package/src/config/plugin.ts +14 -14
  23. package/src/config/policy.ts +57 -57
  24. package/src/config/provider.ts +122 -122
  25. package/src/config/reference.ts +23 -23
  26. package/src/config/shell.ts +10 -10
  27. package/src/config/tool-output.ts +9 -9
  28. package/src/config/warming.ts +21 -21
  29. package/src/config/watcher.ts +8 -8
  30. package/src/config/websearch.ts +17 -17
  31. package/src/config/worktree.ts +10 -10
  32. package/src/config.ts +149 -149
  33. package/src/connection.ts +38 -38
  34. package/src/credential-legacy.ts +29 -29
  35. package/src/credential.ts +78 -78
  36. package/src/durable-event-manifest.ts +7 -7
  37. package/src/event-log.ts +21 -21
  38. package/src/event-manifest.ts +108 -108
  39. package/src/event.ts +205 -205
  40. package/src/file-diff.ts +25 -25
  41. package/src/filesystem-v1.ts +1 -1
  42. package/src/filesystem.ts +48 -48
  43. package/src/form.ts +177 -177
  44. package/src/generate.ts +292 -292
  45. package/src/goal.ts +46 -46
  46. package/src/identifier.ts +32 -32
  47. package/src/index.ts +51 -51
  48. package/src/installation-event.ts +20 -20
  49. package/src/instruction-entry.ts +40 -40
  50. package/src/instruction.ts +25 -25
  51. package/src/integration-id.ts +13 -13
  52. package/src/integration.ts +129 -129
  53. package/src/job.ts +79 -79
  54. package/src/legacy-event.ts +1 -1
  55. package/src/llm.ts +6 -6
  56. package/src/location-event.ts +8 -8
  57. package/src/location.ts +36 -36
  58. package/src/lsp-event.ts +7 -7
  59. package/src/mcp-event.ts +63 -63
  60. package/src/mcp.ts +171 -171
  61. package/src/model-compatibility.ts +55 -55
  62. package/src/model.ts +176 -176
  63. package/src/models-dev.ts +9 -9
  64. package/src/money.ts +18 -18
  65. package/src/permission-saved.ts +25 -25
  66. package/src/permission-v1.ts +1 -1
  67. package/src/permission.ts +67 -67
  68. package/src/persistent-pty.ts +73 -73
  69. package/src/plugin.ts +62 -62
  70. package/src/project-id.ts +9 -9
  71. package/src/project.ts +62 -62
  72. package/src/prompt-input.ts +33 -33
  73. package/src/prompt.ts +117 -117
  74. package/src/provider.ts +136 -136
  75. package/src/pty-ticket.ts +10 -10
  76. package/src/pty.ts +61 -61
  77. package/src/push.ts +86 -86
  78. package/src/question.ts +22 -22
  79. package/src/reference.ts +40 -40
  80. package/src/rpc.ts +167 -167
  81. package/src/schema.ts +41 -41
  82. package/src/server-event.ts +8 -8
  83. package/src/session-error.ts +14 -14
  84. package/src/session-event.ts +739 -739
  85. package/src/session-fork.ts +10 -10
  86. package/src/session-id.ts +12 -12
  87. package/src/session-inbox.ts +102 -102
  88. package/src/session-legacy.ts +117 -117
  89. package/src/session-message.ts +352 -352
  90. package/src/session-metadata.ts +11 -11
  91. package/src/session-revert.ts +86 -86
  92. package/src/session-stats.ts +68 -68
  93. package/src/session-status-event.ts +53 -53
  94. package/src/session-transfer.ts +11 -11
  95. package/src/session-v1.ts +1 -1
  96. package/src/session.ts +147 -147
  97. package/src/shell.ts +90 -90
  98. package/src/skill.ts +68 -68
  99. package/src/snapshot.ts +6 -6
  100. package/src/token-usage.ts +18 -18
  101. package/src/tool.ts +143 -143
  102. package/src/tui-event.ts +59 -59
  103. package/src/usage-limits.ts +76 -76
  104. package/src/v1/filesystem.ts +11 -11
  105. package/src/v1/legacy-event.ts +18 -18
  106. package/src/v1/permission.ts +66 -66
  107. package/src/v1/session.ts +667 -667
  108. package/src/vcs-event.ts +14 -14
  109. package/src/vcs.ts +41 -41
  110. package/src/websearch.ts +44 -44
  111. package/src/workspace-event.ts +32 -32
  112. package/src/workspace-id.ts +19 -19
  113. package/src/workspace.ts +20 -20
  114. package/src/worktree-event.ts +22 -22
  115. package/src/worktree.ts +109 -109
  116. package/tsconfig.build.json +11 -11
  117. package/tsconfig.json +14 -14
  118. package/test/agent.test.ts +0 -10
  119. package/test/automation.test.ts +0 -48
  120. package/test/compatibility.test.ts +0 -10
  121. package/test/config.test.ts +0 -194
  122. package/test/contract-hygiene.test.ts +0 -352
  123. package/test/credential-legacy.test.ts +0 -55
  124. package/test/event-manifest.test.ts +0 -228
  125. package/test/event.test.ts +0 -52
  126. package/test/legacy-event.test.ts +0 -46
  127. package/test/mcp.test.ts +0 -37
  128. package/test/model.test.ts +0 -104
  129. package/test/session-cursor.test.ts +0 -16
  130. package/test/session-error.test.ts +0 -51
  131. package/test/session-legacy.test.ts +0 -178
  132. package/test/session-terminal.test.ts +0 -50
  133. package/test/token-usage.test.ts +0 -18
  134. package/test/v1-isolation.test.ts +0 -26
  135. package/test/vcs.test.ts +0 -23
  136. package/test/worktree.test.ts +0 -45
package/src/automation.ts CHANGED
@@ -1,224 +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> {}
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> {}
package/src/blob-store.ts CHANGED
@@ -1,25 +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" })
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 CHANGED
@@ -1,18 +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
- }
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
+ }
@@ -1,26 +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
- }) {}
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
+ }) {}
@@ -1,14 +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
- }) {}
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
+ }) {}