@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/LICENSE ADDED
@@ -0,0 +1,109 @@
1
+ # Functional Source License, Version 1.1, ALv2 Future License
2
+
3
+ > This licence covers the repository except the directories listed in NOTICE. In particular, the
4
+ > assistant packages `packages/agent-*` (agent-core, agent-a2ui, agent-voice, agent-plugins) are
5
+ > licensed under the MIT License; see the LICENSE file in each of those directories (ADR 0350).
6
+
7
+ ## Abbreviation
8
+
9
+ FSL-1.1-ALv2
10
+
11
+ ## Notice
12
+
13
+ Copyright 2026 Tim O'Connell
14
+
15
+ ## Terms and Conditions
16
+
17
+ ### Licensor ("We")
18
+
19
+ The party offering the Software under these Terms and Conditions.
20
+
21
+ ### The Software
22
+
23
+ The "Software" is each version of the software that we make available under
24
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
25
+ Conditions with the Software.
26
+
27
+ ### License Grant
28
+
29
+ Subject to your compliance with this License Grant and the Patents,
30
+ Redistribution and Trademark clauses below, we hereby grant you the right to
31
+ use, copy, modify, create derivative works, publicly perform, publicly display
32
+ and redistribute the Software for any Permitted Purpose identified below.
33
+
34
+ ### Permitted Purpose
35
+
36
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
37
+ means making the Software available to others in a commercial product or
38
+ service that:
39
+
40
+ 1. substitutes for the Software;
41
+
42
+ 2. substitutes for any other product or service we offer using the Software
43
+ that exists as of the date we make the Software available; or
44
+
45
+ 3. offers the same or substantially similar functionality as the Software.
46
+
47
+ Permitted Purposes specifically include using the Software:
48
+
49
+ 1. for your internal use and access;
50
+
51
+ 2. for non-commercial education;
52
+
53
+ 3. for non-commercial research; and
54
+
55
+ 4. in connection with professional services that you provide to a licensee
56
+ using the Software in accordance with these Terms and Conditions.
57
+
58
+ ### Patents
59
+
60
+ To the extent your use for a Permitted Purpose would necessarily infringe our
61
+ patents, the license grant above includes a license under our patents. If you
62
+ make a claim against any party that the Software infringes or contributes to
63
+ the infringement of any patent, then your patent license to the Software ends
64
+ immediately.
65
+
66
+ ### Redistribution
67
+
68
+ The Terms and Conditions apply to all copies, modifications and derivatives of
69
+ the Software.
70
+
71
+ If you redistribute any copies, modifications or derivatives of the Software,
72
+ you must include a copy of or a link to these Terms and Conditions and not
73
+ remove any copyright notices provided in or with the Software.
74
+
75
+ ### Disclaimer
76
+
77
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
78
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
79
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
80
+
81
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
82
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
83
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
84
+
85
+ ### Trademarks
86
+
87
+ Except for displaying the License Details and identifying us as the origin of
88
+ the Software, you have no right under these Terms and Conditions to use our
89
+ trademarks, trade names, service marks or product names.
90
+
91
+ ## Grant of Future License
92
+
93
+ We hereby irrevocably grant you an additional license to use the Software under
94
+ the Apache License, Version 2.0 that is effective on the second anniversary of
95
+ the date we make the Software available. On or after that date, you may use the
96
+ Software under the Apache License, Version 2.0, in which case the following
97
+ will apply:
98
+
99
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
100
+ this file except in compliance with the License.
101
+
102
+ You may obtain a copy of the License at
103
+
104
+ http://www.apache.org/licenses/LICENSE-2.0
105
+
106
+ Unless required by applicable law or agreed to in writing, software distributed
107
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
108
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
109
+ specific language governing permissions and limitations under the License.
@@ -0,0 +1,14 @@
1
+ export declare const reviewDue: import("@composable-os/sdk").AutomationSpec<{
2
+ readonly type: "dateRelative";
3
+ readonly object: "knowledge.procedure";
4
+ readonly field: "nextReview";
5
+ readonly offsetDays: 0;
6
+ }>;
7
+ export declare const knowledgeAutomations: {
8
+ reviewDue: import("@composable-os/sdk").AutomationSpec<{
9
+ readonly type: "dateRelative";
10
+ readonly object: "knowledge.procedure";
11
+ readonly field: "nextReview";
12
+ readonly offsetDays: 0;
13
+ }>;
14
+ };
@@ -0,0 +1,42 @@
1
+ // The Knowledge automations (stage 38 step 5, ADR 0706). The notices of read and understood (a
2
+ // version to read, the 7-day reminder, the owners' weekly notice, the welcome of a new account)
3
+ // are the host's, in this pack's words (`acknowledge.notices` in index.ts): only the host knows who
4
+ // must read a procedure and who has not. This one is the review reminder: on a procedure's next
5
+ // review date (its last publish plus its "review every" months, a formula; none when it is 0),
6
+ // its owner is told to check it is still right, or the admins when it has none.
7
+ import { defineAutomation } from "@composable-os/sdk";
8
+ import { PROCEDURE } from "./tools.js";
9
+ export const reviewDue = defineAutomation({
10
+ label: "Time to review a procedure",
11
+ description: "On a published procedure's next review date (its last publish plus its review period, 12 " +
12
+ "months unless set; never when 0), tells its owner to check it is still right, or the " +
13
+ "admins when it has no owner.",
14
+ trigger: { type: "dateRelative", object: PROCEDURE, field: "nextReview", offsetDays: 0 },
15
+ // No condition: the next review is empty while the procedure is not published (no version).
16
+ steps: [
17
+ {
18
+ name: "tell",
19
+ label: "Tell the owner, or the admins",
20
+ notifies: [
21
+ { to: { field: "owner" }, message: "Time to check this is still right: {record}" },
22
+ { to: "admins", message: "Time to check this is still right: {record}" },
23
+ ],
24
+ },
25
+ ],
26
+ async run(event, step, ctx) {
27
+ const procedure = event.record;
28
+ if (!procedure)
29
+ return { skipped: "no procedure" };
30
+ return step.do("tell", async () => {
31
+ const owner = procedure.data?.owner;
32
+ await ctx.notify(typeof owner === "string" && owner ? { field: "owner" } : "admins", {
33
+ title: "Time to check this is still right: {record}",
34
+ body: "Read the procedure as it is published. If it is still right, publish it again as a " +
35
+ "small fix to start a new review period; if not, change it and publish.",
36
+ link: "record",
37
+ });
38
+ return { told: typeof owner === "string" && owner ? "owner" : "admins" };
39
+ });
40
+ },
41
+ });
42
+ export const knowledgeAutomations = { reviewDue };
@@ -0,0 +1,468 @@
1
+ import { type ClientHolding, type PackClient, type UseMutation, type UseQuery } from "@composable-os/client";
2
+ import type { z } from "@composable-os/sdk";
3
+ import type { confirm, helpTopics, readStatus, toRead } from "../tools.ts";
4
+ type Io<T extends {
5
+ input: z.ZodType;
6
+ output: z.ZodType;
7
+ }> = {
8
+ input: z.input<T["input"]>;
9
+ output: z.output<T["output"]>;
10
+ };
11
+ /** The objects, as the host names them. */
12
+ export declare const PROCEDURE = "knowledge.procedure";
13
+ export declare const HELP_PAGE = "knowledge.helppage";
14
+ /** A published record as staff or the public read it: its content fields and its slug. */
15
+ export interface Published {
16
+ object: string;
17
+ id: string;
18
+ values: Record<string, unknown>;
19
+ version?: number;
20
+ publishedAt?: string;
21
+ }
22
+ /** A part of a highlighted title, heading or snippet: plain, or a matching word. */
23
+ export interface Segment {
24
+ text: string;
25
+ match: boolean;
26
+ }
27
+ export interface SearchHit {
28
+ object: string;
29
+ id: string;
30
+ slug: string;
31
+ title: string | null;
32
+ titleHighlight: Segment[];
33
+ version: number;
34
+ section: {
35
+ field: string;
36
+ anchor: string | null;
37
+ heading: string;
38
+ headingHighlight: Segment[];
39
+ };
40
+ snippet: Segment[] | null;
41
+ }
42
+ type Page<T> = {
43
+ items: T[];
44
+ nextCursor: string | null;
45
+ };
46
+ type ListInput = {
47
+ object: string;
48
+ filter?: unknown;
49
+ sort?: {
50
+ field: string;
51
+ direction: "asc" | "desc";
52
+ };
53
+ cursor?: string;
54
+ limit?: number;
55
+ };
56
+ /** The operations this entry calls, as the generated client types them. */
57
+ export type KnowledgeOperations = {
58
+ "content.staffGet": {
59
+ kind: "query";
60
+ input: {
61
+ object: string;
62
+ id?: string;
63
+ slug?: string;
64
+ };
65
+ output: Published & {
66
+ redirect?: string;
67
+ };
68
+ };
69
+ "content.staffList": {
70
+ kind: "query";
71
+ input: ListInput;
72
+ output: Page<Published>;
73
+ };
74
+ "x.knowledge.toRead": {
75
+ kind: "query";
76
+ } & Io<typeof toRead>;
77
+ "x.knowledge.confirm": {
78
+ kind: "mutation";
79
+ } & Io<typeof confirm>;
80
+ "x.knowledge.readStatus": {
81
+ kind: "query";
82
+ } & Io<typeof readStatus>;
83
+ "content.get": {
84
+ kind: "query";
85
+ input: {
86
+ object: string;
87
+ slug: string;
88
+ };
89
+ output: (Published & {
90
+ kind: "record";
91
+ }) | {
92
+ kind: "redirect";
93
+ object: string;
94
+ slug: string;
95
+ };
96
+ };
97
+ "content.list": {
98
+ kind: "query";
99
+ input: ListInput;
100
+ output: Page<Published>;
101
+ };
102
+ "content.search": {
103
+ kind: "query";
104
+ input: {
105
+ object: string;
106
+ q: string;
107
+ cursor?: string;
108
+ limit?: number;
109
+ };
110
+ output: Page<SearchHit>;
111
+ };
112
+ "x.knowledge.helpTopics": {
113
+ kind: "query";
114
+ } & Io<typeof helpTopics>;
115
+ };
116
+ type Name = keyof KnowledgeOperations & string;
117
+ type In<N extends Name> = KnowledgeOperations[N]["input"];
118
+ /** The client of every operation this entry calls (ADR 0453). */
119
+ export type KnowledgeClient = PackClient<KnowledgeOperations>;
120
+ export type { UseMutation, UseQuery } from "@composable-os/client";
121
+ /**
122
+ * The operations each hook calls (ADR 0453). The staff client (a pack-role account's too) gets
123
+ * the procedure hooks; a customer's client and the public's get the help centre's.
124
+ */
125
+ export declare const KNOWLEDGE_HOOKS_CALL: {
126
+ readonly useProcedures: readonly ["content.staffList"];
127
+ readonly useProcedure: readonly ["content.staffGet"];
128
+ readonly useSearchProcedures: readonly ["content.search"];
129
+ readonly useToRead: readonly ["x.knowledge.toRead"];
130
+ readonly useConfirm: readonly ["x.knowledge.confirm"];
131
+ readonly useReadStatus: readonly ["x.knowledge.readStatus"];
132
+ readonly useHelpTopics: readonly ["x.knowledge.helpTopics"];
133
+ readonly useHelpPages: readonly ["content.list"];
134
+ readonly useHelpPage: readonly ["content.get"];
135
+ readonly useSearchHelp: readonly ["content.search"];
136
+ };
137
+ /**
138
+ * Hooks for a React or React Native app:
139
+ * `const knowledge = createKnowledgeHooks({ useQuery, useMutation }, api)`. The hooks a client
140
+ * cannot back are not there, and calling one does not compile.
141
+ */
142
+ export declare function createKnowledgeHooks<C extends ClientHolding>(react: {
143
+ useQuery: UseQuery;
144
+ useMutation: UseMutation;
145
+ }, client: C): import("@composable-os/client").HooksFor<{
146
+ /** Staff: a page of published procedures (by section, or as asked). */
147
+ useProcedures(input?: Omit<In<"content.staffList">, "object">): {
148
+ data: Page<Published> | undefined;
149
+ isPending: boolean;
150
+ error: unknown;
151
+ refetch?: () => unknown;
152
+ };
153
+ /** Staff: one procedure as published, by id or address. */
154
+ useProcedure(by: {
155
+ id: string;
156
+ } | {
157
+ slug: string;
158
+ } | null): {
159
+ data: (Published & {
160
+ redirect?: string;
161
+ }) | undefined;
162
+ isPending: boolean;
163
+ error: unknown;
164
+ refetch?: () => unknown;
165
+ };
166
+ /** Staff: procedures whose published words match, each with its section's anchor. */
167
+ useSearchProcedures(q: string): {
168
+ data: Page<SearchHit> | undefined;
169
+ isPending: boolean;
170
+ error: unknown;
171
+ refetch?: () => unknown;
172
+ };
173
+ /** Staff: what I must read, and what I confirmed. */
174
+ useToRead(): {
175
+ data: {
176
+ toRead: {
177
+ id: string;
178
+ title: string | null;
179
+ version: number;
180
+ publishedAt: string;
181
+ since: string;
182
+ }[];
183
+ confirmed: {
184
+ id: string;
185
+ title: string | null;
186
+ version: number;
187
+ publishedAt: string;
188
+ confirmedAt: string;
189
+ }[];
190
+ } | undefined;
191
+ isPending: boolean;
192
+ error: unknown;
193
+ refetch?: () => unknown;
194
+ };
195
+ /** Staff: "I have read and understood this", for the version read. */
196
+ useConfirm(): {
197
+ mutate(input: {
198
+ id: string;
199
+ version: number;
200
+ }): void;
201
+ mutateAsync(input: {
202
+ id: string;
203
+ version: number;
204
+ }): Promise<{
205
+ id: string;
206
+ version: number;
207
+ confirmedAt: string;
208
+ }>;
209
+ data: {
210
+ id: string;
211
+ version: number;
212
+ confirmedAt: string;
213
+ } | undefined;
214
+ isPending: boolean;
215
+ error: unknown;
216
+ reset?: () => void;
217
+ };
218
+ /** Those who manage: who has read what (one procedure, or every one's counts). */
219
+ useReadStatus(id?: string): {
220
+ data: {
221
+ procedures: {
222
+ id: string;
223
+ title: string | null;
224
+ version: number;
225
+ publishedAt: string;
226
+ mustRead: number;
227
+ confirmed: number;
228
+ }[];
229
+ procedure: {
230
+ id: string;
231
+ title: string | null;
232
+ version: number;
233
+ publishedAt: string;
234
+ everyone: boolean;
235
+ roles: string[];
236
+ people: {
237
+ account: string;
238
+ name: string;
239
+ email: string;
240
+ confirmed: {
241
+ version: number;
242
+ confirmedAt: string;
243
+ } | null;
244
+ lastConfirmed: {
245
+ version: number;
246
+ confirmedAt: string;
247
+ } | null;
248
+ since: string | null;
249
+ }[];
250
+ } | null;
251
+ } | undefined;
252
+ isPending: boolean;
253
+ error: unknown;
254
+ refetch?: () => unknown;
255
+ };
256
+ /** Anyone: the help topics, in their order. */
257
+ useHelpTopics(): {
258
+ data: {
259
+ topics: {
260
+ id: string;
261
+ name: string | null;
262
+ slug: string | null;
263
+ order: number | null;
264
+ icon: string | null;
265
+ }[];
266
+ } | undefined;
267
+ isPending: boolean;
268
+ error: unknown;
269
+ refetch?: () => unknown;
270
+ };
271
+ /** Anyone: a page of published help pages (a topic's, or as asked). */
272
+ useHelpPages(input?: Omit<In<"content.list">, "object">): {
273
+ data: Page<Published> | undefined;
274
+ isPending: boolean;
275
+ error: unknown;
276
+ refetch?: () => unknown;
277
+ };
278
+ /** Anyone: one published help page by its address; an old address answers `redirect`. */
279
+ useHelpPage(slug: string | null): {
280
+ data: (Published & {
281
+ kind: "record";
282
+ }) | {
283
+ kind: "redirect";
284
+ object: string;
285
+ slug: string;
286
+ } | undefined;
287
+ isPending: boolean;
288
+ error: unknown;
289
+ refetch?: () => unknown;
290
+ };
291
+ /** Anyone: help pages whose published words match, as the reader types. */
292
+ useSearchHelp(q: string): {
293
+ data: Page<SearchHit> | undefined;
294
+ isPending: boolean;
295
+ error: unknown;
296
+ refetch?: () => unknown;
297
+ };
298
+ }, {
299
+ readonly useProcedures: readonly ["content.staffList"];
300
+ readonly useProcedure: readonly ["content.staffGet"];
301
+ readonly useSearchProcedures: readonly ["content.search"];
302
+ readonly useToRead: readonly ["x.knowledge.toRead"];
303
+ readonly useConfirm: readonly ["x.knowledge.confirm"];
304
+ readonly useReadStatus: readonly ["x.knowledge.readStatus"];
305
+ readonly useHelpTopics: readonly ["x.knowledge.helpTopics"];
306
+ readonly useHelpPages: readonly ["content.list"];
307
+ readonly useHelpPage: readonly ["content.get"];
308
+ readonly useSearchHelp: readonly ["content.search"];
309
+ }, import("@composable-os/client").OperationsOf<C>>;
310
+ declare function allKnowledgeHooks(react: {
311
+ useQuery: UseQuery;
312
+ useMutation: UseMutation;
313
+ }, api: KnowledgeClient): {
314
+ /** Staff: a page of published procedures (by section, or as asked). */
315
+ useProcedures(input?: Omit<In<"content.staffList">, "object">): {
316
+ data: Page<Published> | undefined;
317
+ isPending: boolean;
318
+ error: unknown;
319
+ refetch?: () => unknown;
320
+ };
321
+ /** Staff: one procedure as published, by id or address. */
322
+ useProcedure(by: {
323
+ id: string;
324
+ } | {
325
+ slug: string;
326
+ } | null): {
327
+ data: (Published & {
328
+ redirect?: string;
329
+ }) | undefined;
330
+ isPending: boolean;
331
+ error: unknown;
332
+ refetch?: () => unknown;
333
+ };
334
+ /** Staff: procedures whose published words match, each with its section's anchor. */
335
+ useSearchProcedures(q: string): {
336
+ data: Page<SearchHit> | undefined;
337
+ isPending: boolean;
338
+ error: unknown;
339
+ refetch?: () => unknown;
340
+ };
341
+ /** Staff: what I must read, and what I confirmed. */
342
+ useToRead(): {
343
+ data: {
344
+ toRead: {
345
+ id: string;
346
+ title: string | null;
347
+ version: number;
348
+ publishedAt: string;
349
+ since: string;
350
+ }[];
351
+ confirmed: {
352
+ id: string;
353
+ title: string | null;
354
+ version: number;
355
+ publishedAt: string;
356
+ confirmedAt: string;
357
+ }[];
358
+ } | undefined;
359
+ isPending: boolean;
360
+ error: unknown;
361
+ refetch?: () => unknown;
362
+ };
363
+ /** Staff: "I have read and understood this", for the version read. */
364
+ useConfirm(): {
365
+ mutate(input: {
366
+ id: string;
367
+ version: number;
368
+ }): void;
369
+ mutateAsync(input: {
370
+ id: string;
371
+ version: number;
372
+ }): Promise<{
373
+ id: string;
374
+ version: number;
375
+ confirmedAt: string;
376
+ }>;
377
+ data: {
378
+ id: string;
379
+ version: number;
380
+ confirmedAt: string;
381
+ } | undefined;
382
+ isPending: boolean;
383
+ error: unknown;
384
+ reset?: () => void;
385
+ };
386
+ /** Those who manage: who has read what (one procedure, or every one's counts). */
387
+ useReadStatus(id?: string): {
388
+ data: {
389
+ procedures: {
390
+ id: string;
391
+ title: string | null;
392
+ version: number;
393
+ publishedAt: string;
394
+ mustRead: number;
395
+ confirmed: number;
396
+ }[];
397
+ procedure: {
398
+ id: string;
399
+ title: string | null;
400
+ version: number;
401
+ publishedAt: string;
402
+ everyone: boolean;
403
+ roles: string[];
404
+ people: {
405
+ account: string;
406
+ name: string;
407
+ email: string;
408
+ confirmed: {
409
+ version: number;
410
+ confirmedAt: string;
411
+ } | null;
412
+ lastConfirmed: {
413
+ version: number;
414
+ confirmedAt: string;
415
+ } | null;
416
+ since: string | null;
417
+ }[];
418
+ } | null;
419
+ } | undefined;
420
+ isPending: boolean;
421
+ error: unknown;
422
+ refetch?: () => unknown;
423
+ };
424
+ /** Anyone: the help topics, in their order. */
425
+ useHelpTopics(): {
426
+ data: {
427
+ topics: {
428
+ id: string;
429
+ name: string | null;
430
+ slug: string | null;
431
+ order: number | null;
432
+ icon: string | null;
433
+ }[];
434
+ } | undefined;
435
+ isPending: boolean;
436
+ error: unknown;
437
+ refetch?: () => unknown;
438
+ };
439
+ /** Anyone: a page of published help pages (a topic's, or as asked). */
440
+ useHelpPages(input?: Omit<In<"content.list">, "object">): {
441
+ data: Page<Published> | undefined;
442
+ isPending: boolean;
443
+ error: unknown;
444
+ refetch?: () => unknown;
445
+ };
446
+ /** Anyone: one published help page by its address; an old address answers `redirect`. */
447
+ useHelpPage(slug: string | null): {
448
+ data: (Published & {
449
+ kind: "record";
450
+ }) | {
451
+ kind: "redirect";
452
+ object: string;
453
+ slug: string;
454
+ } | undefined;
455
+ isPending: boolean;
456
+ error: unknown;
457
+ refetch?: () => unknown;
458
+ };
459
+ /** Anyone: help pages whose published words match, as the reader types. */
460
+ useSearchHelp(q: string): {
461
+ data: Page<SearchHit> | undefined;
462
+ isPending: boolean;
463
+ error: unknown;
464
+ refetch?: () => unknown;
465
+ };
466
+ };
467
+ /** Every hook of this entry. A block takes the ones it calls: `Pick<KnowledgeHooks, "useToRead">`. */
468
+ export type KnowledgeHooks = ReturnType<typeof allKnowledgeHooks>;