@composable-os/pack-rostering 0.0.0-stage → 0.1.0-beta.13

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 (51) hide show
  1. package/LICENSE +109 -0
  2. package/dist/blocks/rostering-away/away-list.d.ts +8 -0
  3. package/dist/blocks/rostering-away/away-list.js +101 -0
  4. package/dist/blocks/rostering-checklist/checklist.d.ts +9 -0
  5. package/dist/blocks/rostering-checklist/checklist.js +132 -0
  6. package/dist/blocks/rostering-checklist/my-shifts-with-checklist.d.ts +11 -0
  7. package/dist/blocks/rostering-checklist/my-shifts-with-checklist.js +6 -0
  8. package/dist/blocks/rostering-checklists/checklists.d.ts +11 -0
  9. package/dist/blocks/rostering-checklists/checklists.js +76 -0
  10. package/dist/blocks/rostering-my-availability/my-availability.d.ts +7 -0
  11. package/dist/blocks/rostering-my-availability/my-availability.js +143 -0
  12. package/dist/blocks/rostering-my-calendar/my-calendar.d.ts +6 -0
  13. package/dist/blocks/rostering-my-calendar/my-calendar.js +92 -0
  14. package/dist/blocks/rostering-my-shifts/my-hours.d.ts +6 -0
  15. package/dist/blocks/rostering-my-shifts/my-hours.js +63 -0
  16. package/dist/blocks/rostering-my-shifts/my-shifts.d.ts +17 -0
  17. package/dist/blocks/rostering-my-shifts/my-shifts.js +53 -0
  18. package/dist/blocks/rostering-native-checklist/checklist-screen.d.ts +8 -0
  19. package/dist/blocks/rostering-native-checklist/checklist-screen.js +110 -0
  20. package/dist/blocks/rostering-native-my-availability/my-availability-screen.d.ts +7 -0
  21. package/dist/blocks/rostering-native-my-availability/my-availability-screen.js +110 -0
  22. package/dist/blocks/rostering-native-my-calendar/my-calendar-screen.d.ts +10 -0
  23. package/dist/blocks/rostering-native-my-calendar/my-calendar-screen.js +72 -0
  24. package/dist/blocks/rostering-native-my-shifts/my-hours-screen.d.ts +6 -0
  25. package/dist/blocks/rostering-native-my-shifts/my-hours-screen.js +60 -0
  26. package/dist/blocks/rostering-native-my-shifts/my-shifts-screen.d.ts +12 -0
  27. package/dist/blocks/rostering-native-my-shifts/my-shifts-screen.js +56 -0
  28. package/dist/blocks/rostering-native-offers/offers-screen.d.ts +7 -0
  29. package/dist/blocks/rostering-native-offers/offers-screen.js +56 -0
  30. package/dist/blocks/rostering-native-roster/roster-screen.d.ts +7 -0
  31. package/dist/blocks/rostering-native-roster/roster-screen.js +31 -0
  32. package/dist/blocks/rostering-offers/offers.d.ts +7 -0
  33. package/dist/blocks/rostering-offers/offers.js +52 -0
  34. package/dist/blocks/rostering-patterns/patterns.d.ts +7 -0
  35. package/dist/blocks/rostering-patterns/patterns.js +58 -0
  36. package/dist/blocks/rostering-pay/pay.d.ts +7 -0
  37. package/dist/blocks/rostering-pay/pay.js +160 -0
  38. package/dist/blocks/rostering-qualifications/qualifications.d.ts +6 -0
  39. package/dist/blocks/rostering-qualifications/qualifications.js +48 -0
  40. package/dist/blocks/rostering-week/assign.d.ts +12 -0
  41. package/dist/blocks/rostering-week/assign.js +99 -0
  42. package/dist/blocks/rostering-week/week.d.ts +13 -0
  43. package/dist/blocks/rostering-week/week.js +82 -0
  44. package/dist/client/index.d.ts +3113 -0
  45. package/dist/client/index.js +654 -0
  46. package/dist/index.d.ts +1594 -0
  47. package/dist/index.js +541 -0
  48. package/dist/tools.d.ts +1094 -0
  49. package/dist/tools.js +1047 -0
  50. package/package.json +36 -4
  51. package/README.md +0 -3
package/dist/tools.js ADDED
@@ -0,0 +1,1047 @@
1
+ // The Rostering tools (stage 45 step 4, ADR 0626). They become operations x.rostering.<tool>, run in
2
+ // the sandbox, and reach the host only through ctx.ops. None of them holds a rule: who is on two
3
+ // shifts at once (refused), who may take an offer, the cut-off, who is warned about what, who may
4
+ // roster and who learns that someone is away are all the host's (the `staffed` behaviour and its
5
+ // tool-only `staffing.*` operations, ADRs 0621 to 0625; a duty shift's checklist is the host's
6
+ // `checklist.*`). Each operation acts for the staff account
7
+ // the host verified as this tool's caller, never for anything in the input; a tool asks, and
8
+ // passes on what the host answered.
9
+ //
10
+ // Who may call which (the spec's "What an AI may do"):
11
+ // - the team's tools (`rostering:team`, the team role's; `rostering:roster`, granted to an account
12
+ // with another pack role, such as a coach): reading the roster and one's own offers and time off
13
+ // is open to an assistant acting for them; offering, taking, withdrawing, saying one is away and
14
+ // back are a person's own acts (`humanOnly`), and so are making, changing and turning off one's
15
+ // private calendar feed (whose address is a secret shown once);
16
+ // - the rosterers' tools (`rostering:manage`, restricted: admins, and anyone an admin grants it):
17
+ // reading the roster's warnings, qualifications and the uncovered shifts is open to an assistant;
18
+ // putting someone on a shift and saying who is qualified wait for a person (`personApproves`);
19
+ // saying someone else is away, and reading everyone's time off, are a person's (`humanOnly`).
20
+ import { defineTool, z } from "@composable-os/sdk";
21
+ /** The team's tools: the role's permission, or the same tools granted to another role's account. */
22
+ const TEAM_TOOL = {
23
+ permission: ["rostering:team", "rostering:roster"],
24
+ grantLiftsRoleLimits: true,
25
+ };
26
+ /** The rosterers' tools: restricted (held by admins and by grant only, ADR 0625). */
27
+ const MANAGE = "rostering:manage";
28
+ /** How someone is counted for pay; a counted shift's is one of the first two. */
29
+ const basis = z.enum(["by_time", "by_class", "not_counted"]);
30
+ const countedBasis = z.enum(["by_time", "by_class"]);
31
+ /** A shift's kind of work (a class type or a duty), by its object and record id. */
32
+ const kindRef = z.object({ object: z.string(), id: z.string() }).nullable();
33
+ /** A shift, by its object and record id. */
34
+ const shiftRef = { object: z.string().min(1).max(81), id: z.string().min(1).max(64) };
35
+ const localDate = z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "a date, YYYY-MM-DD");
36
+ const localDateTime = z
37
+ .string()
38
+ .regex(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/, "a local date and time, YYYY-MM-DDTHH:MM");
39
+ const localTime = z.string().regex(/^[0-2]\d:[0-5]\d$/, "a time, HH:MM");
40
+ const WEEKDAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
41
+ const warning = z.object({
42
+ // The last two only for a shift booked at free times (an appointment, ADR 0763).
43
+ code: z.enum(["unavailable", "not_qualified", "uncovered", "outside_hours", "client_busy"]),
44
+ object: z.string(),
45
+ id: z.string(),
46
+ account: z.string().nullable(),
47
+ message: z.string(),
48
+ });
49
+ const shift = z.object({
50
+ object: z.string().describe("The kind of record: a class (bookings.class) or a duty shift"),
51
+ id: z.string(),
52
+ title: z.string(),
53
+ kind: z.object({ object: z.string(), id: z.string(), name: z.string() }).nullable(),
54
+ startsAt: z.string().describe("ISO 8601, UTC: show it in `zone`"),
55
+ endsAt: z.string().nullable(),
56
+ zone: z.string().nullable(),
57
+ place: z.string().nullable(),
58
+ uncovered: z.boolean().describe("Nobody is on it"),
59
+ noAccount: z.boolean().describe("Its person has no staff account (a visiting coach)"),
60
+ account: z.string().nullable(),
61
+ name: z.string().nullable().describe("Who is on it"),
62
+ mine: z.boolean().describe("It is the caller's"),
63
+ offer: z
64
+ .object({ id: z.string(), to: z.string().nullable(), from: z.string().nullable() })
65
+ .nullable(),
66
+ warnings: z.array(warning).nullable().describe("For someone who rosters only"),
67
+ checklist: z
68
+ .object({
69
+ name: z.string(),
70
+ state: z
71
+ .enum(["not_started", "in_progress", "done", "missed", "cancelled"])
72
+ .nullable()
73
+ .describe("For its person and whoever rosters only"),
74
+ })
75
+ .nullable()
76
+ .describe("Its checklist, if it has one"),
77
+ });
78
+ const roster = z.object({
79
+ shifts: z.array(shift),
80
+ zone: z.string(),
81
+ days: z
82
+ .array(z.object({ date: z.string(), hours: z.number() }))
83
+ .describe("Each local date and its hours in the zone (23 or 25 on a clock change)"),
84
+ truncated: z
85
+ .boolean()
86
+ .describe("Cut short: more shifts than one answer holds; ask for fewer days"),
87
+ });
88
+ const summary = z.object({
89
+ object: z.string(),
90
+ id: z.string(),
91
+ title: z.string(),
92
+ startsAt: z.string().nullable(),
93
+ endsAt: z.string().nullable(),
94
+ });
95
+ const offerShape = z.object({
96
+ id: z.string(),
97
+ shift: summary,
98
+ from: z.string().nullable(),
99
+ fromName: z.string().nullable(),
100
+ to: z.string().nullable(),
101
+ state: z.enum(["open", "taken", "withdrawn", "cancelled", "lapsed"]),
102
+ madeAt: z.string(),
103
+ takenBy: z.string().nullable(),
104
+ takenAt: z.string().nullable(),
105
+ closesAt: z.string().nullable(),
106
+ });
107
+ const awayShape = z.object({
108
+ id: z.string(),
109
+ account: z.string(),
110
+ name: z.string(),
111
+ kind: z.enum(["leave", "regular", "other"]),
112
+ note: z.string().nullable(),
113
+ startsAt: z.string().nullable(),
114
+ endsAt: z.string().nullable(),
115
+ weekdays: z.array(z.string()),
116
+ startTime: z.string().nullable(),
117
+ endTime: z.string().nullable(),
118
+ fromDate: z.string().nullable(),
119
+ untilDate: z.string().nullable(),
120
+ zone: z.string(),
121
+ });
122
+ const awayInput = {
123
+ kind: z
124
+ .enum(["leave", "other", "regular"])
125
+ .describe("leave or other: a one-off time; regular: every week"),
126
+ note: z.string().max(500).optional(),
127
+ startsAt: localDateTime.optional().describe("A one-off time's start, local"),
128
+ endsAt: localDateTime.optional().describe("A one-off time's end, local"),
129
+ weekdays: z.array(z.enum(WEEKDAYS)).min(1).max(7).optional().describe("A regular time's days"),
130
+ startTime: localTime.optional(),
131
+ endTime: localTime.optional(),
132
+ fromDate: localDate.optional().describe("A regular time's first date"),
133
+ untilDate: localDate.optional().describe("A regular time's last date; empty: ongoing"),
134
+ zone: z.string().min(1).max(64).optional().describe("IANA zone; the organisation's if left out"),
135
+ };
136
+ const awayAnswer = z.object({
137
+ id: z.string(),
138
+ shifts: z.array(summary).describe("Your shifts it covers, to offer"),
139
+ count: z.number(),
140
+ });
141
+ /** Today's date (UTC) and `days` later: the default range when none is given. */
142
+ function range(input, days) {
143
+ const from = input.from ?? new Date().toISOString().slice(0, 10);
144
+ const to = input.to ??
145
+ new Date(Date.parse(`${from}T00:00:00Z`) + (days - 1) * 86_400_000).toISOString().slice(0, 10);
146
+ return { from, to };
147
+ }
148
+ // --- The team's tools ------------------------------------------------------------------------------
149
+ export const week = defineTool({
150
+ description: "The roster: every shift from `from` to `to` (local dates, both included, at most 62 days; " +
151
+ "a week from today when left out), classes and duty shifts alike, each with its kind, time, " +
152
+ "place and who is on it (or nobody), and its open offer. Someone who rosters also sees each " +
153
+ "shift's warnings. Shows nothing of a class's bookings or members.",
154
+ input: z.object({ from: localDate.optional(), to: localDate.optional() }),
155
+ output: roster,
156
+ risk: "read",
157
+ ...TEAM_TOOL,
158
+ handler: async (input, ctx) => roster.parse(await ctx.ops.call("staffing.week", range(input, 7))),
159
+ });
160
+ export const mine = defineTool({
161
+ description: "Your own shifts from `from` to `to` (local dates, both included, at most 62 days; four weeks " +
162
+ "from today when left out), each with its time, place and open offer.",
163
+ input: z.object({ from: localDate.optional(), to: localDate.optional() }),
164
+ output: roster,
165
+ risk: "read",
166
+ ...TEAM_TOOL,
167
+ handler: async (input, ctx) => roster.parse(await ctx.ops.call("staffing.week", { ...range(input, 28), mine: true })),
168
+ });
169
+ export const offers = defineTool({
170
+ description: "Shifts offered that you could take now (you are qualified for the kind of work, free then, " +
171
+ "and it is before the cut-off; `unavailable` says you said you are away then), and your own " +
172
+ "open offers.",
173
+ input: z.object({}),
174
+ output: z.object({
175
+ open: z.array(offerShape.extend({ unavailable: z.boolean() })),
176
+ mine: z.array(offerShape),
177
+ }),
178
+ risk: "read",
179
+ ...TEAM_TOOL,
180
+ handler: async (_input, ctx) => (await ctx.ops.call("staffing.offers", {})),
181
+ });
182
+ export const offer = defineTool({
183
+ description: "Offer one of your shifts for someone else to take: to everyone who could take it, or to one " +
184
+ "named person (`to`). It stays yours, in your list and your pay, until someone takes it. " +
185
+ "Offers close at the cut-off before the shift starts. Whoever rosters may offer any shift, " +
186
+ "and one with nobody on it. A person's own act.",
187
+ input: z.object({
188
+ ...shiftRef,
189
+ to: z.string().min(1).max(64).optional().describe("A staff account: offer it to them only"),
190
+ }),
191
+ output: z.object({ offer: offerShape, told: z.number().nullable() }),
192
+ risk: "write",
193
+ ...TEAM_TOOL,
194
+ humanOnly: true,
195
+ handler: async (input, ctx) => (await ctx.ops.call("staffing.offer", input)),
196
+ });
197
+ export const withdraw = defineTool({
198
+ description: "Withdraw an open offer you made. The shift stays yours. A person's own act.",
199
+ input: z.object({ offer: z.string().min(1).max(64) }),
200
+ output: z.object({ offer: offerShape }),
201
+ risk: "write",
202
+ ...TEAM_TOOL,
203
+ humanOnly: true,
204
+ handler: async (input, ctx) => (await ctx.ops.call("staffing.withdraw", input)),
205
+ });
206
+ export const take = defineTool({
207
+ description: "Take an offered shift: it becomes yours at once and nobody approves it, because you must be " +
208
+ "qualified for it and free then (otherwise it is refused). If you said you are away then, " +
209
+ "confirm with confirmUnavailable. Of several people taking one shift at once, one gets it; " +
210
+ "the others are told who took it. The person who offered it and whoever rosters are told. A " +
211
+ "person's own act.",
212
+ input: z.object({
213
+ offer: z.string().min(1).max(64),
214
+ confirmUnavailable: z.boolean().optional(),
215
+ }),
216
+ output: z.object({ offer: z.string(), shift: summary, warnings: z.array(warning) }),
217
+ risk: "write",
218
+ ...TEAM_TOOL,
219
+ humanOnly: true,
220
+ handler: async (input, ctx) => (await ctx.ops.call("staffing.take", input)),
221
+ });
222
+ export const away = defineTool({
223
+ description: "Say when you cannot work: leave or another one-off time (startsAt and endsAt, local), or a " +
224
+ "regular time off (weekdays with a start and end time, from a date). Nobody approves it. " +
225
+ "Shifts you are already on stay yours: the answer lists them, to offer, and whoever rosters " +
226
+ "is told. Only you and whoever rosters ever see it. A person's own act.",
227
+ input: z.object(awayInput),
228
+ output: awayAnswer,
229
+ risk: "write",
230
+ ...TEAM_TOOL,
231
+ humanOnly: true,
232
+ // What someone writes about their leave never reaches the audit log.
233
+ redact: ["note"],
234
+ handler: async (input, ctx) => (await ctx.ops.call("staffing.away", input)),
235
+ });
236
+ export const back = defineTool({
237
+ description: "Remove a time you said you cannot work (you are back, or it was wrong). Whoever rosters may " +
238
+ "remove anyone's. A person's own act.",
239
+ input: z.object({ id: z.string().min(1).max(64) }),
240
+ output: z.object({ id: z.string() }),
241
+ risk: "write",
242
+ ...TEAM_TOOL,
243
+ humanOnly: true,
244
+ handler: async (input, ctx) => (await ctx.ops.call("staffing.back", input)),
245
+ });
246
+ export const myAway = defineTool({
247
+ description: "The times you said you cannot work, from `from` (today when left out) to `to`, with your " +
248
+ "notes (shown to you only: an assistant reading them gets no notes).",
249
+ input: z.object({ from: localDate.optional(), to: localDate.optional() }),
250
+ output: z.object({ items: z.array(awayShape) }),
251
+ risk: "read",
252
+ ...TEAM_TOOL,
253
+ handler: async (input, ctx) => {
254
+ // Your own: the account is the host-verified caller, never one the input names.
255
+ const caller = ctx.caller;
256
+ if (caller?.kind !== "staff")
257
+ return { items: [] };
258
+ return (await ctx.ops.call("staffing.awayList", { ...input, account: caller.userId }));
259
+ },
260
+ });
261
+ export const me = defineTool({
262
+ description: "Who you are on the roster and what you may do here: your name, whether you roster others, " +
263
+ "whether you handle pay, the organisation's zone and today's date there, and how long before " +
264
+ "a shift offers close.",
265
+ input: z.object({}),
266
+ output: z.object({
267
+ account: z.string(),
268
+ name: z.string(),
269
+ rosters: z.boolean(),
270
+ pays: z.boolean(),
271
+ zone: z.string(),
272
+ today: z.string(),
273
+ cutoffMinutes: z.number(),
274
+ uncoveredDays: z.number(),
275
+ }),
276
+ risk: "read",
277
+ ...TEAM_TOOL,
278
+ handler: async (_input, ctx) => (await ctx.ops.call("staffing.me", {})),
279
+ });
280
+ // --- My hours (the owner's decision of 2026-11-24, ADR 0627's amendment) ------------------------
281
+ // Everyone counted for pay may see their own totals for a pay period: hours and shifts, never money.
282
+ // A person's own read at the screen (`humanOnly`): an assistant never reads anyone's pay, its own
283
+ // person's included. The host answers for the verified caller only, never an account in the input.
284
+ const myPeriod = z.object({
285
+ start: z.string(),
286
+ end: z.string(),
287
+ zone: z.string(),
288
+ state: z.enum(["open", "locked"]),
289
+ ended: z.boolean(),
290
+ version: z.number().nullable(),
291
+ });
292
+ export const myPayPeriods = defineTool({
293
+ description: "The pay periods you can look up your own hours for: the current one and the twelve before " +
294
+ "it, each with its dates and whether it is open or locked. A person's own read.",
295
+ input: z.object({ count: z.number().int().min(1).max(12).optional() }),
296
+ output: z.object({
297
+ set: z.boolean().describe("False until the date a period starts is set: nothing is totalled"),
298
+ periods: z.array(myPeriod),
299
+ }),
300
+ risk: "read",
301
+ ...TEAM_TOOL,
302
+ humanOnly: true,
303
+ handler: async (input, ctx) => (await ctx.ops.call("staffing.myPay.periods", input)),
304
+ });
305
+ export const myPay = defineTool({
306
+ description: "Your own hours for a pay period (the current one when start is left out): how you are " +
307
+ "counted, your shifts and hours per kind of work, and each of your shifts with its minutes " +
308
+ "and whether it was marked not worked. Exactly what payroll is given for you: a locked " +
309
+ "period's locked figures, or a preview of an open one, which may still change. Nothing " +
310
+ "about anyone else. A person's own read.",
311
+ input: z.object({ start: localDate.optional() }),
312
+ output: z.object({
313
+ period: z.object({
314
+ start: z.string(),
315
+ end: z.string(),
316
+ zone: z.string(),
317
+ ended: z.boolean(),
318
+ locked: z.boolean(),
319
+ preview: z.boolean(),
320
+ version: z.number().nullable(),
321
+ }),
322
+ counted: z
323
+ .boolean()
324
+ .describe("False: you are not counted for pay then, and there are no figures"),
325
+ basis,
326
+ totals: z.array(z.object({
327
+ basis: countedBasis,
328
+ kind: kindRef,
329
+ kindName: z.string(),
330
+ shifts: z.number(),
331
+ minutes: z.number(),
332
+ hours: z.string(),
333
+ notWorked: z.number(),
334
+ flagged: z.number(),
335
+ })),
336
+ lines: z.array(z.object({
337
+ object: z.string(),
338
+ id: z.string(),
339
+ title: z.string(),
340
+ kindName: z.string(),
341
+ basis: countedBasis,
342
+ place: z.string().nullable(),
343
+ localDate: z.string(),
344
+ localStart: z.string(),
345
+ localEnd: z.string(),
346
+ shiftMinutes: z.number(),
347
+ beforeMinutes: z.number(),
348
+ afterMinutes: z.number(),
349
+ countedMinutes: z.number(),
350
+ notWorked: z.boolean(),
351
+ listTaken: z.boolean().nullable(),
352
+ flagged: z.boolean(),
353
+ clockChange: z.string().nullable(),
354
+ })),
355
+ minutes: z.number().nullable(),
356
+ hours: z.string().nullable(),
357
+ }),
358
+ risk: "read",
359
+ ...TEAM_TOOL,
360
+ humanOnly: true,
361
+ handler: async (input, ctx) => (await ctx.ops.call("staffing.myPay", input)),
362
+ });
363
+ // --- My calendar (the feed, ADR 0628) ------------------------------------------------------------
364
+ const feedState = z.object({
365
+ active: z
366
+ .boolean()
367
+ .describe("Whether you have a calendar feed (its address is never shown again)"),
368
+ createdAt: z.string().nullable(),
369
+ });
370
+ export const feed = defineTool({
371
+ description: "Whether you have a private calendar feed of your own shifts (for your phone's calendar), " +
372
+ "and when its address was made. The address itself is shown only once, by feedRotate.",
373
+ input: z.object({}),
374
+ output: feedState,
375
+ risk: "read",
376
+ ...TEAM_TOOL,
377
+ handler: async (_input, ctx) => feedState.parse(await ctx.ops.call("staffing.feed.status", {})),
378
+ });
379
+ export const feedRotate = defineTool({
380
+ description: "A new private address for your calendar feed: your own shifts, from two weeks back to four " +
381
+ "months ahead, for a calendar app to subscribe to. Any old address stops working at once. " +
382
+ "Shown this once: anyone with it sees your shifts, so do not share it. A person's own act.",
383
+ input: z.object({}),
384
+ output: z.object({
385
+ path: z
386
+ .string()
387
+ .describe("The address on this host: put its origin before it (https://, or webcal:// to open it in a calendar app)"),
388
+ createdAt: z.string(),
389
+ }),
390
+ risk: "write",
391
+ ...TEAM_TOOL,
392
+ humanOnly: true,
393
+ // The address is a secret: never in the audit log or a stored reply.
394
+ redactResult: ["path"],
395
+ handler: async (_input, ctx) => (await ctx.ops.call("staffing.feed.rotate", {})),
396
+ });
397
+ export const feedRevoke = defineTool({
398
+ description: "Turn your calendar feed off: its address stops working (a calendar app keeps the shifts it " +
399
+ "last fetched and gets no more). An admin may turn off anyone's (account). A person's own act.",
400
+ input: z.object({
401
+ account: z.string().min(1).max(64).optional().describe("Someone else's: an admin only"),
402
+ }),
403
+ output: z.object({ account: z.string(), revoked: z.boolean() }),
404
+ risk: "write",
405
+ ...TEAM_TOOL,
406
+ humanOnly: true,
407
+ handler: async (input, ctx) => (await ctx.ops.call("staffing.feed.revoke", input)),
408
+ });
409
+ // --- The rosterers' tools --------------------------------------------------------------------------
410
+ export const assign = defineTool({
411
+ description: "Put a member of staff on a shift (a class or a duty shift), or nobody (account null). Made " +
412
+ "with its warnings (away, not qualified, nobody on it), which `check` shows first; refused " +
413
+ "if they are on another shift then. A shift of a weekly pattern keeps it as its own. The " +
414
+ "people on and off it are told; its open offer is cancelled. Whoever rosters; an assistant " +
415
+ "may ask, and a person applies it.",
416
+ input: z.object({
417
+ ...shiftRef,
418
+ account: z.string().min(1).max(64).nullable(),
419
+ }),
420
+ output: z.object({ shift: summary, warnings: z.array(warning) }),
421
+ risk: "write",
422
+ permission: MANAGE,
423
+ personApproves: true,
424
+ handler: async (input, ctx) => (await ctx.ops.call("staffing.assign", input)),
425
+ });
426
+ /** The shift putting someone on another would clash with (refused), if any. */
427
+ const clash = z
428
+ .object({
429
+ object: z.string(),
430
+ id: z.string(),
431
+ title: z.string(),
432
+ startsAt: z.string(),
433
+ endsAt: z.string(),
434
+ })
435
+ .nullable();
436
+ export const check = defineTool({
437
+ description: "What putting someone (account; null for nobody; left out for the shift as it is) on a " +
438
+ "shift would be made with: its warnings (away, not qualified, nobody on it) and the other " +
439
+ "shift it would clash with (refused). Changes nothing. Whoever rosters.",
440
+ input: z.object({
441
+ ...shiftRef,
442
+ account: z.string().min(1).max(64).nullable().optional(),
443
+ }),
444
+ output: z.object({
445
+ warnings: z.array(warning),
446
+ clash,
447
+ }),
448
+ risk: "read",
449
+ permission: MANAGE,
450
+ handler: async (input, ctx) => (await ctx.ops.call("staffing.check", input)),
451
+ });
452
+ const candidate = z.object({
453
+ account: z.string(),
454
+ name: z.string(),
455
+ eligible: z.boolean().describe("Qualified, free and available: could take it"),
456
+ noProfile: z.boolean().describe("The shift cannot name them (a class needs a coach profile)"),
457
+ warnings: z.array(warning),
458
+ clash,
459
+ });
460
+ export const candidates = defineTool({
461
+ description: "Who could be put on a shift: every member of staff with what putting them on it would be " +
462
+ "made with (warnings, or the shift it would clash with), the eligible first; who is on it; " +
463
+ "and, for a shift of a weekly pattern, the pattern's person and whether it keeps its own. " +
464
+ "Whoever rosters.",
465
+ input: z.object(shiftRef),
466
+ output: z.object({
467
+ current: z.object({ account: z.string().nullable(), name: z.string().nullable() }),
468
+ pattern: z
469
+ .object({ account: z.string().nullable(), name: z.string().nullable(), own: z.boolean() })
470
+ .nullable(),
471
+ people: z.array(candidate),
472
+ truncated: z.boolean(),
473
+ }),
474
+ risk: "read",
475
+ permission: MANAGE,
476
+ handler: async (input, ctx) => (await ctx.ops.call("staffing.candidates", input)),
477
+ });
478
+ export const follow = defineTool({
479
+ description: "Put a shift of a weekly pattern back to its pattern's person: it drops its own person and " +
480
+ "follows the pattern again. Refused for a one-off shift, and if the pattern's person is on " +
481
+ "another shift then. Whoever rosters; an assistant may ask, and a person applies it.",
482
+ input: z.object(shiftRef),
483
+ output: z.object({ object: z.string(), id: z.string(), warnings: z.array(warning) }),
484
+ risk: "write",
485
+ permission: MANAGE,
486
+ personApproves: true,
487
+ handler: async (input, ctx) => (await ctx.ops.call("staffing.follow", input)),
488
+ });
489
+ export const people = defineTool({
490
+ description: "The active members of staff and every kind of work a shift can be of (class types, duties), " +
491
+ "to say who may do which. Names only. Whoever rosters.",
492
+ input: z.object({}),
493
+ output: z.object({
494
+ people: z.array(z.object({ account: z.string(), name: z.string() })),
495
+ kinds: z.array(z.object({ object: z.string(), objectLabel: z.string(), id: z.string(), name: z.string() })),
496
+ truncated: z.boolean(),
497
+ }),
498
+ risk: "read",
499
+ permission: MANAGE,
500
+ handler: async (_input, ctx) => (await ctx.ops.call("staffing.people", {})),
501
+ });
502
+ const patternShape = z.object({
503
+ object: z.string(),
504
+ id: z.string(),
505
+ title: z.string(),
506
+ objectLabel: z.string(),
507
+ kind: z.object({ object: z.string(), id: z.string(), name: z.string() }).nullable(),
508
+ weekdays: z.array(z.string()),
509
+ time: z.string().nullable(),
510
+ length: z.number().nullable(),
511
+ firstDate: z.string().nullable(),
512
+ lastDate: z.string().nullable(),
513
+ zone: z.string(),
514
+ account: z.string().nullable(),
515
+ name: z.string().nullable(),
516
+ noAccount: z.boolean(),
517
+ });
518
+ export const patterns = defineTool({
519
+ description: "The regular week: every class series and duty series that has not ended, with its days, " +
520
+ "time, length, dates and its regular person (or nobody). Whoever rosters.",
521
+ input: z.object({}),
522
+ output: z.object({ patterns: z.array(patternShape), truncated: z.boolean() }),
523
+ risk: "read",
524
+ permission: MANAGE,
525
+ handler: async (_input, ctx) => (await ctx.ops.call("staffing.patterns", {})),
526
+ });
527
+ export const setPattern = defineTool({
528
+ description: "Change a regular pattern's person (a class series' coach, a duty series' person), or nobody " +
529
+ "(account null), from a date (today when left out): its shifts from then follow, except " +
530
+ "those that keep their own person. Refused whole if it would put them on two shifts at once " +
531
+ "on any date, naming the dates. Whoever rosters; an assistant may ask, and a person applies it.",
532
+ input: z.object({
533
+ object: z.string().min(1).max(81).describe("bookings.series or rostering.dutyseries"),
534
+ id: z.string().min(1).max(64),
535
+ account: z.string().min(1).max(64).nullable(),
536
+ from: localDate.optional(),
537
+ }),
538
+ output: z.object({
539
+ object: z.string(),
540
+ id: z.string(),
541
+ account: z.string().nullable(),
542
+ from: z.string(),
543
+ }),
544
+ risk: "write",
545
+ permission: MANAGE,
546
+ personApproves: true,
547
+ handler: async (input, ctx) => (await ctx.ops.call("staffing.setPattern", input)),
548
+ });
549
+ export const planCheck = defineTool({
550
+ description: "Before an import makes patterns or shifts: for each plan (a weekly pattern, or one dated " +
551
+ "shift, with its person), the dates it would make, the dates it would clash with a shift " +
552
+ "they are on or an earlier plan (title and start; `ended` when both are over), the dates " +
553
+ "they said they are away and whether they are not qualified. Changes nothing. Whoever " +
554
+ "rosters, a person only (it reads people's time off).",
555
+ input: z.object({
556
+ plans: z
557
+ .array(z.object({
558
+ key: z.string().max(80).optional(),
559
+ kind: z
560
+ .object({ object: z.string().min(1).max(81), id: z.string().min(1).max(64) })
561
+ .nullable()
562
+ .optional(),
563
+ account: z.string().min(1).max(64).nullable(),
564
+ weekdays: z.array(z.enum(WEEKDAYS)).min(1).max(7).optional(),
565
+ date: localDate.optional(),
566
+ time: localTime,
567
+ length: z.number().int().min(1).max(1440),
568
+ firstDate: localDate.optional(),
569
+ lastDate: localDate.optional(),
570
+ zone: z.string().min(1).max(64).optional(),
571
+ }))
572
+ .min(1)
573
+ .max(1000),
574
+ horizonDays: z.number().int().min(1).max(366).optional(),
575
+ }),
576
+ output: z.object({
577
+ plans: z.array(z.object({
578
+ key: z.string().nullable(),
579
+ dates: z.number(),
580
+ clashes: z.array(z.object({
581
+ date: z.string(),
582
+ startsAt: z.string(),
583
+ other: z.object({ title: z.string(), startsAt: z.string(), endsAt: z.string() }),
584
+ ended: z.boolean(),
585
+ })),
586
+ away: z.array(z.string()),
587
+ notQualified: z.boolean(),
588
+ first: z.object({ date: z.string(), startsAt: z.string(), endsAt: z.string() }).nullable(),
589
+ })),
590
+ truncated: z.boolean(),
591
+ }),
592
+ risk: "read",
593
+ permission: MANAGE,
594
+ humanOnly: true,
595
+ handler: async (input, ctx) => (await ctx.ops.call("staffing.planCheck", input)),
596
+ });
597
+ export const qualify = defineTool({
598
+ description: "Say whether a member of staff may do a kind of work (a class type, a duty): qualified people " +
599
+ "may take an offered shift of it without anybody approving, and putting someone else on it " +
600
+ "is warned about. Whoever rosters; an assistant may ask, and a person applies it.",
601
+ input: z.object({
602
+ account: z.string().min(1).max(64),
603
+ kind: z.object({
604
+ object: z.string().min(1).max(81).describe("programs.classtype or rostering.duty"),
605
+ id: z.string().min(1).max(64),
606
+ }),
607
+ qualified: z.boolean().default(true),
608
+ }),
609
+ output: z.object({
610
+ account: z.string(),
611
+ kind: z.object({ object: z.string(), id: z.string() }),
612
+ qualified: z.boolean(),
613
+ changed: z.boolean(),
614
+ }),
615
+ risk: "write",
616
+ permission: MANAGE,
617
+ personApproves: true,
618
+ handler: async (input, ctx) => (await ctx.ops.call("staffing.qualify", input)),
619
+ });
620
+ export const qualifications = defineTool({
621
+ description: "Who may do which kind of work: everyone's, or one person's (account), or one kind of " +
622
+ "work's (kindObject). Whoever rosters.",
623
+ input: z.object({
624
+ account: z.string().min(1).max(64).optional(),
625
+ kindObject: z.string().min(1).max(81).optional(),
626
+ }),
627
+ output: z.object({
628
+ items: z.array(z.object({
629
+ account: z.string(),
630
+ name: z.string(),
631
+ kind: z.object({ object: z.string(), id: z.string(), name: z.string() }),
632
+ setBy: z.string(),
633
+ setAt: z.string(),
634
+ })),
635
+ }),
636
+ risk: "read",
637
+ permission: MANAGE,
638
+ handler: async (input, ctx) => (await ctx.ops.call("staffing.qualifications", input)),
639
+ });
640
+ export const awayFor = defineTool({
641
+ description: "Say when someone else cannot work (their leave, a regular time off), as they would " +
642
+ "themselves. Their shifts stay theirs, with a warning; the answer lists them. Whoever " +
643
+ "rosters, a person only.",
644
+ input: z.object({ account: z.string().min(1).max(64), ...awayInput }),
645
+ output: awayAnswer,
646
+ risk: "write",
647
+ permission: MANAGE,
648
+ humanOnly: true,
649
+ redact: ["note"],
650
+ handler: async (input, ctx) => (await ctx.ops.call("staffing.away", input)),
651
+ });
652
+ export const awayList = defineTool({
653
+ description: "Everyone's times they cannot work (or one person's, account), with their notes, from `from` " +
654
+ "(today when left out) to `to`. Whoever rosters, a person only: never read by an assistant.",
655
+ input: z.object({
656
+ account: z.string().min(1).max(64).optional(),
657
+ from: localDate.optional(),
658
+ to: localDate.optional(),
659
+ }),
660
+ output: z.object({ items: z.array(awayShape) }),
661
+ risk: "read",
662
+ permission: MANAGE,
663
+ humanOnly: true,
664
+ handler: async (input, ctx) => (await ctx.ops.call("staffing.awayList", input)),
665
+ });
666
+ export const uncovered = defineTool({
667
+ description: "Shifts with nobody on them from now for `days` days (the uncovered window, a setting, when " +
668
+ "left out; at most 62), and whether each is offered. Whoever rosters.",
669
+ input: z.object({ days: z.number().int().min(1).max(62).optional() }),
670
+ output: z.object({ items: z.array(summary.extend({ offered: z.boolean() })) }),
671
+ risk: "read",
672
+ permission: MANAGE,
673
+ handler: async (input, ctx) => (await ctx.ops.call("staffing.uncovered", input)),
674
+ });
675
+ export const markNotWorked = defineTool({
676
+ description: "Mark a shift that has started as not worked, with why (nobody ran the class, they did not " +
677
+ "come in), so it counts for nothing in its pay period; notWorked false clears the mark. A " +
678
+ "shift in a locked pay period is refused until the period is reopened. Whoever rosters; an " +
679
+ "assistant may ask, and a person applies it.",
680
+ input: z.object({
681
+ ...shiftRef,
682
+ notWorked: z.boolean().default(true),
683
+ reason: z.string().trim().min(1).max(500).optional(),
684
+ }),
685
+ output: z.object({
686
+ object: z.string(),
687
+ id: z.string(),
688
+ notWorked: z.boolean(),
689
+ changed: z.boolean(),
690
+ }),
691
+ risk: "write",
692
+ permission: MANAGE,
693
+ personApproves: true,
694
+ // Why someone did not work a shift is theirs: kept with the mark, not in the audit log.
695
+ redact: ["reason"],
696
+ handler: async (input, ctx) => (await ctx.ops.call("staffing.markNotWorked", input)),
697
+ });
698
+ // --- Pay (restricted, a person only: never an assistant, whatever is granted) ---------------------
699
+ /** Pay: restricted (held by admins and by grant only, ADR 0625), and every tool `humanOnly`. */
700
+ const PAY = "rostering:pay";
701
+ export const payBasis = defineTool({
702
+ description: "Say how a member of staff is counted for pay from a date on (today when left out): " +
703
+ "by_time (their hours), by_class (their classes and shifts) or not_counted (salaried, the " +
704
+ "default). No rates are kept: payroll applies them. Whoever handles pay, a person only.",
705
+ input: z.object({ account: z.string().min(1).max(64), basis, from: localDate.optional() }),
706
+ output: z.object({ account: z.string(), from: z.string(), changed: z.boolean() }),
707
+ risk: "write",
708
+ permission: PAY,
709
+ humanOnly: true,
710
+ // How someone is counted is pay: the audit log says whose and from when, not how.
711
+ redact: ["basis"],
712
+ handler: async (input, ctx) => (await ctx.ops.call("staffing.payBasis", input)),
713
+ });
714
+ export const payBases = defineTool({
715
+ description: "Who is counted for pay and how (by time, by class, not counted), today and from which " +
716
+ "dates; with everyone, every member of staff. Whoever handles pay, a person only.",
717
+ input: z.object({
718
+ account: z.string().min(1).max(64).optional(),
719
+ everyone: z
720
+ .boolean()
721
+ .optional()
722
+ .describe("Also every active member of staff with no basis set yet (not counted)"),
723
+ }),
724
+ output: z.object({
725
+ today: z.string(),
726
+ items: z.array(z.object({
727
+ account: z.string(),
728
+ name: z.string(),
729
+ basis,
730
+ history: z.array(z.object({ from: z.string(), basis, setBy: z.string(), setAt: z.string() })),
731
+ })),
732
+ truncated: z.boolean().describe("Cut short: ask for one person's (account)"),
733
+ }),
734
+ risk: "read",
735
+ permission: PAY,
736
+ humanOnly: true,
737
+ handler: async (input, ctx) => (await ctx.ops.call("staffing.payBases", input)),
738
+ });
739
+ const version = z.object({
740
+ id: z.string(),
741
+ version: z.number(),
742
+ state: z.enum(["locked", "reopened"]),
743
+ lockedBy: z.string(),
744
+ lockedByName: z.string(),
745
+ lockedAt: z.string(),
746
+ reopenedBy: z.string().nullable(),
747
+ reopenedAt: z.string().nullable(),
748
+ reopenReason: z.string().nullable(),
749
+ });
750
+ export const periods = defineTool({
751
+ description: "The pay periods (the pay period setting: fortnightly by default): the current one and the " +
752
+ "`count` before it, each open or locked, with its versions. Whoever handles pay, a person only.",
753
+ input: z.object({ count: z.number().int().min(1).max(60).optional() }),
754
+ output: z.object({
755
+ setting: z.object({
756
+ period: z.enum(["weekly", "fortnightly", "monthly"]),
757
+ start: z.string().nullable(),
758
+ day: z.number(),
759
+ zone: z.string(),
760
+ }),
761
+ set: z.boolean().describe("False until the date a period starts is set: nothing is totalled"),
762
+ periods: z.array(z.object({
763
+ start: z.string(),
764
+ end: z.string(),
765
+ zone: z.string(),
766
+ state: z.enum(["open", "locked"]),
767
+ ended: z.boolean(),
768
+ versions: z.array(version),
769
+ })),
770
+ }),
771
+ risk: "read",
772
+ permission: PAY,
773
+ humanOnly: true,
774
+ handler: async (input, ctx) => (await ctx.ops.call("staffing.payPeriod.list", input)),
775
+ });
776
+ export const periodTotals = defineTool({
777
+ description: "One pay period's totals: per counted person and kind of work, the shifts and the hours " +
778
+ "(whole minutes, and hours to two places), and one line per shift with its evidence (its " +
779
+ "class list taken, by whom, flagged for review when not by its person). A locked period's " +
780
+ "are its locked lines; an open one's are a preview from the roster as it stands. Whoever " +
781
+ "handles pay, a person only.",
782
+ input: z.object({ start: localDate, version: z.number().int().min(1).optional() }),
783
+ output: z.object({
784
+ period: z.object({
785
+ start: z.string(),
786
+ end: z.string(),
787
+ zone: z.string(),
788
+ locked: z.boolean(),
789
+ preview: z.boolean(),
790
+ version: version.nullable(),
791
+ }),
792
+ totals: z.array(z.object({
793
+ account: z.string(),
794
+ name: z.string(),
795
+ email: z.string(),
796
+ basis: countedBasis,
797
+ kind: kindRef,
798
+ kindName: z.string(),
799
+ shifts: z.number(),
800
+ minutes: z.number(),
801
+ hours: z.string(),
802
+ notWorked: z.number(),
803
+ flagged: z.number(),
804
+ })),
805
+ lines: z.array(z.object({
806
+ account: z.string(),
807
+ name: z.string(),
808
+ email: z.string(),
809
+ basis: countedBasis,
810
+ object: z.string(),
811
+ id: z.string(),
812
+ kind: kindRef,
813
+ kindName: z.string(),
814
+ title: z.string(),
815
+ place: z.string().nullable(),
816
+ localDate: z.string(),
817
+ localStart: z.string(),
818
+ localEnd: z.string(),
819
+ shiftMinutes: z.number(),
820
+ beforeMinutes: z.number(),
821
+ afterMinutes: z.number(),
822
+ countedMinutes: z.number(),
823
+ counted: z.boolean(),
824
+ notWorkedReason: z.string().nullable(),
825
+ listTaken: z.boolean().nullable(),
826
+ markedBy: z.string().nullable(),
827
+ flagged: z.boolean(),
828
+ })),
829
+ minutes: z.number(),
830
+ hours: z.string(),
831
+ }),
832
+ risk: "read",
833
+ permission: PAY,
834
+ humanOnly: true,
835
+ handler: async (input, ctx) => (await ctx.ops.call("staffing.payPeriod.totals", input)),
836
+ });
837
+ export const lock = defineTool({
838
+ description: "Lock a pay period that has ended: its totals are written from the roster as it stands and " +
839
+ "never change; shifts inside it can no longer be changed until it is reopened. Correct the " +
840
+ "roster first (reassign, mark not worked). Whoever handles pay, a person only.",
841
+ input: z.object({ start: localDate }),
842
+ output: z.object({ id: z.string(), start: z.string(), end: z.string(), version: z.number() }),
843
+ risk: "write",
844
+ permission: PAY,
845
+ humanOnly: true,
846
+ handler: async (input, ctx) => (await ctx.ops.call("staffing.payPeriod.lock", input)),
847
+ });
848
+ export const reopen = defineTool({
849
+ description: "Reopen a locked pay period, saying why, to correct its shifts; its locked version is kept. " +
850
+ "Lock it again for a new version. Whoever handles pay, a person only.",
851
+ input: z.object({ start: localDate, reason: z.string().trim().min(1).max(500) }),
852
+ output: z.object({ id: z.string(), start: z.string(), version: z.number() }),
853
+ risk: "write",
854
+ permission: PAY,
855
+ humanOnly: true,
856
+ redact: ["reason"],
857
+ handler: async (input, ctx) => (await ctx.ops.call("staffing.payPeriod.reopen", input)),
858
+ });
859
+ export const exportPeriod = defineTool({
860
+ description: "A pay period as a CSV file for payroll: a summary row per person and kind of work (shifts, " +
861
+ "hours as a decimal and in minutes), then a row per shift. From its locked version, or a " +
862
+ "preview of an open period, marked as such. No rates and no money. Whoever handles pay, a " +
863
+ "person only.",
864
+ input: z.object({ start: localDate, version: z.number().int().min(1).optional() }),
865
+ output: z.object({
866
+ filename: z.string(),
867
+ contentType: z.literal("text/csv"),
868
+ csv: z.string(),
869
+ locked: z.boolean(),
870
+ version: z.number().nullable(),
871
+ }),
872
+ risk: "read",
873
+ permission: PAY,
874
+ humanOnly: true,
875
+ handler: async (input, ctx) => (await ctx.ops.call("staffing.payPeriod.export", input)),
876
+ });
877
+ // --- Checklists (stage 45 step 4b, ADR 0650) -------------------------------------------------------
878
+ // A duty may carry a checklist its shift's person ticks off. Every checklist tool is a person's own,
879
+ // at the screen (`humanOnly`): a tick says a person did the step, and how a checklist went is read
880
+ // only by its person and whoever rosters, never by an assistant. The host decides whose it is to
881
+ // tick (the shift's person, or whoever rosters, for them, with why) and whether it may be ticked
882
+ // now; these tools ask and pass on what it answers.
883
+ const checklistTick = z.object({
884
+ id: z.string(),
885
+ state: z.enum(["done", "not_done", "cleared"]),
886
+ done: z.boolean(),
887
+ why: z.string().nullable(),
888
+ note: z.string().nullable(),
889
+ onBehalfWhy: z.string().nullable(),
890
+ withheld: z.boolean().describe("Has words only its author and whoever rosters read"),
891
+ by: z.string(),
892
+ byName: z.string(),
893
+ for: z.string(),
894
+ forName: z.string(),
895
+ onBehalf: z.boolean(),
896
+ at: z.string(),
897
+ label: z.string().describe('"Ticked by X", or "Ticked by X for Y"'),
898
+ });
899
+ const checklistRun = z.object({
900
+ id: z.string(),
901
+ object: z.string(),
902
+ record: z.string(),
903
+ template: z.object({ id: z.string(), name: z.string(), version: z.number() }),
904
+ state: z.enum(["open", "done", "missed", "cancelled"]),
905
+ account: z.string().nullable(),
906
+ name: z.string().nullable(),
907
+ opens: z.string(),
908
+ closes: z.string(),
909
+ tickUntil: z.string(),
910
+ madeAt: z.string(),
911
+ closedAt: z.string().nullable(),
912
+ closedBy: z.string().nullable(),
913
+ closedByName: z.string().nullable(),
914
+ closedWhy: z.string().nullable(),
915
+ steps: z.array(z.object({
916
+ position: z.number(),
917
+ text: z.string(),
918
+ required: z.boolean(),
919
+ asksNote: z.boolean(),
920
+ tick: checklistTick.nullable().describe("The latest tick"),
921
+ history: z
922
+ .array(checklistTick)
923
+ .describe("Earlier ticks, the latest 20: all for whoever rosters, your own otherwise"),
924
+ historyTruncated: z.boolean(),
925
+ missed: z.boolean(),
926
+ })),
927
+ corrections: z.array(z.object({
928
+ id: z.string(),
929
+ text: z.string(),
930
+ by: z.string(),
931
+ byName: z.string(),
932
+ at: z.string(),
933
+ })),
934
+ });
935
+ export const checklist = defineTool({
936
+ description: "A shift's checklist and how it is going: each step, its tick (who ticked it, and for whom), " +
937
+ "what was missed, and corrections; before it opens, its steps. Its person and whoever " +
938
+ "rosters only; `canTick` says whether you may tick it now. A person's own read.",
939
+ input: z.object(shiftRef),
940
+ output: z.object({
941
+ template: z.object({ id: z.string(), name: z.string() }).nullable(),
942
+ run: checklistRun.nullable(),
943
+ preview: z
944
+ .array(z.object({ text: z.string(), required: z.boolean(), asksNote: z.boolean() }))
945
+ .nullable(),
946
+ opens: z.string().nullable(),
947
+ closes: z.string().nullable(),
948
+ tickUntil: z.string().nullable(),
949
+ canTick: z.boolean(),
950
+ onBehalf: z.boolean(),
951
+ forName: z.string().nullable(),
952
+ you: z.string(),
953
+ youRoster: z.boolean(),
954
+ }),
955
+ risk: "read",
956
+ ...TEAM_TOOL,
957
+ humanOnly: true,
958
+ handler: async (input, ctx) => (await ctx.ops.call("checklist.forRecord", input)),
959
+ });
960
+ export const tick = defineTool({
961
+ description: "Tick one step of your shift's checklist: done (with a note where the step asks for one), " +
962
+ "not done (with why), or clear your tick. Every tick is kept; the latest counts, and only " +
963
+ "whoever rosters changes a tick someone else made. From when the shift starts until 2 hours " +
964
+ "after it ends. Whoever rosters may tick someone's for them, saying why (forWhy): it is kept " +
965
+ "as ticked by them for that person. A person's own act.",
966
+ input: z.object({
967
+ ...shiftRef,
968
+ step: z.number().int().min(0).max(49),
969
+ state: z.enum(["done", "not_done", "clear"]),
970
+ note: z.string().trim().max(1000).optional(),
971
+ why: z.string().trim().max(500).optional(),
972
+ forWhy: z.string().trim().max(500).optional(),
973
+ }),
974
+ output: z.object({
975
+ run: z.string(),
976
+ step: z.number(),
977
+ state: z.enum(["done", "not_done", "clear"]),
978
+ ticked: z.number(),
979
+ of: z.number(),
980
+ }),
981
+ risk: "write",
982
+ ...TEAM_TOOL,
983
+ humanOnly: true,
984
+ // What someone writes on a step, why it was not done, why it was ticked for them, and how it
985
+ // went: never in the audit log.
986
+ redact: ["note", "why", "forWhy", "state"],
987
+ handler: async (input, ctx) => (await ctx.ops.call("checklist.tick", input)),
988
+ });
989
+ export const checklistDone = defineTool({
990
+ description: "Mark your shift's checklist done, once every required step is ticked. Done is final: it " +
991
+ "never changes again. Whoever rosters may mark someone's done for them, saying why. A " +
992
+ "person's own act.",
993
+ input: z.object({ ...shiftRef, forWhy: z.string().trim().max(500).optional() }),
994
+ output: z.object({ run: z.string(), state: z.literal("done") }),
995
+ risk: "write",
996
+ ...TEAM_TOOL,
997
+ humanOnly: true,
998
+ redact: ["forWhy"],
999
+ handler: async (input, ctx) => (await ctx.ops.call("checklist.complete", input)),
1000
+ });
1001
+ export const checklistRuns = defineTool({
1002
+ description: "How checklists went, by checklist and date: every run from `from` to `to` (local dates, at " +
1003
+ "most 62 days), with its shift, its person, whether it is open, done, missed or cancelled, " +
1004
+ "the steps ticked, those missed, and ticks made for the person by someone else. Whoever " +
1005
+ "rosters, a person only.",
1006
+ input: z.object({
1007
+ from: localDate,
1008
+ to: localDate,
1009
+ template: z.string().min(1).max(64).optional(),
1010
+ }),
1011
+ output: z.object({
1012
+ zone: z.string(),
1013
+ runs: z.array(z.object({
1014
+ id: z.string(),
1015
+ object: z.string(),
1016
+ record: z.string(),
1017
+ title: z.string(),
1018
+ template: z.object({ id: z.string(), name: z.string() }),
1019
+ state: z.enum(["open", "done", "missed", "cancelled"]),
1020
+ account: z.string().nullable(),
1021
+ name: z.string().nullable(),
1022
+ opens: z.string(),
1023
+ closes: z.string(),
1024
+ steps: z.number(),
1025
+ ticked: z.number(),
1026
+ onBehalf: z.number(),
1027
+ missed: z.array(z.string()),
1028
+ corrections: z.number(),
1029
+ })),
1030
+ truncated: z.boolean(),
1031
+ }),
1032
+ risk: "read",
1033
+ permission: MANAGE,
1034
+ humanOnly: true,
1035
+ handler: async (input, ctx) => (await ctx.ops.call("checklist.runs", input)),
1036
+ });
1037
+ export const checklistCorrect = defineTool({
1038
+ description: "Add a correction beside a closed checklist (done, missed or cancelled): a note kept with " +
1039
+ "it, never a change to its ticks. Whoever rosters, a person only.",
1040
+ input: z.object({ run: z.string().min(1).max(64), text: z.string().trim().min(1).max(1000) }),
1041
+ output: z.object({ id: z.string(), run: z.string() }),
1042
+ risk: "write",
1043
+ permission: MANAGE,
1044
+ humanOnly: true,
1045
+ redact: ["text"],
1046
+ handler: async (input, ctx) => (await ctx.ops.call("checklist.correct", input)),
1047
+ });