@hippo-digital/hippocampus 2.7.2 → 2.8.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.
Files changed (74) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/README.md +5 -4
  3. package/agents/knowledge-builder.md +2 -0
  4. package/agents/workflow-orchestrator.md +2 -0
  5. package/assets/dist/hippocampus.css +1 -1
  6. package/assets/hippocampus.scss +124 -0
  7. package/bin/hippocampus.js +1 -0
  8. package/docs/add-project-context.md +8 -2
  9. package/docs/ask-whats-already-known.md +6 -2
  10. package/docs/check-for-unintended-consequences.md +7 -2
  11. package/docs/data-and-governance.md +6 -2
  12. package/docs/describe-the-context-of-use.md +134 -0
  13. package/docs/design-actions-and-decisions.md +8 -3
  14. package/docs/hippocampus-for-designers-and-researchers.md +98 -220
  15. package/docs/hippocampus-technical.md +16 -0
  16. package/docs/human-centred-design.md +165 -0
  17. package/docs/import-a-research-round.md +9 -2
  18. package/docs/link-insights-to-needs.md +6 -2
  19. package/docs/record-a-usability-test.md +118 -0
  20. package/docs/record-design-principles.md +76 -0
  21. package/docs/research-knowledge-graph.md +25 -6
  22. package/docs/review-and-promote-a-draft.md +7 -2
  23. package/docs/set-quality-objectives.md +87 -0
  24. package/docs/source-model.md +104 -23
  25. package/docs/start-here.md +67 -34
  26. package/docs/turn-personas-into-users-and-needs.md +9 -2
  27. package/docs/weigh-options-against-requirements.md +96 -0
  28. package/docs/write-requirements.md +161 -0
  29. package/lib/breadcrumb.js +67 -14
  30. package/lib/create-router.js +125 -2
  31. package/lib/docs.js +28 -4
  32. package/lib/flow-map.js +15 -4
  33. package/lib/hcd-views.js +362 -0
  34. package/lib/known.js +5 -2
  35. package/lib/lint-knowledge.js +170 -1
  36. package/lib/load-knowledge.js +128 -5
  37. package/lib/record-links.js +11 -2
  38. package/lib/schema.js +190 -4
  39. package/lib/tidy-principles.js +112 -0
  40. package/package.json +1 -1
  41. package/scripts/import-design-actions.js +11 -2
  42. package/scripts/init.js +19 -0
  43. package/scripts/migrate-knowledge.js +9 -1
  44. package/scripts/smoke-routes.js +12 -1
  45. package/scripts/tidy-principles.js +68 -0
  46. package/skills/COVERAGE-MATRIX.md +2 -0
  47. package/skills/README.md +5 -0
  48. package/skills/SKILL-FORMAT.md +1 -1
  49. package/skills/add-scenario/SKILL.md +5 -1
  50. package/skills/add-user-needs/SKILL.md +11 -1
  51. package/skills/create-journey-from-scenario/SKILL.md +5 -2
  52. package/skills/ingest-research-round/SKILL.md +3 -3
  53. package/skills/ingest-user-personas/SKILL.md +24 -7
  54. package/skills/map-research-to-graph/SKILL.md +7 -5
  55. package/skills/record-design-decision/SKILL.md +1 -0
  56. package/skills/review-research-import-draft/SKILL.md +7 -1
  57. package/skills/skills.json +54 -1
  58. package/skills/structure-research-draft/SKILL.md +12 -2
  59. package/skills/weigh-options-against-requirements/SKILL.md +60 -0
  60. package/skills/write-requirements/SKILL.md +69 -0
  61. package/views/hippocampus/_layout.html +15 -12
  62. package/views/hippocampus/components/_activity.njk +36 -0
  63. package/views/hippocampus/components/_journey-step.njk +30 -0
  64. package/views/hippocampus/context.html +197 -0
  65. package/views/hippocampus/design.html +128 -0
  66. package/views/hippocampus/evaluation.html +119 -0
  67. package/views/hippocampus/index.html +57 -11
  68. package/views/hippocampus/journey.html +25 -1
  69. package/views/hippocampus/journeys.html +3 -0
  70. package/views/hippocampus/plan.html +64 -0
  71. package/views/hippocampus/requirements.html +94 -0
  72. package/views/hippocampus/research.html +20 -1
  73. package/views/hippocampus/scenarios.html +3 -0
  74. package/views/hippocampus/user.html +43 -3
@@ -5,7 +5,8 @@ const { listDocSections, readDoc, docImagePath, packageVersion } = require('./do
5
5
  const { listTemplates, allTemplates } = require('./templates')
6
6
  const { hrefFor, listHrefFor } = require('./record-links')
7
7
  const { matchesText, facet, matchesFacet, queryWithout } = require('./filter')
8
- const { buildTrail } = require('./breadcrumb')
8
+ const { buildTrail, navItems } = require('./breadcrumb')
9
+ const hcd = require('./hcd-views')
9
10
 
10
11
  function createHippocampusRouter ({ basePath, knowledgeStore, paths }) {
11
12
  const {
@@ -32,6 +33,22 @@ function createHippocampusRouter ({ basePath, knowledgeStore, paths }) {
32
33
  router.use('/assets', express.static(path.join(packagePaths.assetsDir, 'dist'), { fallthrough: true }))
33
34
  router.use('/assets', express.static(path.join(packagePaths.assetsDir, 'javascript'), { fallthrough: true }))
34
35
 
36
+ // nhsuk-prototype-kit 8.5.2 renders through a view class that joins
37
+ // "views/" onto every name and resolves it against the project root, so
38
+ // `hippocampus/index` became `views/hippocampus/index` and was looked for
39
+ // under the package's views directory as views/views/... - every viewer page
40
+ // was a 500 and `doctor` reported the prototype never started. Under that
41
+ // class the viewer passes `../hippocampus/...`, which the kit's join folds
42
+ // back to `hippocampus/...`. Kits that pass the name through unchanged get
43
+ // it unchanged.
44
+ router.use((req, res, next) => {
45
+ if (kitPrefixesViews(req.app)) {
46
+ const render = res.render.bind(res)
47
+ res.render = (name, ...rest) => render(typeof name === 'string' && name.startsWith('hippocampus/') ? `../${name}` : name, ...rest)
48
+ }
49
+ next()
50
+ })
51
+
35
52
  router.use((req, res, next) => {
36
53
  res.locals.basePath = basePath
37
54
  res.locals.hippocampusAssets = `${basePath}/assets`
@@ -53,6 +70,7 @@ function createHippocampusRouter ({ basePath, knowledgeStore, paths }) {
53
70
  // The trail is derived from the URL. A page about one record adds its own
54
71
  // name by setting res.locals.breadcrumbLeaf before rendering.
55
72
  res.locals.breadcrumbItems = buildTrail({ basePath, path: req.path })
73
+ res.locals.knowledgeNav = navItems()
56
74
  const result = validateKnowledge()
57
75
  res.locals.knowledgeValidation = result
58
76
 
@@ -120,6 +138,34 @@ function createHippocampusRouter ({ basePath, knowledgeStore, paths }) {
120
138
  res.render('hippocampus/project', { knowledge })
121
139
  })
122
140
 
141
+ // The five activity pages. Each is the landing page for its part of the
142
+ // cycle: what the knowledge base holds for that activity, what is thin, and
143
+ // the way into the sections under it.
144
+ router.get('/plan', (req, res) => {
145
+ const knowledge = getKnowledge()
146
+ res.render('hippocampus/plan', { knowledge, plan: hcd.planView(knowledge) })
147
+ })
148
+
149
+ router.get('/context', (req, res) => {
150
+ const knowledge = getKnowledge()
151
+ res.render('hippocampus/context', { knowledge, context: hcd.contextView(knowledge) })
152
+ })
153
+
154
+ router.get('/requirements', (req, res) => {
155
+ const knowledge = getKnowledge()
156
+ res.render('hippocampus/requirements', { knowledge, view: hcd.requirementsView(knowledge) })
157
+ })
158
+
159
+ router.get('/design', (req, res) => {
160
+ const knowledge = getKnowledge()
161
+ res.render('hippocampus/design', { knowledge, design: hcd.designView(knowledge) })
162
+ })
163
+
164
+ router.get('/evaluation', (req, res) => {
165
+ const knowledge = getKnowledge()
166
+ res.render('hippocampus/evaluation', { knowledge, evaluation: hcd.evaluationView(knowledge) })
167
+ })
168
+
123
169
  router.get('/users/:userId', (req, res) => {
124
170
  const knowledge = getKnowledge()
125
171
  const userGraph = getUserKnowledgeGraph(req.params.userId)
@@ -153,6 +199,7 @@ function createHippocampusRouter ({ basePath, knowledgeStore, paths }) {
153
199
  const story = r.story || {}
154
200
  return [
155
201
  { key: 'Priority', value: r.priority },
202
+ { key: 'Quality', value: hcd.DIMENSION_LABELS[r.qualityDimension] },
156
203
  { key: 'Reference', value: r.reference },
157
204
  // The story's design question is the reason to carry stories at all,
158
205
  // so it sits next to the story rather than below the connections.
@@ -165,9 +212,52 @@ function createHippocampusRouter ({ basePath, knowledgeStore, paths }) {
165
212
  Insight: (r) => [
166
213
  { key: 'Confidence', value: r.confidence },
167
214
  { key: 'Impact', value: r.impact },
215
+ { key: 'Finding', value: r.polarity },
216
+ { key: 'Rating', value: r.rating },
217
+ { key: 'Rating signed off by', value: r.signedOffBy },
218
+ { key: 'Quality', value: hcd.DIMENSION_LABELS[r.qualityDimension] },
168
219
  { key: 'Reference', value: r.reference },
169
220
  { key: 'Summary', value: r.summary }
170
221
  ],
222
+ Requirement: (r) => {
223
+ const measure = r.measure || {}
224
+ return [
225
+ { key: 'Kind', value: r.kind },
226
+ { key: 'The user must be able to', value: r.verb },
227
+ { key: 'Comes from', value: r.source },
228
+ { key: 'Quality', value: hcd.DIMENSION_LABELS[measure.dimension || r.qualityDimension] },
229
+ { key: 'Measured on the task', value: measure.task },
230
+ { key: 'Sample size', value: measure.sampleSize },
231
+ { key: 'Success rate', value: measure.successRate != null ? `${Math.round(measure.successRate * 100)}%` : null },
232
+ { key: 'Time limit', value: measure.timeLimit },
233
+ { key: 'These numbers are', value: r.measure ? (measure.valuesStatus === 'agreed' ? 'agreed' : 'a placeholder - not yet agreed with the team or checked with users') : null },
234
+ { key: 'Status', value: r.status },
235
+ { key: 'Reference', value: r.reference }
236
+ ]
237
+ },
238
+ Principle: (r) => [
239
+ { key: 'Kind', value: r.kind },
240
+ { key: 'Principle', value: r.statement },
241
+ { key: 'Source', value: r.source },
242
+ { key: 'Source file', value: r.sourcePath },
243
+ { key: 'Reference', value: r.reference }
244
+ ],
245
+ Goal: (r) => [
246
+ { key: 'Goal', value: r.statement },
247
+ { key: 'Reference', value: r.reference }
248
+ ],
249
+ 'Quality objective': (r) => [
250
+ { key: 'Dimension', value: hcd.DIMENSION_LABELS[r.dimension] },
251
+ { key: 'Objective', value: r.statement },
252
+ { key: 'Criteria', list: r.criteria },
253
+ { key: 'Reference', value: r.reference }
254
+ ],
255
+ Decision: (r) => [
256
+ { key: 'Status', value: r.status },
257
+ { key: 'Decision', value: r.decision },
258
+ { key: 'Consequence', value: r.consequence },
259
+ { key: 'Reference', value: r.reference }
260
+ ],
171
261
  Screen: (r) => [
172
262
  { key: 'Route', value: r.route },
173
263
  { key: 'Purpose', value: r.purpose },
@@ -200,6 +290,11 @@ function createHippocampusRouter ({ basePath, knowledgeStore, paths }) {
200
290
  router.get('/needs/:id', renderRecord('Need', '/user-needs', 'user needs'))
201
291
  router.get('/insights/:id', renderRecord('Insight', '/research', 'research'))
202
292
  router.get('/screens/:id', renderRecord('Screen', '/screens', 'screens'))
293
+ router.get('/requirements/:id', renderRecord('Requirement', '/requirements', 'requirements'))
294
+ router.get('/principles/:id', renderRecord('Principle', '/design', 'design'))
295
+ router.get('/decisions/:id', renderRecord('Decision', '/design', 'design'))
296
+ router.get('/goals/:id', renderRecord('Goal', '/context', 'context of use'))
297
+ router.get('/objectives/:id', renderRecord('Quality objective', '/plan', 'plan'))
203
298
 
204
299
  // Screens had no list page at all, so the only way to a screen was to know
205
300
  // its id. They are the thing a content designer is looking for.
@@ -278,10 +373,19 @@ function createHippocampusRouter ({ basePath, knowledgeStore, paths }) {
278
373
  })
279
374
  })
280
375
 
376
+ // ?method= narrows the rounds to one research method, which is how the
377
+ // Context of use and Evaluation pages link to "the research behind this".
281
378
  router.get('/research', (req, res) => {
282
379
  const knowledge = getKnowledge()
283
380
  const research = getResearchViewModel()
284
- res.render('hippocampus/research', { knowledge, research })
381
+ const method = hcd.METHOD_LABELS[req.query.method] ? req.query.method : ''
382
+ for (const round of research.rounds) {
383
+ round.methodTags = (round.methods || []).map((key) => ({ key, label: hcd.METHOD_LABELS[key] || key }))
384
+ }
385
+ if (method) research.rounds = research.rounds.filter((round) => (round.methods || []).includes(method))
386
+ res.render('hippocampus/research', {
387
+ knowledge, research, method, methodLabel: hcd.METHOD_LABELS[method] || ''
388
+ })
285
389
  })
286
390
 
287
391
  router.get('/graph', (req, res) => {
@@ -458,4 +562,23 @@ function uniqueById (items) {
458
562
  return Object.values(Object.fromEntries(items.map((item) => [item.id, item])))
459
563
  }
460
564
 
565
+ // Asks the host's view class what it does with a name, once per app, rather
566
+ // than reading the kit's version: behaviour is what matters, and a kit that
567
+ // changes it back needs no release here.
568
+ const viewPrefixByApp = new WeakMap()
569
+ function kitPrefixesViews (app) {
570
+ if (!app || typeof app.get !== 'function') return false
571
+ if (viewPrefixByApp.has(app)) return viewPrefixByApp.get(app)
572
+ let prefixed = false
573
+ try {
574
+ const View = app.get('view')
575
+ const probe = new View('hippocampus-probe', { defaultEngine: 'html', engines: {}, root: app.get('views') })
576
+ prefixed = typeof probe.path === 'string' && /^views[\\/]hippocampus-probe/.test(probe.path)
577
+ } catch (error) {
578
+ prefixed = false
579
+ }
580
+ viewPrefixByApp.set(app, prefixed)
581
+ return prefixed
582
+ }
583
+
461
584
  module.exports = { createHippocampusRouter }
package/lib/docs.js CHANGED
@@ -33,12 +33,36 @@ const SECTIONS = [
33
33
  {
34
34
  id: 'start',
35
35
  title: 'Start here',
36
- description: 'What Hippocampus is, how evidence moves through it, and how to get it running.'
36
+ description: 'What Hippocampus is, how it follows the human-centred design cycle, and how to get it running.'
37
37
  },
38
+ // The five activities of human-centred design, as the CPUX-F curriculum
39
+ // teaches them and as the viewer's navigation is built. A recipe sits with
40
+ // the activity it serves, so a team working on requirements finds every
41
+ // requirements task in one place.
38
42
  {
39
- id: 'recipes',
40
- title: 'Task recipes',
41
- description: 'One page per job. Each says what you will see in the viewer and what someone runs to get there.'
43
+ id: 'plan',
44
+ title: '1. Plan',
45
+ description: 'Why the service exists, the rules it works within, and what it must achieve for its users.'
46
+ },
47
+ {
48
+ id: 'context',
49
+ title: '2. Context of use',
50
+ description: 'Users, their goals and tasks, the conditions they work in - and bringing in the research that describes them.'
51
+ },
52
+ {
53
+ id: 'requirements',
54
+ title: '3. Requirements',
55
+ description: 'User needs, and the requirements a design can be checked against.'
56
+ },
57
+ {
58
+ id: 'design',
59
+ title: '4. Design',
60
+ description: 'Weighing options against requirements, recording principles and decisions, and checking what a design could break.'
61
+ },
62
+ {
63
+ id: 'evaluation',
64
+ title: '5. Evaluation',
65
+ description: 'Usability tests and their findings, and whether the design meets the requirements.'
42
66
  },
43
67
  {
44
68
  id: 'governance',
package/lib/flow-map.js CHANGED
@@ -26,8 +26,9 @@ const COLUMNS = [
26
26
  { key: 'research', title: 'Research', types: ['Research round'] },
27
27
  { key: 'gathered', title: 'Who, and what they said', types: ['Participant', 'Evidence'] },
28
28
  { key: 'learned', title: 'What we learned', types: ['Insight', 'User', 'Scenario'] },
29
- { key: 'needed', title: 'What people need', types: ['Need'] },
30
- { key: 'built', title: 'What we design', types: ['Screen', 'Journey', 'Design action', 'Decision', 'Assumption'] }
29
+ { key: 'needed', title: 'What people need', types: ['Need', 'Goal'] },
30
+ { key: 'required', title: 'What they must be able to do', types: ['Requirement', 'Quality objective'] },
31
+ { key: 'built', title: 'What we design', types: ['Screen', 'Journey', 'Design action', 'Decision', 'Principle', 'Assumption'] }
31
32
  ]
32
33
 
33
34
  // Relationship types whose stored direction is the opposite of how the work
@@ -36,7 +37,9 @@ const COLUMNS = [
36
37
  // what lets every flow run left to right.
37
38
  const READS_BACKWARDS = new Set([
38
39
  'supported-by', 'addresses-need', 'responds-to-insight', 'resolves-action',
39
- 'uses-evidence', 'renders-screen', 'records-decision'
40
+ 'uses-evidence', 'renders-screen', 'records-decision',
41
+ 'derives-from', 'based-on-insight', 'constrained-by', 'refines-objective',
42
+ 'weighed-against', 'applies-principle', 'verified-by'
40
43
  ])
41
44
 
42
45
  // How each connection reads once it is pointing the right way.
@@ -54,7 +57,15 @@ const PHRASES = {
54
57
  'drives-journey': 'drives',
55
58
  'uses-evidence': 'is used by',
56
59
  'renders-screen': 'is rendered by',
57
- 'records-decision': 'is recorded by'
60
+ 'records-decision': 'is recorded by',
61
+ 'derives-from': 'becomes',
62
+ 'based-on-insight': 'grounds',
63
+ 'constrained-by': 'constrains',
64
+ 'refines-objective': 'is measured by',
65
+ 'verified-by': 'evaluated',
66
+ 'weighed-against': 'weighs',
67
+ 'applies-principle': 'guides',
68
+ 'observed-on': 'was seen on'
58
69
  }
59
70
 
60
71
  const BOX_WIDTH = 168
@@ -0,0 +1,362 @@
1
+ // The viewer's five activity pages, as view models.
2
+ //
3
+ // The navigation follows the human-centred design cycle the CPUX-F curriculum
4
+ // teaches (ISO 9241-210): plan, understand the context of use, specify the
5
+ // requirements, design, evaluate. Each function here answers one of those
6
+ // pages from the loaded knowledge, so the templates only lay things out.
7
+ //
8
+ // Pure: knowledge in, a plain object out. Nothing here reads files.
9
+
10
+ const { solutionWording, serviceNamesOf } = require('./lint-knowledge')
11
+
12
+ // Which research methods inform which activity. A round can appear on both
13
+ // pages - an interview with prototype tasks is the commonest NCRS round and
14
+ // it does both jobs. A survey sits with the context of use: CPUX-F allows one
15
+ // for evaluation, but only as a measure of satisfaction, and a round that did
16
+ // that will usually say usability-test as well.
17
+ const CONTEXT_METHODS = new Set([
18
+ 'contextual-interview', 'interview', 'observation', 'focus-group',
19
+ 'user-survey', 'desk-research', 'analytics', 'card-sort'
20
+ ])
21
+ const EVALUATION_METHODS = new Set(['usability-test', 'usability-inspection', 'preference-test'])
22
+
23
+ const METHOD_LABELS = {
24
+ 'contextual-interview': 'Contextual interview',
25
+ interview: 'Interview',
26
+ observation: 'Observation',
27
+ 'focus-group': 'Focus group',
28
+ 'user-survey': 'User survey',
29
+ 'usability-test': 'Usability test',
30
+ 'usability-inspection': 'Usability inspection',
31
+ 'card-sort': 'Card sort',
32
+ 'preference-test': 'Preference test',
33
+ 'desk-research': 'Desk research',
34
+ analytics: 'Analytics',
35
+ other: 'Other'
36
+ }
37
+
38
+ const DIMENSION_LABELS = {
39
+ usability: 'Usability',
40
+ effectiveness: 'Effectiveness',
41
+ efficiency: 'Efficiency',
42
+ satisfaction: 'Satisfaction',
43
+ accessibility: 'Accessibility',
44
+ 'user-experience': 'User experience',
45
+ harm: 'Avoidance of harm'
46
+ }
47
+
48
+ const USER_TYPES = [
49
+ { key: 'primary', label: 'Primary users', hint: 'Use the service for what it is for.' },
50
+ { key: 'secondary', label: 'Secondary users', hint: 'Support it: set up access, train people, maintain it.' },
51
+ { key: 'indirect', label: 'Indirect users', hint: 'Never touch it, but live with what it produces.' },
52
+ { key: null, label: 'Not yet classified', hint: 'Mark each user primary, secondary or indirect.' }
53
+ ]
54
+
55
+ const REQUIREMENT_KINDS = [
56
+ { key: 'user-qualitative', label: 'What users must be able to do', hint: 'Recognise, select or input - checkable against a design.' },
57
+ { key: 'user-quantitative', label: 'How well', hint: 'A measurable level of quality, and how it is measured.' },
58
+ { key: 'organisational', label: 'Rules users work within', hint: 'Information governance, access control, policy. They come from a source, not from a need.' },
59
+ { key: 'market', label: 'Market requirements', hint: 'What the service must offer to be adopted.' }
60
+ ]
61
+
62
+ const PRINCIPLE_KINDS = [
63
+ { key: 'design-principle', label: 'Principles the team arrived at' },
64
+ { key: 'interaction-principle', label: 'Interaction principles' },
65
+ { key: 'heuristic', label: 'Heuristics' },
66
+ { key: 'ui-guideline', label: 'Design system guidelines' },
67
+ { key: 'design-pattern', label: 'Design patterns' }
68
+ ]
69
+
70
+ const RATINGS = [
71
+ { key: 'catastrophic', label: 'Catastrophic', tag: 'red', hint: 'Risk of major harm to the user or the organisation.' },
72
+ { key: 'critical', label: 'Critical', tag: 'red', hint: 'Participants gave up, or risk of minor harm.' },
73
+ { key: 'major', label: 'Major', tag: 'orange', hint: 'Substantial delay or moderate dissatisfaction.' },
74
+ { key: 'minor', label: 'Minor', tag: 'yellow', hint: 'Noticeable delay or minor dissatisfaction.' },
75
+ { key: 'positive', label: 'Positive', tag: 'green', hint: 'Something that worked, so a later change keeps it.' }
76
+ ]
77
+
78
+ const OUTCOMES = {
79
+ meets: { label: 'Meets', tag: 'green' },
80
+ partly: { label: 'Partly', tag: 'yellow' },
81
+ fails: { label: 'Fails', tag: 'red' },
82
+ 'not-assessed': { label: 'Not assessed', tag: 'grey' }
83
+ }
84
+
85
+ const stateOf = (record) => record.state || 'as-is'
86
+ const rels = (knowledge, type) => (knowledge.relationships || []).filter((rel) => rel.type === type)
87
+ const ref = (knowledge, id) => knowledge.index.entities[id] || null
88
+
89
+ function methodTags (round) {
90
+ return (round.methods || []).map((method) => ({ key: method, label: METHOD_LABELS[method] || method }))
91
+ }
92
+
93
+ function roundsFor (knowledge, methods) {
94
+ return (knowledge.researchRounds || [])
95
+ .filter((round) => (round.methods || []).some((method) => methods.has(method)))
96
+ .map((round) => ({
97
+ ...round,
98
+ methodTags: methodTags(round),
99
+ insightCount: (knowledge.insights || []).filter((insight) => insight.roundId === round.id).length
100
+ }))
101
+ .sort((a, b) => String(b.date).localeCompare(String(a.date)))
102
+ }
103
+
104
+ // ── Plan ──────────────────────────────────────────────────────────────
105
+
106
+ function planView (knowledge) {
107
+ const refines = rels(knowledge, 'refines-objective')
108
+ const objectives = (knowledge.qualityObjectives || []).map((objective) => ({
109
+ ...objective,
110
+ dimensionLabel: DIMENSION_LABELS[objective.dimension] || objective.dimension,
111
+ requirements: refines.filter((rel) => rel.to === objective.id).map((rel) => ref(knowledge, rel.from)).filter(Boolean)
112
+ }))
113
+ const context = knowledge.projectContext || {}
114
+ return {
115
+ objectives,
116
+ dimensions: Object.entries(DIMENSION_LABELS).map(([key, label]) => ({
117
+ key, label, count: objectives.filter((o) => o.dimension === key).length
118
+ })),
119
+ context,
120
+ // Policies and constraints are where organisational requirements come
121
+ // from, so the plan page says how many have been turned into one.
122
+ rules: {
123
+ policies: (context.policies || []).length,
124
+ constraints: (context.constraints || []).length,
125
+ organisational: (knowledge.requirements || []).filter((r) => r.kind === 'organisational').length
126
+ }
127
+ }
128
+ }
129
+
130
+ // ── Context of use ────────────────────────────────────────────────────
131
+
132
+ function collectConditions (records, field) {
133
+ const byText = new Map()
134
+ for (const { record, type } of records) {
135
+ for (const text of ((record.environment || {})[field] || [])) {
136
+ if (!byText.has(text)) byText.set(text, [])
137
+ byText.get(text).push({ id: record.id, label: record.label || record.title, type })
138
+ }
139
+ }
140
+ return [...byText.entries()].map(([text, from]) => ({ text, from }))
141
+ }
142
+
143
+ function contextView (knowledge) {
144
+ const users = (knowledge.users || []).map((user) => ({
145
+ ...user,
146
+ goals: (knowledge.goals || []).filter((goal) => goal.userId === user.id),
147
+ needCount: (knowledge.needs || []).filter((need) => need.userId === user.id).length,
148
+ personas: (knowledge.users || []).filter((other) => other.userGroupId === user.id)
149
+ }))
150
+
151
+ const usersByType = USER_TYPES.map((type) => ({
152
+ ...type,
153
+ users: users.filter((user) => (user.userType || null) === type.key)
154
+ })).filter((group) => group.users.length)
155
+
156
+ const asIsScenarios = (knowledge.scenarios || []).filter((s) => stateOf(s) === 'as-is').map((scenario) => ({
157
+ ...scenario,
158
+ user: ref(knowledge, scenario.userId),
159
+ goal: scenario.goalId ? ref(knowledge, scenario.goalId) : null
160
+ }))
161
+ const asIsJourneys = (knowledge.journeys || []).filter((j) => stateOf(j) === 'as-is')
162
+
163
+ const sources = [
164
+ ...(knowledge.users || []).map((record) => ({ record, type: 'User' })),
165
+ ...(knowledge.scenarios || []).map((record) => ({ record, type: 'Scenario' }))
166
+ ]
167
+ const environment = [
168
+ { key: 'physical', label: 'Physical', hint: 'Where the work happens: ward, vehicle, home visit, office.', items: collectConditions(sources, 'physical') },
169
+ { key: 'social', label: 'Social', hint: 'Rules, roles and pressures: information governance, workload, who else is there.', items: collectConditions(sources, 'social') },
170
+ { key: 'technical', label: 'Technical', hint: 'Devices, connectivity, the other systems open at the same time.', items: collectConditions(sources, 'technical') }
171
+ ]
172
+
173
+ const resources = new Map()
174
+ for (const { record, type } of sources) {
175
+ for (const text of record.resources || []) {
176
+ if (!resources.has(text)) resources.set(text, [])
177
+ resources.get(text).push({ id: record.id, label: record.label || record.title, type })
178
+ }
179
+ }
180
+
181
+ // The CPUX-F table of what describes the context of use, and how much of
182
+ // each this knowledge base holds. A zero is a gap, not a failure.
183
+ const deliverables = [
184
+ { label: 'User group profiles', covers: 'Users', count: users.filter((u) => u.kind !== 'persona').length },
185
+ { label: 'Personas', covers: 'Users, goals', count: users.filter((u) => u.kind === 'persona').length },
186
+ { label: 'Goals', covers: 'Goals', count: (knowledge.goals || []).length },
187
+ { label: 'As-is scenarios', covers: 'Users, goals, tasks, resources, environment', count: asIsScenarios.length },
188
+ { label: 'User journey maps (as-is)', covers: 'Users, goals, tasks, resources, environment', count: asIsJourneys.length }
189
+ ]
190
+
191
+ return {
192
+ usersByType,
193
+ unclassifiedCount: users.filter((user) => !user.userType).length,
194
+ goalCount: (knowledge.goals || []).length,
195
+ environment,
196
+ environmentCount: environment.reduce((sum, part) => sum + part.items.length, 0),
197
+ resources: [...resources.entries()].map(([text, from]) => ({ text, from })),
198
+ asIsScenarios,
199
+ asIsJourneys,
200
+ deliverables,
201
+ rounds: roundsFor(knowledge, CONTEXT_METHODS),
202
+ roundsWithoutMethod: (knowledge.researchRounds || []).filter((round) => !(round.methods || []).length).length
203
+ }
204
+ }
205
+
206
+ // ── Requirements ──────────────────────────────────────────────────────
207
+
208
+ function evaluationOf (knowledge, requirementId) {
209
+ const found = rels(knowledge, 'verified-by').filter((rel) => rel.from === requirementId)
210
+ if (!found.length) return null
211
+ const latest = found[found.length - 1]
212
+ return { ...(OUTCOMES[latest.outcome] || OUTCOMES['not-assessed']), outcome: latest.outcome || 'not-assessed', insight: ref(knowledge, latest.to), count: found.length }
213
+ }
214
+
215
+ function requirementView (knowledge, requirement) {
216
+ const derived = new Set([...(requirement.needIds || []),
217
+ ...rels(knowledge, 'derives-from').filter((rel) => rel.from === requirement.id).map((rel) => rel.to)])
218
+ return {
219
+ ...requirement,
220
+ needs: [...derived].map((id) => ref(knowledge, id)).filter(Boolean),
221
+ constrainedBy: rels(knowledge, 'constrained-by').filter((rel) => rel.from === requirement.id).map((rel) => ref(knowledge, rel.to)).filter(Boolean),
222
+ constrains: rels(knowledge, 'constrained-by').filter((rel) => rel.to === requirement.id).map((rel) => ref(knowledge, rel.from)).filter(Boolean),
223
+ weighedCount: rels(knowledge, 'weighed-against').filter((rel) => rel.to === requirement.id).length,
224
+ evaluation: evaluationOf(knowledge, requirement.id),
225
+ dimensionLabel: DIMENSION_LABELS[(requirement.measure || {}).dimension || requirement.qualityDimension] || null
226
+ }
227
+ }
228
+
229
+ function requirementsView (knowledge) {
230
+ const requirements = (knowledge.requirements || []).map((requirement) => requirementView(knowledge, requirement))
231
+ const covered = new Set(requirements.flatMap((r) => r.needs.map((n) => n.id)))
232
+ const needs = knowledge.needs || []
233
+ const serviceNames = serviceNamesOf(knowledge.project)
234
+ return {
235
+ groups: REQUIREMENT_KINDS.map((kind) => ({ ...kind, requirements: requirements.filter((r) => r.kind === kind.key) }))
236
+ .filter((group) => group.requirements.length),
237
+ total: requirements.length,
238
+ needs: {
239
+ total: needs.length,
240
+ withoutRequirement: needs.filter((need) => !covered.has(need.id)).length,
241
+ namingSolution: needs.filter((need) => solutionWording(need.statement, serviceNames)).length,
242
+ withoutGoal: needs.filter((need) => !need.goalId && !/\b(so that|in order to)\b/i.test(need.statement || '')).length
243
+ },
244
+ placeholders: requirements.filter((r) => r.measure && r.measure.valuesStatus !== 'agreed').length
245
+ }
246
+ }
247
+
248
+ // ── Design ────────────────────────────────────────────────────────────
249
+
250
+ /**
251
+ * The options for each open design question, weighed against the
252
+ * requirements. Rows are requirements, columns are the decisions that resolve
253
+ * the action, and a cell is how that option fares. This is the view that
254
+ * turned Round 16's five options into "02 or 03, plus 01 and/or 05": laid out
255
+ * this way it shows which requirements no option meets on its own.
256
+ */
257
+ function optionMatrices (knowledge) {
258
+ const resolves = rels(knowledge, 'resolves-action')
259
+ const weighed = rels(knowledge, 'weighed-against')
260
+ return (knowledge.designActions || []).map((action) => {
261
+ const decisions = resolves.filter((rel) => rel.to === action.id).map((rel) => knowledge.index.decisions[rel.from]).filter(Boolean)
262
+ const decisionIds = new Set(decisions.map((d) => d.id))
263
+ const cells = weighed.filter((rel) => decisionIds.has(rel.from))
264
+ if (!decisions.length || !cells.length) return null
265
+ const requirementIds = [...new Set(cells.map((rel) => rel.to))]
266
+ const rows = requirementIds.map((id) => {
267
+ const requirement = knowledge.index.requirements[id]
268
+ const outcomes = decisions.map((decision) => {
269
+ const cell = cells.find((rel) => rel.from === decision.id && rel.to === id)
270
+ return cell ? { ...(OUTCOMES[cell.outcome] || OUTCOMES['not-assessed']), note: cell.note } : null
271
+ })
272
+ return {
273
+ requirement,
274
+ outcomes,
275
+ unmet: outcomes.every((o) => !o || o.label !== 'Meets')
276
+ }
277
+ }).filter((row) => row.requirement)
278
+ return {
279
+ action,
280
+ decisions: decisions.map((decision) => ({
281
+ ...decision,
282
+ fails: rows.filter((row) => (row.outcomes[decisions.indexOf(decision)] || {}).label === 'Fails').length
283
+ })),
284
+ rows,
285
+ unmetCount: rows.filter((row) => row.unmet).length
286
+ }
287
+ }).filter(Boolean)
288
+ }
289
+
290
+ function designView (knowledge) {
291
+ const applies = rels(knowledge, 'applies-principle')
292
+ const principles = (knowledge.principles || []).map((principle) => ({
293
+ ...principle,
294
+ appliedBy: applies.filter((rel) => rel.to === principle.id).length +
295
+ (knowledge.journeys || []).flatMap((j) => j.steps || []).filter((step) => (step.principleIds || []).includes(principle.id)).length
296
+ }))
297
+ return {
298
+ principleGroups: PRINCIPLE_KINDS.map((kind) => ({ ...kind, principles: principles.filter((p) => p.kind === kind.key) }))
299
+ .filter((group) => group.principles.length),
300
+ principleCount: principles.length,
301
+ matrices: optionMatrices(knowledge),
302
+ decisions: (knowledge.decisions || []).map((decision) => ({
303
+ ...decision,
304
+ weighed: rels(knowledge, 'weighed-against').filter((rel) => rel.from === decision.id).length
305
+ })),
306
+ toBeScenarios: (knowledge.scenarios || []).filter((s) => stateOf(s) === 'to-be'),
307
+ toBeJourneys: (knowledge.journeys || []).filter((j) => stateOf(j) === 'to-be'),
308
+ screens: {
309
+ total: (knowledge.screens || []).length,
310
+ applyingPrinciples: new Set(applies.filter((rel) => knowledge.index.screens[rel.from]).map((rel) => rel.from)).size
311
+ }
312
+ }
313
+ }
314
+
315
+ // ── Evaluation ────────────────────────────────────────────────────────
316
+
317
+ function evaluationView (knowledge) {
318
+ const rounds = roundsFor(knowledge, EVALUATION_METHODS)
319
+ const roundIds = new Set(rounds.map((round) => round.id))
320
+ const findings = (knowledge.insights || []).filter((insight) => roundIds.has(insight.roundId) || insight.rating || insight.polarity === 'positive')
321
+ const observedOn = rels(knowledge, 'observed-on')
322
+
323
+ const byRating = RATINGS.map((rating) => ({
324
+ ...rating,
325
+ findings: findings.filter((f) => f.rating === rating.key || (rating.key === 'positive' && !f.rating && f.polarity === 'positive'))
326
+ }))
327
+ const unrated = findings.filter((f) => !f.rating && f.polarity !== 'positive')
328
+
329
+ const userRequirements = (knowledge.requirements || []).filter((r) => r.kind.startsWith('user-'))
330
+ const verification = userRequirements.map((requirement) => ({
331
+ requirement,
332
+ evaluation: evaluationOf(knowledge, requirement.id)
333
+ }))
334
+
335
+ return {
336
+ rounds,
337
+ findingCount: findings.length,
338
+ byRating,
339
+ unrated,
340
+ verification,
341
+ verified: verification.filter((v) => v.evaluation).length,
342
+ screensWithFindings: [...new Set(observedOn.map((rel) => rel.to))]
343
+ .map((id) => ({ screen: knowledge.index.screens[id], count: observedOn.filter((rel) => rel.to === id).length }))
344
+ .filter((entry) => entry.screen)
345
+ .sort((a, b) => b.count - a.count)
346
+ }
347
+ }
348
+
349
+ module.exports = {
350
+ planView,
351
+ contextView,
352
+ requirementsView,
353
+ requirementView,
354
+ designView,
355
+ evaluationView,
356
+ optionMatrices,
357
+ METHOD_LABELS,
358
+ DIMENSION_LABELS,
359
+ OUTCOMES,
360
+ CONTEXT_METHODS,
361
+ EVALUATION_METHODS
362
+ }
package/lib/known.js CHANGED
@@ -29,12 +29,15 @@ const SEARCH_FIELDS = {
29
29
  designActions: ['title', 'action', 'rationale'],
30
30
  decisions: ['title', 'decision', 'consequence'],
31
31
  screens: ['title', 'purpose'],
32
- journeys: ['title', 'description']
32
+ journeys: ['title', 'description'],
33
+ goals: ['statement'],
34
+ requirements: ['statement', 'source'],
35
+ principles: ['title', 'statement']
33
36
  }
34
37
 
35
38
  // The kinds of record that are design work - things someone would build twice
36
39
  // if they did not know they existed.
37
- const BUILT_TYPES = new Set(['screens', 'journeys', 'designActions', 'decisions'])
40
+ const BUILT_TYPES = new Set(['screens', 'journeys', 'designActions', 'decisions', 'requirements', 'principles'])
38
41
  const FINDING_TYPES = new Set(['insights', 'evidence'])
39
42
 
40
43
  function escapeRegex (text) {