@composable-os/pack-knowledge 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.
package/dist/index.js ADDED
@@ -0,0 +1,325 @@
1
+ // Knowledge (stage 38 step 5, ADR 0706): how the business does things, written down once, and the
2
+ // answers to its customers' common questions. Any product can turn it on (`packs` in its
3
+ // product.ts). The platform ships no procedures and no help pages: they are the business's, added
4
+ // in the admin, by the assistant or by an MCP client, with a person publishing each.
5
+ //
6
+ // Everything that is a rule is the host's, declared here as behaviours (ADR 0404):
7
+ // - both objects are `publishable` (ADRs 0446, 0441): staff and the assistant edit a working
8
+ // copy; a person with the publish permission publishes it (an AI asks, ADR 0480);
9
+ // - a procedure is for staff only: it declares no `public` and no `signedIn`, so nothing an edit
10
+ // can change makes it public. `staffRead` (ADR 0701) opens its published version, never the
11
+ // draft, to every staff account, pack roles included (a coach, a cleaner, the door), through
12
+ // `content.staffGet`, `content.staffList` and `content.search`;
13
+ // - a procedure is `acknowledge`d (ADR 0702): its "must read" (everyone, or staff roles, pack
14
+ // roles and granted pack permissions) is asked to confirm each version that asks again, with
15
+ // one tap; the host keeps the confirmation, and who must read, the owner and the review period are a
16
+ // person's to change, once published only an admin's or a holder of knowledge:manage
17
+ // (`managed`, ADR 0706). The notices are this pack's words, sent by the host;
18
+ // - a help page is public in its published wording only (ADR 0442): `content.get`,
19
+ // `content.list` and `content.search` serve the version last published, never a draft.
20
+ // The tools in tools.ts compose the host's operations and add no rule of their own.
21
+ import { defineExtension, MUST_READ_SCHEMA } from "@composable-os/sdk";
22
+ import { knowledgeAutomations } from "./automations.js";
23
+ import { confirm, draftHelpPage, draftProcedure, helpTopics, MANAGE, readStatus, toRead, WRITE, } from "./tools.js";
24
+ const HELP_ICONS = [
25
+ { value: "calendar", label: "Calendar" },
26
+ { value: "credit-card", label: "Payments" },
27
+ { value: "user-round", label: "Account" },
28
+ { value: "smartphone", label: "App" },
29
+ { value: "map-pin", label: "Getting here" },
30
+ { value: "baby", label: "Children" },
31
+ { value: "shield-check", label: "Safety" },
32
+ { value: "wrench", label: "Care and repairs" },
33
+ { value: "circle-help", label: "Other" },
34
+ ];
35
+ export default defineExtension({
36
+ id: "knowledge",
37
+ version: "0.1.0",
38
+ contractVersion: 1,
39
+ label: "Knowledge",
40
+ description: "Staff procedures read in their published wording and confirmed as read and understood, " +
41
+ "with a review reminder, and help pages for customers on the business's website.",
42
+ permissions: {
43
+ // ack.*: a person's own list and confirmation, and who has read what for those who manage
44
+ // (ADR 0702, from this pack's person-only tools). public.list: the help topics.
45
+ // notification.send: the review reminder.
46
+ operations: [
47
+ "ack.mine",
48
+ "ack.confirm",
49
+ "ack.status",
50
+ "ack.overview",
51
+ "public.list",
52
+ "notification.send",
53
+ ],
54
+ modules: ["ops"],
55
+ },
56
+ // Read status is for admins and those they allow (decision 13); writing procedures and help
57
+ // pages is every member's, and a coach's or a cleaner's when an admin grants it (ADR 0600).
58
+ grantable: [MANAGE, WRITE],
59
+ restricted: [MANAGE],
60
+ grantableLabels: {
61
+ [MANAGE]: "See who has read and confirmed each procedure, and change who must read one once published",
62
+ [WRITE]: "Write procedures and help pages (a person allowed to publish publishes them)",
63
+ },
64
+ objects: {
65
+ procedure: {
66
+ label: "Procedure",
67
+ plural: "Procedures",
68
+ icon: "list-checks",
69
+ titleField: "title",
70
+ owner: "owner",
71
+ description: "How the business does something, for staff: read by every staff account in the wording " +
72
+ "last published, never the draft, and confirmed as read and understood by those who " +
73
+ "must read it.",
74
+ navigation: "main",
75
+ navigationOrder: 60,
76
+ fields: {
77
+ title: { type: "text", label: "Title", required: true },
78
+ slug: {
79
+ type: "slug",
80
+ label: "Address",
81
+ description: "How a link names the procedure. Made from the title.",
82
+ },
83
+ summary: {
84
+ type: "text",
85
+ label: "Summary",
86
+ description: "One or two sentences for lists and search results.",
87
+ },
88
+ body: {
89
+ type: "richText",
90
+ label: "Body",
91
+ description: "The procedure. Each heading is a section that search and the assistant link to. " +
92
+ "Name a role, not a person ('the duty manager', not 'Sam').",
93
+ },
94
+ section: { type: "relation", label: "Section", to: "knowledge.section" },
95
+ owner: {
96
+ type: "user",
97
+ label: "Kept right by",
98
+ description: "Who keeps it right: told when it is time to review it, and each week who has not " +
99
+ "confirmed it.",
100
+ },
101
+ mustRead: {
102
+ type: "document",
103
+ label: "Must read",
104
+ schema: MUST_READ_SCHEMA,
105
+ description: "Who is asked to confirm it: everyone, or some staff roles, pack roles (a coach, a " +
106
+ "cleaner) and granted permissions (the front desk). Every staff account may read it " +
107
+ "either way. Changing it counts at once.",
108
+ },
109
+ reviewEvery: {
110
+ type: "number",
111
+ label: "Review every (months)",
112
+ default: 12,
113
+ min: 0,
114
+ max: 120,
115
+ step: 1,
116
+ description: "How often its owner is asked to check it is still right. 0: never.",
117
+ },
118
+ nextReview: {
119
+ type: "formula",
120
+ label: "Next review",
121
+ description: "Its last publish plus the review period. Empty when it is never reviewed.",
122
+ expression: 'if(coalesce(reviewEvery, 12) > 0, dateAdd(publishedAt, coalesce(reviewEvery, 12), "month"), null)',
123
+ },
124
+ },
125
+ indexes: [["section"], ["owner"]],
126
+ publishable: {
127
+ content: ["title", "summary", "body", "section"],
128
+ slug: "slug",
129
+ staffRead: true,
130
+ acknowledge: {
131
+ who: "mustRead",
132
+ manage: MANAGE,
133
+ managed: ["reviewEvery", "owner"],
134
+ owner: "owner",
135
+ notices: {
136
+ asked: {
137
+ title: "Please read: {record}",
138
+ body: "A procedure you must read has been published or changed. Read it and confirm " +
139
+ "you have read and understood it.",
140
+ },
141
+ reminder: {
142
+ title: "Still to read: {record}",
143
+ body: "Read this procedure and confirm you have read and understood it.",
144
+ afterDays: 7,
145
+ },
146
+ outstanding: { title: "Not yet confirmed: {record}" },
147
+ welcome: {
148
+ title: "Procedures to read",
149
+ body: "Welcome. Read these procedures and confirm each one:",
150
+ },
151
+ },
152
+ },
153
+ },
154
+ },
155
+ section: {
156
+ label: "Section",
157
+ plural: "Sections",
158
+ icon: "shapes",
159
+ titleField: "name",
160
+ navigation: "settings",
161
+ description: "A group of procedures (opening and closing, safety, the front desk). Staff only.",
162
+ fields: {
163
+ name: { type: "text", label: "Name", required: true },
164
+ order: { type: "number", label: "Order", step: 1 },
165
+ },
166
+ indexes: [["order"]],
167
+ },
168
+ helppage: {
169
+ label: "Help page",
170
+ plural: "Help pages",
171
+ icon: "newspaper",
172
+ titleField: "title",
173
+ description: "An answer to a customer's question, on the business's website for anyone. The public " +
174
+ "reads the version last published.",
175
+ navigation: "main",
176
+ navigationOrder: 61,
177
+ fields: {
178
+ title: { type: "text", label: "Title", required: true },
179
+ slug: {
180
+ type: "slug",
181
+ label: "Address",
182
+ description: "Where the page is read: /help/<address>. Made from the title.",
183
+ },
184
+ summary: {
185
+ type: "text",
186
+ label: "Summary",
187
+ description: "One or two sentences for lists, search results and link previews.",
188
+ },
189
+ body: { type: "richText", label: "Body" },
190
+ topic: { type: "relation", label: "Topic", to: "knowledge.helptopic" },
191
+ order: { type: "number", label: "Order in its topic", step: 1 },
192
+ related: {
193
+ type: "relation",
194
+ label: "Related pages",
195
+ to: "knowledge.helppage",
196
+ many: true,
197
+ },
198
+ seoTitle: { type: "text", label: "Search title" },
199
+ seoDescription: { type: "text", label: "Search description" },
200
+ noindex: {
201
+ type: "boolean",
202
+ label: "Hide from search engines",
203
+ description: "Asks search engines not to list the page.",
204
+ },
205
+ },
206
+ indexes: [["topic", "order"]],
207
+ publishable: {
208
+ content: [
209
+ "title",
210
+ "summary",
211
+ "body",
212
+ "topic",
213
+ "order",
214
+ "related",
215
+ "seoTitle",
216
+ "seoDescription",
217
+ "noindex",
218
+ ],
219
+ slug: "slug",
220
+ },
221
+ public: {
222
+ read: [
223
+ "title",
224
+ "slug",
225
+ "summary",
226
+ "body",
227
+ "topic",
228
+ "order",
229
+ "related",
230
+ "seoTitle",
231
+ "seoDescription",
232
+ "noindex",
233
+ "publishedAt",
234
+ ],
235
+ },
236
+ },
237
+ helptopic: {
238
+ label: "Help topic",
239
+ plural: "Help topics",
240
+ icon: "tags",
241
+ titleField: "name",
242
+ navigation: "settings",
243
+ description: "A group of help pages, as the help centre's menu shows them.",
244
+ fields: {
245
+ name: { type: "text", label: "Name", required: true },
246
+ slug: { type: "slug", label: "Address" },
247
+ order: { type: "number", label: "Order", step: 1 },
248
+ icon: { type: "select", label: "Icon", options: HELP_ICONS },
249
+ },
250
+ indexes: [["order"]],
251
+ // Every live topic is public: a help centre's menu.
252
+ public: { read: ["name", "slug", "order", "icon"] },
253
+ },
254
+ },
255
+ views: {
256
+ procedureDrafts: {
257
+ label: "Procedure drafts",
258
+ object: "knowledge.procedure",
259
+ filter: { field: "publishState", op: "eq", value: "draft" },
260
+ sort: { field: "updatedAt", direction: "desc" },
261
+ columns: ["title", "section", "owner", "updatedAt"],
262
+ },
263
+ procedures: {
264
+ label: "Published procedures",
265
+ object: "knowledge.procedure",
266
+ filter: { field: "publishState", op: "eq", value: "published" },
267
+ sort: { field: "title", direction: "asc" },
268
+ columns: ["title", "section", "owner", "publishedVersion", "publishedAt", "nextReview"],
269
+ },
270
+ reviewDue: {
271
+ label: "Procedures by next review",
272
+ object: "knowledge.procedure",
273
+ filter: {
274
+ and: [
275
+ { field: "publishState", op: "eq", value: "published" },
276
+ { field: "nextReview", op: "is_not_null" },
277
+ ],
278
+ },
279
+ sort: { field: "nextReview", direction: "asc" },
280
+ columns: ["title", "owner", "nextReview", "publishedAt"],
281
+ },
282
+ helpDrafts: {
283
+ label: "Help page drafts",
284
+ object: "knowledge.helppage",
285
+ filter: { field: "publishState", op: "eq", value: "draft" },
286
+ sort: { field: "updatedAt", direction: "desc" },
287
+ columns: ["title", "topic", "updatedAt"],
288
+ },
289
+ helpPages: {
290
+ label: "Published help pages",
291
+ object: "knowledge.helppage",
292
+ filter: { field: "publishState", op: "eq", value: "published" },
293
+ sort: { field: "title", direction: "asc" },
294
+ columns: ["title", "topic", "publishedVersion", "publishedAt"],
295
+ },
296
+ },
297
+ recordTabs: {
298
+ sectionProcedures: {
299
+ label: "Procedures",
300
+ on: "knowledge.section",
301
+ view: {
302
+ type: "table",
303
+ object: "knowledge.procedure",
304
+ relation: "section",
305
+ columns: ["title", "publishState", "owner", "nextReview"],
306
+ sort: { field: "title", direction: "asc" },
307
+ },
308
+ order: 10,
309
+ },
310
+ topicPages: {
311
+ label: "Help pages",
312
+ on: "knowledge.helptopic",
313
+ view: {
314
+ type: "table",
315
+ object: "knowledge.helppage",
316
+ relation: "topic",
317
+ columns: ["title", "publishState", "order"],
318
+ sort: { field: "order", direction: "asc" },
319
+ },
320
+ order: 10,
321
+ },
322
+ },
323
+ tools: { toRead, confirm, readStatus, helpTopics, draftProcedure, draftHelpPage },
324
+ automations: knowledgeAutomations,
325
+ });
@@ -0,0 +1,131 @@
1
+ import { z } from "@composable-os/sdk";
2
+ export declare const PROCEDURE = "knowledge.procedure";
3
+ export declare const SECTION = "knowledge.section";
4
+ export declare const HELP_PAGE = "knowledge.helppage";
5
+ export declare const HELP_TOPIC = "knowledge.helptopic";
6
+ export declare const MANAGE = "knowledge:manage";
7
+ export declare const WRITE = "knowledge:write";
8
+ type Inline = {
9
+ type: "text";
10
+ text: string;
11
+ };
12
+ type Block = {
13
+ type: "paragraph";
14
+ content: Inline[];
15
+ } | {
16
+ type: "heading";
17
+ level: number;
18
+ content: Inline[];
19
+ } | {
20
+ type: "list";
21
+ style: "bullet" | "ordered";
22
+ items: {
23
+ content: Inline[];
24
+ }[];
25
+ };
26
+ /**
27
+ * Notes as the platform's rich text (ADR 0440): `#`, `##` and `###` start a heading (a section of
28
+ * the procedure, which search and citations link to), `-` or `*` a bullet, `1.` a numbered step,
29
+ * and a blank line ends a paragraph. Everything else is plain words: no HTML, no marks.
30
+ */
31
+ export declare function notesToRichText(notes: string): {
32
+ blocks: Block[];
33
+ };
34
+ export declare const toRead: import("@composable-os/sdk").ToolSpec<z.ZodObject<{}, z.core.$strip>, z.ZodObject<{
35
+ toRead: z.ZodArray<z.ZodObject<{
36
+ id: z.ZodString;
37
+ title: z.ZodNullable<z.ZodString>;
38
+ version: z.ZodNumber;
39
+ publishedAt: z.ZodString;
40
+ since: z.ZodString;
41
+ }, z.core.$strip>>;
42
+ confirmed: z.ZodArray<z.ZodObject<{
43
+ id: z.ZodString;
44
+ title: z.ZodNullable<z.ZodString>;
45
+ version: z.ZodNumber;
46
+ publishedAt: z.ZodString;
47
+ confirmedAt: z.ZodString;
48
+ }, z.core.$strip>>;
49
+ }, z.core.$strip>>;
50
+ export declare const confirm: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
51
+ id: z.ZodString;
52
+ version: z.ZodNumber;
53
+ }, z.core.$strip>, z.ZodObject<{
54
+ id: z.ZodString;
55
+ version: z.ZodNumber;
56
+ confirmedAt: z.ZodString;
57
+ }, z.core.$strip>>;
58
+ export declare const readStatus: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
59
+ id: z.ZodOptional<z.ZodString>;
60
+ }, z.core.$strip>, z.ZodObject<{
61
+ procedures: z.ZodArray<z.ZodObject<{
62
+ id: z.ZodString;
63
+ title: z.ZodNullable<z.ZodString>;
64
+ version: z.ZodNumber;
65
+ publishedAt: z.ZodString;
66
+ mustRead: z.ZodNumber;
67
+ confirmed: z.ZodNumber;
68
+ }, z.core.$strip>>;
69
+ procedure: z.ZodNullable<z.ZodObject<{
70
+ id: z.ZodString;
71
+ title: z.ZodNullable<z.ZodString>;
72
+ version: z.ZodNumber;
73
+ publishedAt: z.ZodString;
74
+ everyone: z.ZodBoolean;
75
+ roles: z.ZodArray<z.ZodString>;
76
+ people: z.ZodArray<z.ZodObject<{
77
+ account: z.ZodString;
78
+ name: z.ZodString;
79
+ email: z.ZodString;
80
+ confirmed: z.ZodNullable<z.ZodObject<{
81
+ version: z.ZodNumber;
82
+ confirmedAt: z.ZodString;
83
+ }, z.core.$strip>>;
84
+ lastConfirmed: z.ZodNullable<z.ZodObject<{
85
+ version: z.ZodNumber;
86
+ confirmedAt: z.ZodString;
87
+ }, z.core.$strip>>;
88
+ since: z.ZodNullable<z.ZodString>;
89
+ }, z.core.$strip>>;
90
+ }, z.core.$strip>>;
91
+ }, z.core.$strip>>;
92
+ export declare const helpTopics: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
93
+ limit: z.ZodDefault<z.ZodNumber>;
94
+ }, z.core.$strip>, z.ZodObject<{
95
+ topics: z.ZodArray<z.ZodObject<{
96
+ id: z.ZodString;
97
+ name: z.ZodNullable<z.ZodString>;
98
+ slug: z.ZodNullable<z.ZodString>;
99
+ order: z.ZodNullable<z.ZodNumber>;
100
+ icon: z.ZodNullable<z.ZodString>;
101
+ }, z.core.$strip>>;
102
+ }, z.core.$strip>>;
103
+ export declare const draftProcedure: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
104
+ section: z.ZodOptional<z.ZodString>;
105
+ id: z.ZodOptional<z.ZodString>;
106
+ title: z.ZodString;
107
+ summary: z.ZodOptional<z.ZodString>;
108
+ notes: z.ZodOptional<z.ZodString>;
109
+ }, z.core.$strip>, z.ZodObject<{
110
+ id: z.ZodString;
111
+ created: z.ZodBoolean;
112
+ open: z.ZodObject<{
113
+ object: z.ZodString;
114
+ id: z.ZodString;
115
+ }, z.core.$strip>;
116
+ }, z.core.$strip>>;
117
+ export declare const draftHelpPage: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
118
+ topic: z.ZodOptional<z.ZodString>;
119
+ id: z.ZodOptional<z.ZodString>;
120
+ title: z.ZodString;
121
+ summary: z.ZodOptional<z.ZodString>;
122
+ notes: z.ZodOptional<z.ZodString>;
123
+ }, z.core.$strip>, z.ZodObject<{
124
+ id: z.ZodString;
125
+ created: z.ZodBoolean;
126
+ open: z.ZodObject<{
127
+ object: z.ZodString;
128
+ id: z.ZodString;
129
+ }, z.core.$strip>;
130
+ }, z.core.$strip>>;
131
+ export {};