@opencode/schema 2.2.2 → 2.2.4

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.
@@ -78,6 +78,16 @@ export declare const ShellCondition: Schema.Struct<{
78
78
  readonly changes: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Boolean>>, Schema.optionalKey<Schema.Boolean>, never, never>;
79
79
  }>;
80
80
  export type ShellCondition = typeof ShellCondition.Type;
81
+ /**
82
+ * Runs `code` in a confined Code Mode runtime before firing, with no model call and no `fetch`. Tools called statically
83
+ * as `tools.<path>(...)` are extracted from the AST and authorized at creation; the program receives `state` (initially
84
+ * `null`), `now` (epoch ms) and `runs` (completed checks), and returns a boolean or `{ wake, state?, message? }`.
85
+ */
86
+ export declare const CodeCondition: Schema.Struct<{
87
+ readonly type: Schema.tag<"code">;
88
+ readonly code: Schema.String;
89
+ }>;
90
+ export type CodeCondition = typeof CodeCondition.Type;
81
91
  /** Checked before firing; the schedule wakes the Session only when the condition passes. */
82
92
  export declare const Condition: Schema.Union<readonly [Schema.Struct<{
83
93
  readonly type: Schema.tag<"shell">;
@@ -85,6 +95,9 @@ export declare const Condition: Schema.Union<readonly [Schema.Struct<{
85
95
  readonly is: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
86
96
  readonly matches: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
87
97
  readonly changes: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Boolean>>, Schema.optionalKey<Schema.Boolean>, never, never>;
98
+ }>, Schema.Struct<{
99
+ readonly type: Schema.tag<"code">;
100
+ readonly code: Schema.String;
88
101
  }>]>;
89
102
  export type Condition = typeof Condition.Type;
90
103
  export declare const CheckMode: Schema.Literals<readonly ["if", "until"]>;
@@ -97,6 +110,9 @@ export declare const StoredCheck: Schema.Struct<{
97
110
  readonly is: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
98
111
  readonly matches: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
99
112
  readonly changes: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Boolean>>, Schema.optionalKey<Schema.Boolean>, never, never>;
113
+ }>, Schema.Struct<{
114
+ readonly type: Schema.tag<"code">;
115
+ readonly code: Schema.String;
100
116
  }>]>;
101
117
  }>;
102
118
  export type StoredCheck = typeof StoredCheck.Type;
@@ -138,12 +154,18 @@ export declare const Info: Schema.Struct<{
138
154
  readonly is: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
139
155
  readonly matches: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
140
156
  readonly changes: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Boolean>>, Schema.optionalKey<Schema.Boolean>, never, never>;
157
+ }>, Schema.Struct<{
158
+ readonly type: Schema.tag<"code">;
159
+ readonly code: Schema.String;
141
160
  }>]>>>, Schema.optionalKey<Schema.Union<readonly [Schema.Struct<{
142
161
  readonly type: Schema.tag<"shell">;
143
162
  readonly run: Schema.String;
144
163
  readonly is: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
145
164
  readonly matches: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
146
165
  readonly changes: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Boolean>>, Schema.optionalKey<Schema.Boolean>, never, never>;
166
+ }>, Schema.Struct<{
167
+ readonly type: Schema.tag<"code">;
168
+ readonly code: Schema.String;
147
169
  }>]>>, never, never>;
148
170
  readonly until: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Union<readonly [Schema.Struct<{
149
171
  readonly type: Schema.tag<"shell">;
@@ -151,12 +173,18 @@ export declare const Info: Schema.Struct<{
151
173
  readonly is: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
152
174
  readonly matches: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
153
175
  readonly changes: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Boolean>>, Schema.optionalKey<Schema.Boolean>, never, never>;
176
+ }>, Schema.Struct<{
177
+ readonly type: Schema.tag<"code">;
178
+ readonly code: Schema.String;
154
179
  }>]>>>, Schema.optionalKey<Schema.Union<readonly [Schema.Struct<{
155
180
  readonly type: Schema.tag<"shell">;
156
181
  readonly run: Schema.String;
157
182
  readonly is: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
158
183
  readonly matches: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
159
184
  readonly changes: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Boolean>>, Schema.optionalKey<Schema.Boolean>, never, never>;
185
+ }>, Schema.Struct<{
186
+ readonly type: Schema.tag<"code">;
187
+ readonly code: Schema.String;
160
188
  }>]>>, never, never>;
161
189
  readonly action: Schema.Union<readonly [Schema.Struct<{
162
190
  readonly type: Schema.tag<"prompt">;
@@ -220,12 +248,18 @@ export declare const CreateInput: Schema.Struct<{
220
248
  readonly is: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
221
249
  readonly matches: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
222
250
  readonly changes: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Boolean>>, Schema.optionalKey<Schema.Boolean>, never, never>;
251
+ }>, Schema.Struct<{
252
+ readonly type: Schema.tag<"code">;
253
+ readonly code: Schema.String;
223
254
  }>]>>>, Schema.optionalKey<Schema.Union<readonly [Schema.Struct<{
224
255
  readonly type: Schema.tag<"shell">;
225
256
  readonly run: Schema.String;
226
257
  readonly is: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
227
258
  readonly matches: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
228
259
  readonly changes: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Boolean>>, Schema.optionalKey<Schema.Boolean>, never, never>;
260
+ }>, Schema.Struct<{
261
+ readonly type: Schema.tag<"code">;
262
+ readonly code: Schema.String;
229
263
  }>]>>, never, never>;
230
264
  readonly until: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Union<readonly [Schema.Struct<{
231
265
  readonly type: Schema.tag<"shell">;
@@ -233,12 +267,18 @@ export declare const CreateInput: Schema.Struct<{
233
267
  readonly is: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
234
268
  readonly matches: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
235
269
  readonly changes: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Boolean>>, Schema.optionalKey<Schema.Boolean>, never, never>;
270
+ }>, Schema.Struct<{
271
+ readonly type: Schema.tag<"code">;
272
+ readonly code: Schema.String;
236
273
  }>]>>>, Schema.optionalKey<Schema.Union<readonly [Schema.Struct<{
237
274
  readonly type: Schema.tag<"shell">;
238
275
  readonly run: Schema.String;
239
276
  readonly is: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
240
277
  readonly matches: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
241
278
  readonly changes: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Boolean>>, Schema.optionalKey<Schema.Boolean>, never, never>;
279
+ }>, Schema.Struct<{
280
+ readonly type: Schema.tag<"code">;
281
+ readonly code: Schema.String;
242
282
  }>]>>, never, never>;
243
283
  readonly ends: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Struct<{
244
284
  readonly after: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
@@ -288,13 +328,23 @@ export declare const ShellConditionInput: Schema.Struct<{
288
328
  readonly matches: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
289
329
  readonly changes: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Boolean>>, Schema.optionalKey<Schema.Boolean>, never, never>;
290
330
  }>;
291
- export type ConditionInput = typeof ShellConditionInput.Type;
292
- export declare const ConditionInput: Schema.Struct<{
331
+ export declare const CodeConditionInput: Schema.Struct<{
332
+ readonly code: Schema.String;
333
+ }>;
334
+ export declare const ConditionInput: Schema.Union<readonly [Schema.Struct<{
293
335
  readonly run: Schema.String;
294
336
  readonly is: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
295
337
  readonly matches: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
296
338
  readonly changes: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Boolean>>, Schema.optionalKey<Schema.Boolean>, never, never>;
297
- }>;
339
+ readonly code: Schema.optionalKey<Schema.Never>;
340
+ }>, Schema.Struct<{
341
+ readonly code: Schema.String;
342
+ readonly run: Schema.optionalKey<Schema.Never>;
343
+ readonly is: Schema.optionalKey<Schema.Never>;
344
+ readonly matches: Schema.optionalKey<Schema.Never>;
345
+ readonly changes: Schema.optionalKey<Schema.Never>;
346
+ }>]>;
347
+ export type ConditionInput = typeof ConditionInput.Type;
298
348
  /** A schedule as callers describe it: when it fires, optional condition, when it stops, and the prompt it sends. */
299
349
  export declare const Request: Schema.Struct<{
300
350
  readonly name: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
@@ -347,28 +397,56 @@ export declare const Request: Schema.Struct<{
347
397
  readonly at: Schema.optionalKey<Schema.Never>;
348
398
  readonly every: Schema.optionalKey<Schema.Never>;
349
399
  }>]>>, never, never>;
350
- readonly if: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Struct<{
400
+ readonly if: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Union<readonly [Schema.Struct<{
351
401
  readonly run: Schema.String;
352
402
  readonly is: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
353
403
  readonly matches: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
354
404
  readonly changes: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Boolean>>, Schema.optionalKey<Schema.Boolean>, never, never>;
355
- }>>>, Schema.optionalKey<Schema.Struct<{
405
+ readonly code: Schema.optionalKey<Schema.Never>;
406
+ }>, Schema.Struct<{
407
+ readonly code: Schema.String;
408
+ readonly run: Schema.optionalKey<Schema.Never>;
409
+ readonly is: Schema.optionalKey<Schema.Never>;
410
+ readonly matches: Schema.optionalKey<Schema.Never>;
411
+ readonly changes: Schema.optionalKey<Schema.Never>;
412
+ }>]>>>, Schema.optionalKey<Schema.Union<readonly [Schema.Struct<{
356
413
  readonly run: Schema.String;
357
414
  readonly is: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
358
415
  readonly matches: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
359
416
  readonly changes: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Boolean>>, Schema.optionalKey<Schema.Boolean>, never, never>;
360
- }>>, never, never>;
361
- readonly until: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Struct<{
417
+ readonly code: Schema.optionalKey<Schema.Never>;
418
+ }>, Schema.Struct<{
419
+ readonly code: Schema.String;
420
+ readonly run: Schema.optionalKey<Schema.Never>;
421
+ readonly is: Schema.optionalKey<Schema.Never>;
422
+ readonly matches: Schema.optionalKey<Schema.Never>;
423
+ readonly changes: Schema.optionalKey<Schema.Never>;
424
+ }>]>>, never, never>;
425
+ readonly until: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Union<readonly [Schema.Struct<{
362
426
  readonly run: Schema.String;
363
427
  readonly is: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
364
428
  readonly matches: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
365
429
  readonly changes: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Boolean>>, Schema.optionalKey<Schema.Boolean>, never, never>;
366
- }>>>, Schema.optionalKey<Schema.Struct<{
430
+ readonly code: Schema.optionalKey<Schema.Never>;
431
+ }>, Schema.Struct<{
432
+ readonly code: Schema.String;
433
+ readonly run: Schema.optionalKey<Schema.Never>;
434
+ readonly is: Schema.optionalKey<Schema.Never>;
435
+ readonly matches: Schema.optionalKey<Schema.Never>;
436
+ readonly changes: Schema.optionalKey<Schema.Never>;
437
+ }>]>>>, Schema.optionalKey<Schema.Union<readonly [Schema.Struct<{
367
438
  readonly run: Schema.String;
368
439
  readonly is: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
369
440
  readonly matches: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
370
441
  readonly changes: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Boolean>>, Schema.optionalKey<Schema.Boolean>, never, never>;
371
- }>>, never, never>;
442
+ readonly code: Schema.optionalKey<Schema.Never>;
443
+ }>, Schema.Struct<{
444
+ readonly code: Schema.String;
445
+ readonly run: Schema.optionalKey<Schema.Never>;
446
+ readonly is: Schema.optionalKey<Schema.Never>;
447
+ readonly matches: Schema.optionalKey<Schema.Never>;
448
+ readonly changes: Schema.optionalKey<Schema.Never>;
449
+ }>]>>, never, never>;
372
450
  readonly ends: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Struct<{
373
451
  readonly after: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
374
452
  readonly at: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
package/dist/schedule.js CHANGED
@@ -56,8 +56,17 @@ export const ShellCondition = Schema.Struct({
56
56
  matches: Schema.String.pipe(optional),
57
57
  changes: Schema.Boolean.pipe(optional),
58
58
  }).annotate({ identifier: "Schedule.Condition.Shell" });
59
+ /**
60
+ * Runs `code` in a confined Code Mode runtime before firing, with no model call and no `fetch`. Tools called statically
61
+ * as `tools.<path>(...)` are extracted from the AST and authorized at creation; the program receives `state` (initially
62
+ * `null`), `now` (epoch ms) and `runs` (completed checks), and returns a boolean or `{ wake, state?, message? }`.
63
+ */
64
+ export const CodeCondition = Schema.Struct({
65
+ type: Schema.tag("code"),
66
+ code: Schema.String,
67
+ }).annotate({ identifier: "Schedule.Condition.Code" });
59
68
  /** Checked before firing; the schedule wakes the Session only when the condition passes. */
60
- export const Condition = Schema.Union([ShellCondition]).pipe(Schema.toTaggedUnion("type"), Schema.annotate({ identifier: "Schedule.Condition" }));
69
+ export const Condition = Schema.Union([ShellCondition, CodeCondition]).pipe(Schema.toTaggedUnion("type"), Schema.annotate({ identifier: "Schedule.Condition" }));
61
70
  export const CheckMode = Schema.Literals(["if", "until"]).annotate({ identifier: "Schedule.CheckMode" });
62
71
  export const StoredCheck = Schema.Struct({
63
72
  mode: CheckMode,
@@ -103,7 +112,7 @@ export const CreateInput = Schema.Struct({
103
112
  ends: Ends.pipe(optional),
104
113
  action: Action,
105
114
  }).annotate({ identifier: "Schedule.CreateInput" });
106
- /** Declares a trigger absent, so `{ in, every }` fails instead of decoding as a one-shot. */
115
+ /** Declares a variant field absent, so `{ in, every }` or `{ run, code }` fails instead of silently dropping one. */
107
116
  const absent = Schema.optionalKey(Schema.Never);
108
117
  /** The `when` callers write: exactly one of `in`, `at`, `every` or `cron`, with an optional `tz`. */
109
118
  export const WhenInput = Schema.Union([
@@ -125,8 +134,28 @@ export const ShellConditionInput = Schema.Struct({
125
134
  changes: Schema.Boolean.pipe(optional).annotate({
126
135
  description: "Wake when exit is 0 and stdout differs from the previous check.",
127
136
  }),
128
- }).annotate({ identifier: "Schedule.ConditionInput" });
129
- export const ConditionInput = ShellConditionInput;
137
+ }).annotate({ identifier: "Schedule.ShellConditionInput" });
138
+ export const CodeConditionInput = Schema.Struct({
139
+ code: Schema.String.check(Schema.isMinLength(1)).annotate({
140
+ description: [
141
+ "Code Mode JavaScript check (no fetch; 30s, 20 tool calls, 32 KB output cap).",
142
+ 'Call tools statically as tools.<ns>.<tool>(...) or tools["ns-name"].tool(...); each is authorized once at creation to run unattended.',
143
+ "Runs once at creation with state = null (if baselines state without waking; until matches immediately if true), with globals state, now (epoch ms) and runs.",
144
+ "Return a boolean or { wake, state?, message? } (message is appended to prompt on wake), e.g.:",
145
+ 'const t = await tools.slack.read_thread({ id }); return { wake: state !== null && t.count > state.count, state: { count: t.count }, message: "New reply" }',
146
+ ].join(" "),
147
+ }),
148
+ }).annotate({ identifier: "Schedule.CodeConditionInput" });
149
+ export const ConditionInput = Schema.Union([
150
+ Schema.Struct({ ...ShellConditionInput.fields, code: absent }),
151
+ Schema.Struct({
152
+ ...CodeConditionInput.fields,
153
+ run: absent,
154
+ is: absent,
155
+ matches: absent,
156
+ changes: absent,
157
+ }),
158
+ ]).annotate({ identifier: "Schedule.ConditionInput" });
130
159
  /** A schedule as callers describe it: when it fires, optional condition, when it stops, and the prompt it sends. */
131
160
  export const Request = Schema.Struct({
132
161
  name: Schema.String.pipe(optional).annotate({ description: "A short label for the schedule." }),
@@ -134,10 +163,10 @@ export const Request = Schema.Struct({
134
163
  description: 'When it fires: { in: "20 minutes" }, { at: "2026-10-27T09:00" }, { every: "1 hour" } or { cron: "0 9 * * 1-5" }. Optional with `until` (defaults to { every: "30 seconds" }).',
135
164
  }),
136
165
  if: ConditionInput.pipe(optional).annotate({
137
- description: "Recurring gate: check on each slot with no model call, and wake on every slot where it passes.",
166
+ description: "Recurring gate ({ run } shell command or { code } Code Mode script): check on each slot with no model call, and wake on every slot where it passes.",
138
167
  }),
139
168
  until: ConditionInput.pipe(optional).annotate({
140
- description: 'One-shot gate: poll with no model call, wake once when it passes, and stop. Defaults ends.after to "24 hours".',
169
+ description: 'One-shot gate ({ run } shell command or { code } Code Mode script): poll with no model call, wake once when it passes, and stop. Defaults ends.after to "24 hours".',
141
170
  }),
142
171
  ends: Ends.pipe(optional).annotate({
143
172
  description: 'Stops a repeating schedule at the first limit reached: { after: "8 hours" }, { at }, { times: 3 }.',
@@ -155,13 +184,17 @@ export const toCreateInput = (sessionID, request) => ({
155
184
  ends: request.ends,
156
185
  action: { type: "prompt", prompt: request.prompt },
157
186
  });
158
- const toCondition = (condition) => ({
159
- type: "shell",
160
- run: condition.run,
161
- is: condition.is,
162
- matches: condition.matches,
163
- changes: condition.changes,
164
- });
187
+ const toCondition = (condition) => {
188
+ if (condition.code !== undefined)
189
+ return { type: "code", code: condition.code };
190
+ return {
191
+ type: "shell",
192
+ run: condition.run,
193
+ is: condition.is,
194
+ matches: condition.matches,
195
+ changes: condition.changes,
196
+ };
197
+ };
165
198
  const toWhen = (when) => {
166
199
  if (when.in !== undefined)
167
200
  return { type: "in", in: when.in, tz: when.tz };