@hippo-digital/hippocampus 2.9.0 → 2.10.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/CHANGELOG.md +81 -0
- package/bin/hippocampus.js +2 -0
- package/docs/export-a-trace.md +88 -0
- package/docs/record-intended-purpose-hazards-and-controls.md +202 -0
- package/docs/review-and-promote-a-draft.md +10 -2
- package/docs/source-model.md +49 -4
- package/lib/breadcrumb.js +8 -0
- package/lib/collections.js +4 -0
- package/lib/create-router.js +101 -1
- package/lib/known.js +5 -2
- package/lib/lint-knowledge.js +119 -0
- package/lib/load-knowledge.js +60 -7
- package/lib/record-links.js +10 -2
- package/lib/review.js +33 -0
- package/lib/schema-version.js +50 -9
- package/lib/schema.js +240 -19
- package/lib/trace.js +571 -0
- package/package.json +1 -1
- package/scripts/import-design-actions.js +3 -1
- package/scripts/init.js +2 -1
- package/scripts/migrate-knowledge.js +27 -26
- package/scripts/promote-draft.js +11 -3
- package/scripts/promote-research-draft.js +17 -1
- package/scripts/smoke-routes.js +7 -1
- package/scripts/trace-export.js +61 -0
- package/scripts/trace-verify.js +47 -0
- package/scripts/validate-knowledge.js +10 -0
- package/views/hippocampus/_layout.html +2 -1
- package/views/hippocampus/components.html +48 -0
- package/views/hippocampus/design.html +1 -0
- package/views/hippocampus/safety.html +89 -0
package/lib/create-router.js
CHANGED
|
@@ -262,6 +262,54 @@ function createHippocampusRouter ({ basePath, knowledgeStore, paths }) {
|
|
|
262
262
|
{ key: 'Owner', value: r.owner },
|
|
263
263
|
{ key: 'Reference', value: r.reference }
|
|
264
264
|
],
|
|
265
|
+
'Intended purpose': (r) => [
|
|
266
|
+
{ key: 'Version', value: r.version },
|
|
267
|
+
{ key: 'Status', value: r.status },
|
|
268
|
+
{ key: 'Statement', value: r.statement },
|
|
269
|
+
{ key: 'Indications', value: r.indications },
|
|
270
|
+
{ key: 'Structure and function', value: r.structureAndFunction },
|
|
271
|
+
{ key: 'Intended population', value: r.population && r.population.included },
|
|
272
|
+
{ key: 'Excluded', value: r.population && r.population.excluded },
|
|
273
|
+
{ key: 'Use environment', value: r.useEnvironment },
|
|
274
|
+
{ key: 'Foreseeable misuse', list: r.foreseeableMisuse },
|
|
275
|
+
{ key: 'Must not do', list: r.mustNotDo },
|
|
276
|
+
{ key: 'Agreed by', value: r.agreedBy ? (r.agreedOn ? `${r.agreedBy} (${r.agreedOn})` : r.agreedBy) : null },
|
|
277
|
+
{ key: 'Supersedes', value: r.supersedes },
|
|
278
|
+
{ key: 'Reference', value: r.reference }
|
|
279
|
+
],
|
|
280
|
+
Hazard: (r) => {
|
|
281
|
+
const risk = (x) => (x ? `${x.risk} - ${x.severity}, ${x.likelihood}${x.justification ? `. ${x.justification}` : ''}` : null)
|
|
282
|
+
return [
|
|
283
|
+
{ key: 'Status', value: r.status },
|
|
284
|
+
{ key: 'Number in the hazard log', value: r.logNumber },
|
|
285
|
+
{ key: 'Effect', value: r.effect },
|
|
286
|
+
{ key: 'Hazard', value: r.hazard },
|
|
287
|
+
{ key: 'Harm', value: r.harm },
|
|
288
|
+
{ key: 'Causes', list: (r.causes || []).map((c) => `${c.number}. ${c.statement}`) },
|
|
289
|
+
{ key: 'Initial risk', value: risk(r.initialRisk) },
|
|
290
|
+
{ key: 'Residual risk', value: risk(r.residualRisk) },
|
|
291
|
+
{ key: 'Assessed by', value: r.assessedBy ? (r.assessedOn ? `${r.assessedBy} (${r.assessedOn})` : r.assessedBy) : (r.initialRisk ? 'Nobody named' : null) },
|
|
292
|
+
{ key: 'Owner', value: r.owner },
|
|
293
|
+
{ key: 'Outside references', list: (r.outsideReferences || []).map((o) => `${o.system} ${o.id}${o.kind ? ` (${o.kind})` : ''}`) },
|
|
294
|
+
{ key: 'Reference', value: r.reference }
|
|
295
|
+
]
|
|
296
|
+
},
|
|
297
|
+
Control: (r) => [
|
|
298
|
+
{ key: 'Kind', value: { 'hit-design': 'HIT design', 'user-training': 'User training', 'business-process': 'Business process' }[r.kind] },
|
|
299
|
+
{ key: 'Stage', value: r.stage === 'existing' ? 'Existing - counted in the initial risk' : 'Additional - taken into the residual risk' },
|
|
300
|
+
{ key: 'Status', value: r.status },
|
|
301
|
+
{ key: 'Owner', value: r.owner },
|
|
302
|
+
{ key: 'Outside references', list: (r.outsideReferences || []).map((o) => `${o.system} ${o.id}${o.kind ? ` (${o.kind})` : ''}`) },
|
|
303
|
+
{ key: 'Reference', value: r.reference }
|
|
304
|
+
],
|
|
305
|
+
Component: (r) => [
|
|
306
|
+
{ key: 'Prototype file', value: r.prototypePath },
|
|
307
|
+
{ key: 'Macros', value: (r.macros || []).join(', ') },
|
|
308
|
+
{ key: 'Usage guide', value: r.guide },
|
|
309
|
+
{ key: 'Production file', value: r.productionPath },
|
|
310
|
+
{ key: 'Ported from commit', value: r.portedFromCommit },
|
|
311
|
+
{ key: 'Reference', value: r.reference }
|
|
312
|
+
],
|
|
265
313
|
Screen: (r) => [
|
|
266
314
|
{ key: 'Route', value: r.route },
|
|
267
315
|
{ key: 'Purpose', value: r.purpose },
|
|
@@ -270,6 +318,19 @@ function createHippocampusRouter ({ basePath, knowledgeStore, paths }) {
|
|
|
270
318
|
]
|
|
271
319
|
}
|
|
272
320
|
|
|
321
|
+
// Who drafted, reviewed and signed off a record, on every record page that
|
|
322
|
+
// has them. Insights already show their sign-off, so it is not repeated.
|
|
323
|
+
function whoFacts (r) {
|
|
324
|
+
const dated = (name, date) => (name ? (date ? `${name} (${date})` : name) : null)
|
|
325
|
+
return [
|
|
326
|
+
{ key: 'Drafted by', value: r.draftedBy },
|
|
327
|
+
{ key: 'Reviewed by', value: dated(r.reviewedBy, r.reviewedOn) },
|
|
328
|
+
// Insights show their rating's sign-off with the rating.
|
|
329
|
+
{ key: 'Signed off by', value: r.roundId ? null : dated(r.signedOffBy, r.signedOffOn) },
|
|
330
|
+
{ key: 'Write-up confirmed by', value: dated(r.sourceConfirmedBy, r.sourceConfirmedOn) }
|
|
331
|
+
].filter((fact) => fact.value)
|
|
332
|
+
}
|
|
333
|
+
|
|
273
334
|
function renderRecord (expectedType, backHref, backLabel) {
|
|
274
335
|
return (req, res) => {
|
|
275
336
|
const detail = getRecordDetail(req.params.id)
|
|
@@ -284,7 +345,7 @@ function createHippocampusRouter ({ basePath, knowledgeStore, paths }) {
|
|
|
284
345
|
res.render('hippocampus/record', {
|
|
285
346
|
knowledge: getKnowledge(),
|
|
286
347
|
detail,
|
|
287
|
-
facts:
|
|
348
|
+
facts: detail.record ? [...(build ? build(detail.record) : []), ...whoFacts(detail.record)] : [],
|
|
288
349
|
backHref: `${basePath}${backHref}`,
|
|
289
350
|
backLabel
|
|
290
351
|
})
|
|
@@ -299,6 +360,45 @@ function createHippocampusRouter ({ basePath, knowledgeStore, paths }) {
|
|
|
299
360
|
router.get('/decisions/:id', renderRecord('Decision', '/design', 'design'))
|
|
300
361
|
router.get('/goals/:id', renderRecord('Goal', '/context', 'context of use'))
|
|
301
362
|
router.get('/objectives/:id', renderRecord('Quality objective', '/plan', 'plan'))
|
|
363
|
+
router.get('/components/:id', renderRecord('Component', '/components', 'components'))
|
|
364
|
+
router.get('/intended-purpose/:id', renderRecord('Intended purpose', '/safety', 'safety'))
|
|
365
|
+
router.get('/hazards/:id', renderRecord('Hazard', '/safety', 'safety'))
|
|
366
|
+
router.get('/controls/:id', renderRecord('Control', '/safety', 'safety'))
|
|
367
|
+
|
|
368
|
+
// The intended purpose, the hazards and the controls against them, on one
|
|
369
|
+
// page - with the gaps, because what a clinical safety officer looks for
|
|
370
|
+
// first is what is missing.
|
|
371
|
+
router.get('/safety', (req, res) => {
|
|
372
|
+
const knowledge = getKnowledge()
|
|
373
|
+
const { buildTrace } = require('./trace')
|
|
374
|
+
const trace = buildTrace(knowledge)
|
|
375
|
+
const purposes = [...(knowledge.intendedPurposes || [])]
|
|
376
|
+
.sort((a, b) => ['agreed', 'draft', 'superseded'].indexOf(a.status) - ['agreed', 'draft', 'superseded'].indexOf(b.status))
|
|
377
|
+
const safetyKinds = new Set(['no-agreed-purpose', 'decision-not-assessed-against-purpose', 'hazard-without-cause', 'hazard-without-control',
|
|
378
|
+
'hazard-without-initial-risk', 'risk-without-assessor', 'control-not-built', 'control-not-verified', 'finding-without-hazard', 'harm-requirement-not-evaluated'])
|
|
379
|
+
res.render('hippocampus/safety', {
|
|
380
|
+
knowledge,
|
|
381
|
+
purposes,
|
|
382
|
+
hazards: trace.hazards,
|
|
383
|
+
controls: knowledge.controls || [],
|
|
384
|
+
gaps: trace.gaps.filter((gap) => safetyKinds.has(gap.kind)),
|
|
385
|
+
scales: knowledge.project.riskScales || null
|
|
386
|
+
})
|
|
387
|
+
})
|
|
388
|
+
|
|
389
|
+
// Prototype components, and why each one is as it is. The list a production
|
|
390
|
+
// team starts from when it compares its port with the prototype.
|
|
391
|
+
router.get('/components', (req, res) => {
|
|
392
|
+
const knowledge = getKnowledge()
|
|
393
|
+
const query = { q: req.query.q || '' }
|
|
394
|
+
const realised = (knowledge.relationships || []).filter((rel) => rel.type === 'realised-in')
|
|
395
|
+
const components = (knowledge.components || [])
|
|
396
|
+
.filter((component) => matchesText(component, query.q, ['title', 'prototypePath', 'productionPath', 'macros']))
|
|
397
|
+
.map((component) => ({ ...component, reasonCount: realised.filter((rel) => rel.to === component.id).length }))
|
|
398
|
+
res.render('hippocampus/components', {
|
|
399
|
+
knowledge, components, query, hasFilters: Boolean(query.q), facets: []
|
|
400
|
+
})
|
|
401
|
+
})
|
|
302
402
|
|
|
303
403
|
// Screens had no list page at all, so the only way to a screen was to know
|
|
304
404
|
// its id. They are the thing a content designer is looking for.
|
package/lib/known.js
CHANGED
|
@@ -32,12 +32,15 @@ const SEARCH_FIELDS = {
|
|
|
32
32
|
journeys: ['title', 'description'],
|
|
33
33
|
goals: ['statement'],
|
|
34
34
|
requirements: ['statement', 'source'],
|
|
35
|
-
principles: ['title', 'statement']
|
|
35
|
+
principles: ['title', 'statement'],
|
|
36
|
+
components: ['title', 'prototypePath', 'macros'],
|
|
37
|
+
hazards: ['title', 'hazard', 'harm', 'effect'],
|
|
38
|
+
controls: ['statement']
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
// The kinds of record that are design work - things someone would build twice
|
|
39
42
|
// if they did not know they existed.
|
|
40
|
-
const BUILT_TYPES = new Set(['screens', 'journeys', 'designActions', 'decisions', 'requirements', 'principles'])
|
|
43
|
+
const BUILT_TYPES = new Set(['screens', 'journeys', 'designActions', 'decisions', 'requirements', 'principles', 'components'])
|
|
41
44
|
const FINDING_TYPES = new Set(['insights', 'evidence'])
|
|
42
45
|
|
|
43
46
|
function escapeRegex (text) {
|
package/lib/lint-knowledge.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const { recordSchemas, UNRESEARCHED } = require('./schema')
|
|
2
|
+
const { samePerson } = require('./review')
|
|
2
3
|
|
|
3
4
|
const LIST_GLYPH = /^[\s\u00a0]*[\u2022\u25cf\u25aa\u25e6\u2043\u2219\u00b7\u25cb]/
|
|
4
5
|
|
|
@@ -348,7 +349,125 @@ function lintKnowledge (knowledge) {
|
|
|
348
349
|
}
|
|
349
350
|
}
|
|
350
351
|
|
|
352
|
+
// Who did each step (see `review` in schema.js). None of these fields is
|
|
353
|
+
// required, so nothing here is an error. A date with no name, or a record
|
|
354
|
+
// reviewed by the person who drafted it, looks like a mistake; a draft nobody
|
|
355
|
+
// reviewed is a gap the trace export reports, and worth seeing every time.
|
|
356
|
+
for (const collection of Object.keys(recordSchemas)) {
|
|
357
|
+
for (const record of knowledge[collection] || []) {
|
|
358
|
+
for (const [date, who] of [['reviewedOn', 'reviewedBy'], ['signedOffOn', 'signedOffBy'], ['sourceConfirmedOn', 'sourceConfirmedBy']]) {
|
|
359
|
+
if (record[date] && !record[who]) {
|
|
360
|
+
warnings.push({
|
|
361
|
+
rule: 'date-without-person',
|
|
362
|
+
collection,
|
|
363
|
+
id: record.id,
|
|
364
|
+
message: `${collection} ${record.id}: ${date} is set but ${who} is not - a date says when, not who`
|
|
365
|
+
})
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
if (samePerson(record.draftedBy, record.reviewedBy)) {
|
|
369
|
+
warnings.push({
|
|
370
|
+
rule: 'reviewed-by-drafter',
|
|
371
|
+
collection,
|
|
372
|
+
id: record.id,
|
|
373
|
+
message: `${collection} ${record.id}: reviewed by ${record.reviewedBy}, who also drafted it - a review is someone else's check`
|
|
374
|
+
})
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const unreviewed = Object.keys(recordSchemas)
|
|
380
|
+
.flatMap((collection) => (knowledge[collection] || []).map((record) => ({ collection, record })))
|
|
381
|
+
.filter(({ record }) => record.draftedBy && !record.reviewedBy)
|
|
382
|
+
if (unreviewed.length) {
|
|
383
|
+
infos.push({
|
|
384
|
+
rule: 'drafted-not-reviewed',
|
|
385
|
+
count: unreviewed.length,
|
|
386
|
+
ids: unreviewed.map(({ record }) => record.id),
|
|
387
|
+
message: `${unreviewed.length} record${unreviewed.length === 1 ? '' : 's'} name${unreviewed.length === 1 ? 's' : ''} a drafter but no reviewer`
|
|
388
|
+
})
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// A component nothing points at has no recorded reason for being the way it
|
|
392
|
+
// is, which is the question a production team comparing its port will ask.
|
|
393
|
+
const realised = new Set((knowledge.relationships || []).filter((rel) => rel.type === 'realised-in').map((rel) => rel.to))
|
|
394
|
+
const unexplained = (knowledge.components || []).filter((component) => !realised.has(component.id))
|
|
395
|
+
if (unexplained.length) {
|
|
396
|
+
infos.push({
|
|
397
|
+
rule: 'component-without-reason',
|
|
398
|
+
count: unexplained.length,
|
|
399
|
+
ids: unexplained.map((component) => component.id),
|
|
400
|
+
message: `${unexplained.length} of ${knowledge.components.length} components have no realised-in link saying why they changed`
|
|
401
|
+
})
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
warnings.push(...riskWarnings(knowledge))
|
|
405
|
+
|
|
406
|
+
const agreed = (knowledge.intendedPurposes || []).filter((purpose) => purpose.status === 'agreed')
|
|
407
|
+
if (agreed.length > 1) {
|
|
408
|
+
warnings.push({
|
|
409
|
+
rule: 'purpose-agreed-twice',
|
|
410
|
+
ids: agreed.map((purpose) => purpose.id),
|
|
411
|
+
message: `${agreed.length} intended purposes are agreed (${agreed.map((p) => p.id).join(', ')}) - mark the older ones superseded`
|
|
412
|
+
})
|
|
413
|
+
}
|
|
414
|
+
for (const purpose of agreed) {
|
|
415
|
+
if (!purpose.agreedBy) {
|
|
416
|
+
warnings.push({ rule: 'purpose-agreed-by-nobody', id: purpose.id, message: `intended purpose ${purpose.id}: agreed, but agreedBy does not say who agreed it` })
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// A project that has turned the stricter checks on wants every gap in the
|
|
421
|
+
// chain to count, so `validate --strict` fails on them. Without the setting
|
|
422
|
+
// the same list is in the trace export, where it informs rather than blocks.
|
|
423
|
+
if (knowledge.project && knowledge.project.strictTraceability) {
|
|
424
|
+
const { buildTrace } = require('./trace')
|
|
425
|
+
for (const gap of buildTrace(knowledge).gaps) {
|
|
426
|
+
warnings.push({ rule: 'trace-gap', kind: gap.kind, id: gap.id, message: `${gap.id}: ${gap.message} (${gap.kind})` })
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
351
430
|
return { warnings, infos }
|
|
352
431
|
}
|
|
353
432
|
|
|
433
|
+
// Hazard ratings against the project's own scales. Only a named person sets a
|
|
434
|
+
// risk, and a rating means what the project's matrix says it means, so a
|
|
435
|
+
// rating with no assessor, a word off the scale, or a number the matrix would
|
|
436
|
+
// not give is worth saying out loud.
|
|
437
|
+
function riskWarnings (knowledge) {
|
|
438
|
+
const warnings = []
|
|
439
|
+
const scales = knowledge.project && knowledge.project.riskScales
|
|
440
|
+
const rated = (knowledge.hazards || []).filter((hazard) => hazard.initialRisk || hazard.residualRisk)
|
|
441
|
+
if (rated.length && !scales) {
|
|
442
|
+
warnings.push({
|
|
443
|
+
rule: 'risk-scales-missing',
|
|
444
|
+
message: `${rated.length} hazard${rated.length === 1 ? ' is' : 's are'} rated, but project.json sets no riskScales, so the ratings cannot be checked - copy the scales from your hazard log`
|
|
445
|
+
})
|
|
446
|
+
}
|
|
447
|
+
for (const hazard of rated) {
|
|
448
|
+
if (!hazard.assessedBy) {
|
|
449
|
+
warnings.push({ rule: 'risk-without-assessor', id: hazard.id, message: `hazard ${hazard.id}: risk is rated, but assessedBy does not name who rated it` })
|
|
450
|
+
}
|
|
451
|
+
if (hazard.status === 'proposed') {
|
|
452
|
+
warnings.push({ rule: 'proposed-hazard-rated', id: hazard.id, message: `hazard ${hazard.id}: proposed, yet rated - a proposed hazard has no rating until the clinical safety officer accepts it` })
|
|
453
|
+
}
|
|
454
|
+
for (const [field, risk] of [['initialRisk', hazard.initialRisk], ['residualRisk', hazard.residualRisk]]) {
|
|
455
|
+
if (!risk || !scales) continue
|
|
456
|
+
const problems = []
|
|
457
|
+
if (!scales.severity.includes(risk.severity)) problems.push(`severity "${risk.severity}" is not on the scale (${scales.severity.join(', ')})`)
|
|
458
|
+
if (!scales.likelihood.includes(risk.likelihood)) problems.push(`likelihood "${risk.likelihood}" is not on the scale (${scales.likelihood.join(', ')})`)
|
|
459
|
+
if (!Object.prototype.hasOwnProperty.call(scales.risk, String(risk.risk))) problems.push(`risk ${risk.risk} is not a rating the scale defines (${Object.keys(scales.risk).join(', ')})`)
|
|
460
|
+
const expected = scales.matrix && scales.matrix[risk.likelihood] && scales.matrix[risk.likelihood][risk.severity]
|
|
461
|
+
if (expected && expected !== risk.risk) problems.push(`the matrix gives ${expected} for ${risk.severity} and ${risk.likelihood}, not ${risk.risk}`)
|
|
462
|
+
for (const problem of problems) {
|
|
463
|
+
warnings.push({ rule: 'risk-off-scale', id: hazard.id, message: `hazard ${hazard.id}: ${field} ${problem}` })
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
if (hazard.initialRisk && hazard.residualRisk && hazard.residualRisk.risk > hazard.initialRisk.risk) {
|
|
467
|
+
warnings.push({ rule: 'residual-above-initial', id: hazard.id, message: `hazard ${hazard.id}: residual risk ${hazard.residualRisk.risk} is higher than initial ${hazard.initialRisk.risk} - controls should not raise a risk` })
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
return warnings
|
|
471
|
+
}
|
|
472
|
+
|
|
354
473
|
module.exports = { lintKnowledge, solutionWording, serviceNamesOf }
|
package/lib/load-knowledge.js
CHANGED
|
@@ -185,7 +185,13 @@ const OUTWARD = {
|
|
|
185
185
|
'applies-principle': 'Principles applied',
|
|
186
186
|
'observed-on': 'Seen on screens',
|
|
187
187
|
'rests-on': 'Rests on assumptions',
|
|
188
|
-
'challenged-by': 'Challenged by'
|
|
188
|
+
'challenged-by': 'Challenged by',
|
|
189
|
+
'realised-in': 'Realised in components',
|
|
190
|
+
'bounded-by': 'Keeps the product inside',
|
|
191
|
+
'assessed-against-purpose': 'Assessed against the intended purpose',
|
|
192
|
+
'identified-from': 'Identified from',
|
|
193
|
+
'mitigates': 'Hazards this reduces',
|
|
194
|
+
'implemented-by': 'Built by'
|
|
189
195
|
}
|
|
190
196
|
|
|
191
197
|
const INWARD = {
|
|
@@ -212,7 +218,13 @@ const INWARD = {
|
|
|
212
218
|
'applies-principle': 'Applied by',
|
|
213
219
|
'observed-on': 'Findings seen here',
|
|
214
220
|
'rests-on': 'Work that rests on this',
|
|
215
|
-
'challenged-by': 'Challenges'
|
|
221
|
+
'challenged-by': 'Challenges',
|
|
222
|
+
'realised-in': 'Changed because of',
|
|
223
|
+
'bounded-by': 'Requirements that keep the product inside this',
|
|
224
|
+
'assessed-against-purpose': 'Decisions assessed against this',
|
|
225
|
+
'identified-from': 'Hazards identified from this',
|
|
226
|
+
'mitigates': 'Controls',
|
|
227
|
+
'implemented-by': 'Safety controls this builds'
|
|
216
228
|
}
|
|
217
229
|
|
|
218
230
|
function outwardLabel (type) { return OUTWARD[type] || type }
|
|
@@ -222,7 +234,8 @@ function findRecord (knowledge, id) {
|
|
|
222
234
|
for (const collection of ['needs', 'insights', 'screens', 'users', 'scenarios',
|
|
223
235
|
'journeys', 'evidence', 'decisions', 'assumptions', 'researchRounds',
|
|
224
236
|
'participants', 'designActions', 'goals', 'qualityObjectives',
|
|
225
|
-
'requirements', 'principles'
|
|
237
|
+
'requirements', 'principles', 'components', 'intendedPurposes',
|
|
238
|
+
'hazards', 'controls']) {
|
|
226
239
|
const found = (knowledge[collection] || []).find((item) => item.id === id)
|
|
227
240
|
if (found) return found
|
|
228
241
|
}
|
|
@@ -925,6 +938,20 @@ function checkKnowledgeData (raw) {
|
|
|
925
938
|
errors.push(...requirementKindErrors(requirement))
|
|
926
939
|
}
|
|
927
940
|
|
|
941
|
+
for (const component of knowledge.components || []) {
|
|
942
|
+
for (const screenId of component.screenIds || []) requireRef(errors, 'component', component.id, 'screenIds', screenId, index.screens)
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
for (const purpose of knowledge.intendedPurposes || []) {
|
|
946
|
+
for (const userId of purpose.userIds || []) requireRef(errors, 'intended purpose', purpose.id, 'userIds', userId, index.users)
|
|
947
|
+
if (purpose.supersedes) requireRef(errors, 'intended purpose', purpose.id, 'supersedes', purpose.supersedes, index.intendedPurposes)
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
for (const hazard of knowledge.hazards || []) {
|
|
951
|
+
const numbers = (hazard.causes || []).map((cause) => String(cause.number))
|
|
952
|
+
if (new Set(numbers).size !== numbers.length) errors.push(`hazard ${hazard.id}: two causes share a number`)
|
|
953
|
+
}
|
|
954
|
+
|
|
928
955
|
for (const relationship of knowledge.relationships) {
|
|
929
956
|
requireRef(errors, 'relationship', relationship.id, 'from', relationship.from, index.entities)
|
|
930
957
|
requireRef(errors, 'relationship', relationship.id, 'to', relationship.to, index.entities)
|
|
@@ -937,6 +964,18 @@ function checkKnowledgeData (raw) {
|
|
|
937
964
|
`to ${rule.to.join(' or ')}, but this one runs from ${from.collection} to ${to.collection}`
|
|
938
965
|
)
|
|
939
966
|
}
|
|
967
|
+
if (relationship.type === 'assessed-against-purpose' && !relationship.assessment) {
|
|
968
|
+
errors.push(`relationship ${relationship.id}: assessed-against-purpose says whether the decision is within the purpose, changes it, or falls outside it (assessment)`)
|
|
969
|
+
}
|
|
970
|
+
// A cause has to be one the hazard lists, or the link points at nothing.
|
|
971
|
+
if (relationship.cause !== undefined) {
|
|
972
|
+
const hazard = relationship.type === 'mitigates' ? to : relationship.type === 'identified-from' ? from : null
|
|
973
|
+
if (!hazard || hazard.collection !== 'hazards') {
|
|
974
|
+
errors.push(`relationship ${relationship.id}: only mitigates and identified-from links name a hazard's cause`)
|
|
975
|
+
} else if (!(hazard.item.causes || []).some((cause) => String(cause.number) === String(relationship.cause))) {
|
|
976
|
+
errors.push(`relationship ${relationship.id}: hazard ${hazard.id} has no cause ${relationship.cause}`)
|
|
977
|
+
}
|
|
978
|
+
}
|
|
940
979
|
}
|
|
941
980
|
|
|
942
981
|
return errors
|
|
@@ -960,6 +999,10 @@ function buildIndex (knowledge) {
|
|
|
960
999
|
qualityObjectives: byId(knowledge.qualityObjectives || []),
|
|
961
1000
|
requirements: byId(knowledge.requirements || []),
|
|
962
1001
|
principles: byId(knowledge.principles || []),
|
|
1002
|
+
components: byId(knowledge.components || []),
|
|
1003
|
+
intendedPurposes: byId(knowledge.intendedPurposes || []),
|
|
1004
|
+
hazards: byId(knowledge.hazards || []),
|
|
1005
|
+
controls: byId(knowledge.controls || []),
|
|
963
1006
|
relationships: byId(knowledge.relationships)
|
|
964
1007
|
}
|
|
965
1008
|
index.entities = buildEntityIndex(knowledge)
|
|
@@ -987,7 +1030,11 @@ function buildEntityIndex (knowledge) {
|
|
|
987
1030
|
goals: { type: 'Goal', labelKey: 'statement' },
|
|
988
1031
|
qualityObjectives: { type: 'Quality objective', labelKey: 'statement' },
|
|
989
1032
|
requirements: { type: 'Requirement', labelKey: 'statement' },
|
|
990
|
-
principles: { type: 'Principle', labelKey: 'title' }
|
|
1033
|
+
principles: { type: 'Principle', labelKey: 'title' },
|
|
1034
|
+
components: { type: 'Component', labelKey: 'title' },
|
|
1035
|
+
intendedPurposes: { type: 'Intended purpose', labelKey: 'title' },
|
|
1036
|
+
hazards: { type: 'Hazard', labelKey: 'title' },
|
|
1037
|
+
controls: { type: 'Control', labelKey: 'statement' }
|
|
991
1038
|
}
|
|
992
1039
|
|
|
993
1040
|
const entities = {}
|
|
@@ -1013,12 +1060,18 @@ const RELATIONSHIP_ENDS = {
|
|
|
1013
1060
|
'based-on-insight': { from: ['requirements'], to: ['insights'] },
|
|
1014
1061
|
'constrained-by': { from: ['requirements'], to: ['requirements'] },
|
|
1015
1062
|
'refines-objective': { from: ['requirements'], to: ['qualityObjectives'] },
|
|
1016
|
-
'verified-by': { from: ['requirements'], to: ['insights'] },
|
|
1063
|
+
'verified-by': { from: ['requirements', 'controls'], to: ['insights'] },
|
|
1017
1064
|
'weighed-against': { from: ['decisions'], to: ['requirements'] },
|
|
1018
1065
|
'applies-principle': { from: ['screens', 'requirements', 'decisions', 'journeys'], to: ['principles'] },
|
|
1019
|
-
'observed-on': { from: ['insights'], to: ['screens'] },
|
|
1066
|
+
'observed-on': { from: ['insights', 'hazards'], to: ['screens'] },
|
|
1020
1067
|
'rests-on': { from: ['designActions', 'decisions', 'requirements'], to: ['assumptions'] },
|
|
1021
|
-
'challenged-by': { from: ['assumptions', 'decisions', 'requirements'], to: ['evidence', 'insights'] }
|
|
1068
|
+
'challenged-by': { from: ['assumptions', 'decisions', 'requirements'], to: ['evidence', 'insights'] },
|
|
1069
|
+
'realised-in': { from: ['decisions', 'requirements', 'designActions', 'insights'], to: ['components'] },
|
|
1070
|
+
'bounded-by': { from: ['requirements'], to: ['intendedPurposes'] },
|
|
1071
|
+
'assessed-against-purpose': { from: ['decisions'], to: ['intendedPurposes'] },
|
|
1072
|
+
'identified-from': { from: ['hazards'], to: ['insights', 'evidence', 'scenarios'] },
|
|
1073
|
+
'mitigates': { from: ['controls'], to: ['hazards'] },
|
|
1074
|
+
'implemented-by': { from: ['controls'], to: ['requirements', 'decisions', 'designActions', 'screens', 'components'] }
|
|
1022
1075
|
}
|
|
1023
1076
|
|
|
1024
1077
|
/**
|
package/lib/record-links.js
CHANGED
|
@@ -25,7 +25,11 @@ const ROUTES = {
|
|
|
25
25
|
Assumption: null,
|
|
26
26
|
'Research round': null,
|
|
27
27
|
Participant: null,
|
|
28
|
-
'Design action': null
|
|
28
|
+
'Design action': null,
|
|
29
|
+
Component: (id) => `/components/${id}`,
|
|
30
|
+
'Intended purpose': (id) => `/intended-purpose/${id}`,
|
|
31
|
+
Hazard: (id) => `/hazards/${id}`,
|
|
32
|
+
Control: (id) => `/controls/${id}`
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
// Where a whole TYPE lives, as opposed to one record. Several types have no
|
|
@@ -43,7 +47,11 @@ const LIST_ROUTES = {
|
|
|
43
47
|
Requirement: '/requirements',
|
|
44
48
|
Principle: '/design',
|
|
45
49
|
Decision: '/design',
|
|
46
|
-
'Quality objective': '/plan'
|
|
50
|
+
'Quality objective': '/plan',
|
|
51
|
+
Component: '/components',
|
|
52
|
+
'Intended purpose': '/safety',
|
|
53
|
+
Hazard: '/safety',
|
|
54
|
+
Control: '/safety'
|
|
47
55
|
}
|
|
48
56
|
|
|
49
57
|
function listHrefFor (type, basePath = '') {
|
package/lib/review.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Who drafted and who reviewed a record, written onto the record itself.
|
|
2
|
+
//
|
|
3
|
+
// `draft promote` has always refused a draft without a reviewer, but it kept the
|
|
4
|
+
// name only in hippocampus/manifests/drafts.json. A trace reads records, not the
|
|
5
|
+
// manifest, so a reviewed finding and an unreviewed one looked the same in it.
|
|
6
|
+
// Promotion now writes the names where a trace can see them.
|
|
7
|
+
|
|
8
|
+
function today () {
|
|
9
|
+
return new Date().toISOString().slice(0, 10)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The records with who drafted and reviewed them filled in. A record that
|
|
14
|
+
* already names its own drafter or reviewer keeps it: a draft can carry records
|
|
15
|
+
* reviewed earlier, by someone else, and promotion must not claim them.
|
|
16
|
+
*/
|
|
17
|
+
function stampReview (records, { draftedBy, reviewer, on = today() } = {}) {
|
|
18
|
+
return (records || []).map((record) => {
|
|
19
|
+
const stamped = { ...record }
|
|
20
|
+
if (draftedBy && !stamped.draftedBy) stamped.draftedBy = draftedBy
|
|
21
|
+
if (reviewer && !stamped.reviewedBy) {
|
|
22
|
+
stamped.reviewedBy = reviewer
|
|
23
|
+
stamped.reviewedOn = on
|
|
24
|
+
}
|
|
25
|
+
return stamped
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function samePerson (a, b) {
|
|
30
|
+
return Boolean(a && b) && String(a).trim().toLowerCase() === String(b).trim().toLowerCase()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = { stampReview, samePerson, today }
|
package/lib/schema-version.js
CHANGED
|
@@ -18,14 +18,28 @@ const META_FILENAME = '_meta.json'
|
|
|
18
18
|
//
|
|
19
19
|
// Raise this when a release adds a value or record type that older packages
|
|
20
20
|
// would reject, and list what needs it in FEATURES_NEEDING.
|
|
21
|
-
const FEATURE_LEVEL = '2.
|
|
21
|
+
const FEATURE_LEVEL = '2.10.0'
|
|
22
22
|
|
|
23
|
-
// What, in a knowledge base, needs which level. Checked
|
|
24
|
-
//
|
|
23
|
+
// What, in a knowledge base, needs which level. Checked by every command that
|
|
24
|
+
// writes records (draft promote, promote research, import design-actions), so
|
|
25
|
+
// the level is written only once something actually needs it. validate warns
|
|
26
|
+
// when a hand edit has added one without it, and migrate records it.
|
|
25
27
|
const FEATURES_NEEDING = {
|
|
26
28
|
'2.9.0': {
|
|
27
29
|
relationshipTypes: ['rests-on', 'challenged-by'],
|
|
28
30
|
researchMethods: ['expert-review']
|
|
31
|
+
},
|
|
32
|
+
// Releases 2 and 3 of the traceability work ship together. A collection an
|
|
33
|
+
// older package does not read is ignored, not refused - but the links into
|
|
34
|
+
// it then point at nothing, so it needs the level too. observed-on from a
|
|
35
|
+
// hazard and verified-by from a control are older types with new ends; they
|
|
36
|
+
// need a hazard or control to exist, so the collections carry them.
|
|
37
|
+
//
|
|
38
|
+
// The level is the version that ships the feature. A level no published
|
|
39
|
+
// version has would tell people to upgrade to something they cannot install.
|
|
40
|
+
'2.10.0': {
|
|
41
|
+
relationshipTypes: ['realised-in', 'bounded-by', 'assessed-against-purpose', 'identified-from', 'mitigates', 'implemented-by'],
|
|
42
|
+
collections: ['components', 'intendedPurposes', 'hazards', 'controls']
|
|
29
43
|
}
|
|
30
44
|
}
|
|
31
45
|
|
|
@@ -75,19 +89,44 @@ function compareVersions (a, b) {
|
|
|
75
89
|
return 0
|
|
76
90
|
}
|
|
77
91
|
|
|
92
|
+
// Each versioned feature this knowledge uses, with the level it needs.
|
|
93
|
+
function featuresUsed (knowledge) {
|
|
94
|
+
const linkTypes = new Set((knowledge.relationships || []).map((r) => r.type))
|
|
95
|
+
const methods = new Set((knowledge.researchRounds || []).flatMap((r) => r.methods || []))
|
|
96
|
+
const used = []
|
|
97
|
+
for (const [level, uses] of Object.entries(FEATURES_NEEDING)) {
|
|
98
|
+
for (const type of uses.relationshipTypes || []) if (linkTypes.has(type)) used.push({ level, feature: `${type} links` })
|
|
99
|
+
for (const method of uses.researchMethods || []) if (methods.has(method)) used.push({ level, feature: `the ${method} method` })
|
|
100
|
+
for (const collection of uses.collections || []) if ((knowledge[collection] || []).length) used.push({ level, feature: `${collection} records` })
|
|
101
|
+
}
|
|
102
|
+
return used
|
|
103
|
+
}
|
|
104
|
+
|
|
78
105
|
// The lowest level that can read this knowledge, from what it actually uses.
|
|
79
106
|
function levelNeeded (knowledge) {
|
|
80
107
|
let needed = null
|
|
81
|
-
for (const
|
|
82
|
-
|
|
83
|
-
const methods = new Set((knowledge.researchRounds || []).flatMap((r) => r.methods || []))
|
|
84
|
-
const used = (uses.relationshipTypes || []).some((t) => linkTypes.has(t)) ||
|
|
85
|
-
(uses.researchMethods || []).some((m) => methods.has(m))
|
|
86
|
-
if (used && (!needed || compareVersions(level, needed) > 0)) needed = level
|
|
108
|
+
for (const { level } of featuresUsed(knowledge)) {
|
|
109
|
+
if (!needed || compareVersions(level, needed) > 0) needed = level
|
|
87
110
|
}
|
|
88
111
|
return needed
|
|
89
112
|
}
|
|
90
113
|
|
|
114
|
+
// What the knowledge needs and _meta.json does not yet say: { level, features }
|
|
115
|
+
// or null. Records added by hand, or by a command older than this check, are
|
|
116
|
+
// the usual cause, and an older package then fails on them with a schema error
|
|
117
|
+
// instead of asking for an upgrade.
|
|
118
|
+
function unrecordedLevel (knowledgeSourceDir, knowledge) {
|
|
119
|
+
const needed = levelNeeded(knowledge)
|
|
120
|
+
if (!needed) return null
|
|
121
|
+
const metaPath = path.join(knowledgeSourceDir, META_FILENAME)
|
|
122
|
+
const recorded = fs.existsSync(metaPath) ? JSON.parse(fs.readFileSync(metaPath, 'utf8')).requiresPackage : null
|
|
123
|
+
if (recorded && compareVersions(recorded, needed) >= 0) return null
|
|
124
|
+
const features = featuresUsed(knowledge)
|
|
125
|
+
.filter(({ level }) => !recorded || compareVersions(level, recorded) > 0)
|
|
126
|
+
.map(({ feature }) => feature)
|
|
127
|
+
return { level: needed, features }
|
|
128
|
+
}
|
|
129
|
+
|
|
91
130
|
// Writes requiresPackage into _meta.json when the knowledge now needs a higher
|
|
92
131
|
// level than it records. Never lowers it: removing the last use of a feature
|
|
93
132
|
// is not worth a write, and an over-cautious level costs an upgrade at most.
|
|
@@ -160,7 +199,9 @@ module.exports = {
|
|
|
160
199
|
FEATURE_LEVEL,
|
|
161
200
|
FEATURES_NEEDING,
|
|
162
201
|
compareVersions,
|
|
202
|
+
featuresUsed,
|
|
163
203
|
levelNeeded,
|
|
204
|
+
unrecordedLevel,
|
|
164
205
|
recordLevelNeeded,
|
|
165
206
|
migrations,
|
|
166
207
|
readMeta,
|