ekms 8.0.0 → 8.1.0

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 (122) hide show
  1. package/common/animals.instance.json +3003 -1651
  2. package/common/animals.js +17 -20
  3. package/common/articles.js +103 -0
  4. package/common/articles.test.json +310 -0
  5. package/common/asking.instance.json +2 -0
  6. package/common/asking.js +253 -0
  7. package/common/asking.test.json +2290 -0
  8. package/common/avatar.js +6 -10
  9. package/common/characters.js +23 -30
  10. package/common/colors.instance.json +25513 -0
  11. package/common/colors.js +67 -0
  12. package/common/colors.test.json +4425 -0
  13. package/common/comparable.instance.json +1750 -0
  14. package/common/comparable.js +36 -28
  15. package/common/comparable.test.json +1196 -2
  16. package/common/concept.js +121 -119
  17. package/common/conjunction.instance.json +2 -0
  18. package/common/conjunction.js +104 -0
  19. package/common/conjunction.test.json +322 -0
  20. package/common/countable.js +20 -14
  21. package/common/countable.test.json +1050 -0
  22. package/common/crew.instance.json +16855 -9731
  23. package/common/crew.js +39 -42
  24. package/common/crew.test.json +714 -452
  25. package/common/currency.js +28 -46
  26. package/common/dialogues.js +177 -426
  27. package/common/dialogues.test.json +684 -450
  28. package/common/dimension.instance.json +508 -289
  29. package/common/dimension.js +22 -24
  30. package/common/dimension.test.json +727 -1944
  31. package/common/edible.instance.json +20548 -10848
  32. package/common/edible.js +4 -9
  33. package/common/emotions.instance.json +255 -123
  34. package/common/emotions.js +36 -39
  35. package/common/evaluate.instance.json +2 -0
  36. package/common/evaluate.js +53 -0
  37. package/common/evaluate.test.json +574 -0
  38. package/common/events.js +11 -15
  39. package/common/fastfood.instance.json +223039 -113390
  40. package/common/fastfood.js +77 -87
  41. package/common/fastfood.test.json +8205 -3733
  42. package/common/formulas.instance.json +444 -244
  43. package/common/formulas.js +20 -27
  44. package/common/formulas.test.json +1027 -955
  45. package/common/gdefaults.js +40 -27
  46. package/common/help.js +9 -14
  47. package/common/help.test.json +71 -18
  48. package/common/helpers/concept.js +33 -10
  49. package/common/helpers/dialogues.js +22 -4
  50. package/common/helpers/formulas.js +0 -14
  51. package/common/helpers/meta.js +0 -1
  52. package/common/helpers/properties.js +72 -76
  53. package/common/helpers.js +35 -24
  54. package/common/hierarchy.js +17 -25
  55. package/common/javascript.js +12 -19
  56. package/common/kirk.instance.json +586 -298
  57. package/common/kirk.js +6 -9
  58. package/common/length.instance.json +9158 -5124
  59. package/common/length.js +5 -9
  60. package/common/listener.js +48 -0
  61. package/common/listener.test.json +104 -0
  62. package/common/math.instance.json +409 -1202
  63. package/common/math.js +17 -21
  64. package/common/meta.js +24 -50
  65. package/common/nameable.instance.json +2 -0
  66. package/common/nameable.js +144 -0
  67. package/common/nameable.test.json +3191 -0
  68. package/common/negation.instance.json +2 -0
  69. package/common/negation.js +38 -0
  70. package/common/negation.test.json +308 -0
  71. package/common/numbers.js +28 -32
  72. package/common/ordering.instance.json +449 -273
  73. package/common/ordering.js +81 -87
  74. package/common/ordinals.instance.json +2 -0
  75. package/common/ordinals.js +60 -0
  76. package/common/ordinals.test.json +306 -0
  77. package/common/people.instance.json +2176 -1141
  78. package/common/people.js +9 -14
  79. package/common/percentages.instance.json +2 -0
  80. package/common/percentages.js +53 -0
  81. package/common/percentages.test.json +751 -0
  82. package/common/pipboy.instance.json +12120 -6879
  83. package/common/pipboy.js +53 -62
  84. package/common/pipboy.test.json +2835 -0
  85. package/common/pokemon.instance.json +4415 -2351
  86. package/common/pokemon.js +8 -21
  87. package/common/pos.js +16 -14
  88. package/common/pressure.instance.json +2348 -1373
  89. package/common/pressure.js +5 -9
  90. package/common/properties.instance.json +151 -87
  91. package/common/properties.js +156 -167
  92. package/common/properties.test.json +17605 -4030
  93. package/common/punctuation.js +24 -8
  94. package/common/punctuation.test.json +233 -5
  95. package/common/reports.instance.json +1027 -551
  96. package/common/reports.js +77 -103
  97. package/common/reports.test.json +15623 -10458
  98. package/common/scorekeeper.js +19 -31
  99. package/common/sdefaults.js +17 -8
  100. package/common/sizeable.js +13 -12
  101. package/common/spock.instance.json +585 -297
  102. package/common/spock.js +6 -9
  103. package/common/stgame.js +20 -20
  104. package/common/stm.js +182 -29
  105. package/common/stm.test.json +1734 -1
  106. package/common/tell.js +15 -19
  107. package/common/temperature.instance.json +2480 -1493
  108. package/common/temperature.js +5 -9
  109. package/common/tester.js +15 -4
  110. package/common/testing.js +8 -13
  111. package/common/time.js +21 -26
  112. package/common/tokenize.js +8 -8
  113. package/common/tokenize.test.json +86 -1
  114. package/common/ui.instance.json +151 -460
  115. package/common/ui.js +22 -34
  116. package/common/ui.test.json +641 -5357
  117. package/common/weight.instance.json +8072 -4490
  118. package/common/weight.js +5 -9
  119. package/common/weight.test.json +242 -238
  120. package/common/yesno.js +6 -6
  121. package/main.js +68 -45
  122. package/package.json +44 -6
package/common/animals.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const { defaultContextCheck } = require('./helpers')
2
- const { Config, knowledgeModule, where } = require('./runtime').theprogrammablemind
2
+ const { knowledgeModule, where } = require('./runtime').theprogrammablemind
3
3
  const hierarchy = require('./hierarchy')
4
4
  const animals_tests = require('./animals.test.json')
5
5
  const animals_instance = require('./animals.instance.json')
@@ -25,26 +25,23 @@ const template = {
25
25
  ],
26
26
  }
27
27
 
28
- const createConfig = () => {
29
- const config = new Config({ name: 'animals' }, module)
30
- config.add(hierarchy())
31
- return config
32
- }
33
-
34
28
  knowledgeModule( {
35
- module,
36
- description: 'animals related concepts',
37
- createConfig, newWay: true,
38
- test: {
39
- name: './animals.test.json',
40
- contents: animals_tests,
41
- checks: {
42
- context: defaultContextCheck,
43
- },
29
+ config: { name: 'animals' },
30
+ includes: [hierarchy],
44
31
 
32
+ module,
33
+ description: 'animals related concepts',
34
+ newWay: true,
35
+ test: {
36
+ name: './animals.test.json',
37
+ contents: animals_tests,
38
+ checks: {
39
+ context: defaultContextCheck(),
45
40
  },
46
- template: {
47
- template,
48
- instance: animals_instance
49
- }
41
+
42
+ },
43
+ template: {
44
+ template,
45
+ instance: animals_instance
46
+ }
50
47
  })
@@ -0,0 +1,103 @@
1
+ const { knowledgeModule, where, stableId } = require('./runtime').theprogrammablemind
2
+ const gdefaults = require('./gdefaults.js')
3
+ const pos = require('./pos.js')
4
+ const { defaultContextCheck } = require('./helpers')
5
+ const tests = require('./articles.test.json')
6
+
7
+ let config = {
8
+ name: 'articles',
9
+ operators: [
10
+ "([thisitthat|])",
11
+ "([it])",
12
+ "([this])",
13
+ "([that])",
14
+ "([queryable])",
15
+ /*
16
+ "(<what> ([whatAble|]))",
17
+ "([what:optional])",
18
+ */
19
+ "(<the|> ([theAble]))",
20
+ "(<a|a,an> ([theAble|]))",
21
+ ],
22
+ bridges: [
23
+ // { id: "what", level: 0, optional: "{ ...next(operator), query: ['what'], determined: true }", bridge: "{ ...after, query: ['what'], modifiers: ['what'], what: operator }" },
24
+ // { id: "whatAble", level: 0, bridge: "{ ...next(operator) }" },
25
+ {
26
+ id: 'the',
27
+ level: 0,
28
+ bridge: '{ ...after[0], focusableForPhrase: true, pullFromContext: true, concept: true, wantsValue: true, determiner: "the", modifiers: append(["determiner"], after[0].modifiers)}'
29
+ },
30
+ {
31
+ id: "a",
32
+ level: 0,
33
+ // bridge: "{ ...after[0], pullFromContext: false, instance: true, concept: true, number: 'one', wantsValue: true, determiner: operator, modifiers: append(['determiner'], after[0].modifiers) }"
34
+ bridge: "{ ...after[0], pullFromContext: false, instance: true, concept: true, number: 'one', wantsValue: true, determiner: operator, modifiers: append(['determiner'], after[0].modifiers) }"
35
+ },
36
+ { id: "queryable" },
37
+ {
38
+ id: "theAble",
39
+ children: ['noun'],
40
+ bridge: "{ ...next(operator) }"
41
+ },
42
+
43
+ {
44
+ id: "thisitthat",
45
+ level: 0,
46
+ isA: ['queryable'],
47
+ before: ['verb'],
48
+ bridge: "{ ...next(operator) }"
49
+ },
50
+ {
51
+ id: "it",
52
+ level: 0,
53
+ isA: ['thisitthat'],
54
+ bridge: "{ ...next(operator), pullFromContext: true, unknown: true, determined: true }"
55
+ },
56
+ {
57
+ id: "this",
58
+ level: 0,
59
+ isA: ['thisitthat'],
60
+ bridge: "{ ...next(operator), unknown: true, pullFromContext: true }"
61
+ },
62
+ {
63
+ id: "that",
64
+ level: 0,
65
+ isA: ['thisitthat'],
66
+ bridge: "{ ...next(operator), unknown: true, pullFromContext: true }"
67
+ },
68
+ ],
69
+ words: {
70
+ "literals": {
71
+ "the": [{"id": "the", "initial": "{ modifiers: [] }" }],
72
+ }
73
+ },
74
+ hierarchy: [
75
+ ['it', 'pronoun'],
76
+ ['this', 'pronoun'],
77
+ // ['questionMark', 'isEd'],
78
+ ['a', 'articlePOS'],
79
+ ['the', 'articlePOS'],
80
+ ['it', 'queryable'],
81
+ // ['it', 'toAble'],
82
+ ['this', 'queryable'],
83
+ ],
84
+
85
+ };
86
+
87
+ knowledgeModule( {
88
+ config,
89
+ includes: [pos, gdefaults],
90
+
91
+ module,
92
+ description: 'articles',
93
+ newWay: true,
94
+ test: {
95
+ name: './articles.test.json',
96
+ contents: tests,
97
+ checks: {
98
+ objects: ['onNevermindWasCalled', 'nevermindType', 'idSuffix'],
99
+ context: defaultContextCheck(),
100
+ },
101
+
102
+ },
103
+ })
@@ -0,0 +1,310 @@
1
+ [
2
+ {
3
+ "associations": [
4
+ [
5
+ [
6
+ "the",
7
+ 0
8
+ ],
9
+ [
10
+ "theAble",
11
+ 0
12
+ ]
13
+ ]
14
+ ],
15
+ "config": {
16
+ },
17
+ "contexts": [
18
+ {
19
+ "concept": true,
20
+ "dead": true,
21
+ "default": true,
22
+ "determiner": "the",
23
+ "focusableForPhrase": true,
24
+ "level": 1,
25
+ "marker": "theAble",
26
+ "modifiers": [
27
+ "determiner"
28
+ ],
29
+ "pullFromContext": true,
30
+ "range": {
31
+ "end": 10,
32
+ "start": 0
33
+ },
34
+ "text": "the theable",
35
+ "topLevel": true,
36
+ "types": [
37
+ "theAble"
38
+ ],
39
+ "value": "theAble",
40
+ "wantsValue": true,
41
+ "word": "theable"
42
+ }
43
+ ],
44
+ "developerTest": false,
45
+ "generatedParenthesized": [
46
+ ""
47
+ ],
48
+ "metadata": {
49
+ "opChoices": [
50
+ {
51
+ "counter": 1,
52
+ "op": [
53
+ "theAble",
54
+ 0
55
+ ],
56
+ "ops": [
57
+ [
58
+ "the",
59
+ 0
60
+ ],
61
+ [
62
+ "theAble",
63
+ 0
64
+ ]
65
+ ]
66
+ },
67
+ {
68
+ "counter": 2,
69
+ "op": [
70
+ "the",
71
+ 0
72
+ ],
73
+ "ops": [
74
+ [
75
+ "the",
76
+ 0
77
+ ]
78
+ ]
79
+ }
80
+ ]
81
+ },
82
+ "objects": {
83
+ "nameToUUID": {
84
+ "articles": "articles1",
85
+ "gdefaults": "gdefaults2",
86
+ "pos": "pos2",
87
+ "tokenize": "tokenize2"
88
+ },
89
+ "namespaced": {
90
+ "articles1": {
91
+ },
92
+ "gdefaults2": {
93
+ },
94
+ "pos2": {
95
+ },
96
+ "tokenize2": {
97
+ }
98
+ },
99
+ "processed": [
100
+ {
101
+ "context": {
102
+ "concept": true,
103
+ "dead": true,
104
+ "default": true,
105
+ "determiner": "the",
106
+ "focusableForPhrase": true,
107
+ "level": 1,
108
+ "marker": "theAble",
109
+ "modifiers": [
110
+ "determiner"
111
+ ],
112
+ "pullFromContext": true,
113
+ "range": {
114
+ "end": 10,
115
+ "start": 0
116
+ },
117
+ "text": "the theable",
118
+ "topLevel": true,
119
+ "types": [
120
+ "theAble"
121
+ ],
122
+ "value": "theAble",
123
+ "wantsValue": true,
124
+ "word": "theable"
125
+ },
126
+ "generatedParenthesized": "",
127
+ "paraphrases": "the theable",
128
+ "paraphrasesParenthesized": "(the (theable))",
129
+ "responses": [
130
+ ""
131
+ ]
132
+ }
133
+ ]
134
+ },
135
+ "paraphrases": [
136
+ "the theable"
137
+ ],
138
+ "paraphrasesParenthesized": [
139
+ "(the (theable))"
140
+ ],
141
+ "query": "the theable",
142
+ "responses": [
143
+ ""
144
+ ]
145
+ },
146
+ {
147
+ "associations": [
148
+ [
149
+ [
150
+ "a",
151
+ 0
152
+ ],
153
+ [
154
+ "theAble",
155
+ 0
156
+ ]
157
+ ]
158
+ ],
159
+ "config": {
160
+ },
161
+ "contexts": [
162
+ {
163
+ "concept": true,
164
+ "dead": true,
165
+ "default": true,
166
+ "determiner": {
167
+ "default": true,
168
+ "level": 0,
169
+ "marker": "a",
170
+ "range": {
171
+ "end": 0,
172
+ "start": 0
173
+ },
174
+ "text": "a",
175
+ "word": "a"
176
+ },
177
+ "level": 1,
178
+ "marker": "theAble",
179
+ "modifiers": [
180
+ "determiner"
181
+ ],
182
+ "number": "one",
183
+ "pullFromContext": false,
184
+ "range": {
185
+ "end": 8,
186
+ "start": 0
187
+ },
188
+ "text": "a theable",
189
+ "topLevel": true,
190
+ "types": [
191
+ "theAble"
192
+ ],
193
+ "value": "theAble",
194
+ "wantsValue": true,
195
+ "word": "theable"
196
+ }
197
+ ],
198
+ "developerTest": false,
199
+ "generatedParenthesized": [
200
+ ""
201
+ ],
202
+ "metadata": {
203
+ "opChoices": [
204
+ {
205
+ "counter": 1,
206
+ "op": [
207
+ "theAble",
208
+ 0
209
+ ],
210
+ "ops": [
211
+ [
212
+ "a",
213
+ 0
214
+ ],
215
+ [
216
+ "theAble",
217
+ 0
218
+ ]
219
+ ]
220
+ },
221
+ {
222
+ "counter": 2,
223
+ "op": [
224
+ "a",
225
+ 0
226
+ ],
227
+ "ops": [
228
+ [
229
+ "a",
230
+ 0
231
+ ]
232
+ ]
233
+ }
234
+ ]
235
+ },
236
+ "objects": {
237
+ "nameToUUID": {
238
+ "articles": "articles1",
239
+ "gdefaults": "gdefaults2",
240
+ "pos": "pos2",
241
+ "tokenize": "tokenize2"
242
+ },
243
+ "namespaced": {
244
+ "articles1": {
245
+ },
246
+ "gdefaults2": {
247
+ },
248
+ "pos2": {
249
+ },
250
+ "tokenize2": {
251
+ }
252
+ },
253
+ "processed": [
254
+ {
255
+ "context": {
256
+ "concept": true,
257
+ "dead": true,
258
+ "default": true,
259
+ "determiner": {
260
+ "default": true,
261
+ "level": 0,
262
+ "marker": "a",
263
+ "range": {
264
+ "end": 0,
265
+ "start": 0
266
+ },
267
+ "text": "a",
268
+ "word": "a"
269
+ },
270
+ "level": 1,
271
+ "marker": "theAble",
272
+ "modifiers": [
273
+ "determiner"
274
+ ],
275
+ "number": "one",
276
+ "pullFromContext": false,
277
+ "range": {
278
+ "end": 8,
279
+ "start": 0
280
+ },
281
+ "text": "a theable",
282
+ "topLevel": true,
283
+ "types": [
284
+ "theAble"
285
+ ],
286
+ "value": "theAble",
287
+ "wantsValue": true,
288
+ "word": "theable"
289
+ },
290
+ "generatedParenthesized": "",
291
+ "paraphrases": "a theable",
292
+ "paraphrasesParenthesized": "((a) (theable))",
293
+ "responses": [
294
+ ""
295
+ ]
296
+ }
297
+ ]
298
+ },
299
+ "paraphrases": [
300
+ "a theable"
301
+ ],
302
+ "paraphrasesParenthesized": [
303
+ "((a) (theable))"
304
+ ],
305
+ "query": "a theable",
306
+ "responses": [
307
+ ""
308
+ ]
309
+ }
310
+ ]
@@ -0,0 +1,2 @@
1
+ {
2
+ }
@@ -0,0 +1,253 @@
1
+ const { knowledgeModule, where, stableId } = require('./runtime').theprogrammablemind
2
+ const meta = require('./meta.js')
3
+ const gdefaults = require('./gdefaults.js')
4
+ const sdefaults = require('./sdefaults.js')
5
+ const conjunction = require('./conjunction.js')
6
+ const asking_tests = require('./asking.test.json')
7
+ const { defaultContextCheck, indent, focus, requiredArgument } = require('./helpers')
8
+ const pluralize = require('pluralize')
9
+
10
+ // TODO implement what / what did you say ...
11
+ let config = {
12
+ name: 'asking',
13
+ operators: [
14
+ "([nevermind])",
15
+ { pattern: "([nevermindTestSetup] (allowed))", development: true },
16
+ { pattern: "([whichOnesTestSetup] (choices)*)", development: true },
17
+ ],
18
+ bridges: [
19
+ {
20
+ id: "nevermind",
21
+ bridge: "{ ...next(operator) }",
22
+ semantic: (args) => {
23
+ const {config, context} = args
24
+ // stop asking all questions
25
+ for (const semantic of config.semantics) {
26
+ if (semantic.isQuestion) {
27
+ let doRemove = true
28
+ if (semantic.onNevermind && semantic.getWasAsked() && !semantic.getWasApplied()) {
29
+ doRemove = semantic.onNevermind(args)
30
+ }
31
+ if (doRemove) {
32
+ config.removeSemantic(semantic)
33
+ }
34
+ }
35
+ }
36
+ }
37
+ },
38
+
39
+ {
40
+ id: "whichOnesTestSetup",
41
+ development: true,
42
+ generatorp: async ({context, gs}) => `${context.marker} ${await gs(context.choices)}`,
43
+ bridge: "{ ...next(operator), choices: after }",
44
+ semantic: ({askWhich, context}) => {
45
+ const choices = context.choices
46
+ const chosen = ({ choice, objects }) => {
47
+ objects.choice = choice
48
+ }
49
+
50
+ const question = async ({choices, g, gs, wasAsked, state}) => {
51
+ if (wasAsked) {
52
+ return `${await g(state.lastChoice)} is not a choice. The choices are: ${await gs(choices, ' ', ' or ')}`
53
+ } else {
54
+ return `Which value do you want: ${await gs(choices, ' ', ' or ')}`
55
+ }
56
+ }
57
+
58
+ const isChoice = ({context, choices, state}) => {
59
+ state.lastChoice = context
60
+ for (const choice of choices) {
61
+ if (choice.value == context.value) {
62
+ return true
63
+ }
64
+ }
65
+ }
66
+
67
+ const onNevermind = ({objects, context}) => {
68
+ objects.onNevermindWasCalled = true
69
+ return true
70
+ }
71
+
72
+ askWhich({ choices, chosen, question, isChoice, onNevermind })
73
+ }
74
+ },
75
+
76
+ {
77
+ id: "nevermindTestSetup",
78
+ development: true,
79
+ bridge: "{ ...next(operator), type: after[0], postModifiers: ['type'] }",
80
+ semantic: ({ask, context}) => {
81
+ const nevermindType = context.type.value
82
+ ask({
83
+ applyq: () => 'the test question?',
84
+ onNevermind: ({objects, context}) => {
85
+ objects.onNevermindWasCalled = true
86
+ objects.nevermindType = nevermindType
87
+ return nevermindType == 'accept'
88
+ },
89
+ matchr: () => false,
90
+ applyr: () => {},
91
+ })
92
+ }
93
+ },
94
+ ],
95
+ };
96
+
97
+ const getAsk = (config) => (uuid) => {
98
+ return (asks) => {
99
+ const ask = (ask) => {
100
+ let oneShot = true // default
101
+ if (ask.oneShot === false) {
102
+ oneShot = false
103
+ }
104
+
105
+ const id_q = stableId('semantic')
106
+ const id_rs = []
107
+ let wasAsked = false
108
+ let wasApplied = false
109
+ const getWasAsked = () => {
110
+ return wasAsked
111
+ }
112
+ const setWasAsked = (value) => {
113
+ wasAsked = value
114
+ }
115
+ const getWasApplied = () => {
116
+ return wasApplied
117
+ }
118
+ const setWasApplied = (value) => {
119
+ wasApplied = value
120
+ }
121
+
122
+ const semanticsr = ask.semanticsr || []
123
+ if (semanticsr.length == 0) {
124
+ semanticsr.push({ match: ask.matchr, apply: ask.applyr })
125
+ }
126
+ for (const semantic of semanticsr) {
127
+ const id_r = stableId('semantic')
128
+ id_rs.push(id_r)
129
+ config.addSemantic({
130
+ uuid,
131
+ id: id_r,
132
+ tied_ids: [id_q],
133
+ oneShot,
134
+ where: semantic.where || ask.where || where(2),
135
+ source: 'response',
136
+ match: (args) => semantic.match(args),
137
+ apply: async (args) => {
138
+ setWasApplied(true)
139
+ await semantic.apply(args)
140
+ },
141
+ })
142
+ }
143
+
144
+ config.addSemantic({
145
+ uuid,
146
+ oneShot,
147
+ id: id_q,
148
+ tied_ids: id_rs,
149
+ where: ask.where,
150
+ isQuestion: true, // do one question at a time
151
+ getWasAsked,
152
+ getWasApplied,
153
+ onNevermind: ask.onNevermind,
154
+ source: 'question',
155
+ match: ({ context }) => context.marker == 'controlEnd' || context.marker == 'controlBetween',
156
+ apply: async (args) => {
157
+ let matchq = ask.matchq
158
+ let applyq = ask.applyq
159
+ if (!matchq) {
160
+ let wasAsked = false
161
+ matchq = () => !wasAsked,
162
+ applyq = (args) => {
163
+ wasAsked = true
164
+ return ask.applyq(args)
165
+ }
166
+ }
167
+ if (await matchq(args)) {
168
+ setWasApplied(false)
169
+ // args.context.motivationKeep = true
170
+ args.verbatim(await applyq({ ...args, wasAsked: getWasAsked() }))
171
+ setWasAsked(true)
172
+ args.context.controlKeepMotivation = true
173
+ }
174
+ args.context.cascade = true
175
+ }
176
+ })
177
+ }
178
+ if (!Array.isArray(asks)) {
179
+ asks = [asks]
180
+ }
181
+
182
+ [...asks].reverse().forEach( (a) => ask(a) )
183
+ }
184
+ }
185
+
186
+
187
+ const initializer = ({objects, config, isModule}) => {
188
+ config.addArgs(({config, api, isA}) => ({
189
+ getUUIDScoped: (uuid) => {
190
+ const ask = getAsk(config)(uuid)
191
+ return {
192
+ ask,
193
+ askWhich: ({ choices, chosen, question, isChoice, onNevermind }) => {
194
+ let state = {}
195
+
196
+ requiredArgument(choices, 'choices')
197
+ requiredArgument(chosen, 'chosen')
198
+
199
+ if (!onNevermind) {
200
+ onNevermind = ({objects, context}) => {
201
+ return true
202
+ }
203
+ }
204
+
205
+ if (!question) {
206
+ const question = async ({choices, g, gs, wasAsked, state}) => {
207
+ if (wasAsked) {
208
+ return `${await g(state.lastChoice)} is not a choice. The choices are: ${await gs(choices, ' ', ' or ')}`
209
+ } else {
210
+ return `Which value do you want: ${await gs(choices, ' ', ' or ')}`
211
+ }
212
+ }
213
+ }
214
+
215
+ if (!isChoice) {
216
+ const isChoice = ({context, choices, state}) => {
217
+ state.lastChoice = context
218
+ for (const choice of choices) {
219
+ if (choice.value == context.value) {
220
+ return true
221
+ }
222
+ }
223
+ }
224
+ }
225
+
226
+ ask({
227
+ applyq: async (args) => await question({...args, choices, state}),
228
+ onNevermind,
229
+ matchr: (args) => isChoice({...args, choices, state}),
230
+ applyr: (args) => chosen({...args, choice: args.context}),
231
+ })
232
+ }
233
+ }
234
+ },
235
+ }))
236
+ }
237
+
238
+ knowledgeModule( {
239
+ config,
240
+ includes: [conjunction, gdefaults, sdefaults],
241
+ initializer,
242
+ module,
243
+ description: 'asking the user questions',
244
+ newWay: true,
245
+ test: {
246
+ name: './asking.test.json',
247
+ contents: asking_tests,
248
+ checks: {
249
+ objects: ['onNevermindWasCalled', 'nevermindType', 'choice'],
250
+ context: defaultContextCheck(),
251
+ },
252
+ },
253
+ })