theprogrammablemind_4wp 9.5.1 → 9.6.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
@@ -12,10 +12,9 @@ const _ = require('lodash')
12
12
  const stringify = require('json-stable-stringify')
13
13
  const Lines = require('./lines')
14
14
  const flattens = require('./src/flatten')
15
- const { appendNoDups, updateQueries, safeNoDups, stableId, where, suggestAssociationsFix, suggestAssociationsFixFromSummaries, validProps } = require('./src/helpers')
15
+ const { sortJson, appendNoDups, updateQueries, safeNoDups, stableId, where, suggestAssociationsFix, suggestAssociationsFixFromSummaries, validProps } = require('./src/helpers')
16
16
  const runtime = require('./runtime')
17
- const sortJson = runtime.sortJson
18
- const debug = require('./src/debug')
17
+ const db = require('./src/debug')
19
18
 
20
19
  const getConfig_getObjectsCheck = (config, testConfig) => {
21
20
  let testConfigName = config.name
@@ -46,33 +45,33 @@ const getSuggestionMessage = (suggestion) => {
46
45
  return `Try adding this to the associations: { context: ${JSON.stringify(getSuggestion(suggestion))}, choose: <indexOfMainElement> },\n If that does not work look at the logs and check when the operators become wrong during an interation. Deduce the change based on the previous iteration and what operator was applied.`
47
46
  }
48
47
 
49
- const getConfig_getContextCheck = (testConfig) => {
50
- return (testConfig.checks && testConfig.checks.context) || []
51
- }
52
-
53
48
  const pickContext = (contextChecks) => (context) => {
54
49
  return project2(context, contextChecks)
55
50
  }
56
51
 
57
52
  const pickObjects = (config, testConfig, getObjects) => {
58
- /*
59
- let testConfigName = config.name
60
- if (testConfig.testModuleName) {
61
- objects = getObjects(config.config.objects)(config.getConfigs()[testConfig.testModuleName].uuid)
62
- testConfigName = testConfig.testModuleName
63
- }
64
- */
65
53
  const checks = getConfig_getObjectsCheck(config, testConfig)
54
+ const contextChecks = config.getContextChecks()
66
55
  const projection = {}
67
56
  for (const km in checks) {
68
57
  const objects = getObjects(km)
69
58
  if (!objects) {
70
59
  throw new Error(`In the checks for ${config.name} the KM ${km} does not exist`)
71
60
  }
72
- if (checks[km] && checks[km].find((check) => check.match && check.apply)) {
73
- projection[km] = project2(objects, checks[km])
61
+
62
+ if (false) {
63
+ if (checks[km] && checks[km].find((check) => check.match && check.apply)) {
64
+ projection[km] = project2(objects, checks[km])
65
+ } else {
66
+ projection[km] = project(objects, checks[km])
67
+ }
74
68
  } else {
75
- projection[km] = project(objects, checks[km])
69
+ const lastIndex = contextChecks.length - 1
70
+ const last = contextChecks[lastIndex]
71
+ contextChecks[lastIndex] = { match: last.match, apply: () => [...new Set([...(checks[km] || []), ...last.apply()])] }
72
+
73
+ // projection[km] = project2(objects, [...checks[km], ...contextChecks])
74
+ projection[km] = project2(objects, contextChecks)
76
75
  }
77
76
  }
78
77
  return projection
@@ -237,9 +236,10 @@ const doWithRetries = async (n, url, queryParams, data) => {
237
236
  body: JSON.stringify(data),
238
237
  timeout: 1000 * 60 * 5, // it does not respect this timeout so that's why I have the retries
239
238
  headers: {
240
- mode: 'no-cors',
239
+ // mode: 'no-cors',
241
240
  'Content-Type': 'application/json'
242
- }
241
+ },
242
+ credentials: 'same-origin',
243
243
  })
244
244
  if (result.ok) {
245
245
  return JSON.parse(JSON.stringify(await result.json()))
@@ -316,6 +316,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
316
316
  }
317
317
 
318
318
  let startCounter = 0
319
+ let contextIdCounter = 0
319
320
  while (true) {
320
321
  if (queries.length === 0) {
321
322
  break
@@ -356,8 +357,9 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
356
357
  }
357
358
  const summary = { summaries: json.summaries, length: json.contexts.length }
358
359
  summaries.push(summary)
359
- const { contextsPrime, generatedPrime, paraphrasesPrime, paraphrasesParenthesizedPrime, generatedParenthesizedPrime, responsesPrime } =
360
- await processContextsB({ isTest, isProcess, isModule, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
360
+ const { updatedContextIdCounter, contextsPrime, generatedPrime, paraphrasesPrime, paraphrasesParenthesizedPrime, generatedParenthesizedPrime, responsesPrime } =
361
+ await processContextsB({ contextIdCounter, isTest, isProcess, isModule, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
362
+ contextIdCounter = updatedContextIdCounter
361
363
  if (isTest) {
362
364
  const end = runtime.performance.performance.now()
363
365
  clientSideTime = end - start
@@ -475,6 +477,7 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug, tim
475
477
  return
476
478
  }
477
479
  // initialize in between test so state is not preserved since the test was adding without state
480
+ config.testConfig.testModuleName = testConfig.testModuleName
478
481
  await config.rebuild()
479
482
  const errorHandler = (error) => {
480
483
  if (error.metadata) {
@@ -838,7 +841,7 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
838
841
  }
839
842
  console.log(responses.trace)
840
843
 
841
- if (true) {
844
+ if (false) {
842
845
  if (global.beforeObjects) {
843
846
  console.log('objects', runtime.jsonDiff.diffString(global.beforeObjects, config.get('objects')))
844
847
  } else {
@@ -913,7 +916,7 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
913
916
  console.log('')
914
917
  const screen_width = process.stdout.columns
915
918
  // || 0 for when running without a console
916
- const widths = [70, 10, Math.max(80, screen_width - 71 || 0)]
919
+ const widths = Lines.addRemainder([70, 10])
917
920
  const lines = new Lines(widths)
918
921
  lines.setElement(0, 0, '--- The paraphrases are ----------')
919
922
  lines.setElement(0, 2, '--- The response strings are ----------')
@@ -933,12 +936,15 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
933
936
  }
934
937
  }
935
938
 
936
- const defaultProcess = ({ config, errorHandler }) => async (promise) => {
939
+ const defaultProcess = ({ config, errorHandler, print }) => async (promise) => {
937
940
  try {
938
941
  const responses = await promise
939
942
  defaultInnerProcess(config, errorHandler, responses)
940
943
  } catch (error) {
941
944
  error.config = config
945
+ if (print) {
946
+ print()
947
+ }
942
948
  defaultErrorHandler(error)
943
949
  }
944
950
  }
@@ -963,8 +969,11 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
963
969
  }
964
970
  }
965
971
  const fragmentToTodo = (query, index) => {
966
- const pr = instance.fragments[index]
967
- return Object.assign({}, toProperties(query), { property: 'fragments', previousResults: pr, skipSemantics: false })
972
+ let pr = []
973
+ if (instance.fragments) {
974
+ pr = instance.fragments[index]
975
+ }
976
+ return Object.assign({}, toProperties(query), { property: 'fragments', previousResults: pr, skipSemantics: true })
968
977
  }
969
978
 
970
979
  const looper = async (configs) => {
@@ -973,7 +982,7 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
973
982
  return
974
983
  }
975
984
  const { property, hierarchy, query: queryOrExtraConfig, previousResults, initializer, skipSemantics } = configs.shift()
976
- // queries are strings or { query: "blah", development: true/false }
985
+ // queries are strings or { query: "blah", scope: "development" | "testing" }
977
986
  if (typeof queryOrExtraConfig === 'string' || queryOrExtraConfig.query || queryOrExtraConfig.isFragment) {
978
987
  let query = queryOrExtraConfig
979
988
  const isFragment = queryOrExtraConfig.isFragment
@@ -1253,8 +1262,8 @@ const knowledgeModuleImpl = async ({
1253
1262
  config.setTestConfig(testConfig)
1254
1263
  }
1255
1264
 
1256
- const createConfig = async () => {
1257
- const config = new Config(configStruct, moduleFromJSFile, _process, apiKMs)
1265
+ const createConfig = async (rootIsProcess, testingModuleName) => {
1266
+ const config = new Config(configStruct, moduleFromJSFile, _process, apiKMs, rootIsProcess, testingModuleName)
1258
1267
  if (sendObjectsToServer) {
1259
1268
  config.setSendObjectsToServer()
1260
1269
  }
@@ -1318,13 +1327,32 @@ const knowledgeModuleImpl = async ({
1318
1327
  parser.add_argument('-cl', '--checkForLoop', { nargs: '?', help: 'Check for loops in the priorities, Optional argument is list of operator keys to consider. For example [["banana", 0], ["food", 1]]' })
1319
1328
  parser.add_argument('-r', '--reset', { action: 'store_true', help: 'Get the server to bypass the cache and rebuild everything' })
1320
1329
  parser.add_argument('-q', '--query', { help: 'Run the specified query' })
1330
+ parser.add_argument('-f', '--filter', { help: 'for -pd only the data for the knowledge modules that start with this string will be shown' })
1321
1331
  parser.add_argument('-ip ', '--server', { help: 'Server to run against' })
1322
1332
  parser.add_argument('-qp ', '--queryParams', { help: 'Query params for the server call' })
1323
1333
  parser.add_argument('-dt', '--deleteTest', { help: 'Delete the specified query from the tests file.' })
1324
1334
  parser.add_argument('--parenthesized', { action: 'store_true', help: 'Show the generated phrases with parenthesis.' })
1325
1335
  parser.add_argument('-c', '--clean', { help: 'Remove data from the test files. a === association' })
1326
1336
  parser.add_argument('-od', '--objectDiff', { action: 'store_true', help: 'When showing the objects use a colour diff' })
1327
- parser.add_argument('-p', '--print', { help: 'Print the specified elements c === config, w === words, b === bridges, o === operators d === objects (d for data), h === hierarchy, ha === hierarchy ancestors g === generators, s === semantics, l === load t=tests ordering p === priorities a === associations j === JSON sent to server. for example --print wb' })
1337
+ parser.add_argument('-p', '--print', { help:
1338
+ `Print the specified elements
1339
+ a === associations
1340
+ b === bridges,
1341
+ c === config,
1342
+ cc === test checks,
1343
+ d === objects (d for data),
1344
+ g === generators,
1345
+ h === hierarchy,
1346
+ ha === hierarchy ancestors,
1347
+ j === JSON sent to server,
1348
+ l === load ordering,
1349
+ o === operators,
1350
+ p === priorities,
1351
+ s === semantics,
1352
+ t === tests ordering,
1353
+ w === words,
1354
+ for example --print wb' })
1355
+ ` })
1328
1356
  parser.add_argument('-s', '--save', { action: 'store_true', help: 'When running with the --query flag this will save the current run to the test file. When running without the --query flag all tests will be run and resaved.' })
1329
1357
  parser.add_argument('-fr', '--failRebuild', { action: 'store_true', help: 'If a rebuild is required fail out.' })
1330
1358
  parser.add_argument('-sd', '--saveDeveloper', { action: 'store_true', help: 'Same as -s but the query will not show up in the info command.' })
@@ -1347,16 +1375,13 @@ const knowledgeModuleImpl = async ({
1347
1375
  if (args.rebuildTemplateFull) {
1348
1376
  args.rebuildTemplate = true
1349
1377
  }
1350
- config = await createConfig()
1378
+ config = await createConfig(true, configStruct.name)
1351
1379
 
1352
1380
  // 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
1381
  if (args.rebuildTemplate) {
1354
1382
  global.pauseDebugging = true
1355
1383
  }
1356
1384
 
1357
- // setupConfig(config)
1358
- processResults = processResults({ config, errorHandler })
1359
-
1360
1385
  if (args.rebuildTemplate) {
1361
1386
  global.pauseDebugging = false
1362
1387
  }
@@ -1488,6 +1513,12 @@ const knowledgeModuleImpl = async ({
1488
1513
  counter += 1
1489
1514
  }
1490
1515
  }
1516
+ if (hasArg('cc')) {
1517
+ for (const cc of config.getContextChecks()) {
1518
+ const printable = { ...cc, match: cc.match.toString(), apply: cc.apply.toString() }
1519
+ console.log(JSON.stringify(printable, null, 2))
1520
+ }
1521
+ }
1491
1522
  if (hasArg('c')) {
1492
1523
  const { data } = setupProcessB({ config })
1493
1524
  console.log('Config as sent to server')
@@ -1549,14 +1580,29 @@ const knowledgeModuleImpl = async ({
1549
1580
  }
1550
1581
  }
1551
1582
  }
1583
+
1552
1584
  if (hasArg('d')) {
1553
- console.log(JSON.stringify(config.config.objects, null, 2))
1585
+ if (args.filter) {
1586
+ console.log(`objects (data) filtered by ${args.filter} ================`)
1587
+ const projection = { namespaced: {} }
1588
+ for (const key of Object.keys(config.config.objects.namespaced)) {
1589
+ if (key.startsWith(args.filter)) {
1590
+ projection.namespaced[key] = config.config.objects.namespaced[key]
1591
+ }
1592
+ }
1593
+ console.log(JSON.stringify(projection, null, 2))
1594
+ } else {
1595
+ console.log('objects (data) ================')
1596
+ console.log(JSON.stringify(config.config.objects, null, 2))
1597
+ }
1554
1598
  }
1599
+
1555
1600
  if (hasArg('p')) {
1556
1601
  for (const priority of config.config.priorities) {
1557
1602
  console.log(JSON.stringify(priority))
1558
1603
  }
1559
1604
  }
1605
+
1560
1606
  if (hasArg('g')) {
1561
1607
  const easyToRead = _.cloneDeep(config.config.generators)
1562
1608
  for (const semantic of easyToRead) {
@@ -1568,6 +1614,7 @@ const knowledgeModuleImpl = async ({
1568
1614
  }
1569
1615
  console.dir(easyToRead)
1570
1616
  }
1617
+
1571
1618
  if (hasArg('s')) {
1572
1619
  const easyToRead = _.cloneDeep(config.config.semantics)
1573
1620
  for (const semantic of easyToRead) {
@@ -1579,6 +1626,10 @@ const knowledgeModuleImpl = async ({
1579
1626
  }
1580
1627
  }
1581
1628
 
1629
+ // setupConfig(config)
1630
+ processResults = processResults({ config, errorHandler, print: printConfig })
1631
+
1632
+
1582
1633
  checkTemplate(template)
1583
1634
 
1584
1635
  if (template) {
@@ -1912,6 +1963,7 @@ const knowledgeModuleImpl = async ({
1912
1963
  try {
1913
1964
  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
1965
  } catch (error) {
1966
+ printConfig()
1915
1967
  console.log('Error', error)
1916
1968
  }
1917
1969
  }
@@ -1949,33 +2001,17 @@ const knowledgeModuleImpl = async ({
1949
2001
 
1950
2002
  // remove test only stuff
1951
2003
  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
- */
2004
+ config.removeDevelopmentElements(config.config, config.scope)
1969
2005
  }
1970
2006
  }
1971
2007
 
1972
2008
  // no cache 21 minutes + rebuild fails "node tester_rebuild -m colors"
1973
2009
  // cache okay
1974
- const createConfigExport = async (useCache = true) => {
2010
+ const createConfigExport = async ({ useCache=true, rootIsProcess, testingModuleName } = {}) => {
1975
2011
  if (useCache && createConfig.cached) {
1976
2012
  return createConfig.cached
1977
2013
  }
1978
- const config = await createConfig()
2014
+ const config = await createConfig(rootIsProcess, testingModuleName)
1979
2015
  await initConfig(config)
1980
2016
  // config.rebuild({ isModule: true })
1981
2017
  createConfig.cached = config
@@ -2011,9 +2047,15 @@ const ensureTestFile = (module, name, type) => {
2011
2047
  }
2012
2048
 
2013
2049
  const knowledgeModule = async (...args) => {
2014
- await knowledgeModuleImpl(...args).catch((e) => {
2050
+ await knowledgeModuleImpl(...args).catch(async (e) => {
2015
2051
  console.error(e)
2016
- process.exit(-1)
2052
+ function sleep(ms) {
2053
+ return new Promise((resolve) => {
2054
+ setTimeout(resolve, ms);
2055
+ });
2056
+ }
2057
+ await sleep(1) // get the stderr to flush
2058
+ await process.exit(-1); // tiny trick: empty write forces flush of console.error buffer
2017
2059
  })
2018
2060
  }
2019
2061
 
@@ -2038,5 +2080,6 @@ module.exports = {
2038
2080
  gs,
2039
2081
  flattens,
2040
2082
  writeTest,
2041
- getConfigForTest
2083
+ getConfigForTest,
2084
+ debug: db,
2042
2085
  }
package/lines.js CHANGED
@@ -5,6 +5,13 @@ class Lines {
5
5
  this.rows = []
6
6
  }
7
7
 
8
+ static SCREEN_WIDTH = 164
9
+
10
+ static addRemainder(widths) {
11
+ const sum = widths.reduce((a, b) => a + b)
12
+ return [...widths, Lines.SCREEN_WIDTH - sum]
13
+ }
14
+
8
15
  addLine () {
9
16
  this.lines.push(this.widths.map((width) => ''.padEnd(width)))
10
17
  }
package/package.json CHANGED
@@ -3,14 +3,14 @@
3
3
  "@eslint/js": "^9.21.0",
4
4
  "@typescript-eslint/eslint-plugin": "^4.28.4",
5
5
  "@typescript-eslint/parser": "^4.28.4",
6
+ "argparse": "^2.0.1",
6
7
  "eslint": "^7.32.0",
7
8
  "eslint-config-standard": "^16.0.3",
8
9
  "eslint-plugin-import": "^2.23.4",
9
10
  "eslint-plugin-node": "^11.1.0",
10
11
  "eslint-plugin-promise": "^5.1.0",
11
12
  "globals": "^16.0.0",
12
- "jest": "^29.7.0",
13
- "argparse": "^2.0.1"
13
+ "jest": "^30.2.0"
14
14
  },
15
15
  "scripts": {
16
16
  "to:debug": "node inspect node_modules/.bin/jest --runInBand -t NEO23",
@@ -45,6 +45,7 @@
45
45
  "runtime.js",
46
46
  "src/helpers.js",
47
47
  "src/flatten.js",
48
+ "src/fragments.js",
48
49
  "src/unflatten.js",
49
50
  "src/config.js",
50
51
  "src/configHelpers.js",
@@ -61,6 +62,7 @@
61
62
  "dependencies": {
62
63
  "base-64": "^1.0.0",
63
64
  "deep-equal": "^2.0.4",
65
+ "flatted": "^3.3.3",
64
66
  "fs": "0.0.1-security",
65
67
  "json-diff": "^1.0.3",
66
68
  "json-stable-stringify": "^1.0.1",
@@ -68,9 +70,8 @@
68
70
  "node-fetch": "^2.6.1",
69
71
  "readline": "^1.3.0",
70
72
  "scriptjs": "^2.5.9",
71
- "sort-json": "^2.0.0",
72
73
  "uuid": "^8.3.2"
73
74
  },
74
- "version": "9.5.1",
75
+ "version": "9.6.0",
75
76
  "license": "UNLICENSED"
76
77
  }
package/runtime.js CHANGED
@@ -12,7 +12,6 @@ module.exports = {
12
12
  ArgumentParser: 'Should not be called in the browser',
13
13
  readline: 'Should not be called in the browser',
14
14
  jsonDiff: 'Should not be called in the browser',
15
- sortJson: 'Should not be called in the browser',
16
15
  util: 'Should not be called in the browser',
17
16
  performance: 'Should not be called in the browser'
18
17
  }