@hippo-digital/hippocampus 2.3.0 → 2.5.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 +115 -0
- package/README.md +19 -0
- package/assets/dist/hippocampus.css +1 -1
- package/assets/hippocampus.scss +34 -1
- package/docs/agent-roadmap.md +6 -1
- package/docs/agent-workflow.md +6 -1
- package/docs/ask-whats-already-known.md +159 -0
- package/docs/colour-pairings.md +6 -0
- package/docs/components.md +7 -1
- package/docs/custom-agents-usage.md +6 -1
- package/docs/design-actions-and-decisions.md +5 -0
- package/docs/diagrams/README.md +44 -0
- package/docs/diagrams/evidence-flow.mmd +56 -0
- package/docs/diagrams/mermaid.config.json +20 -0
- package/docs/hippocampus-for-designers-and-researchers.md +7 -1
- package/docs/hippocampus-technical.md +7 -1
- package/docs/images/evidence-flow.svg +1 -0
- package/docs/import-a-research-round.md +229 -0
- package/docs/prompt-architecture-guardrails.md +6 -1
- package/docs/repeatable-research-round-ingestion.md +6 -1
- package/docs/research-knowledge-graph.md +7 -1
- package/docs/research-source-file-conventions.md +7 -2
- package/docs/review-and-promote-a-draft.md +203 -0
- package/docs/source-model.md +28 -1
- package/docs/start-here.md +206 -0
- package/lib/create-router.js +41 -7
- package/lib/docs.js +288 -30
- package/lib/lint-knowledge.js +22 -1
- package/lib/schema.js +58 -12
- package/package.json +1 -1
- package/scripts/import-research-deck.js +31 -6
- package/scripts/known.js +2 -2
- package/scripts/promote-research-draft.js +76 -6
- package/scripts/smoke-routes.js +8 -1
- package/skills/ingest-user-personas/SKILL.md +1 -1
- package/views/hippocampus/doc.html +15 -0
- package/views/hippocampus/docs.html +42 -13
- package/views/hippocampus/evidence-impact.html +4 -0
- package/views/hippocampus/record.html +10 -2
- package/views/hippocampus/research.html +9 -4
package/lib/docs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const fs = require('fs')
|
|
2
2
|
const path = require('path')
|
|
3
|
-
const {
|
|
3
|
+
const { Marked } = require('marked')
|
|
4
4
|
const packagePaths = require('./package-paths')
|
|
5
5
|
|
|
6
6
|
// Docs are served, not copied.
|
|
@@ -14,58 +14,316 @@ const packagePaths = require('./package-paths')
|
|
|
14
14
|
// `hippocampus skills install` copies them, with hashes so an upgrade can tell
|
|
15
15
|
// a stale copy from an edited one.
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
// The guide is grouped for the people reading it, not by filename. Each doc
|
|
18
|
+
// says where it belongs in front matter at its top:
|
|
19
|
+
//
|
|
20
|
+
// ---
|
|
21
|
+
// title: Ingest a research round
|
|
22
|
+
// section: recipes
|
|
23
|
+
// order: 20
|
|
24
|
+
// audience: [viewer, cli]
|
|
25
|
+
// summary: Take a deck or a transcript from the inbox to a reviewed draft.
|
|
26
|
+
// ---
|
|
27
|
+
//
|
|
28
|
+
// Every key is optional, and every default is what the list did before front
|
|
29
|
+
// matter existed. A doc nobody has migrated still appears - in Reference,
|
|
30
|
+
// titled by its first heading - rather than vanishing because it did not say
|
|
31
|
+
// where it goes.
|
|
32
|
+
const SECTIONS = [
|
|
33
|
+
{
|
|
34
|
+
id: 'start',
|
|
35
|
+
title: 'Start here',
|
|
36
|
+
description: 'What Hippocampus is, how evidence moves through it, and how to get it running.'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
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.'
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
id: 'governance',
|
|
45
|
+
title: 'Data and governance',
|
|
46
|
+
description: 'Where research data goes, who approves it, and when anything leaves the machine.'
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
id: 'reference',
|
|
50
|
+
title: 'Reference',
|
|
51
|
+
description: 'Record shapes, file conventions and the detail the recipes link to.'
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
id: 'contributors',
|
|
55
|
+
title: 'For contributors',
|
|
56
|
+
description: 'How the package works inside, and how agents are set up to work on it.'
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
const DEFAULT_SECTION = 'reference'
|
|
61
|
+
const DEFAULT_ORDER = 999
|
|
62
|
+
|
|
63
|
+
// Who a page is written for. A label, never a filter: hiding a page from
|
|
64
|
+
// somebody because of who we guessed they were is how a reviewer ends up
|
|
65
|
+
// unable to find the governance page.
|
|
66
|
+
const AUDIENCES = { viewer: 'Viewer', cli: 'Command line' }
|
|
67
|
+
|
|
68
|
+
const IMAGE_PATTERN = /^[a-z0-9-]+\.(svg|png)$/
|
|
20
69
|
|
|
21
70
|
function slugOf (filename) {
|
|
22
71
|
return filename.replace(/\.md$/, '')
|
|
23
72
|
}
|
|
24
73
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
74
|
+
// Deliberately small. Front matter here is five flat keys, and a YAML parser
|
|
75
|
+
// would be a seventh dependency to read them.
|
|
76
|
+
//
|
|
77
|
+
// It is also strict about what counts as front matter at all: a block whose
|
|
78
|
+
// lines are not all `key: value`, `key: [a, b]`, a `- item` under a bare key,
|
|
79
|
+
// a comment or blank is left in the body untouched. A doc that happens to open
|
|
80
|
+
// with a horizontal rule must not lose its first paragraph to a parser that
|
|
81
|
+
// guessed - and a malformed block that renders on the page is a mistake its
|
|
82
|
+
// author will see, where one silently dropped is not.
|
|
83
|
+
function parseFrontMatter (contents) {
|
|
84
|
+
const match = /^---[ \t]*\r?\n(?:([\s\S]*?)\r?\n)?---[ \t]*(?:\r?\n|$)/.exec(contents)
|
|
85
|
+
if (!match) return { data: {}, body: contents }
|
|
86
|
+
|
|
87
|
+
const data = {}
|
|
88
|
+
let listKey = null
|
|
89
|
+
|
|
90
|
+
for (const line of (match[1] || '').split(/\r?\n/)) {
|
|
91
|
+
if (!line.trim() || /^\s*#/.test(line)) continue
|
|
92
|
+
|
|
93
|
+
const item = /^\s+-\s+(.*)$/.exec(line)
|
|
94
|
+
if (item && listKey) {
|
|
95
|
+
data[listKey].push(unquote(withoutComment(item[1])))
|
|
96
|
+
continue
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const pair = /^([A-Za-z][\w-]*)\s*:\s*(.*)$/.exec(line)
|
|
100
|
+
if (!pair) return { data: {}, body: contents }
|
|
101
|
+
|
|
102
|
+
const key = pair[1]
|
|
103
|
+
const raw = withoutComment(pair[2])
|
|
104
|
+
const list = /^\[(.*)\]$/.exec(raw)
|
|
105
|
+
if (list) {
|
|
106
|
+
data[key] = list[1].split(',').map(unquote).filter(Boolean)
|
|
107
|
+
listKey = null
|
|
108
|
+
} else if (!raw.trim()) {
|
|
109
|
+
data[key] = []
|
|
110
|
+
listKey = key
|
|
111
|
+
} else {
|
|
112
|
+
data[key] = unquote(raw)
|
|
113
|
+
listKey = null
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return { data, body: contents.slice(match[0].length) }
|
|
31
118
|
}
|
|
32
119
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
120
|
+
// YAML's rule: a # after whitespace starts a comment, unless it is inside
|
|
121
|
+
// quotes. Without this, `section: recipes # where it goes` is an unknown
|
|
122
|
+
// section, and the guide quietly moves to Reference.
|
|
123
|
+
function withoutComment (raw) {
|
|
124
|
+
const value = raw.trim()
|
|
125
|
+
const quoted = /^(['"])(.*?)\1\s*(?:#.*)?$/.exec(value)
|
|
126
|
+
if (quoted) return `${quoted[1]}${quoted[2]}${quoted[1]}`
|
|
127
|
+
return value.replace(/\s+#.*$/, '')
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function unquote (value) {
|
|
131
|
+
const trimmed = String(value).trim()
|
|
132
|
+
const quoted = /^(['"])(.*)\1$/.exec(trimmed)
|
|
133
|
+
return quoted ? quoted[2] : trimmed
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function text (value) {
|
|
137
|
+
return typeof value === 'string' && value.trim() ? value.trim() : ''
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function headingOf (body) {
|
|
141
|
+
const heading = body.match(/^#\s+(.+)$/m)
|
|
142
|
+
return heading ? heading[1].trim() : ''
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function summaryOf (body) {
|
|
146
|
+
const rest = body.replace(/^#\s+.+$/m, '').trim()
|
|
147
|
+
const paragraph = rest.split(/\n\s*\n/).find((block) => block.trim() && !block.trim().startsWith('#'))
|
|
36
148
|
if (!paragraph) return ''
|
|
37
|
-
const
|
|
38
|
-
return
|
|
149
|
+
const plain = paragraph.replace(/\s+/g, ' ').replace(/[*_`[\]]/g, '').trim()
|
|
150
|
+
return plain.length > 200 ? `${plain.slice(0, 197)}...` : plain
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function orderOf (value) {
|
|
154
|
+
return /^-?\d+$/.test(text(value)) ? Number(value) : DEFAULT_ORDER
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Everything the list and the page need from one file, with front matter
|
|
158
|
+
// already taken off. The body is the only thing that reaches marked, the title
|
|
159
|
+
// finder and the summary finder - front matter that got as far as any of them
|
|
160
|
+
// would render as a stray paragraph at the top of every guide, and become the
|
|
161
|
+
// summary on every card.
|
|
162
|
+
function describe (filename, contents) {
|
|
163
|
+
const slug = slugOf(filename)
|
|
164
|
+
const { data, body } = parseFrontMatter(contents)
|
|
165
|
+
|
|
166
|
+
const section = SECTIONS.some((candidate) => candidate.id === text(data.section))
|
|
167
|
+
? text(data.section)
|
|
168
|
+
: DEFAULT_SECTION
|
|
169
|
+
|
|
170
|
+
const declared = [].concat(data.audience || []).filter((value) => AUDIENCES[value])
|
|
171
|
+
const audience = declared.length ? [...new Set(declared)] : Object.keys(AUDIENCES)
|
|
172
|
+
|
|
173
|
+
return {
|
|
174
|
+
slug,
|
|
175
|
+
title: text(data.title) || headingOf(body) || slug.replace(/-/g, ' ').replace(/^./, (c) => c.toUpperCase()),
|
|
176
|
+
summary: text(data.summary) || summaryOf(body),
|
|
177
|
+
section,
|
|
178
|
+
order: orderOf(data.order),
|
|
179
|
+
audience,
|
|
180
|
+
audienceLabels: audience.map((value) => AUDIENCES[value]),
|
|
181
|
+
body
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function sectionIndex (id) {
|
|
186
|
+
return SECTIONS.findIndex((section) => section.id === id)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function byPlace (a, b) {
|
|
190
|
+
return sectionIndex(a.section) - sectionIndex(b.section) ||
|
|
191
|
+
a.order - b.order ||
|
|
192
|
+
a.title.localeCompare(b.title)
|
|
39
193
|
}
|
|
40
194
|
|
|
41
|
-
function
|
|
42
|
-
|
|
43
|
-
|
|
195
|
+
function summaryFields ({ body, ...rest }) {
|
|
196
|
+
return rest
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Flat, in reading order: Start here first, contributors last. The smoke test
|
|
200
|
+
// only wants slugs from this, so it stays flat rather than learning sections.
|
|
201
|
+
function listDocs (docsDir = packagePaths.docsDir) {
|
|
202
|
+
if (!fs.existsSync(docsDir)) return []
|
|
203
|
+
return fs.readdirSync(docsDir)
|
|
44
204
|
.filter((name) => name.endsWith('.md'))
|
|
45
|
-
.
|
|
46
|
-
.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
205
|
+
.map((name) => summaryFields(describe(name, fs.readFileSync(path.join(docsDir, name), 'utf8'))))
|
|
206
|
+
.sort(byPlace)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Sections with nothing in them are left out. An empty heading on the list
|
|
210
|
+
// reads as "this part of the guide is missing", which until it is written it
|
|
211
|
+
// is - but the list is not the place to say so.
|
|
212
|
+
function listDocSections (docsDir = packagePaths.docsDir) {
|
|
213
|
+
const docs = listDocs(docsDir)
|
|
214
|
+
return SECTIONS
|
|
215
|
+
.map((section) => ({ ...section, docs: docs.filter((doc) => doc.section === section.id) }))
|
|
216
|
+
.filter((section) => section.docs.length)
|
|
50
217
|
}
|
|
51
218
|
|
|
52
|
-
function readDoc (slug) {
|
|
219
|
+
function readDoc (slug, docsDir = packagePaths.docsDir) {
|
|
53
220
|
// The slug comes off a URL, so it is checked against the directory listing
|
|
54
221
|
// rather than joined onto a path and hoped for.
|
|
55
222
|
if (!/^[a-z0-9-]+$/.test(slug)) return null
|
|
56
|
-
const filePath = path.join(
|
|
223
|
+
const filePath = path.join(docsDir, `${slug}.md`)
|
|
57
224
|
if (!fs.existsSync(filePath)) return null
|
|
58
225
|
|
|
59
|
-
const
|
|
226
|
+
const doc = describe(`${slug}.md`, fs.readFileSync(filePath, 'utf8'))
|
|
227
|
+
const all = listDocs(docsDir)
|
|
228
|
+
const at = all.findIndex((candidate) => candidate.slug === slug)
|
|
229
|
+
const section = SECTIONS.find((candidate) => candidate.id === doc.section)
|
|
230
|
+
|
|
60
231
|
return {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
html:
|
|
232
|
+
...summaryFields(doc),
|
|
233
|
+
sectionTitle: section.title,
|
|
234
|
+
html: renderMarkdown(doc.body),
|
|
235
|
+
// Reading order runs across sections on purpose: the page after Start here
|
|
236
|
+
// is the first recipe, not nothing.
|
|
237
|
+
previous: at > 0 ? pageLink(all[at - 1]) : null,
|
|
238
|
+
next: at >= 0 && at < all.length - 1 ? pageLink(all[at + 1]) : null
|
|
64
239
|
}
|
|
65
240
|
}
|
|
66
241
|
|
|
242
|
+
function pageLink (doc) {
|
|
243
|
+
return { slug: doc.slug, title: doc.title }
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Diagrams the guides embed. Only files that are in docs/images, only by a
|
|
247
|
+
// name that is just a slug and an image extension: a URL segment is never
|
|
248
|
+
// joined onto a path until it has matched an entry in the directory listing.
|
|
249
|
+
function docImagePath (file, docsDir = packagePaths.docsDir) {
|
|
250
|
+
if (!IMAGE_PATTERN.test(file || '')) return null
|
|
251
|
+
const imagesDir = path.join(docsDir, 'images')
|
|
252
|
+
if (!fs.existsSync(imagesDir)) return null
|
|
253
|
+
if (!fs.readdirSync(imagesDir).includes(file)) return null
|
|
254
|
+
return path.join(imagesDir, file)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function listDocImages (docsDir = packagePaths.docsDir) {
|
|
258
|
+
const imagesDir = path.join(docsDir, 'images')
|
|
259
|
+
if (!fs.existsSync(imagesDir)) return []
|
|
260
|
+
return fs.readdirSync(imagesDir).filter((name) => IMAGE_PATTERN.test(name)).sort()
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Markdown to HTML, with two things marked no longer does on its own.
|
|
264
|
+
//
|
|
265
|
+
// Heading ids. `headerIds: true` was passed here for as long as this file has
|
|
266
|
+
// existed, but marked dropped that option in v8 and ignores it, so no heading
|
|
267
|
+
// in any guide had an id and no link to part of a guide could work. The ids
|
|
268
|
+
// follow GitHub's rule - lower case, punctuation dropped, spaces to hyphens,
|
|
269
|
+
// repeats numbered - so one link works in the viewer and on GitHub alike.
|
|
270
|
+
//
|
|
271
|
+
// Links between guides. They are written `source-model.md`, which is right on
|
|
272
|
+
// GitHub and in an editor, and a 404 in the viewer, where the page is
|
|
273
|
+
// `docs/source-model`. Only a bare sibling `.md` is rewritten; anything with a
|
|
274
|
+
// scheme, a leading slash or a directory is left as it was written.
|
|
275
|
+
function renderMarkdown (body) {
|
|
276
|
+
const seen = new Map()
|
|
277
|
+
const md = new Marked({
|
|
278
|
+
walkTokens (token) {
|
|
279
|
+
if (token.type === 'link') token.href = docHref(token.href)
|
|
280
|
+
},
|
|
281
|
+
renderer: {
|
|
282
|
+
heading ({ tokens, depth }) {
|
|
283
|
+
const inner = this.parser.parseInline(tokens)
|
|
284
|
+
const id = uniqueId(seen, headingId(inner))
|
|
285
|
+
return `<h${depth} id="${id}">${inner}</h${depth}>\n`
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
})
|
|
289
|
+
return md.parse(body)
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function docHref (href) {
|
|
293
|
+
const match = /^(?:\.\/)?([a-z0-9-]+)\.md(#[^\s]*)?$/.exec(href || '')
|
|
294
|
+
return match ? `${match[1]}${match[2] || ''}` : href
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function headingId (html) {
|
|
298
|
+
return html
|
|
299
|
+
.replace(/<[^>]*>/g, '')
|
|
300
|
+
.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
|
301
|
+
.replace(/"/g, '"').replace(/'/g, "'")
|
|
302
|
+
.toLowerCase()
|
|
303
|
+
.trim()
|
|
304
|
+
.replace(/[^\p{L}\p{N}\s_-]/gu, '')
|
|
305
|
+
.replace(/\s/g, '-')
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function uniqueId (seen, base) {
|
|
309
|
+
const id = base || 'section'
|
|
310
|
+
const count = seen.get(id) || 0
|
|
311
|
+
seen.set(id, count + 1)
|
|
312
|
+
return count ? `${id}-${count}` : id
|
|
313
|
+
}
|
|
314
|
+
|
|
67
315
|
function packageVersion () {
|
|
68
316
|
return require('../package.json').version
|
|
69
317
|
}
|
|
70
318
|
|
|
71
|
-
module.exports = {
|
|
319
|
+
module.exports = {
|
|
320
|
+
SECTIONS,
|
|
321
|
+
listDocs,
|
|
322
|
+
listDocSections,
|
|
323
|
+
readDoc,
|
|
324
|
+
docImagePath,
|
|
325
|
+
listDocImages,
|
|
326
|
+
parseFrontMatter,
|
|
327
|
+
renderMarkdown,
|
|
328
|
+
packageVersion
|
|
329
|
+
}
|
package/lib/lint-knowledge.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { recordSchemas } = require('./schema')
|
|
1
|
+
const { recordSchemas, UNRESEARCHED } = require('./schema')
|
|
2
2
|
|
|
3
3
|
const LIST_GLYPH = /^[\s\u00a0]*[\u2022\u25cf\u25aa\u25e6\u2043\u2219\u00b7\u25cb]/
|
|
4
4
|
|
|
@@ -144,6 +144,27 @@ function lintKnowledge (knowledge) {
|
|
|
144
144
|
})
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
+
// A user written down before anyone researched them - common when a workbook
|
|
148
|
+
// names a user group long before persona work reaches it. The schema still
|
|
149
|
+
// requires a responsibility and an access need (see UNRESEARCHED in
|
|
150
|
+
// schema.js), so the honest entry is that exact value, and this counts it.
|
|
151
|
+
// Reported per field, because "nobody has asked about their access needs" is
|
|
152
|
+
// the gap worth chasing, and it hides inside a user who otherwise looks done.
|
|
153
|
+
const unresearched = (list) => Array.isArray(list) && list.length > 0 &&
|
|
154
|
+
list.every((item) => String(item).trim().toLowerCase() === UNRESEARCHED.toLowerCase())
|
|
155
|
+
for (const [field, label] of [['accessNeeds', 'access needs'], ['responsibilities', 'responsibilities']]) {
|
|
156
|
+
const users = (knowledge.users || []).filter((user) => unresearched(user[field]))
|
|
157
|
+
if (users.length) {
|
|
158
|
+
infos.push({
|
|
159
|
+
rule: 'user-unresearched',
|
|
160
|
+
field,
|
|
161
|
+
count: users.length,
|
|
162
|
+
ids: users.map((user) => user.id),
|
|
163
|
+
message: `${users.length} of ${knowledge.users.length} users have ${label} not yet researched`
|
|
164
|
+
})
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
147
168
|
const defaultPriority = (knowledge.needs || []).filter((need) => need.priority === 'medium')
|
|
148
169
|
if (defaultPriority.length && knowledge.needs.length) {
|
|
149
170
|
const share = Math.round((defaultPriority.length / knowledge.needs.length) * 100)
|
package/lib/schema.js
CHANGED
|
@@ -4,6 +4,24 @@ const id = z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, 'Use lowercase kebab-c
|
|
|
4
4
|
const nonEmptyString = z.string().trim().min(1)
|
|
5
5
|
const stringList = z.array(nonEmptyString).min(1)
|
|
6
6
|
|
|
7
|
+
// The identifier a record already has in the system it came from: a Jira key, or
|
|
8
|
+
// a workbook row such as "FB-013" or "US-010". It keeps a decision traceable to
|
|
9
|
+
// the ticket a team actually works from, and gives an importer a stable key to
|
|
10
|
+
// find a record it wrote earlier and update it rather than add a second copy.
|
|
11
|
+
const reference = nonEmptyString.optional()
|
|
12
|
+
|
|
13
|
+
// How much a finding matters - a different question from how sure we are of it,
|
|
14
|
+
// which is `confidence`. A finding can be critical and only weakly evidenced;
|
|
15
|
+
// folding the two together makes the most severe item in a log read as middling.
|
|
16
|
+
const impact = z.enum(['critical', 'high', 'medium', 'low', 'unknown']).optional()
|
|
17
|
+
|
|
18
|
+
// What a user record says when nobody has researched that part of it yet. The
|
|
19
|
+
// schema still requires at least one responsibility and one access need, because
|
|
20
|
+
// relaxing that would let data written by this version break the previous one.
|
|
21
|
+
// Writing this exact value instead is honest, and the linter counts it, so a gap
|
|
22
|
+
// is reported every time rather than passing as a finding.
|
|
23
|
+
const UNRESEARCHED = 'Not yet researched'
|
|
24
|
+
|
|
7
25
|
const ProjectSchema = z.object({
|
|
8
26
|
id,
|
|
9
27
|
name: nonEmptyString,
|
|
@@ -93,7 +111,21 @@ const UserSchema = z.object({
|
|
|
93
111
|
label: nonEmptyString,
|
|
94
112
|
description: nonEmptyString,
|
|
95
113
|
responsibilities: stringList,
|
|
96
|
-
accessNeeds: stringList
|
|
114
|
+
accessNeeds: stringList,
|
|
115
|
+
reference
|
|
116
|
+
}).passthrough()
|
|
117
|
+
|
|
118
|
+
// A user story derived from the need it belongs to. In the workbooks teams keep,
|
|
119
|
+
// stories are one per need, so a story is a facet of its need rather than a record
|
|
120
|
+
// type of its own: it renders wherever the need does, and needs no page,
|
|
121
|
+
// relationship type or validator of its own.
|
|
122
|
+
const NeedStorySchema = z.object({
|
|
123
|
+
reference,
|
|
124
|
+
text: nonEmptyString,
|
|
125
|
+
// The design question the story exists to answer. For a designer it is the most
|
|
126
|
+
// useful part, and the part most often lost when stories become tickets.
|
|
127
|
+
designQuestion: nonEmptyString.optional(),
|
|
128
|
+
acceptanceCriteria: z.array(nonEmptyString).optional()
|
|
97
129
|
}).passthrough()
|
|
98
130
|
|
|
99
131
|
const NeedSchema = z.object({
|
|
@@ -102,7 +134,8 @@ const NeedSchema = z.object({
|
|
|
102
134
|
statement: nonEmptyString,
|
|
103
135
|
priority: z.enum(['high', 'medium', 'low']),
|
|
104
136
|
evidenceIds: z.array(id).min(1),
|
|
105
|
-
reference
|
|
137
|
+
reference,
|
|
138
|
+
story: NeedStorySchema.optional()
|
|
106
139
|
}).passthrough()
|
|
107
140
|
|
|
108
141
|
const LocationSearchSchema = z.object({
|
|
@@ -127,7 +160,8 @@ const ScenarioSchema = z.object({
|
|
|
127
160
|
needIds: z.array(id).min(1),
|
|
128
161
|
happyPath: stringList,
|
|
129
162
|
edgeCases: stringList,
|
|
130
|
-
locationSearch: LocationSearchSchema.optional()
|
|
163
|
+
locationSearch: LocationSearchSchema.optional(),
|
|
164
|
+
reference
|
|
131
165
|
}).passthrough()
|
|
132
166
|
|
|
133
167
|
const PainPointSchema = z.object({
|
|
@@ -162,7 +196,8 @@ const JourneySchema = z.object({
|
|
|
162
196
|
scenarioId: id,
|
|
163
197
|
entryPoint: nonEmptyString,
|
|
164
198
|
exitPoint: nonEmptyString,
|
|
165
|
-
steps: z.array(JourneyStepSchema).min(1)
|
|
199
|
+
steps: z.array(JourneyStepSchema).min(1),
|
|
200
|
+
reference
|
|
166
201
|
}).passthrough()
|
|
167
202
|
|
|
168
203
|
const ScreenSchema = z.object({
|
|
@@ -176,7 +211,8 @@ const ScreenSchema = z.object({
|
|
|
176
211
|
// knowledge base models the service, not only the screens this repo happens
|
|
177
212
|
// to render, so the route smoke test skips these instead of failing on them.
|
|
178
213
|
external: z.boolean().optional(),
|
|
179
|
-
sourcePath: nonEmptyString.optional()
|
|
214
|
+
sourcePath: nonEmptyString.optional(),
|
|
215
|
+
reference
|
|
180
216
|
}).passthrough()
|
|
181
217
|
|
|
182
218
|
const EvidenceSchema = z.object({
|
|
@@ -186,7 +222,9 @@ const EvidenceSchema = z.object({
|
|
|
186
222
|
summary: nonEmptyString,
|
|
187
223
|
confidence: z.enum(['high', 'medium', 'low']),
|
|
188
224
|
sourcePath: nonEmptyString.optional(),
|
|
189
|
-
quotes: z.array(nonEmptyString).optional()
|
|
225
|
+
quotes: z.array(nonEmptyString).optional(),
|
|
226
|
+
reference,
|
|
227
|
+
impact
|
|
190
228
|
}).passthrough()
|
|
191
229
|
|
|
192
230
|
const DecisionSchema = z.object({
|
|
@@ -194,13 +232,15 @@ const DecisionSchema = z.object({
|
|
|
194
232
|
title: nonEmptyString,
|
|
195
233
|
status: z.enum(['proposed', 'accepted', 'superseded', 'rejected']),
|
|
196
234
|
decision: nonEmptyString,
|
|
197
|
-
consequence: nonEmptyString
|
|
235
|
+
consequence: nonEmptyString,
|
|
236
|
+
reference
|
|
198
237
|
}).passthrough()
|
|
199
238
|
|
|
200
239
|
const AssumptionSchema = z.object({
|
|
201
240
|
id,
|
|
202
241
|
statement: nonEmptyString,
|
|
203
|
-
risk: z.enum(['high', 'medium', 'low'])
|
|
242
|
+
risk: z.enum(['high', 'medium', 'low']),
|
|
243
|
+
reference
|
|
204
244
|
}).passthrough()
|
|
205
245
|
|
|
206
246
|
const ResearchRoundSchema = z.object({
|
|
@@ -209,7 +249,8 @@ const ResearchRoundSchema = z.object({
|
|
|
209
249
|
date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/, 'Use YYYY-MM-DD dates'),
|
|
210
250
|
sourceType: nonEmptyString,
|
|
211
251
|
sourcePath: nonEmptyString.optional(),
|
|
212
|
-
summary: nonEmptyString
|
|
252
|
+
summary: nonEmptyString,
|
|
253
|
+
reference
|
|
213
254
|
}).passthrough()
|
|
214
255
|
|
|
215
256
|
const ParticipantSchema = z.object({
|
|
@@ -217,7 +258,8 @@ const ParticipantSchema = z.object({
|
|
|
217
258
|
label: nonEmptyString,
|
|
218
259
|
role: nonEmptyString,
|
|
219
260
|
organisation: nonEmptyString.optional(),
|
|
220
|
-
roundIds: z.array(id).min(1)
|
|
261
|
+
roundIds: z.array(id).min(1),
|
|
262
|
+
reference
|
|
221
263
|
}).passthrough()
|
|
222
264
|
|
|
223
265
|
const InsightSchema = z.object({
|
|
@@ -227,7 +269,9 @@ const InsightSchema = z.object({
|
|
|
227
269
|
summary: nonEmptyString,
|
|
228
270
|
confidence: z.enum(['high', 'medium', 'low']),
|
|
229
271
|
participantIds: z.array(id),
|
|
230
|
-
evidenceIds: z.array(id)
|
|
272
|
+
evidenceIds: z.array(id),
|
|
273
|
+
reference,
|
|
274
|
+
impact
|
|
231
275
|
}).passthrough()
|
|
232
276
|
|
|
233
277
|
const DesignActionSchema = z.object({
|
|
@@ -236,7 +280,8 @@ const DesignActionSchema = z.object({
|
|
|
236
280
|
status: z.enum(['proposed', 'in-progress', 'done', 'parked']),
|
|
237
281
|
action: nonEmptyString,
|
|
238
282
|
rationale: nonEmptyString,
|
|
239
|
-
insightIds: z.array(id).min(1)
|
|
283
|
+
insightIds: z.array(id).min(1),
|
|
284
|
+
reference
|
|
240
285
|
}).passthrough()
|
|
241
286
|
|
|
242
287
|
const RelationshipSchema = z.object({
|
|
@@ -339,6 +384,7 @@ const recordSchemas = {
|
|
|
339
384
|
}
|
|
340
385
|
|
|
341
386
|
module.exports = {
|
|
387
|
+
UNRESEARCHED,
|
|
342
388
|
KnowledgeSchema,
|
|
343
389
|
ResearchImportDraftSchema,
|
|
344
390
|
ProjectContextImportDraftSchema,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hippo-digital/hippocampus",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "A design-knowledge base for NHS Prototype Kit projects: research, insights, needs, journeys and screens, traceable end to end.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "index.js",
|
|
@@ -103,6 +103,11 @@ function buildDraft (args, slides) {
|
|
|
103
103
|
const relationships = []
|
|
104
104
|
const seenParticipants = new Map()
|
|
105
105
|
const quotes = []
|
|
106
|
+
// An action has to respond to an insight - the schema says so - so one found
|
|
107
|
+
// before any insight cannot be kept as a record. It used to be kept anyway
|
|
108
|
+
// with no insight, which failed the whole file on schema validation: nothing
|
|
109
|
+
// imported, and sync marked the file failed and never tried it again.
|
|
110
|
+
const unlinkedActions = []
|
|
106
111
|
|
|
107
112
|
const addParticipant = (label, role) => {
|
|
108
113
|
const key = label.toLowerCase()
|
|
@@ -141,6 +146,10 @@ function buildDraft (args, slides) {
|
|
|
141
146
|
|
|
142
147
|
const addAction = (statement, sourceSection) => {
|
|
143
148
|
if (!isSubstantive(statement)) return null
|
|
149
|
+
if (!insights.length) {
|
|
150
|
+
unlinkedActions.push(statement)
|
|
151
|
+
return null
|
|
152
|
+
}
|
|
144
153
|
const item = {
|
|
145
154
|
id: kebab(`${args.artefactId} action ${designActions.length + 1}`),
|
|
146
155
|
title: truncate(statement, 120),
|
|
@@ -158,6 +167,13 @@ function buildDraft (args, slides) {
|
|
|
158
167
|
return item
|
|
159
168
|
}
|
|
160
169
|
|
|
170
|
+
// The participant codes a line cites, as the ids addParticipant gives them.
|
|
171
|
+
// This once built `<round> participant <code>`, left over from when
|
|
172
|
+
// participants were per round; nothing matched, the filter below dropped
|
|
173
|
+
// every link, and every insight imported with no participants while the fit
|
|
174
|
+
// said "good". Lines with an explicit "Insight:" prefix passed none at all.
|
|
175
|
+
const citedParticipants = (line) => (line.match(PARTICIPANT_TOKEN) || []).map((token) => kebab(`participant ${token}`))
|
|
176
|
+
|
|
161
177
|
for (const slide of slides) {
|
|
162
178
|
const mode = modeFor(slide.title)
|
|
163
179
|
|
|
@@ -179,14 +195,14 @@ function buildDraft (args, slides) {
|
|
|
179
195
|
}
|
|
180
196
|
|
|
181
197
|
const explicitInsight = parsePrefixedLine(line, ['Insight', 'Finding', 'Observation'])
|
|
182
|
-
if (explicitInsight) { addInsight(explicitInsight, slide.title,
|
|
198
|
+
if (explicitInsight) { addInsight(explicitInsight, slide.title, citedParticipants(line)); continue }
|
|
183
199
|
|
|
184
200
|
const explicitAction = parsePrefixedLine(line, ['Action', 'Design action', 'Recommendation'])
|
|
185
201
|
if (explicitAction) { addAction(explicitAction, slide.title); continue }
|
|
186
202
|
|
|
187
203
|
// Otherwise fall back to the heading's mode.
|
|
188
204
|
if (line === slide.title || isSpeakerNote(line)) continue
|
|
189
|
-
if (mode === 'insight') addInsight(line, slide.title, (line
|
|
205
|
+
if (mode === 'insight') addInsight(line, slide.title, citedParticipants(line))
|
|
190
206
|
else if (mode === 'action') addAction(line, slide.title)
|
|
191
207
|
else if (mode === 'participant' && /\b\d+\s+\w/.test(line)) addInsight(`Sample composition: ${line}`, slide.title, [])
|
|
192
208
|
}
|
|
@@ -202,9 +218,15 @@ function buildDraft (args, slides) {
|
|
|
202
218
|
sourceDeck: path.relative(ctx.root, path.resolve(args.deck)),
|
|
203
219
|
importedAt: new Date().toISOString(),
|
|
204
220
|
warnings: [
|
|
205
|
-
...assessFit({ participants, insights, designActions, slides, quotes }),
|
|
221
|
+
...assessFit({ participants, insights, designActions, slides, quotes, unlinkedActions }),
|
|
206
222
|
...(args.dateDerived === 'false'
|
|
207
223
|
? [`The round date ${args.date} is today's date, not the date of the research. No date was found in the file or folder name. Set it before promoting.`]
|
|
224
|
+
: []),
|
|
225
|
+
...(unlinkedActions.length === 1
|
|
226
|
+
? ['1 design action was found before any insight and left out, because an action has to respond to an insight. It is in the extracted text below; add it in review, linked to the insight it responds to.']
|
|
227
|
+
: []),
|
|
228
|
+
...(unlinkedActions.length > 1
|
|
229
|
+
? [`${unlinkedActions.length} design actions were found before any insight and left out, because an action has to respond to an insight. They are in the extracted text below; add them in review, each linked to the insight it responds to.`]
|
|
208
230
|
: [])
|
|
209
231
|
],
|
|
210
232
|
researchRounds: [
|
|
@@ -283,11 +305,11 @@ function validateDraft (draft) {
|
|
|
283
305
|
throw new Error(`Imported draft does not match ResearchImportDraftSchema:\n- ${issues.join('\n- ')}`)
|
|
284
306
|
}
|
|
285
307
|
|
|
286
|
-
function assessFit ({ participants, insights, designActions, slides, quotes }) {
|
|
308
|
+
function assessFit ({ participants, insights, designActions, slides, quotes, unlinkedActions = [] }) {
|
|
287
309
|
const warnings = []
|
|
288
310
|
if (!participants.length) warnings.push('No participants were detected. Use participant codes such as P12 in the artefact, or lines like "Participant: P1 - Policy administrator".')
|
|
289
311
|
if (!insights.length) warnings.push('No insights were detected. Put findings under a section titled "Insights", "Findings" or "What we learned", or prefix lines with "Insight:".')
|
|
290
|
-
if (!designActions.length) warnings.push('No design actions were detected. Put them under a section titled "Design actions" or "Recommendations", or prefix lines with "Action:".')
|
|
312
|
+
if (!designActions.length && !unlinkedActions.length) warnings.push('No design actions were detected. Put them under a section titled "Design actions" or "Recommendations", or prefix lines with "Action:".')
|
|
291
313
|
if (slides.length && insights.length / slides.length < 0.2) warnings.push('Low insight density for the number of sections. Check whether findings use unsupported headings.')
|
|
292
314
|
if (quotes && quotes.length && !quotes.some((quote) => quote.participants.length)) {
|
|
293
315
|
warnings.push(`${quotes.length} quotes were found but none carry a participant code. Attribute quotes as 'P12 - "quote"' so evidence can be traced to a person.`)
|
|
@@ -401,9 +423,12 @@ function appendSection (lines, title, items, renderItem) {
|
|
|
401
423
|
}
|
|
402
424
|
}
|
|
403
425
|
|
|
426
|
+
// A list marker in front of the prefix is still the prefix: notes are written
|
|
427
|
+
// as "- Insight: ...", and requiring the line to start with the word itself
|
|
428
|
+
// skipped every bulleted line in a Markdown or text note.
|
|
404
429
|
function parsePrefixedLine (line, prefixes) {
|
|
405
430
|
for (const prefix of prefixes) {
|
|
406
|
-
const match = line.match(new RegExp(
|
|
431
|
+
const match = line.match(new RegExp(`^(?:[-*\\u2022]\\s+|\\d+[.)]\\s+)?${escapeRegExp(prefix)}\\s*[:\\-]\\s*(.+)$`, 'i'))
|
|
407
432
|
if (match) return match[1].trim()
|
|
408
433
|
}
|
|
409
434
|
return null
|
package/scripts/known.js
CHANGED
|
@@ -69,14 +69,14 @@ function section (title, items, render, note) {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
console.log(`What the knowledge base holds on: ${result.terms.join(', ')}`)
|
|
72
|
-
console.log(`(${ctx.root}, ${result.coverage.rounds.length} research rounds)`)
|
|
72
|
+
console.log(`(${ctx.root}, ${result.coverage.rounds.length} research round${result.coverage.rounds.length === 1 ? '' : 's'})`)
|
|
73
73
|
|
|
74
74
|
if (result.nothingFound) {
|
|
75
75
|
console.log('\nNo record names this.')
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
section('Findings', result.findings, (f) => f.kind === 'insight'
|
|
79
|
-
? ` insight ${f.id} [${f.confidence}, ${f.participants} participants, ${roundLabel(f.round)}]\n ${clip(f.label)}`
|
|
79
|
+
? ` insight ${f.id} [${f.confidence}, ${f.participants} participant${f.participants === 1 ? '' : 's'}, ${roundLabel(f.round)}]\n ${clip(f.label)}`
|
|
80
80
|
: ` evidence ${f.id} [${f.confidence}, ${f.sourceType}]\n ${clip(f.label)}`,
|
|
81
81
|
'oldest round first; each is a separate claim')
|
|
82
82
|
|