@hippo-digital/hippocampus 2.7.1 → 2.8.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 (72) hide show
  1. package/CHANGELOG.md +60 -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 +52 -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 +90 -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 +2 -2
  41. package/scripts/init.js +19 -0
  42. package/scripts/migrate-knowledge.js +9 -1
  43. package/scripts/smoke-routes.js +12 -1
  44. package/scripts/tidy-principles.js +68 -0
  45. package/skills/COVERAGE-MATRIX.md +2 -0
  46. package/skills/README.md +5 -0
  47. package/skills/add-scenario/SKILL.md +4 -0
  48. package/skills/add-user-needs/SKILL.md +11 -1
  49. package/skills/create-journey-from-scenario/SKILL.md +4 -1
  50. package/skills/ingest-research-round/SKILL.md +3 -3
  51. package/skills/ingest-user-personas/SKILL.md +24 -7
  52. package/skills/map-research-to-graph/SKILL.md +7 -5
  53. package/skills/record-design-decision/SKILL.md +1 -0
  54. package/skills/review-research-import-draft/SKILL.md +7 -1
  55. package/skills/skills.json +54 -1
  56. package/skills/structure-research-draft/SKILL.md +12 -2
  57. package/skills/weigh-options-against-requirements/SKILL.md +60 -0
  58. package/skills/write-requirements/SKILL.md +69 -0
  59. package/views/hippocampus/_layout.html +15 -12
  60. package/views/hippocampus/components/_activity.njk +36 -0
  61. package/views/hippocampus/components/_journey-step.njk +30 -0
  62. package/views/hippocampus/context.html +197 -0
  63. package/views/hippocampus/design.html +128 -0
  64. package/views/hippocampus/evaluation.html +119 -0
  65. package/views/hippocampus/index.html +57 -11
  66. package/views/hippocampus/journey.html +25 -1
  67. package/views/hippocampus/journeys.html +3 -0
  68. package/views/hippocampus/plan.html +64 -0
  69. package/views/hippocampus/requirements.html +94 -0
  70. package/views/hippocampus/research.html +20 -1
  71. package/views/hippocampus/scenarios.html +3 -0
  72. 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 {
@@ -53,6 +54,7 @@ function createHippocampusRouter ({ basePath, knowledgeStore, paths }) {
53
54
  // The trail is derived from the URL. A page about one record adds its own
54
55
  // name by setting res.locals.breadcrumbLeaf before rendering.
55
56
  res.locals.breadcrumbItems = buildTrail({ basePath, path: req.path })
57
+ res.locals.knowledgeNav = navItems()
56
58
  const result = validateKnowledge()
57
59
  res.locals.knowledgeValidation = result
58
60
 
@@ -120,6 +122,34 @@ function createHippocampusRouter ({ basePath, knowledgeStore, paths }) {
120
122
  res.render('hippocampus/project', { knowledge })
121
123
  })
122
124
 
125
+ // The five activity pages. Each is the landing page for its part of the
126
+ // cycle: what the knowledge base holds for that activity, what is thin, and
127
+ // the way into the sections under it.
128
+ router.get('/plan', (req, res) => {
129
+ const knowledge = getKnowledge()
130
+ res.render('hippocampus/plan', { knowledge, plan: hcd.planView(knowledge) })
131
+ })
132
+
133
+ router.get('/context', (req, res) => {
134
+ const knowledge = getKnowledge()
135
+ res.render('hippocampus/context', { knowledge, context: hcd.contextView(knowledge) })
136
+ })
137
+
138
+ router.get('/requirements', (req, res) => {
139
+ const knowledge = getKnowledge()
140
+ res.render('hippocampus/requirements', { knowledge, view: hcd.requirementsView(knowledge) })
141
+ })
142
+
143
+ router.get('/design', (req, res) => {
144
+ const knowledge = getKnowledge()
145
+ res.render('hippocampus/design', { knowledge, design: hcd.designView(knowledge) })
146
+ })
147
+
148
+ router.get('/evaluation', (req, res) => {
149
+ const knowledge = getKnowledge()
150
+ res.render('hippocampus/evaluation', { knowledge, evaluation: hcd.evaluationView(knowledge) })
151
+ })
152
+
123
153
  router.get('/users/:userId', (req, res) => {
124
154
  const knowledge = getKnowledge()
125
155
  const userGraph = getUserKnowledgeGraph(req.params.userId)
@@ -153,6 +183,7 @@ function createHippocampusRouter ({ basePath, knowledgeStore, paths }) {
153
183
  const story = r.story || {}
154
184
  return [
155
185
  { key: 'Priority', value: r.priority },
186
+ { key: 'Quality', value: hcd.DIMENSION_LABELS[r.qualityDimension] },
156
187
  { key: 'Reference', value: r.reference },
157
188
  // The story's design question is the reason to carry stories at all,
158
189
  // so it sits next to the story rather than below the connections.
@@ -165,9 +196,52 @@ function createHippocampusRouter ({ basePath, knowledgeStore, paths }) {
165
196
  Insight: (r) => [
166
197
  { key: 'Confidence', value: r.confidence },
167
198
  { key: 'Impact', value: r.impact },
199
+ { key: 'Finding', value: r.polarity },
200
+ { key: 'Rating', value: r.rating },
201
+ { key: 'Rating signed off by', value: r.signedOffBy },
202
+ { key: 'Quality', value: hcd.DIMENSION_LABELS[r.qualityDimension] },
168
203
  { key: 'Reference', value: r.reference },
169
204
  { key: 'Summary', value: r.summary }
170
205
  ],
206
+ Requirement: (r) => {
207
+ const measure = r.measure || {}
208
+ return [
209
+ { key: 'Kind', value: r.kind },
210
+ { key: 'The user must be able to', value: r.verb },
211
+ { key: 'Comes from', value: r.source },
212
+ { key: 'Quality', value: hcd.DIMENSION_LABELS[measure.dimension || r.qualityDimension] },
213
+ { key: 'Measured on the task', value: measure.task },
214
+ { key: 'Sample size', value: measure.sampleSize },
215
+ { key: 'Success rate', value: measure.successRate != null ? `${Math.round(measure.successRate * 100)}%` : null },
216
+ { key: 'Time limit', value: measure.timeLimit },
217
+ { key: 'These numbers are', value: r.measure ? (measure.valuesStatus === 'agreed' ? 'agreed' : 'a placeholder - not yet agreed with the team or checked with users') : null },
218
+ { key: 'Status', value: r.status },
219
+ { key: 'Reference', value: r.reference }
220
+ ]
221
+ },
222
+ Principle: (r) => [
223
+ { key: 'Kind', value: r.kind },
224
+ { key: 'Principle', value: r.statement },
225
+ { key: 'Source', value: r.source },
226
+ { key: 'Source file', value: r.sourcePath },
227
+ { key: 'Reference', value: r.reference }
228
+ ],
229
+ Goal: (r) => [
230
+ { key: 'Goal', value: r.statement },
231
+ { key: 'Reference', value: r.reference }
232
+ ],
233
+ 'Quality objective': (r) => [
234
+ { key: 'Dimension', value: hcd.DIMENSION_LABELS[r.dimension] },
235
+ { key: 'Objective', value: r.statement },
236
+ { key: 'Criteria', list: r.criteria },
237
+ { key: 'Reference', value: r.reference }
238
+ ],
239
+ Decision: (r) => [
240
+ { key: 'Status', value: r.status },
241
+ { key: 'Decision', value: r.decision },
242
+ { key: 'Consequence', value: r.consequence },
243
+ { key: 'Reference', value: r.reference }
244
+ ],
171
245
  Screen: (r) => [
172
246
  { key: 'Route', value: r.route },
173
247
  { key: 'Purpose', value: r.purpose },
@@ -200,6 +274,11 @@ function createHippocampusRouter ({ basePath, knowledgeStore, paths }) {
200
274
  router.get('/needs/:id', renderRecord('Need', '/user-needs', 'user needs'))
201
275
  router.get('/insights/:id', renderRecord('Insight', '/research', 'research'))
202
276
  router.get('/screens/:id', renderRecord('Screen', '/screens', 'screens'))
277
+ router.get('/requirements/:id', renderRecord('Requirement', '/requirements', 'requirements'))
278
+ router.get('/principles/:id', renderRecord('Principle', '/design', 'design'))
279
+ router.get('/decisions/:id', renderRecord('Decision', '/design', 'design'))
280
+ router.get('/goals/:id', renderRecord('Goal', '/context', 'context of use'))
281
+ router.get('/objectives/:id', renderRecord('Quality objective', '/plan', 'plan'))
203
282
 
204
283
  // Screens had no list page at all, so the only way to a screen was to know
205
284
  // its id. They are the thing a content designer is looking for.
@@ -278,10 +357,19 @@ function createHippocampusRouter ({ basePath, knowledgeStore, paths }) {
278
357
  })
279
358
  })
280
359
 
360
+ // ?method= narrows the rounds to one research method, which is how the
361
+ // Context of use and Evaluation pages link to "the research behind this".
281
362
  router.get('/research', (req, res) => {
282
363
  const knowledge = getKnowledge()
283
364
  const research = getResearchViewModel()
284
- res.render('hippocampus/research', { knowledge, research })
365
+ const method = hcd.METHOD_LABELS[req.query.method] ? req.query.method : ''
366
+ for (const round of research.rounds) {
367
+ round.methodTags = (round.methods || []).map((key) => ({ key, label: hcd.METHOD_LABELS[key] || key }))
368
+ }
369
+ if (method) research.rounds = research.rounds.filter((round) => (round.methods || []).includes(method))
370
+ res.render('hippocampus/research', {
371
+ knowledge, research, method, methodLabel: hcd.METHOD_LABELS[method] || ''
372
+ })
285
373
  })
286
374
 
287
375
  router.get('/graph', (req, res) => {
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) {