theprogrammablemind_4wp 9.6.0-beta.9 → 9.6.1

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/client.js CHANGED
@@ -798,6 +798,8 @@ const defaultErrorHandler = async (error) => {
798
798
  if (typeof runtime.process.exit === 'function' && doErrorExit) {
799
799
  runtime.process.exit(-1)
800
800
  }
801
+
802
+ error.config = null // otherwise it dumps to much on the console
801
803
 
802
804
  throw error
803
805
  }
@@ -1224,6 +1226,7 @@ const knowledgeModuleImpl = async ({
1224
1226
  errorHandler = defaultErrorHandler,
1225
1227
  process: processResults = defaultProcess,
1226
1228
  stopAtFirstFailure = true,
1229
+ demoInitializer,
1227
1230
  ...rest
1228
1231
  } = {}) => {
1229
1232
  const unknownArgs = Object.keys(rest)
@@ -1308,7 +1311,7 @@ const knowledgeModuleImpl = async ({
1308
1311
  const helpDebugPriority = 'In order to get a debug break when a specific set of priorities is created set set DEBUG_PRIORITY environment variable to the JSON of the priorities that you want to break on. For example DEBUG_PRIORITY=\'[["verb", 0], ["article", 0]]\''
1309
1312
  const helpDebugContextualPriority = 'In order to get a debug break when a specific set of contextual priorities is created set set DEBUG_CONTEXTUAL_PRIORITY environment variable to the JSON of the priorities that you want to break on. For example DEBUG_CONTEXTUAL_PRIORITY=\'{ context: [["verb", 0], ["article", 0], select: 1}\''
1310
1313
  const helpDebugBridge = 'In order to get a debug break when a specific bridge is created set the DEBUG_BRIDGE environment variable to id to break on. For example DEBUG_BRIDGE=\'car\''
1311
- const helpDebugOperator = 'In order to get a debug break when a specific hierarcy is created set the DEBUG_OPERATOR environment variable to debug any config loaded. For example DEBUG_OPERATOR=\'([operator] ([arg]))\''
1314
+ const helpDebugOperator = 'In order to get a debug break when a specific hierarchy is created set the DEBUG_OPERATOR environment variable to debug any config loaded. For example DEBUG_OPERATOR=\'([operator] ([arg]))\''
1312
1315
 
1313
1316
  parser.add_argument('-tmn', '--testModuleName', { help: 'When running tests instead of using the current modules tests use the specified modules tests' })
1314
1317
  parser.add_argument('-t', '--test', { action: 'store_true', help: 'Run the tests. Create tests by running with the --query + --save flag' })
@@ -1377,6 +1380,10 @@ const knowledgeModuleImpl = async ({
1377
1380
  }
1378
1381
  config = await createConfig(true, configStruct.name)
1379
1382
 
1383
+ if (demoInitializer) {
1384
+ await config.setDemoInitializer(demoInitializer)
1385
+ }
1386
+
1380
1387
  // dont debug the load of the KM's if rebuild template is on since we want to debug the template rebuild not the load
1381
1388
  if (args.rebuildTemplate) {
1382
1389
  global.pauseDebugging = true
@@ -1459,7 +1466,7 @@ const knowledgeModuleImpl = async ({
1459
1466
  let tests = JSON.parse(runtime.fs.readFileSync(testConfig.name))
1460
1467
  tests = tests.filter((test) => test.query !== args.deleteTest)
1461
1468
  writeTestFile(testConfig.name, tests)
1462
- console.log(`Remove the test for "${args.deleteTest}"`)
1469
+ console.log(`Delete the test for "${args.deleteTest}"`)
1463
1470
  return
1464
1471
  }
1465
1472
 
@@ -2013,6 +2020,9 @@ const knowledgeModuleImpl = async ({
2013
2020
  }
2014
2021
  const config = await createConfig(rootIsProcess, testingModuleName)
2015
2022
  await initConfig(config)
2023
+ if (demoInitializer) {
2024
+ config.setDemoInitializer(demoInitializer)
2025
+ }
2016
2026
  // config.rebuild({ isModule: true })
2017
2027
  createConfig.cached = config
2018
2028
  return createConfig.cached
package/package.json CHANGED
@@ -73,6 +73,6 @@
73
73
  "scriptjs": "^2.5.9",
74
74
  "uuid": "^8.3.2"
75
75
  },
76
- "version": "9.6.0-beta.9",
76
+ "version": "9.6.1",
77
77
  "license": "UNLICENSED"
78
78
  }
package/src/config.js CHANGED
@@ -338,6 +338,7 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
338
338
 
339
339
  // done in setTestConfig
340
340
  if (bridge.check) {
341
+ /*
341
342
  if (!config.testConfig) {
342
343
  config.testConfig = {}
343
344
  }
@@ -347,6 +348,7 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
347
348
  if (!config.testConfig?.checks?.context) {
348
349
  config.testConfig.checks.context = []
349
350
  }
351
+ */
350
352
  config.contextChecksFromBridges.push({
351
353
  'bridge.id': bridge.id,
352
354
  'bridge.check': bridge.check,
@@ -405,9 +407,15 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
405
407
  if (bridge.generatorp) {
406
408
  const match = bridge.generatorp.match || (() => true)
407
409
  const apply = typeof bridge.generatorp === 'function' ? bridge.generatorp : bridge.generatorp.apply || bridge.generatorp
408
- let level = bridge.generatorp.level >= 0 ? bridge.generatorp.level : bridge.level + 1
409
- if (!bridge.bridge) {
410
- level = 0
410
+
411
+ let level
412
+ if (bridge.generatorp.level >= 0) {
413
+ level = bridge.generatorp.level
414
+ } else {
415
+ level = bridge.level + 1
416
+ if (!bridge.bridge ) {
417
+ level = 0
418
+ }
411
419
  }
412
420
 
413
421
  const generator = {
@@ -427,11 +435,25 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
427
435
  if (bridge.generatorr) {
428
436
  const match = bridge.generatorr.match || (() => true)
429
437
  const apply = typeof bridge.generatorr === 'function' ? bridge.generatorr : bridge.generatorr.apply || bridge.generatorr
430
- const level = bridge.generatorr.level >= 0 ? bridge.generatorr.level : bridge.level + 1
438
+ // const level = bridge.generatorr.level >= 0 ? bridge.generatorr.level : bridge.level + 1
439
+ let level
440
+ if (bridge.generatorr.level >= 0) {
441
+ level = bridge.generatorr.level
442
+ } else {
443
+ level = bridge.level + 1
444
+ if (!bridge.bridge ) {
445
+ level = 0
446
+ }
447
+ }
431
448
  const generator = {
432
449
  where: bridge.generatorr.where || bridge.where || helpers.where(4),
433
450
  // match: async (args) => bridge.id === args.context.marker && args.context.level === level && !args.context.paraphrase && (args.context.response || args.context.isResponse) && await match(args),
434
- match: async (args) => args.isA(args.context.marker, bridge.id) && args.context.level === level && !args.context.paraphrase && (args.context.response || args.context.isResponse) && await match(args),
451
+ match: async (args) => {
452
+ if (bridge.callId == args.callId) {
453
+ debugger
454
+ }
455
+ return args.isA(args.context.marker, bridge.id) && args.context.level === level && !args.context.paraphrase && (args.context.response != null || args.context.isResponse) && await match(args)
456
+ },
435
457
  apply: (args) => apply(args),
436
458
  applyWrapped: apply,
437
459
  property: 'generatorr'
@@ -523,6 +545,7 @@ const handleCalculatedProps = (baseConfig, moreConfig, { addFirst, uuid } = {})
523
545
  'associations',
524
546
  'before',
525
547
  'bridge',
548
+ 'callId',
526
549
  'check',
527
550
  'children',
528
551
  'conditional',
@@ -536,6 +559,7 @@ const handleCalculatedProps = (baseConfig, moreConfig, { addFirst, uuid } = {})
536
559
  'generatorr',
537
560
  'generators',
538
561
  'id',
562
+ 'init',
539
563
  'inverted',
540
564
  'isA',
541
565
  'level',
@@ -1094,19 +1118,6 @@ class Config {
1094
1118
  this.testConfig.checks.context = []
1095
1119
  }
1096
1120
  this.testConfig.checks.context = this.contextChecksFromBridges.concat(this.testConfig.checks.context)
1097
- /*
1098
- const currentTestConfig = testConfig // add bridge has added check.context's
1099
-
1100
- if (!this.testConfig.checks) {
1101
- debugger
1102
- // this.testConfig.checks =
1103
- }
1104
-
1105
- // set during bridge setup
1106
- if (currentTestConfig.checks?.context) {
1107
- this.testConfig.checks.context = currentTestConfig.checks.context.concat(this.testConfig.checks.context)
1108
- }
1109
- */
1110
1121
  }
1111
1122
 
1112
1123
  getTestConfig () {
@@ -1224,10 +1235,10 @@ class Config {
1224
1235
  async getEvaluator (s, calls, log, context, args) {
1225
1236
  const instance = await s({ ...args, ...context, evaluate: true })
1226
1237
  calls.touch(instance)
1227
- if (!instance.evalue && !instance.verbatim && !instance.value) {
1238
+ if (instance.evalue == null && !instance.verbatim && !instance.value) {
1228
1239
  this.warningNotEvaluated(log, context)
1229
1240
  }
1230
- if (!instance.evalue) {
1241
+ if (instance.evalue == null) {
1231
1242
  instance.evalue = instance.value
1232
1243
  instance.edefault = true
1233
1244
  }
@@ -2140,6 +2151,11 @@ class Config {
2140
2151
  }
2141
2152
  }
2142
2153
 
2154
+ async setDemoInitializer(demoInitializer) {
2155
+ this.demoInitializer = demoInitializer
2156
+ // await this.demoInitializer(this)
2157
+ }
2158
+
2143
2159
  // configs = [ { config, namespace } ... ]
2144
2160
  constructor (config, module, clientProcess, apiKMs, rootIsProcess, testingModuleName) {
2145
2161
  if (config instanceof Config) {
@@ -2163,6 +2179,7 @@ class Config {
2163
2179
  config.priorities = config.priorities || []
2164
2180
  }
2165
2181
 
2182
+ this.demoInitializer = null
2166
2183
  this.contextChecksFromBridges = []
2167
2184
 
2168
2185
  this._enable = []
@@ -2276,7 +2293,7 @@ class Config {
2276
2293
 
2277
2294
  async restart_auto_rebuild () {
2278
2295
  this._stop_auto_rebuild = false
2279
- await this.rebuild()
2296
+ return await this.rebuild()
2280
2297
  }
2281
2298
 
2282
2299
  getAddedArgs (args) {
@@ -2479,6 +2496,7 @@ class Config {
2479
2496
  this.valid()
2480
2497
  const cp = new Config()
2481
2498
  cp.logs = []
2499
+ cp.demoInitializer = this.demoInitializer
2482
2500
  cp.maxDepth = this.maxDepth
2483
2501
  cp.debugLoops = this.debugLoops
2484
2502
  cp.transitoryMode = this.transitoryMode
@@ -2553,6 +2571,11 @@ class Config {
2553
2571
  cp.config.objects.namespaced[km._uuid] = {}
2554
2572
  })
2555
2573
  }
2574
+
2575
+ if (cp.demoInitializer) {
2576
+ await cp.demoInitializer(cp)
2577
+ }
2578
+
2556
2579
  cp.valid()
2557
2580
  return cp
2558
2581
  }
@@ -2855,7 +2878,11 @@ class Config {
2855
2878
  let defaults = () => []
2856
2879
  if (this.loadOrdering) {
2857
2880
  for (const name of this.loadOrdering) {
2858
- const checks = this.kms[name].testConfig?.checks?.context || []
2881
+ const config = this.kms[name]
2882
+ let checks = config.testConfig?.checks?.context || []
2883
+ if (config.contextChecksFromBridges) {
2884
+ checks = config.contextChecksFromBridges.concat(checks)
2885
+ }
2859
2886
  const oldDefaults = defaults
2860
2887
  for (const check of checks) {
2861
2888
  if (!check.match) {
@@ -3077,6 +3104,15 @@ class Config {
3077
3104
  this.removeDevelopmentElements(this.config)
3078
3105
  }
3079
3106
 
3107
+ if (this.testConfig?.testModuleName) {
3108
+ const km = this.km(this.testConfig.testModuleName)
3109
+ if (km.demoInitializer) {
3110
+ await km.demoInitializer(km)
3111
+ }
3112
+ } else if (this.demoInitializer) {
3113
+ await this.demoInitializer(this)
3114
+ }
3115
+
3080
3116
  this.valid()
3081
3117
  this.checks()
3082
3118
  }
@@ -3462,7 +3498,8 @@ class Config {
3462
3498
  }
3463
3499
 
3464
3500
  // TODO get rid of useOldVersion arg
3465
- addInternal (more, { uuid, km, addFirst = false, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false, handleCalculatedProps: hcps = false } = {}) {
3501
+ addInternal (more,
3502
+ { uuid, km, addFirst = false, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false, handleCalculatedProps: hcps = false } = {}) {
3466
3503
  validConfigProps(more)
3467
3504
  if (more instanceof Config) {
3468
3505
  more.initialize({ force: false })
@@ -86,6 +86,28 @@ const cleanAssign = (dest, ...srcs) => {
86
86
  Object.assign(dest, ...srcs)
87
87
  }
88
88
 
89
+ class ContextHierarchy {
90
+ constructor(contexts = []) {
91
+ this.contexts = [...contexts]
92
+ }
93
+
94
+ push(context) {
95
+ this.contexts.push(context)
96
+ }
97
+
98
+ pop() {
99
+ this.contexts.pop()
100
+ }
101
+
102
+ under(marker) {
103
+ for (let i = this.contexts.length - 1; i >= 0; --i) {
104
+ if (this.contexts[i].marker == marker) {
105
+ return true
106
+ }
107
+ }
108
+ }
109
+ }
110
+
89
111
  const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
90
112
  if (!args.objects) {
91
113
  args.objects = config.get('objects')
@@ -105,6 +127,7 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
105
127
  if (global.theprogrammablemind && global.theprogrammablemind.loadForTesting) {
106
128
  args.calls = new InitCalls(Object.keys(global.theprogrammablemind.loadForTesting)[0])
107
129
  }
130
+ args.contextHierarchy = new ContextHierarchy()
108
131
  args.cleanAssign = cleanAssign
109
132
  args.km = (name) => config.getConfig(name)
110
133
  args.api = (name) => config.getConfig(name).api
package/src/debug.js CHANGED
@@ -51,6 +51,7 @@ const counter = (name, { breakAt = [], debugBreak = true, tag = '' } = {}) => {
51
51
  hit(name)
52
52
  return true
53
53
  }
54
+ return counters[name]
54
55
  }
55
56
 
56
57
  const get = (name) => {
package/src/fragments.js CHANGED
@@ -1,6 +1,18 @@
1
1
  const _ = require('lodash')
2
2
  const helpers = require('./helpers')
3
3
 
4
+ function pathEquals (p1, p2) {
5
+ if (p1.length !== p2.length) {
6
+ return false
7
+ }
8
+ for (let i = 0; i < p1.length; ++i) {
9
+ if (p1[i] !== p2[i]) {
10
+ return false
11
+ }
12
+ }
13
+ return true
14
+ }
15
+
4
16
  function fragmentInstantiator (args, contexts) {
5
17
  return new Object({
6
18
  contexts: () => {
@@ -10,6 +22,7 @@ function fragmentInstantiator (args, contexts) {
10
22
  const instantiated = _.cloneDeep(contexts)
11
23
  const todo = [{ context: instantiated, path: [] }]
12
24
  args = { ...args }
25
+ args.pathEquals = pathEquals
13
26
  while (todo.length > 0) {
14
27
  const { context, path } = todo.pop()
15
28
  args.context = context
package/src/semantics.js CHANGED
@@ -156,11 +156,21 @@ class Semantics {
156
156
  }
157
157
 
158
158
  async applyToContext (args, context, options) {
159
+ args.contextHierarchy.push(context)
160
+ try {
161
+ return await this.applyToContextHelper(args, context, options)
162
+ } finally {
163
+ args.contextHierarchy.pop()
164
+ }
165
+ }
166
+
167
+ async applyToContextHelper (args, context, options) {
159
168
  // let context_prime = {}
160
169
  if (!(context instanceof Array || context instanceof Object)) {
161
170
  return context
162
171
  }
163
172
  args = { ...args }
173
+
164
174
  const config = args.config
165
175
  const debug = config.getDebug()
166
176
  let contextPrime = Object.assign({}, context)