@hippo-digital/hippocampus 2.4.0 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +128 -0
- package/README.md +19 -0
- package/assets/dist/hippocampus.css +1 -1
- package/assets/hippocampus.scss +34 -1
- package/bin/hippocampus.js +1 -1
- package/docs/add-project-context.md +225 -0
- 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/check-for-unintended-consequences.md +191 -0
- package/docs/colour-pairings.md +6 -0
- package/docs/components.md +7 -1
- package/docs/custom-agents-usage.md +6 -1
- package/docs/data-and-governance.md +188 -0
- 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 +9 -3
- package/docs/hippocampus-technical.md +7 -1
- package/docs/images/evidence-flow.svg +1 -0
- package/docs/import-a-research-round.md +233 -0
- package/docs/link-insights-to-needs.md +225 -0
- package/docs/prompt-architecture-guardrails.md +6 -1
- package/docs/repeatable-research-round-ingestion.md +9 -3
- package/docs/research-knowledge-graph.md +12 -4
- package/docs/research-source-file-conventions.md +7 -2
- package/docs/review-and-promote-a-draft.md +212 -0
- package/docs/source-model.md +7 -1
- package/docs/start-here.md +223 -0
- package/docs/turn-personas-into-users-and-needs.md +207 -0
- package/lib/create-router.js +26 -3
- package/lib/docs.js +288 -30
- package/lib/templates.js +1 -1
- package/package.json +1 -1
- package/scripts/consequences.js +7 -5
- package/scripts/import-project-context.js +17 -5
- package/scripts/import-research-deck.js +31 -6
- package/scripts/known.js +2 -2
- package/scripts/link-insights-to-needs.js +38 -13
- package/scripts/promote-project-context-draft.js +66 -15
- package/scripts/promote-research-draft.js +99 -12
- package/scripts/smoke-routes.js +8 -1
- package/scripts/sync-project-context.js +90 -12
- package/skills/ingest-project-context/SKILL.md +1 -1
- package/skills/skills.json +2 -2
- package/skills/structure-project-context-draft/SKILL.md +1 -1
- package/templates/project-context.xlsx +0 -0
- package/views/hippocampus/doc.html +15 -0
- package/views/hippocampus/docs.html +42 -13
- 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/templates.js
CHANGED
|
@@ -24,7 +24,7 @@ const DESCRIBED = {
|
|
|
24
24
|
'Purpose, vision, policy context, channels, constraints, risks, milestones ' +
|
|
25
25
|
'and source facts. One sheet per kind, one row per record.',
|
|
26
26
|
command: 'hippocampus import project-context <file>',
|
|
27
|
-
then: 'hippocampus promote project-context'
|
|
27
|
+
then: 'hippocampus promote project-context --draft <the draft it names>'
|
|
28
28
|
},
|
|
29
29
|
'service-blueprint.xlsx': {
|
|
30
30
|
title: 'Service blueprint',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hippo-digital/hippocampus",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.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",
|
package/scripts/consequences.js
CHANGED
|
@@ -54,6 +54,8 @@ if (flags.json) {
|
|
|
54
54
|
|
|
55
55
|
const LIMIT = flags.all ? Infinity : 25
|
|
56
56
|
const clip = (text, n = 108) => (text && text.length > n ? `${text.slice(0, n - 1)}…` : text || '')
|
|
57
|
+
// "1 roles" and "2 participant(s)" read as a draft nobody finished.
|
|
58
|
+
const count = (n, word) => `${n} ${word}${n === 1 ? '' : 's'}`
|
|
57
59
|
const roundLabel = (round) => (round ? `${round.title}, ${round.date}` : 'no research round')
|
|
58
60
|
let clipped = false
|
|
59
61
|
|
|
@@ -71,11 +73,11 @@ const { scenario, persona } = result
|
|
|
71
73
|
console.log('Checking a journey against the users we already know')
|
|
72
74
|
console.log(` ${scenario.title}`)
|
|
73
75
|
console.log(` ${scenario.id} · ${scenario.userLabel} (${scenario.userId})`)
|
|
74
|
-
console.log(` (${ctx.root}, ${result.researchRounds
|
|
76
|
+
console.log(` (${ctx.root}, ${count(result.researchRounds, 'research round')})`)
|
|
75
77
|
|
|
76
78
|
console.log('\nThis user in the research')
|
|
77
79
|
if (persona.participants.length) {
|
|
78
|
-
console.log(` ${persona.participants.length
|
|
80
|
+
console.log(` ${count(persona.participants.length, 'participant')} whose role matches "${persona.matchedOn.join('", "')}", in ${count(persona.rounds.length, 'round')}: ` +
|
|
79
81
|
persona.rounds.map((r) => `${r.title} (${r.date})`).join('; '))
|
|
80
82
|
} else {
|
|
81
83
|
console.log(` No participant's role matches "${persona.matchedOn.join('", "')}". No round has included this kind of user,`)
|
|
@@ -95,7 +97,7 @@ section('What this journey stands on', standsOn, (g) => g.kind === 'insight'
|
|
|
95
97
|
|
|
96
98
|
const needCount = result.reaches.reduce((n, u) => n + u.needs.length, 0)
|
|
97
99
|
if (result.reaches.length) {
|
|
98
|
-
console.log(`\nUsers we already know who stand on the same ground (${result.reaches.length}
|
|
100
|
+
console.log(`\nUsers we already know who stand on the same ground (${count(result.reaches.length, 'role')}, ${count(needCount, 'need')})`)
|
|
99
101
|
for (const user of result.reaches) {
|
|
100
102
|
console.log(` ${user.label} (${user.userId})`)
|
|
101
103
|
for (const need of user.needs.slice(0, LIMIT)) {
|
|
@@ -134,9 +136,9 @@ console.log('\nQuestions every new kind of user raises')
|
|
|
134
136
|
for (const c of result.concerns) {
|
|
135
137
|
console.log(` ${c.id.padEnd(12)} ${c.question}`)
|
|
136
138
|
if (c.nobodyAsked) {
|
|
137
|
-
console.log(` Nobody has asked. No record in ${result.researchRounds}
|
|
139
|
+
console.log(` Nobody has asked. No record in ${count(result.researchRounds, 'round')} names it. That is the finding.`)
|
|
138
140
|
} else {
|
|
139
|
-
if (c.findings) console.log(` ${c.findings
|
|
141
|
+
if (c.findings) console.log(` ${count(c.findings, 'finding')}, in ${count(c.roundsWithFindings, 'round')}`)
|
|
140
142
|
for (const n of c.namedBy.slice(0, 6)) console.log(` named by ${n.id}${n.status ? ` [${n.status}]` : ''}`)
|
|
141
143
|
if (c.namedBy.length > 6) console.log(` ... and ${c.namedBy.length - 6} more`)
|
|
142
144
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const fs = require('fs')
|
|
2
2
|
const path = require('path')
|
|
3
3
|
const AdmZip = require('adm-zip')
|
|
4
|
-
const { PDFParse } = require('pdf-parse')
|
|
5
4
|
const { XMLParser } = require('fast-xml-parser')
|
|
6
5
|
const { ProjectContextImportDraftSchema } = require('../lib/schema')
|
|
7
6
|
const { createContextOrExit } = require('../lib/context')
|
|
@@ -18,8 +17,10 @@ function ctx () {
|
|
|
18
17
|
async function main () {
|
|
19
18
|
const args = parseArgs(process.argv.slice(2))
|
|
20
19
|
if (!args.document || !args.contextId || !args.title) {
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
// `hippocampus import project-context` runs sync-project-context.js, which
|
|
21
|
+
// calls this with all three. Reaching here means it was run by hand.
|
|
22
|
+
throw new Error('Usage: npx hippocampus import project-context path/to/file.xlsx\n' +
|
|
23
|
+
'A filled-in copy of templates/project-context.xlsx needs no guessing; a .pptx or .pdf works too.')
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
// A spreadsheet is a different kind of input from a deck or a PDF. Those are
|
|
@@ -45,8 +46,8 @@ async function main () {
|
|
|
45
46
|
? `Read ${sections.length} tabs`
|
|
46
47
|
: `Imported ${sections.length} ${sectionLabel(args.document).toLowerCase()}`)
|
|
47
48
|
reportFit(draft)
|
|
48
|
-
console.log(`Draft written to ${outputPath}`)
|
|
49
|
-
console.log(`Review written to ${reviewPath}`)
|
|
49
|
+
console.log(`Draft written to ${shown(outputPath)}`)
|
|
50
|
+
console.log(`Review written to ${shown(reviewPath)}`)
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
function parseArgs (args) {
|
|
@@ -98,6 +99,10 @@ function extractPowerPointSlides (deckPath) {
|
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
async function extractPdfPages (pdfPath) {
|
|
102
|
+
// Loaded here, not at the top: the PDF parser is the one dependency that has
|
|
103
|
+
// refused to load on some Node versions, and a spreadsheet or a deck should
|
|
104
|
+
// not fail to import because of a parser it never uses.
|
|
105
|
+
const { PDFParse } = require('pdf-parse')
|
|
101
106
|
const parser = new PDFParse({ data: fs.readFileSync(pdfPath) })
|
|
102
107
|
|
|
103
108
|
try {
|
|
@@ -488,6 +493,13 @@ function kebab (value) {
|
|
|
488
493
|
.replace(/^-+|-+$/g, '')
|
|
489
494
|
}
|
|
490
495
|
|
|
496
|
+
// Paths as the person would type them from the project root, not the
|
|
497
|
+
// absolute path of wherever the project happens to live.
|
|
498
|
+
function shown (file) {
|
|
499
|
+
const relative = path.relative(ctx().root, file)
|
|
500
|
+
return relative && !relative.startsWith('..') ? relative : file
|
|
501
|
+
}
|
|
502
|
+
|
|
491
503
|
function camelCase (value) {
|
|
492
504
|
return value.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase())
|
|
493
505
|
}
|
|
@@ -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
|
|