@hippo-digital/hippocampus 1.0.0-rc.8 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/CHANGELOG.md +141 -3
  2. package/README.md +36 -0
  3. package/agents/README.md +6 -6
  4. package/agents/accessibility-tester.md +2 -2
  5. package/agents/ingestion-curator.md +9 -9
  6. package/agents/knowledge-builder.md +9 -9
  7. package/agents/prototype-builder.md +3 -3
  8. package/agents/screenshot-runner.md +2 -2
  9. package/agents/workflow-orchestrator.md +16 -16
  10. package/assets/dist/hippocampus.css +1 -1
  11. package/assets/hippocampus.scss +994 -133
  12. package/assets/javascript/blueprint.js +21 -0
  13. package/assets/javascript/trace.js +54 -0
  14. package/bin/hippocampus.js +9 -3
  15. package/docs/agent-roadmap.md +2 -2
  16. package/docs/custom-agents-usage.md +1 -1
  17. package/docs/repeatable-research-round-ingestion.md +3 -3
  18. package/docs/research-knowledge-graph.md +5 -5
  19. package/index.js +2 -1
  20. package/lib/breadcrumb.js +80 -0
  21. package/lib/create-router.js +246 -6
  22. package/lib/discover-projects.js +5 -0
  23. package/lib/filter.js +81 -0
  24. package/lib/flow-map.js +214 -0
  25. package/lib/lint-knowledge.js +31 -0
  26. package/lib/load-knowledge.js +335 -34
  27. package/lib/record-links.js +51 -0
  28. package/lib/templates.js +174 -0
  29. package/package.json +1 -1
  30. package/scripts/doctor.js +10 -0
  31. package/scripts/install-skills.js +93 -3
  32. package/scripts/lib/make-blueprint-template.py +107 -0
  33. package/scripts/smoke-routes.js +19 -0
  34. package/scripts/validate-skills.js +64 -5
  35. package/skills/README.md +18 -18
  36. package/skills/SKILL-FORMAT.md +24 -5
  37. package/skills/{add-prototype-screen.skill.md → add-prototype-screen/SKILL.md} +2 -0
  38. package/skills/{add-scenario.skill.md → add-scenario/SKILL.md} +2 -0
  39. package/skills/{add-user-needs.skill.md → add-user-needs/SKILL.md} +2 -0
  40. package/skills/{audit-knowledge-source.skill.md → audit-knowledge-source/SKILL.md} +2 -0
  41. package/skills/{capture-route-review-pack.skill.md → capture-route-review-pack/SKILL.md} +2 -0
  42. package/skills/{create-journey-from-scenario.skill.md → create-journey-from-scenario/SKILL.md} +2 -0
  43. package/skills/{deliver-service-slice.skill.md → deliver-service-slice/SKILL.md} +2 -0
  44. package/skills/examples/README.md +1 -1
  45. package/skills/examples/non-copilot-research-ingestion.md +1 -1
  46. package/skills/examples/non-copilot-service-slice.md +1 -1
  47. package/skills/{generate-service-slice.skill.md → generate-service-slice/SKILL.md} +2 -0
  48. package/skills/{ingest-project-context.skill.md → ingest-project-context/SKILL.md} +2 -0
  49. package/skills/{ingest-research-round.skill.md → ingest-research-round/SKILL.md} +2 -0
  50. package/skills/{ingest-user-personas.skill.md → ingest-user-personas/SKILL.md} +2 -0
  51. package/skills/{map-research-to-graph.skill.md → map-research-to-graph/SKILL.md} +2 -0
  52. package/skills/{onboard-team-member.skill.md → onboard-team-member/SKILL.md} +2 -0
  53. package/skills/{record-accessibility-review.skill.md → record-accessibility-review/SKILL.md} +2 -0
  54. package/skills/{record-design-decision.skill.md → record-design-decision/SKILL.md} +2 -0
  55. package/skills/{review-research-import-draft.skill.md → review-research-import-draft/SKILL.md} +2 -0
  56. package/skills/skills.json +21 -21
  57. package/skills/skills.schema.json +1 -1
  58. package/skills/{structure-project-context-draft.skill.md → structure-project-context-draft/SKILL.md} +2 -0
  59. package/skills/{structure-research-draft.skill.md → structure-research-draft/SKILL.md} +2 -0
  60. package/skills/{triage-research-corpus.skill.md → triage-research-corpus/SKILL.md} +2 -0
  61. package/skills/{write-delivery-summary.skill.md → write-delivery-summary/SKILL.md} +2 -0
  62. package/skills/{write-route-review-summary.skill.md → write-route-review-summary/SKILL.md} +2 -0
  63. package/templates/service-blueprint.xlsx +0 -0
  64. package/views/hippocampus/_layout.html +116 -3
  65. package/views/hippocampus/blueprint-classic.html +0 -1
  66. package/views/hippocampus/blueprint.html +0 -1
  67. package/views/hippocampus/components/_blueprint-cell.njk +6 -3
  68. package/views/hippocampus/components/_blueprint-controls.njk +2 -1
  69. package/views/hippocampus/components/_breadcrumb.njk +29 -0
  70. package/views/hippocampus/components/_connections.njk +38 -0
  71. package/views/hippocampus/components/_filters.njk +56 -0
  72. package/views/hippocampus/components/_journey-step.njk +11 -7
  73. package/views/hippocampus/components/_screen-preview.njk +41 -0
  74. package/views/hippocampus/doc.html +0 -1
  75. package/views/hippocampus/docs.html +67 -6
  76. package/views/hippocampus/evidence-impact.html +66 -33
  77. package/views/hippocampus/graph.html +137 -31
  78. package/views/hippocampus/handover-empty.html +0 -1
  79. package/views/hippocampus/handover.html +0 -1
  80. package/views/hippocampus/index.html +102 -13
  81. package/views/hippocampus/journey-flow.html +0 -1
  82. package/views/hippocampus/journey.html +21 -6
  83. package/views/hippocampus/journeys.html +63 -0
  84. package/views/hippocampus/project.html +19 -2
  85. package/views/hippocampus/record.html +33 -0
  86. package/views/hippocampus/research.html +14 -2
  87. package/views/hippocampus/route-review.html +0 -1
  88. package/views/hippocampus/scenarios.html +21 -3
  89. package/views/hippocampus/screens.html +45 -0
  90. package/views/hippocampus/trace.html +35 -22
  91. package/views/hippocampus/user-needs.html +55 -19
  92. package/views/hippocampus/user.html +131 -79
  93. package/views/hippocampus/users.html +33 -19
package/lib/filter.js ADDED
@@ -0,0 +1,81 @@
1
+ // Finding a record in the explorer.
2
+ //
3
+ // 132 needs and 108 insights, and until now not one input field in the whole
4
+ // viewer - the only way to a record was to scroll past the others. This is the
5
+ // filtering behind that, kept server-side and driven by query parameters so it
6
+ // works without JavaScript, survives a refresh, and gives a filtered view a URL
7
+ // somebody can paste to a colleague.
8
+
9
+ /**
10
+ * Case-insensitive match across the named fields. A multi-word query matches
11
+ * when every word appears somewhere in the record: people type two or three
12
+ * remembered words in the order they happen to recall them, not a phrase.
13
+ */
14
+ function matchesText (item, query, fields) {
15
+ if (!query) return true
16
+ const haystack = fields
17
+ .map((field) => item[field])
18
+ .flatMap((value) => Array.isArray(value) ? value : [value])
19
+ .filter((value) => typeof value === 'string')
20
+ .join(' ')
21
+ .toLowerCase()
22
+ return query.toLowerCase().split(/\s+/).filter(Boolean)
23
+ .every((word) => haystack.includes(word))
24
+ }
25
+
26
+ /**
27
+ * The options for one facet, each carrying how many records it would leave.
28
+ *
29
+ * Counted against the records matching every OTHER active filter, not against
30
+ * the whole collection - so the numbers say what will happen if you click,
31
+ * and an option that would strand you on an empty page is marked rather than
32
+ * silently offered.
33
+ */
34
+ function facet ({ items, key, label, selected, labelFor = (value) => value }) {
35
+ const counts = new Map()
36
+ for (const item of items) {
37
+ const values = Array.isArray(item[key]) ? item[key] : [item[key]]
38
+ for (const value of values) {
39
+ if (value === undefined || value === null || value === '') continue
40
+ counts.set(value, (counts.get(value) || 0) + 1)
41
+ }
42
+ }
43
+ const options = [...counts.entries()]
44
+ .map(([value, count]) => ({ value, count, label: labelFor(value), selected: value === selected }))
45
+ .sort((a, b) => b.count - a.count || String(a.label).localeCompare(String(b.label)))
46
+ return { key, label, selected: selected || '', options }
47
+ }
48
+
49
+ function matchesFacet (item, key, selected) {
50
+ if (!selected) return true
51
+ const values = Array.isArray(item[key]) ? item[key] : [item[key]]
52
+ return values.some((value) => String(value) === String(selected))
53
+ }
54
+
55
+ /**
56
+ * The query string for this page minus one parameter - what a "clear this
57
+ * filter" link needs. Built here rather than in a template because getting it
58
+ * subtly wrong strands somebody on a filtered page with no way back.
59
+ */
60
+ function queryWithout (query, dropKey) {
61
+ const params = new URLSearchParams()
62
+ for (const [key, value] of Object.entries(query || {})) {
63
+ if (key === dropKey || !value) continue
64
+ params.set(key, value)
65
+ }
66
+ const text = params.toString()
67
+ return text ? `?${text}` : ''
68
+ }
69
+
70
+ function activeFilters (query, labels = {}) {
71
+ return Object.entries(query || {})
72
+ .filter(([, value]) => value)
73
+ .map(([key, value]) => ({
74
+ key,
75
+ value,
76
+ label: labels[key] || key,
77
+ display: (labels.display && labels.display[key] && labels.display[key](value)) || value
78
+ }))
79
+ }
80
+
81
+ module.exports = { matchesText, facet, matchesFacet, queryWithout, activeFilters }
@@ -0,0 +1,214 @@
1
+ // The knowledge base's shape, at the level of record types.
2
+ //
3
+ // /graph used to draw all 438 entities as chips and all 1,031 relationships as
4
+ // `A - label - B` rows. Every fact was on the page and none of them were
5
+ // legible, and a force-directed layout of 438 nodes at median degree 2 would
6
+ // have been a hairball - impressive, and no more readable.
7
+ //
8
+ // There are only twelve record types and nineteen ways they connect. That fits
9
+ // on a screen, and it is the thing a newcomer, a stakeholder or an auditor is
10
+ // actually asking about: how does research become a screen, and where does the
11
+ // chain break.
12
+
13
+ // Which column a type sits in, left to right, as the work flows.
14
+ //
15
+ // Declared rather than computed. A longest-path layering of the real edges puts
16
+ // Design action BEFORE Insight, because the stored edge is `design action
17
+ // responds-to-insight`, pointing from the action to the insight it answers. The
18
+ // arrow is right and the reading is backwards: the insight came first. Narrative
19
+ // order is a judgement about the work, so it is written down here.
20
+ // The order is also chosen to keep flows short. Evidence and User started in
21
+ // the first column, which put the two heaviest connections in the corpus -
22
+ // evidence supporting 112 needs, users having 110 - across three columns, and
23
+ // six long flows diving under the diagram made a tangle nobody could trace a
24
+ // line through. Moved next to what they feed, three remain.
25
+ const COLUMNS = [
26
+ { key: 'research', title: 'Research', types: ['Research round'] },
27
+ { key: 'gathered', title: 'Who, and what they said', types: ['Participant', 'Evidence'] },
28
+ { key: 'learned', title: 'What we learned', types: ['Insight', 'User', 'Scenario'] },
29
+ { key: 'needed', title: 'What people need', types: ['Need'] },
30
+ { key: 'built', title: 'What we design', types: ['Screen', 'Journey', 'Design action', 'Decision', 'Assumption'] }
31
+ ]
32
+
33
+ // Relationship types whose stored direction is the opposite of how the work
34
+ // reads. `need supported-by evidence` is correct as a fact and backwards as a
35
+ // story: the evidence came first and the need rests on it. Flipping these is
36
+ // what lets every flow run left to right.
37
+ const READS_BACKWARDS = new Set([
38
+ 'supported-by', 'addresses-need', 'responds-to-insight', 'resolves-action',
39
+ 'uses-evidence', 'renders-screen', 'records-decision'
40
+ ])
41
+
42
+ // How each connection reads once it is pointing the right way.
43
+ const PHRASES = {
44
+ 'has-participant': 'included',
45
+ 'produced-insight': 'produced',
46
+ 'contributed-to': 'contributed to',
47
+ 'tests-need': 'tests',
48
+ 'supported-by': 'supports',
49
+ 'has-need': 'has',
50
+ 'has-scenario': 'has',
51
+ 'addresses-need': 'is addressed by',
52
+ 'responds-to-insight': 'is answered by',
53
+ 'resolves-action': 'is resolved by',
54
+ 'drives-journey': 'drives',
55
+ 'uses-evidence': 'is used by',
56
+ 'renders-screen': 'is rendered by',
57
+ 'records-decision': 'is recorded by'
58
+ }
59
+
60
+ const BOX_WIDTH = 168
61
+ const BOX_HEIGHT = 52
62
+ const BOX_GAP = 16
63
+ const COLUMN_GAP = 108
64
+ const TOP = 28
65
+ const MAX_STROKE = 18
66
+ const MIN_STROKE = 1.5
67
+ // Room under the boxes for flows that cross more than one column.
68
+ const LONG_FLOW_LANE = 86
69
+
70
+ /**
71
+ * @param nodes entities that appear in at least one relationship
72
+ * @param relationships enriched relationships (fromType / toType present)
73
+ * @returns { width, height, columns, boxes, flows, totals } - geometry ready to
74
+ * render, so the template places nothing itself
75
+ */
76
+ function buildFlowMap ({ nodes, relationships, counts }) {
77
+ const present = new Set(nodes.map((node) => node.type))
78
+
79
+ // Counts come from the whole knowledge base, not from the graph: a type with
80
+ // twelve records and one relationship should read as twelve, or the page
81
+ // quietly under-reports what is there.
82
+ const columns = COLUMNS
83
+ .map((column) => ({ ...column, types: column.types.filter((type) => present.has(type) || counts[type]) }))
84
+ .filter((column) => column.types.length)
85
+
86
+ const boxes = new Map()
87
+ columns.forEach((column, columnIndex) => {
88
+ const x = columnIndex * (BOX_WIDTH + COLUMN_GAP)
89
+ column.types.forEach((type, rowIndex) => {
90
+ boxes.set(type, {
91
+ type,
92
+ count: counts[type] || 0,
93
+ x,
94
+ y: TOP + rowIndex * (BOX_HEIGHT + BOX_GAP),
95
+ column: columnIndex
96
+ })
97
+ })
98
+ })
99
+
100
+ // One flow per (from type, relationship type, to type), oriented to read
101
+ // forwards and sized by how many records take it.
102
+ const tally = new Map()
103
+ for (const rel of relationships) {
104
+ const flip = READS_BACKWARDS.has(rel.type)
105
+ const from = flip ? rel.toType : rel.fromType
106
+ const to = flip ? rel.fromType : rel.toType
107
+ if (!boxes.has(from) || !boxes.has(to)) continue
108
+ const key = `${from}|${rel.type}|${to}`
109
+ const existing = tally.get(key)
110
+ if (existing) existing.count += 1
111
+ else tally.set(key, { from, to, type: rel.type, phrase: PHRASES[rel.type] || rel.type, count: 1 })
112
+ }
113
+
114
+ const flows = [...tally.values()].sort((a, b) => b.count - a.count)
115
+ const biggest = flows.length ? flows[0].count : 1
116
+
117
+ for (const flow of flows) {
118
+ const from = boxes.get(flow.from)
119
+ const to = boxes.get(flow.to)
120
+ // Square-rooted, because stroke width is read as an area rather than a
121
+ // length: linear scaling makes a 202 next to a 1 into a slab beside a
122
+ // hairline and nothing between them is distinguishable.
123
+ flow.width = MIN_STROKE + (MAX_STROKE - MIN_STROKE) * Math.sqrt(flow.count / biggest)
124
+ flow.sameColumn = from.column === to.column
125
+ flow.span = to.column - from.column
126
+ }
127
+
128
+ // Where each flow meets its boxes. Every line left and arrived at the middle
129
+ // of an edge, so six flows met at one point and a box looked like a junction
130
+ // rather than a stage. They fan along the edge instead, ordered by where the
131
+ // other end sits, which is also what stops them crossing each other on the
132
+ // way out.
133
+ const stackHeight = Math.max(...columns.map((c) => c.types.length)) * (BOX_HEIGHT + BOX_GAP)
134
+ const centreOf = (box) => box.y + BOX_HEIGHT / 2
135
+ for (const box of boxes.values()) {
136
+ const out = flows.filter((f) => f.from === box.type)
137
+ const into = flows.filter((f) => f.to === box.type)
138
+ fan(out, box, 'startY', (f) => centreOf(boxes.get(f.to)))
139
+ fan(into, box, 'endY', (f) => centreOf(boxes.get(f.from)))
140
+ }
141
+
142
+ // The further a flow travels, the deeper its lane, so they nest inside one
143
+ // another instead of crossing on the way down.
144
+ const long = flows
145
+ .filter((flow) => Math.abs(flow.span) > 1)
146
+ .sort((a, b) => Math.abs(a.span) - Math.abs(b.span) || b.count - a.count)
147
+ long.forEach((flow, index) => {
148
+ flow.laneDepth = long.length === 1 ? 0.5 : 0.28 + (0.62 * index) / (long.length - 1)
149
+ })
150
+
151
+ for (const flow of flows) {
152
+ flow.path = pathBetween(boxes.get(flow.from), boxes.get(flow.to), flow, stackHeight)
153
+ }
154
+
155
+ const height = TOP * 2 + stackHeight + LONG_FLOW_LANE
156
+ return {
157
+ width: columns.length * BOX_WIDTH + (columns.length - 1) * COLUMN_GAP,
158
+ height,
159
+ columns: columns.map((column, index) => ({
160
+ ...column,
161
+ x: index * (BOX_WIDTH + COLUMN_GAP)
162
+ })),
163
+ boxes: [...boxes.values()],
164
+ flows,
165
+ boxWidth: BOX_WIDTH,
166
+ boxHeight: BOX_HEIGHT
167
+ }
168
+ }
169
+
170
+ // Spread a box's flows along one edge rather than stacking them at its centre.
171
+ function fan (group, box, key, otherEnd) {
172
+ if (!group.length) return
173
+ const sorted = [...group].sort((a, b) => otherEnd(a) - otherEnd(b))
174
+ const usable = BOX_HEIGHT - 16
175
+ const step = sorted.length > 1 ? usable / (sorted.length - 1) : 0
176
+ sorted.forEach((flow, index) => {
177
+ flow[key] = box.y + 8 + (sorted.length > 1 ? index * step : usable / 2)
178
+ })
179
+ }
180
+
181
+ function pathBetween (from, to, flow, stackHeight) {
182
+ const y1 = flow.startY
183
+ const y2 = flow.endY
184
+
185
+ // A flow inside one column - a scenario to a participant - has no horizontal
186
+ // room, so it bows out to the right of the column rather than cutting through
187
+ // the boxes between its ends.
188
+ if (from.column === to.column) {
189
+ const x = from.x + BOX_WIDTH
190
+ const bulge = x + 44
191
+ return `M ${x} ${y1} C ${bulge} ${y1}, ${bulge} ${y2}, ${x} ${y2}`
192
+ }
193
+
194
+ const x1 = from.x + BOX_WIDTH
195
+ const x2 = to.x
196
+
197
+ // A flow crossing more than one column would otherwise run behind the boxes
198
+ // in between, and a line disappearing into one side of a box and out of the
199
+ // other reads as passing THROUGH it - which is a different claim about the
200
+ // data. Those drop into a lane under the diagram instead, each at its own
201
+ // depth so that two long flows crossing the same ground stay separable.
202
+ if (Math.abs(to.column - from.column) > 1) {
203
+ const lane = TOP + stackHeight + LONG_FLOW_LANE * flow.laneDepth
204
+ const reach = Math.abs(x2 - x1) * 0.28
205
+ const out = x1 + (x2 > x1 ? reach : -reach)
206
+ const back = x2 + (x2 > x1 ? -reach : reach)
207
+ return `M ${x1} ${y1} C ${out} ${lane}, ${back} ${lane}, ${x2} ${y2}`
208
+ }
209
+
210
+ const control = (x2 - x1) / 2
211
+ return `M ${x1} ${y1} C ${x1 + control} ${y1}, ${x2 - control} ${y2}, ${x2} ${y2}`
212
+ }
213
+
214
+ module.exports = { buildFlowMap, COLUMNS, READS_BACKWARDS, PHRASES }
@@ -1,5 +1,7 @@
1
1
  const { recordSchemas } = require('./schema')
2
2
 
3
+ const LIST_GLYPH = /^[\s\u00a0]*[\u2022\u25cf\u25aa\u25e6\u2043\u2219\u00b7\u25cb]/
4
+
3
5
  // Parsing answers "is this loadable?". Linting answers the question a team
4
6
  // actually has: "what is thin, and what is missing?" Keeping them apart is what
5
7
  // lets a freshly initialised project boot with nothing in it while still being
@@ -53,6 +55,35 @@ function lintKnowledge (knowledge) {
53
55
  }
54
56
  }
55
57
 
58
+ // A bullet glyph left at the front of a value.
59
+ //
60
+ // Personas are written in Word, and where somebody typed "• " rather than
61
+ // using a list style, the character is part of the text and imports as part
62
+ // of the text. It then renders as a bullet inside a bulleted list, or as a
63
+ // stray dot at the head of a need statement, on every page that shows that
64
+ // record - which is where it gets noticed, months later.
65
+ //
66
+ // Only the unambiguous glyphs. A leading "-" or "1." is a marker often
67
+ // enough to be worth a human's eye and legitimate content often enough
68
+ // ("- 5 degrees", "15. Additional insights") that flagging it would cost
69
+ // more attention than it saves.
70
+ for (const [collection] of Object.entries(recordSchemas)) {
71
+ for (const record of knowledge[collection] || []) {
72
+ for (const [key, value] of Object.entries(record)) {
73
+ for (const text of (Array.isArray(value) ? value : [value])) {
74
+ if (typeof text !== 'string' || !LIST_GLYPH.test(text)) continue
75
+ warnings.push({
76
+ rule: 'list-marker-in-value',
77
+ collection,
78
+ id: record.id,
79
+ message: `${collection} ${record.id}: "${key}" starts with a list marker - ` +
80
+ `"${text.slice(0, 40).trim()}…". A bullet belongs to the page, not to the record.`
81
+ })
82
+ }
83
+ }
84
+ }
85
+ }
86
+
56
87
  const legacyActionLinks = (knowledge.relationships || []).filter((r) => r.type === 'leads-to-action')
57
88
  if (legacyActionLinks.length) {
58
89
  warnings.push({