theprogrammablemind_4wp 9.5.0 → 9.5.1-beta.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.
package/client.js CHANGED
@@ -933,12 +933,15 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
933
933
  }
934
934
  }
935
935
 
936
- const defaultProcess = ({ config, errorHandler }) => async (promise) => {
936
+ const defaultProcess = ({ config, errorHandler, print }) => async (promise) => {
937
937
  try {
938
938
  const responses = await promise
939
939
  defaultInnerProcess(config, errorHandler, responses)
940
940
  } catch (error) {
941
941
  error.config = config
942
+ if (print) {
943
+ print()
944
+ }
942
945
  defaultErrorHandler(error)
943
946
  }
944
947
  }
@@ -963,7 +966,10 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
963
966
  }
964
967
  }
965
968
  const fragmentToTodo = (query, index) => {
966
- const pr = instance.fragments[index]
969
+ let pr = []
970
+ if (instance.fragments) {
971
+ pr = instance.fragments[index]
972
+ }
967
973
  return Object.assign({}, toProperties(query), { property: 'fragments', previousResults: pr, skipSemantics: false })
968
974
  }
969
975
 
@@ -973,7 +979,7 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
973
979
  return
974
980
  }
975
981
  const { property, hierarchy, query: queryOrExtraConfig, previousResults, initializer, skipSemantics } = configs.shift()
976
- // queries are strings or { query: "blah", development: true/false }
982
+ // queries are strings or { query: "blah", scope: "development" | "testing" }
977
983
  if (typeof queryOrExtraConfig === 'string' || queryOrExtraConfig.query || queryOrExtraConfig.isFragment) {
978
984
  let query = queryOrExtraConfig
979
985
  const isFragment = queryOrExtraConfig.isFragment
@@ -1253,8 +1259,8 @@ const knowledgeModuleImpl = async ({
1253
1259
  config.setTestConfig(testConfig)
1254
1260
  }
1255
1261
 
1256
- const createConfig = async () => {
1257
- const config = new Config(configStruct, moduleFromJSFile, _process, apiKMs)
1262
+ const createConfig = async (rootIsProcess, testingModuleName) => {
1263
+ const config = new Config(configStruct, moduleFromJSFile, _process, apiKMs, rootIsProcess, testingModuleName)
1258
1264
  if (sendObjectsToServer) {
1259
1265
  config.setSendObjectsToServer()
1260
1266
  }
@@ -1347,16 +1353,13 @@ const knowledgeModuleImpl = async ({
1347
1353
  if (args.rebuildTemplateFull) {
1348
1354
  args.rebuildTemplate = true
1349
1355
  }
1350
- config = await createConfig()
1356
+ config = await createConfig(true, configStruct.name)
1351
1357
 
1352
1358
  // dont debug the load of the KM's if rebuild template is on since we want to debug the template rebuild not the load
1353
1359
  if (args.rebuildTemplate) {
1354
1360
  global.pauseDebugging = true
1355
1361
  }
1356
1362
 
1357
- // setupConfig(config)
1358
- processResults = processResults({ config, errorHandler })
1359
-
1360
1363
  if (args.rebuildTemplate) {
1361
1364
  global.pauseDebugging = false
1362
1365
  }
@@ -1549,14 +1552,18 @@ const knowledgeModuleImpl = async ({
1549
1552
  }
1550
1553
  }
1551
1554
  }
1555
+
1552
1556
  if (hasArg('d')) {
1557
+ console.log('objects (data) ================')
1553
1558
  console.log(JSON.stringify(config.config.objects, null, 2))
1554
1559
  }
1560
+
1555
1561
  if (hasArg('p')) {
1556
1562
  for (const priority of config.config.priorities) {
1557
1563
  console.log(JSON.stringify(priority))
1558
1564
  }
1559
1565
  }
1566
+
1560
1567
  if (hasArg('g')) {
1561
1568
  const easyToRead = _.cloneDeep(config.config.generators)
1562
1569
  for (const semantic of easyToRead) {
@@ -1568,6 +1575,7 @@ const knowledgeModuleImpl = async ({
1568
1575
  }
1569
1576
  console.dir(easyToRead)
1570
1577
  }
1578
+
1571
1579
  if (hasArg('s')) {
1572
1580
  const easyToRead = _.cloneDeep(config.config.semantics)
1573
1581
  for (const semantic of easyToRead) {
@@ -1579,6 +1587,10 @@ const knowledgeModuleImpl = async ({
1579
1587
  }
1580
1588
  }
1581
1589
 
1590
+ // setupConfig(config)
1591
+ processResults = processResults({ config, errorHandler, print: printConfig })
1592
+
1593
+
1582
1594
  checkTemplate(template)
1583
1595
 
1584
1596
  if (template) {
@@ -1912,6 +1924,7 @@ const knowledgeModuleImpl = async ({
1912
1924
  try {
1913
1925
  await processResults(_process(config, args.query, { commandLineArgs: args, isProcess, isModule: !isProcess, dontAddAssociations: args.dontAddAssociations, writeTests: args.save || args.saveDeveloper, saveDeveloper: args.saveDeveloper, testConfig, testsFN: test }))
1914
1926
  } catch (error) {
1927
+ printConfig()
1915
1928
  console.log('Error', error)
1916
1929
  }
1917
1930
  }
@@ -1949,33 +1962,17 @@ const knowledgeModuleImpl = async ({
1949
1962
 
1950
1963
  // remove test only stuff
1951
1964
  if (!isProcess && !loadForTesting) {
1952
- config.removeDevelopmentElements(config.config)
1953
- /*
1954
- config.config.operators = config.config.operators.filter((operator) => {
1955
- if (operator.development) {
1956
- return false
1957
- } else {
1958
- return true
1959
- }
1960
- })
1961
- config.config.bridges = config.config.bridges.filter((bridge) => {
1962
- if (bridge.development) {
1963
- return false
1964
- } else {
1965
- return true
1966
- }
1967
- })
1968
- */
1965
+ config.removeDevelopmentElements(config.config, config.scope)
1969
1966
  }
1970
1967
  }
1971
1968
 
1972
1969
  // no cache 21 minutes + rebuild fails "node tester_rebuild -m colors"
1973
1970
  // cache okay
1974
- const createConfigExport = async (useCache = true) => {
1971
+ const createConfigExport = async ({ useCache=true, rootIsProcess, testingModuleName } = {}) => {
1975
1972
  if (useCache && createConfig.cached) {
1976
1973
  return createConfig.cached
1977
1974
  }
1978
- const config = await createConfig()
1975
+ const config = await createConfig(rootIsProcess, testingModuleName)
1979
1976
  await initConfig(config)
1980
1977
  // config.rebuild({ isModule: true })
1981
1978
  createConfig.cached = config
package/package.json CHANGED
@@ -71,6 +71,6 @@
71
71
  "sort-json": "^2.0.0",
72
72
  "uuid": "^8.3.2"
73
73
  },
74
- "version": "9.5.0",
74
+ "version": "9.5.1-beta.0",
75
75
  "license": "UNLICENSED"
76
76
  }
package/src/config.js CHANGED
@@ -20,6 +20,8 @@ const bags = [
20
20
  'semantics'
21
21
  ]
22
22
 
23
+ global.GORDO = true
24
+
23
25
  const indent = (string, indent) => {
24
26
  return string.replace(/^/gm, ' '.repeat(indent))
25
27
  }
@@ -287,9 +289,11 @@ const priority_valid = (cp) => {
287
289
  const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
288
290
  ecatch(`While processing the bridge for ${bridge.id}#${bridge.level}`,
289
291
  () => {
292
+ /*
290
293
  if (bridge.development && config.isModule) {
291
294
  return
292
295
  }
296
+ */
293
297
  if (false && !bridge.bridge) {
294
298
  bridge.bridge = '{ ...next(operator) }'
295
299
  }
@@ -439,13 +443,32 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
439
443
  if (semantic.apply && typeof semantic !== 'function') {
440
444
  apply = semantic.apply
441
445
  }
442
- const semanticDef = {
443
- where: semantic.where || bridge.where || helpers.where(4),
444
- match: (args) => bridge.id === args.context.marker && !!args.context.evaluate === evaluate && match(args),
445
- apply: (args) => apply(args),
446
- applyWrapped: semantic,
447
- property: evaluate ? 'evaluator' : 'semantic'
446
+ let semanticDef
447
+ if (semantic.raw) {
448
+ if (!semantic.match) {
449
+ throw new Error(`In the KM "${config.name}", for the bridge ${bridge.id} the semantic is missing the "match" property.`)
450
+ }
451
+ if (!semantic.apply) {
452
+ throw new Error(`In the KM "${config.name}", for the bridge ${bridge.id} the semantic is missing the "apply" property.`)
453
+ }
454
+ semanticDef = {
455
+ match: semantic.match,
456
+ apply: semantic.apply,
457
+ applyWrapped: semantic,
458
+ }
459
+ } else {
460
+ semanticDef = {
461
+ match: (args) => bridge.id === args.context.marker && !!args.context.evaluate === evaluate && match(args),
462
+ apply: (args) => apply(args),
463
+ applyWrapped: semantic,
464
+ }
448
465
  }
466
+ semanticDef.where = semantic.where || bridge.where || helpers.where(4)
467
+ semanticDef.property = evaluate ? 'evaluator' : 'semantic'
468
+ if (semantic.priority) {
469
+ semanticDef.priority = semantic.priority
470
+ }
471
+
449
472
  if (addFirst) {
450
473
  config.config.semantics.unshift(addUUID(semanticDef))
451
474
  } else {
@@ -488,7 +511,7 @@ const handleCalculatedProps = (baseConfig, moreConfig, { addFirst, uuid } = {})
488
511
  if (moreConfig.bridges) {
489
512
  moreConfig.bridges = moreConfig.bridges.map((bridge) => {
490
513
  bridge = { ...bridge }
491
- const valid = ['after', 'conditional', 'associations', 'before', 'bridge', 'check', 'disabled', 'development', 'skipable', 'return_type_selector', 'evaluator', 'evaluators', 'generatorp', 'generatorr', 'generatorpr', 'generators', 'operator', 'id', 'convolution', 'inverted', 'isA', 'children', 'parents',
514
+ const valid = ['after', 'conditional', 'associations', 'before', 'bridge', 'check', 'disabled', 'scope', 'skipable', 'return_type_selector', 'evaluator', 'evaluators', 'generatorp', 'generatorr', 'generatorpr', 'generators', 'operator', 'id', 'convolution', 'inverted', 'isA', 'children', 'parents',
492
515
  'level', 'optional', 'selector', 'separators', 'semantic', 'semantics', 'words', /Bridge$/, 'localHierarchy', 'levelSpecificHierarchy', 'where', 'uuid']
493
516
  helpers.validProps(valid, bridge, 'bridge')
494
517
  handleBridgeProps(baseConfig, bridge, { addFirst, uuid })
@@ -1867,20 +1890,39 @@ class Config {
1867
1890
  return kms
1868
1891
  }
1869
1892
 
1893
+ // scope == 'testing' -> remove none
1894
+ // scope == 'development' -> remove testing
1895
+ // !scope -> remove 'testing' and 'development'
1870
1896
  removeDevelopmentElements (config) {
1871
1897
  if (!config) {
1872
1898
  return
1873
1899
  }
1874
- config.operators = config.operators.filter((element) => !element.development)
1875
- config.bridges = config.bridges.filter((element) => !element.development)
1876
- config.generators = config.generators.filter((element) => !element.development)
1877
- config.semantics = config.semantics.filter((element) => !element.development)
1878
- config.hierarchy = (config.hierarchy).filter((element) => !element.development)
1900
+
1901
+ const keep = (element) => {
1902
+ const old_result = element.scope !== 'testing'
1903
+ let new_result = false
1904
+ if (!this.scope) {
1905
+ new_result = !(element.scope === 'testing' || element.scope == 'development')
1906
+ } else if (this.scope == 'development') {
1907
+ new_result = !(element.scope === 'testing')
1908
+ }
1909
+ if (global.GORDO && old_result !== new_result) {
1910
+ global.GORDO = false
1911
+ debugger // greg23old
1912
+ }
1913
+ return old_result
1914
+ }
1915
+
1916
+ config.operators = config.operators.filter((element) => keep(element))
1917
+ config.bridges = config.bridges.filter((element) => keep(element))
1918
+ config.generators = config.generators.filter((element) => keep(element))
1919
+ config.semantics = config.semantics.filter((element) => keep(element))
1920
+ config.hierarchy = (config.hierarchy).filter((element) => keep(element))
1879
1921
 
1880
1922
  const literals = config.words.literals
1881
1923
  for (const word in literals) {
1882
1924
  const defs = literals[word] || []
1883
- literals[word] = defs.filter((def) => !def.development)
1925
+ literals[word] = defs.filter((def) => keep(def))
1884
1926
  if (literals[word].length === 0) {
1885
1927
  delete literals[word]
1886
1928
  }
@@ -1890,7 +1932,7 @@ class Config {
1890
1932
  const patternsPrime = []
1891
1933
  for (const pattern of patterns) {
1892
1934
  let defs = pattern.defs || []
1893
- defs = defs.filter((def) => !def.development)
1935
+ defs = defs.filter((def) => keep(def))
1894
1936
  if (defs.length !== 0) {
1895
1937
  patternsPrime.push({ ...pattern, defs })
1896
1938
  }
@@ -1900,7 +1942,7 @@ class Config {
1900
1942
  const hierarchy = config.words.hierarchy || []
1901
1943
  const hierarchyPrime = []
1902
1944
  for (const pair of hierarchy) {
1903
- if (!pair.development) {
1945
+ if (keep(pair)) {
1904
1946
  hierarchyPrime.push(pair)
1905
1947
  }
1906
1948
  }
@@ -1925,7 +1967,7 @@ class Config {
1925
1967
  }
1926
1968
 
1927
1969
  // configs = [ { config, namespace } ... ]
1928
- constructor (config, module, clientProcess, apiKMs) {
1970
+ constructor (config, module, clientProcess, apiKMs, rootIsProcess, testingModuleName) {
1929
1971
  if (config instanceof Config) {
1930
1972
  throw new Error('Excepted the config argument to be a hash not a Config object')
1931
1973
  }
@@ -1965,9 +2007,26 @@ class Config {
1965
2007
  this.loadedForTesting = true
1966
2008
  }
1967
2009
  }
2010
+ if (config) {
2011
+ this.name = config.name
2012
+ }
1968
2013
  this.isModule = !isProcess
2014
+ this.scope = null
2015
+ this.rootIsProcess = rootIsProcess
2016
+ this.testingModuleName = testingModuleName
1969
2017
  if (this.isModule) {
2018
+ if (rootIsProcess) {
2019
+ if (testingModuleName == this.name) {
2020
+ this.scope = 'testing'
2021
+ } else {
2022
+ this.scope = 'development'
2023
+ }
2024
+ }
1970
2025
  this.removeDevelopmentElements(config)
2026
+ } else {
2027
+ if (testingModuleName == this.name) {
2028
+ this.scope = 'testing'
2029
+ }
1971
2030
  }
1972
2031
  this.initInstances = []
1973
2032
  this.instances = []
@@ -1998,9 +2057,6 @@ class Config {
1998
2057
  }
1999
2058
  }
2000
2059
  this.terminatorFn = () => {}
2001
- if (config) {
2002
- this.name = config.name
2003
- }
2004
2060
  this.loadOrder = new DigraphInternal()
2005
2061
  this.wasInitialized = false
2006
2062
  this.configs = []
@@ -2290,6 +2346,10 @@ class Config {
2290
2346
  cp.hierarchy = new DigraphInternal(this.config.hierarchy)
2291
2347
  cp.sendObjectsToServer = this.sendObjectsToServer
2292
2348
 
2349
+ cp.scope = this.scope
2350
+ cp.rootIsProcess = this.rootIsProcess
2351
+ cp.testingModuleName = this.testingModuleName
2352
+
2293
2353
  cp.initConfig = _.cloneDeep(this.initConfig)
2294
2354
  cp.defaultConfig()
2295
2355
  // cp.wasInitialized = false; // since default config GREG
@@ -3144,7 +3204,7 @@ class Config {
3144
3204
 
3145
3205
  const mores = []
3146
3206
  for (const createConfig of createConfigs) {
3147
- const more = await createConfig()
3207
+ const more = await createConfig({ rootIsProcess: this.rootIsProcess, testingModuleName: this.testingModuleName })
3148
3208
  if (this.name && this.name === more.name) {
3149
3209
  throw new Error('Cannot add an object to itself for argument number ${index+1}.')
3150
3210
  }
package/src/helpers.js CHANGED
@@ -462,5 +462,5 @@ module.exports = {
462
462
  where,
463
463
  w,
464
464
  suggestAssociationsFix,
465
- suggestAssociationsFixFromSummaries
465
+ suggestAssociationsFixFromSummaries,
466
466
  }
package/src/semantics.js CHANGED
@@ -226,6 +226,9 @@ class Semantics {
226
226
  lines.newRow()
227
227
  lines.setElement(0, 2, semantic.toString())
228
228
  lines.newRow()
229
+ lines.setElement(0, 1, 'DEBUG')
230
+ lines.setElement(0, 2, `To debug this use args.callId === '${args.calls.current()}'`)
231
+ lines.newRow()
229
232
  lines.setElement(0, 1, 'TO')
230
233
  lines.setElement(0, 2, `context_id: ${context.context_id}`)
231
234
  lines.setElement(1, 2, JSON.stringify(helpers.sortJson(context, { depth: 25 }), null, 2))
@@ -233,9 +236,6 @@ class Semantics {
233
236
  lines.setElement(0, 1, 'STACK')
234
237
  lines.setElement(0, 2, stack)
235
238
  lines.newRow()
236
- lines.setElement(0, 1, 'DEBUG')
237
- lines.setElement(0, 2, `To debug this use args.callId === '${args.calls.current()}'`)
238
- lines.newRow()
239
239
  lines.setElement(0, 1, 'ERROR')
240
240
  lines.setElement(0, 2, errorMessage)
241
241
  this.logs.push(lines.toString())
@@ -248,7 +248,7 @@ class Semantics {
248
248
  args.calls.touch(contextPrime)
249
249
  // this.logs.push(`Semantics: applied ${semantic.toString()}\n to\n ${JSON.stringify(context)}\n the result was ${JSON.stringify(contextPrime)}\n`)
250
250
  if (((config || {}).config || {}).debug) {
251
- const widths = [10, 10, 90]
251
+ const widths = [10, 10, 132]
252
252
  const lines = new Lines(widths)
253
253
  lines.setElement(0, 0, 'Semantic')
254
254
  if (semantic.index > -1 && semantic.km) {
@@ -261,6 +261,9 @@ class Semantics {
261
261
  lines.newRow()
262
262
  lines.setElement(0, 2, semantic.toString())
263
263
  lines.newRow()
264
+ lines.setElement(0, 1, 'DEBUG')
265
+ lines.setElement(0, 2, `To debug this use args.callId === '${args.calls.current()}'`)
266
+ lines.newRow()
264
267
  lines.setElement(0, 1, 'TO')
265
268
  lines.setElement(0, 2, `context_id: ${context.context_id}`)
266
269
  lines.setElement(1, 2, JSON.stringify(helpers.sortJson(context, { depth: 25 }), null, 2))
@@ -268,9 +271,6 @@ class Semantics {
268
271
  lines.setElement(0, 1, 'STACK')
269
272
  lines.setElement(0, 2, stack)
270
273
  lines.newRow()
271
- lines.setElement(0, 1, 'DEBUG')
272
- lines.setElement(0, 2, `To debug this use args.callId === '${args.calls.current()}'`)
273
- lines.newRow()
274
274
  lines.setElement(0, 1, 'RESULT')
275
275
  lines.setElement(0, 2, `context_id: ${context.context_id}`)
276
276
  lines.setElement(1, 2, JSON.stringify(contextPrime, null, 2))