@yaks/task 0.0.0-stage → 0.2.36

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 (68) hide show
  1. package/DecisionForm.js +118 -0
  2. package/DecisionForm.js.map +1 -0
  3. package/DecisionForm.ts +211 -0
  4. package/LICENSE +202 -0
  5. package/README.md +389 -2
  6. package/_dist/DecisionForm.d.ts +25 -0
  7. package/_dist/DecisionForm.d.ts.map +1 -0
  8. package/_dist/comp.d.ts +20 -0
  9. package/_dist/comp.d.ts.map +1 -0
  10. package/_dist/decision.d.ts +41 -0
  11. package/_dist/decision.d.ts.map +1 -0
  12. package/_dist/deps.d.ts +58 -0
  13. package/_dist/deps.d.ts.map +1 -0
  14. package/_dist/graph.d.ts +3 -0
  15. package/_dist/graph.d.ts.map +1 -0
  16. package/_dist/mod.d.ts +71 -0
  17. package/_dist/mod.d.ts.map +1 -0
  18. package/_dist/plugin.d.ts +28 -0
  19. package/_dist/plugin.d.ts.map +1 -0
  20. package/_dist/text.d.ts +5 -0
  21. package/_dist/text.d.ts.map +1 -0
  22. package/_dist/tools.d.ts +20 -0
  23. package/_dist/tools.d.ts.map +1 -0
  24. package/_dist/views.d.ts +6 -0
  25. package/_dist/views.d.ts.map +1 -0
  26. package/_dist/vocab.d.ts +7 -0
  27. package/_dist/vocab.d.ts.map +1 -0
  28. package/_dist/words.d.ts +28 -0
  29. package/_dist/words.d.ts.map +1 -0
  30. package/comp.js +66 -0
  31. package/comp.js.map +1 -0
  32. package/comp.ts +77 -0
  33. package/decision.js +156 -0
  34. package/decision.js.map +1 -0
  35. package/decision.ts +174 -0
  36. package/deno.json +1 -0
  37. package/deps.js +127 -0
  38. package/deps.js.map +1 -0
  39. package/deps.ts +163 -0
  40. package/graph.js +9 -0
  41. package/graph.js.map +1 -0
  42. package/graph.ts +10 -0
  43. package/inspect.js +131 -0
  44. package/inspect.js.map +1 -0
  45. package/inspect.ts +144 -0
  46. package/mod.js +71 -0
  47. package/mod.js.map +1 -0
  48. package/mod.ts +83 -0
  49. package/package.json +53 -4
  50. package/plugin.js +46 -0
  51. package/plugin.js.map +1 -0
  52. package/plugin.ts +40 -0
  53. package/text.js +22 -0
  54. package/text.js.map +1 -0
  55. package/text.ts +30 -0
  56. package/tools.js +303 -0
  57. package/tools.js.map +1 -0
  58. package/tools.ts +282 -0
  59. package/views.js +35 -0
  60. package/views.js.map +1 -0
  61. package/views.ts +39 -0
  62. package/vocab.js +18 -0
  63. package/vocab.js.map +1 -0
  64. package/vocab.json +860 -0
  65. package/vocab.ts +20 -0
  66. package/words.js +46 -0
  67. package/words.js.map +1 -0
  68. package/words.ts +57 -0
package/mod.ts ADDED
@@ -0,0 +1,83 @@
1
+ /**
2
+ * @yaks/task — a to-do list as a set of components for a
3
+ * {@link https://jsr.io/@yaks/graph | @yaks/graph}.
4
+ *
5
+ * Say a team keeps a list of what it has to do. Four things come up, and this
6
+ * package is the four answers:
7
+ *
8
+ * - **What is on the list?** An entity with a `task{}` component is a to-do
9
+ * item. `task` is one component among the entity's others, not a record type
10
+ * of its own: the same entity also carries your `doc`, your `estimate`,
11
+ * anything else it is — adding `task` to something makes it something to do
12
+ * without making it stop being what it was. @yaks/project's optional
13
+ * `filed{project, priority, domain, assignee}` places it in a portfolio.
14
+ * - **Where does it stand?** No stored property holds the answer. A task with a
15
+ * `completed` component (@yaks/kernel's mark) is done, one with `cancelled`
16
+ * is cancelled, one with `started` is wip, and one with none is open. `status` is computed from
17
+ * those components, so finishing something records when and by whom instead
18
+ * of overwriting a value, and reopening it means removing a component rather
19
+ * than guessing what the status used to be.
20
+ * - **How do you look at the list?** A `board{query}` is a saved filter. Its
21
+ * membership is never stored — no row records that a task is on a board — so
22
+ * a board is always current, and a task that starts matching the query is on
23
+ * it. The empty query selects nothing, on purpose.
24
+ * - **What is it waiting for?** `requires` and `contains` relate one task to
25
+ * another through {@link https://jsr.io/@yaks/edge | @yaks/edge}, and
26
+ * `blocked{on}` records that something outside the graph is in the way.
27
+ *
28
+ * ## Blocked is not a status
29
+ * There is no `blocked` status, and that is a decision rather than an omission.
30
+ * A blocked task is still open work: rolling it into the status would hide it
31
+ * from every query for open work exactly when somebody needs to see it. So
32
+ * `blocked` is a component read by {@link gated}, and unfinished children are
33
+ * an ordinary count read by {@link openDeps} — "3 left", never an alarm.
34
+ *
35
+ * ## The status rule is written once
36
+ * The rule is data in the vocabulary: `task` declares its status as a ladder
37
+ * of marks (`"status": {"cancelled": "cancelled", "completed": "done",
38
+ * "started": "wip", "default": "open"}`, @yaks/vocab's `status` keyword). @yaks/sql and
39
+ * @yaks/match read it from that declaration, so a saved filter selects the
40
+ * same tasks in a database and in a page, and {@link statusOf} reads it off an
41
+ * entity in hand. A graph that leases its tasks adds a rung where it declares
42
+ * the lease: @yaks/session reads a held claim as `wip`.
43
+ *
44
+ * ## Use
45
+ * ```ts
46
+ * import { loadVocab } from '@yaks/vocab'
47
+ * import { graph } from '@yaks/graph'
48
+ * import { ram } from '@yaks/ram'
49
+ * import { kernel, kernelDoc, kernelKeywords } from '@yaks/kernel'
50
+ * import { edgeDoc, edgeKeywords, edges } from '@yaks/edge'
51
+ * import { taskDoc, tasks } from '@yaks/task'
52
+ *
53
+ * let vocab = loadVocab([kernelDoc, edgeDoc, taskDoc], [
54
+ * kernelKeywords,
55
+ * edgeKeywords,
56
+ * ])
57
+ * let plugins = [kernel(), edges(vocab), tasks()]
58
+ * let g = graph({ storage: ram(vocab), vocab, plugins })
59
+ * await g.apply([{ entity: { eid: 't1' }, task: {}, completed: {} }])
60
+ * ```
61
+ *
62
+ * It imports no platform API, so the same list runs on a server, in a worker,
63
+ * and in a browser tab.
64
+ *
65
+ * @module
66
+ */
67
+
68
+ export * from './words.js'
69
+ export * from './comp.js'
70
+ export * from './deps.js'
71
+ export * from './plugin.js'
72
+
73
+ export {
74
+ answer,
75
+ asked,
76
+ type Choice,
77
+ type Decision,
78
+ DECISION_SETTLED,
79
+ showing,
80
+ type Shown,
81
+ shown,
82
+ waiting,
83
+ } from './decision.js'
package/package.json CHANGED
@@ -1,6 +1,55 @@
1
1
  {
2
2
  "name": "@yaks/task",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.36",
4
+ "homepage": "https://jsr.io/@yaks/task",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./_dist/mod.d.ts",
9
+ "default": "./mod.js"
10
+ },
11
+ "./vocab": {
12
+ "types": "./_dist/vocab.d.ts",
13
+ "default": "./vocab.js"
14
+ },
15
+ "./graph": {
16
+ "types": "./_dist/graph.d.ts",
17
+ "default": "./graph.js"
18
+ },
19
+ "./tools": {
20
+ "types": "./_dist/tools.d.ts",
21
+ "default": "./tools.js"
22
+ },
23
+ "./text": {
24
+ "types": "./_dist/text.d.ts",
25
+ "default": "./text.js"
26
+ },
27
+ "./form": {
28
+ "types": "./_dist/DecisionForm.d.ts",
29
+ "default": "./DecisionForm.js"
30
+ },
31
+ "./views": {
32
+ "types": "./_dist/views.d.ts",
33
+ "default": "./views.js"
34
+ }
35
+ },
36
+ "license": "Apache-2.0",
37
+ "dependencies": {
38
+ "@yaks/draft": "0.2.36",
39
+ "@yaks/edge": "0.2.36",
40
+ "@yaks/fp": "0.2.36",
41
+ "@yaks/graph": "0.2.36",
42
+ "@yaks/inspect": "0.2.36",
43
+ "@yaks/markdown": "0.2.36",
44
+ "@yaks/match": "0.2.36",
45
+ "@yaks/query": "0.2.36",
46
+ "@yaks/render": "0.2.36",
47
+ "@yaks/ui": "0.2.36",
48
+ "@yaks/ux": "0.2.36",
49
+ "@yaks/vocab": "0.2.36",
50
+ "@types/react": "19.3.0",
51
+ "react": "19.3.0"
52
+ },
53
+ "description": "Task components for a graph: a status computed from marks instead of stored, dependency counts, and completion attribution.",
54
+ "repository": "https://github.com/yak-sh/yak.git"
55
+ }
package/plugin.js ADDED
@@ -0,0 +1,46 @@
1
+ // The package as a graph plugin: the components it declares. Who finished a
2
+ // task is kept on @yaks/kernel's `completed` mark by the kernel's own plugin.
3
+ // What a task is filed under, and the board that is a saved filter over the
4
+ // filing, belong to @yaks/project — and so does the guard over a board's query.
5
+ import { hook } from "@yaks/graph/plugin";
6
+ import { deciding } from "./decision.js";
7
+ import { taskDoc } from "./comp.js";
8
+ /**
9
+ * The task plugin: the `task`, `cancelled` and `blocked` components and the
10
+ * `requires` and `contains` relations. A task is done when it wears
11
+ * @yaks/kernel's `completed`, so a graph of tasks loads the kernel beside it.
12
+ *
13
+ * ```ts
14
+ * import { loadVocab } from '@yaks/vocab'
15
+ * import { graph } from '@yaks/graph'
16
+ * import { ram } from '@yaks/ram'
17
+ * import { kernel, kernelDoc, kernelKeywords } from '@yaks/kernel'
18
+ * import { edgeDoc, edgeKeywords, edges } from '@yaks/edge'
19
+ * import { taskDoc, tasks } from '@yaks/task'
20
+ *
21
+ * let vocab = loadVocab([kernelDoc, edgeDoc, taskDoc], [
22
+ * kernelKeywords,
23
+ * edgeKeywords,
24
+ * ])
25
+ * let plugins = [kernel(), edges(vocab), tasks()]
26
+ * let g = graph({ storage: ram(vocab), vocab, plugins })
27
+ * ```
28
+ *
29
+ * The status itself is not stored and not written. `task` declares it as a
30
+ * ladder of marks in the vocabulary (@yaks/vocab's `status` keyword), and
31
+ * every store reads it from there. A graph that leases its tasks adds a rung
32
+ * where it declares the lease, as @yaks/session reads a held claim as `wip`.
33
+ */ export let tasks = ()=>({
34
+ name: '@yaks/task',
35
+ vocab: [
36
+ taskDoc
37
+ ],
38
+ hooks: {
39
+ precondition: hook([
40
+ 'decision',
41
+ 'decided',
42
+ 'task'
43
+ ], deciding)
44
+ }
45
+ });
46
+ //# sourceMappingURL=plugin.js.map
package/plugin.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["./plugin.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,8EAA8E;AAC9E,4EAA4E;AAC5E,gFAAgF;AAEhF,SAAS,IAAI,kCAAoD;AACjE,SAAS,QAAQ,wBAAuB;AACxC,SAAS,OAAO,oBAAmB;AAEnC;;;;;;;;;;;;;;;;;;;;;;;;;CAyBC,GACD,OAAO,IAAI,QAAQ,IAAc,CAAC;IAChC,MAAM;IACN,OAAO;MAAC;KAAQ;IAChB,OAAO;MAAE,cAAc,KAAK;QAAC;QAAY;QAAW;OAAO,EAAE;IAAU;EACzE,CAAC,EAAC"}
package/plugin.ts ADDED
@@ -0,0 +1,40 @@
1
+ // The package as a graph plugin: the components it declares. Who finished a
2
+ // task is kept on @yaks/kernel's `completed` mark by the kernel's own plugin.
3
+ // What a task is filed under, and the board that is a saved filter over the
4
+ // filing, belong to @yaks/project — and so does the guard over a board's query.
5
+
6
+ import { hook, type Plugin } from '@yaks/graph/plugin'
7
+ import { deciding } from './decision.js'
8
+ import { taskDoc } from './comp.js'
9
+
10
+ /**
11
+ * The task plugin: the `task`, `cancelled` and `blocked` components and the
12
+ * `requires` and `contains` relations. A task is done when it wears
13
+ * @yaks/kernel's `completed`, so a graph of tasks loads the kernel beside it.
14
+ *
15
+ * ```ts
16
+ * import { loadVocab } from '@yaks/vocab'
17
+ * import { graph } from '@yaks/graph'
18
+ * import { ram } from '@yaks/ram'
19
+ * import { kernel, kernelDoc, kernelKeywords } from '@yaks/kernel'
20
+ * import { edgeDoc, edgeKeywords, edges } from '@yaks/edge'
21
+ * import { taskDoc, tasks } from '@yaks/task'
22
+ *
23
+ * let vocab = loadVocab([kernelDoc, edgeDoc, taskDoc], [
24
+ * kernelKeywords,
25
+ * edgeKeywords,
26
+ * ])
27
+ * let plugins = [kernel(), edges(vocab), tasks()]
28
+ * let g = graph({ storage: ram(vocab), vocab, plugins })
29
+ * ```
30
+ *
31
+ * The status itself is not stored and not written. `task` declares it as a
32
+ * ladder of marks in the vocabulary (@yaks/vocab's `status` keyword), and
33
+ * every store reads it from there. A graph that leases its tasks adds a rung
34
+ * where it declares the lease, as @yaks/session reads a held claim as `wip`.
35
+ */
36
+ export let tasks = (): Plugin => ({
37
+ name: '@yaks/task',
38
+ vocab: [taskDoc],
39
+ hooks: { precondition: hook(['decision', 'decided', 'task'], deciding) },
40
+ })
package/text.js ADDED
@@ -0,0 +1,22 @@
1
+ let TITLE_LENGTH = 120;
2
+ let firstLine = (text)=>text.trim().split(/\r?\n/, 1)[0].trim();
3
+ let firstSentence = (text)=>text.match(/^.*?[.!?。!?](?=\s|$)/u)?.[0] ?? text;
4
+ let shortTitle = (text)=>{
5
+ let chars = Array.from(text);
6
+ if (chars.length <= TITLE_LENGTH) return text;
7
+ let part = chars.slice(0, TITLE_LENGTH - 1).join('');
8
+ let word = part.replace(/\s+\S*$/u, '');
9
+ return (word || part) + '…';
10
+ };
11
+ /** A short task title and the words that supplied it, kept in full. */ export let taskText = (title, body)=>{
12
+ let text = firstLine(title);
13
+ let words = body?.trim() ? body : title;
14
+ let fromWords = words.trimStart().startsWith(title.trim());
15
+ let summary = shortTitle(text);
16
+ if (fromWords || summary != text) summary = shortTitle(firstSentence(text));
17
+ return {
18
+ title: summary,
19
+ body: !fromWords && summary != title ? title + '\n\n' + words : words
20
+ };
21
+ };
22
+ //# sourceMappingURL=text.js.map
package/text.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.js","sources":["./text.ts"],"names":[],"mappings":"AAAA,IAAI,eAAe;AAEnB,IAAI,YAAY,CAAC,OAAiB,KAAK,IAAI,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC,EAAE,CAAE,IAAI;AAExE,IAAI,gBAAgB,CAAC,OACnB,KAAK,KAAK,CAAC,0BAA0B,CAAC,EAAE,IAAI;AAE9C,IAAI,aAAa,CAAC;EAChB,IAAI,QAAQ,MAAM,IAAI,CAAC;EACvB,IAAI,MAAM,MAAM,IAAI,cAAc,OAAO;EACzC,IAAI,OAAO,MAAM,KAAK,CAAC,GAAG,eAAe,GAAG,IAAI,CAAC;EACjD,IAAI,OAAO,KAAK,OAAO,CAAC,YAAY;EACpC,OAAO,CAAC,QAAQ,IAAI,IAAI;AAC1B;AAEA,qEAAqE,GACrE,OAAO,IAAI,WAAW,CACpB,OACA;EAEA,IAAI,OAAO,UAAU;EACrB,IAAI,QAAQ,MAAM,SAAS,OAAO;EAClC,IAAI,YAAY,MAAM,SAAS,GAAG,UAAU,CAAC,MAAM,IAAI;EACvD,IAAI,UAAU,WAAW;EACzB,IAAI,aAAa,WAAW,MAAM,UAAU,WAAW,cAAc;EACrE,OAAO;IACL,OAAO;IACP,MAAM,CAAC,aAAa,WAAW,QAAQ,QAAQ,SAAS,QAAQ;EAClE;AACF,EAAC"}
package/text.ts ADDED
@@ -0,0 +1,30 @@
1
+ let TITLE_LENGTH = 120
2
+
3
+ let firstLine = (text: string) => text.trim().split(/\r?\n/, 1)[0]!.trim()
4
+
5
+ let firstSentence = (text: string) =>
6
+ text.match(/^.*?[.!?。!?](?=\s|$)/u)?.[0] ?? text
7
+
8
+ let shortTitle = (text: string): string => {
9
+ let chars = Array.from(text)
10
+ if (chars.length <= TITLE_LENGTH) return text
11
+ let part = chars.slice(0, TITLE_LENGTH - 1).join('')
12
+ let word = part.replace(/\s+\S*$/u, '')
13
+ return (word || part) + '…'
14
+ }
15
+
16
+ /** A short task title and the words that supplied it, kept in full. */
17
+ export let taskText = (
18
+ title: string,
19
+ body?: string,
20
+ ): { title: string; body: string } => {
21
+ let text = firstLine(title)
22
+ let words = body?.trim() ? body : title
23
+ let fromWords = words.trimStart().startsWith(title.trim())
24
+ let summary = shortTitle(text)
25
+ if (fromWords || summary != text) summary = shortTitle(firstSentence(text))
26
+ return {
27
+ title: summary,
28
+ body: !fromWords && summary != title ? title + '\n\n' + words : words,
29
+ }
30
+ }
package/tools.js ADDED
@@ -0,0 +1,303 @@
1
+ // What anybody may ask of a to-do list: the module a server imports as
2
+ // `@yaks/task/tools` — the implementations behind the declarations marked
3
+ // `tool: true` in ./vocab.json.
4
+ //
5
+ // They write components that are not this package's, and that is the point: a
6
+ // task with a title carries @yaks/doc's `doc`, and one filed in a portfolio
7
+ // carries @yaks/project's `filed`. A tool returns bundles, which are plain
8
+ // data, so naming a neighbour's component costs no import — and a server that
9
+ // composes neither package refuses the write, naming the component it does not
10
+ // know.
11
+ //
12
+ // There is no `task show`, no `task search` and no `task tree` here. Showing an
13
+ // entity whole is `graph_show`, and ranked text search is `search`; both are in
14
+ // @yaks/mcp's generic tier and work over any vocabulary at all, so a second
15
+ // name for either would be two implementations of one thing. task_new turns a
16
+ // compact plan into tasks and links in one transaction; graph_apply remains
17
+ // the door for arbitrary vocabulary.
18
+ import { argsOf } from "@yaks/graph/call";
19
+ import { answer, check, shows } from "./decision.js";
20
+ import { edited } from "@yaks/graph/tools";
21
+ import { Refused } from "@yaks/graph/errors";
22
+ import { conjoin, line, whole } from "@yaks/query";
23
+ import { taskText } from "./text.js";
24
+ // Where the work is filed, as arguments. The two that name an entity arrive
25
+ // as eids: a person types `P-19`, and the runner resolves every argument the
26
+ // declaration marks `ref` before a tool sees it (@yaks/tools).
27
+ let PLACES = [
28
+ 'project',
29
+ 'assignee',
30
+ 'priority',
31
+ 'domain'
32
+ ];
33
+ // The text a person reads, as arguments. An argument nobody passed is left out
34
+ // of the patch, so the stored title stays as it was instead of being blanked —
35
+ // writing `null` is what clears a property.
36
+ let picked = (args, keys)=>{
37
+ let said = keys.filter((key)=>Object.hasOwn(args, key));
38
+ return said.length ? Object.fromEntries(said.map((key)=>[
39
+ key,
40
+ args[key]
41
+ ])) : undefined;
42
+ };
43
+ let filedIn = (args)=>picked(args, PLACES);
44
+ let docIn = (args)=>picked(args, [
45
+ 'title',
46
+ 'body'
47
+ ]);
48
+ /**
49
+ * A status, as the marks that mean it. Nothing writes `task.status` — it is
50
+ * computed from these — so moving a task means adding one mark and removing
51
+ * the other, which is why finishing something records when and by whom instead
52
+ * of overwriting a value.
53
+ */ export let marked = {
54
+ open: {
55
+ started: null,
56
+ completed: null,
57
+ cancelled: null
58
+ },
59
+ wip: {
60
+ started: {},
61
+ completed: null,
62
+ cancelled: null
63
+ },
64
+ done: {
65
+ completed: {},
66
+ cancelled: null
67
+ },
68
+ cancelled: {
69
+ cancelled: {},
70
+ completed: null
71
+ }
72
+ };
73
+ /**
74
+ * The query a listing runs, with `.task` always part of it.
75
+ *
76
+ * The default is `.task.status=open,wip`. A caller's own query is passed
77
+ * through as typed and narrowed to tasks as a whole (`.a|.b` lists the tasks
78
+ * that are either), and every task comes back whole (`*`): a listing shows
79
+ * tasks, not the words it matched.
80
+ */ // A caller's own query, narrowed: `conjoin` groups it, and refuses one whose
81
+ // groups or quotes do not close, so it cannot reach past the narrowing.
82
+ export let listing = (query, limit)=>whole(conjoin('.task', String(query ?? '').trim() || '.task.status=open', limit == null ? '' : line`.limit=${Number(limit)}`, '*'));
83
+ // Why a task is cancelled, said with the status it explains. A reason written
84
+ // alone would create the `cancelled` mark, and so cancel a task nobody asked
85
+ // to cancel.
86
+ let reasoned = (args)=>{
87
+ if (!Object.hasOwn(args, 'reason')) return {};
88
+ if (!args.status) {
89
+ throw new Refused('A reason is why a task is cancelled: pass status cancelled with it');
90
+ }
91
+ return args.status == 'cancelled' ? {
92
+ cancelled: {
93
+ reason: args.reason == null ? null : String(args.reason)
94
+ }
95
+ } : {};
96
+ };
97
+ let conditions = (args)=>({
98
+ ...Object.hasOwn(args, 'accept') ? {
99
+ accept: args.accept == null ? null : {
100
+ body: String(args.accept)
101
+ }
102
+ } : {},
103
+ ...Object.hasOwn(args, 'blocked') ? {
104
+ blocked: args.blocked == null ? null : {
105
+ on: String(args.blocked)
106
+ }
107
+ } : {},
108
+ ...reasoned(args)
109
+ });
110
+ let fields = (args)=>{
111
+ let doc = docIn(args);
112
+ let filed = filedIn(args);
113
+ return {
114
+ ...args.status ? marked[String(args.status)] : {},
115
+ ...doc ? {
116
+ doc
117
+ } : {},
118
+ ...filed ? {
119
+ filed
120
+ } : {},
121
+ ...conditions(args)
122
+ };
123
+ };
124
+ let plans = (args)=>{
125
+ let tasks = args.tasks;
126
+ let rows = tasks ?? [
127
+ args
128
+ ];
129
+ let named = rows.flatMap((item)=>item.id ? [
130
+ String(item.id)
131
+ ] : []);
132
+ let used = new Set(named);
133
+ if (used.size != named.length) {
134
+ throw new Refused('Each task id must be distinct');
135
+ }
136
+ let fresh = (name)=>{
137
+ while(used.has(name))name += '-';
138
+ used.add(name);
139
+ return name;
140
+ };
141
+ let ids = rows.map((item, i)=>String(item.id ?? fresh(tasks ? `$task-${i + 1}` : '$task')));
142
+ return rows.flatMap((item, i)=>{
143
+ let task = tasks ? {
144
+ ...args,
145
+ ...item
146
+ } : item;
147
+ if (typeof task.title != 'string') {
148
+ throw new Refused('Supply title, or tasks with a title each');
149
+ }
150
+ let eid = ids[i];
151
+ if (!eid.startsWith('$')) {
152
+ throw new Refused('A new task id must start with $');
153
+ }
154
+ let links = [
155
+ ...task.parent ? [
156
+ {
157
+ from: String(task.parent),
158
+ relation: 'contains',
159
+ to: eid
160
+ }
161
+ ] : [],
162
+ ...(task.requires ?? []).map((to)=>({
163
+ from: eid,
164
+ relation: 'requires',
165
+ to
166
+ }))
167
+ ];
168
+ return [
169
+ {
170
+ entity: {
171
+ eid
172
+ },
173
+ task: {},
174
+ ...fields(task),
175
+ doc: taskText(task.title, typeof task.body == 'string' ? task.body : undefined)
176
+ },
177
+ ...links.map((l, n)=>link(l, fresh(`$task-link-${i}-${n}`)))
178
+ ];
179
+ });
180
+ };
181
+ /** A link as its own entity: an edge, and the relation it is. */ let link = ({ from, relation, to }, eid)=>({
182
+ entity: {
183
+ eid
184
+ },
185
+ edge: {
186
+ from,
187
+ to
188
+ },
189
+ [relation]: {}
190
+ });
191
+ /** The `requires` links a task gains: from it to each prerequisite. */ let required = (task)=>(task.requires ?? []).map((to)=>({
192
+ from: String(task.task),
193
+ relation: 'requires',
194
+ to
195
+ }));
196
+ let updates = async (args, graph)=>{
197
+ let items = args.updates;
198
+ let rows = (items ?? [
199
+ args
200
+ ]).map((item)=>{
201
+ let task = items ? {
202
+ ...args,
203
+ ...item
204
+ } : item;
205
+ if (typeof task.task != 'string') {
206
+ throw new Refused('Supply task, or updates with a task each');
207
+ }
208
+ return task;
209
+ });
210
+ let edits = rows.map((task)=>{
211
+ let set = Object.fromEntries(Object.entries(fields(task)).flatMap(([comp, value])=>value == null || !Object.keys(value).length ? [
212
+ [
213
+ comp,
214
+ value
215
+ ]
216
+ ] : Object.entries(value).map(([prop, v])=>[
217
+ `${comp}.${prop}`,
218
+ v
219
+ ])));
220
+ return {
221
+ id: String(task.task),
222
+ set,
223
+ ...(Object.hasOwn(task, 'body') || task.edit) && task.was !== undefined ? {
224
+ was: {
225
+ 'doc.body': task.was
226
+ }
227
+ } : {},
228
+ ...task.edit ? {
229
+ text: [
230
+ {
231
+ was: task.was,
232
+ ...task.edit,
233
+ path: 'doc.body'
234
+ }
235
+ ]
236
+ } : {}
237
+ };
238
+ });
239
+ let links = rows.flatMap(required);
240
+ return [
241
+ ...await edited(graph, edits),
242
+ ...links.map((l, n)=>link(l, `$task-link-${n}`))
243
+ ];
244
+ };
245
+ // A decision on `args.question` and `args.choices`: asked, recommending
246
+ // `pick`, or, given `why`, already made by its writer, who took `pick`.
247
+ let decision = (args, pick, why)=>{
248
+ let question = String(args.question).trim();
249
+ let filed = filedIn(args);
250
+ let choices = args.choices;
251
+ let made = {
252
+ entity: {
253
+ eid: '$decision'
254
+ },
255
+ task: {},
256
+ doc: {
257
+ title: question,
258
+ ...why ? {
259
+ body: why
260
+ } : {}
261
+ },
262
+ decision: {
263
+ question,
264
+ choices: choices.map(({ label, description })=>({
265
+ label,
266
+ description
267
+ })),
268
+ recommended: pick
269
+ },
270
+ ...why == null ? {} : {
271
+ decided: {
272
+ choice: String(pick).trim()
273
+ }
274
+ },
275
+ ...filed ? {
276
+ filed
277
+ } : {}
278
+ };
279
+ check(made);
280
+ return [
281
+ made,
282
+ ...shows('$decision', choices)
283
+ ];
284
+ };
285
+ /** The implementations behind ./vocab.json. Scalar changes are data; partial
286
+ * text changes read through the graph and keep the shared compiler's guard. */ export let runs = ()=>({
287
+ decision_new: (call)=>{
288
+ let args = argsOf(call);
289
+ return decision(args, args.recommended);
290
+ },
291
+ decision_record: (call)=>{
292
+ let args = argsOf(call);
293
+ return decision(args, args.chose, String(args.why).trim());
294
+ },
295
+ decision_answer: (call)=>{
296
+ let args = argsOf(call);
297
+ return answer(String(args.decision), String(args.choice), args.by);
298
+ },
299
+ task_new: (call)=>plans(argsOf(call)),
300
+ task_list: (call, graph)=>graph.read(listing(argsOf(call).query, argsOf(call).limit)),
301
+ task_update: (call, graph)=>updates(argsOf(call), graph)
302
+ });
303
+ //# sourceMappingURL=tools.js.map
package/tools.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.js","sources":["./tools.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,0EAA0E;AAC1E,gCAAgC;AAChC,EAAE;AACF,8EAA8E;AAC9E,4EAA4E;AAC5E,2EAA2E;AAC3E,8EAA8E;AAC9E,+EAA+E;AAC/E,QAAQ;AACR,EAAE;AACF,gFAAgF;AAChF,gFAAgF;AAChF,4EAA4E;AAC5E,8EAA8E;AAC9E,4EAA4E;AAC5E,qCAAqC;AAGrC,SAAS,MAAM,gCAAqC;AACpD,SAAS,MAAM,EAAE,KAAK,EAAe,KAAK,wBAAuB;AACjE,SAAoB,MAAM,iCAAgE;AAC1F,SAAS,OAAO,kCAAuC;AACvD,SAAS,OAAO,EAAa,IAAI,EAAE,KAAK,2BAAgC;AACxE,SAAS,QAAQ,oBAAmB;AAEpC,4EAA4E;AAC5E,6EAA6E;AAC7E,+DAA+D;AAC/D,IAAI,SAAS;EAAC;EAAW;EAAY;EAAY;CAAS;AAE1D,+EAA+E;AAC/E,+EAA+E;AAC/E,4CAA4C;AAC5C,IAAI,SAAS,CACX,MACA;EAEA,IAAI,OAAO,KAAK,MAAM,CAAC,CAAC,MAAQ,OAAO,MAAM,CAAC,MAAM;EACpD,OAAO,KAAK,MAAM,GACd,OAAO,WAAW,CAAC,KAAK,GAAG,CAAC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