@hippo-digital/hippocampus 1.0.0-rc.5 → 1.0.0-rc.6

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 CHANGED
@@ -62,6 +62,37 @@ three things the release gate's hand-written stand-in could not.
62
62
  The viewer's landing page no longer captions itself "Prototype Kit add-on
63
63
  spike", which was a development-era label every install would have seen.
64
64
 
65
+ ### The blueprint importer
66
+
67
+ Run against a real service blueprint it produced **88 unmapped rows and one
68
+ mapped**. Four faults, all silent:
69
+
70
+ - **It did not speak the schema's vocabulary.** A blueprint authored against the
71
+ data model uses `Frontstage`, `Backstage`, `Support processes`,
72
+ `Data dependencies`, `Security and governance`, `Exception handling` and
73
+ `Future state`. The triage table matched `Back office`, `Data`, `Processes`,
74
+ `Exception journeys` and `Future steps` - a different dialect. Both are now
75
+ covered, along with `Screen` and `User action`.
76
+ - **Two lanes were unreachable at any label.** `frontstage` and
77
+ `securityAndGovernance` appeared nowhere as a destination, so no spelling
78
+ could have imported them.
79
+ - **Step names came from the wrong row, and the first two lanes were dropped.**
80
+ The header was guessed as whichever of the first six rows had the most
81
+ populated cells, read the names from the row *after* it, and started lanes two
82
+ rows further down. Steps were named after the contents of the User action row,
83
+ and `Screen` and `User action` never appeared at all. The header is now the row
84
+ above the first labelled row, which is structural rather than a guess.
85
+ - **Ordinary tables were forced into blueprint shape.** An Evidence tab became 74
86
+ lanes named after repeated step names. A blueprint's step-header row has an
87
+ empty column 0 and its lane labels are distinct; a table has neither. A sheet
88
+ failing either test is read flat, which keeps every cell for review.
89
+
90
+ The same file now maps every lane, names its steps correctly and classifies all
91
+ four sheets, with nothing unmapped.
92
+
93
+ The grid logic is exported and covered by unit tests - `npm run test:unit`, also
94
+ run by the release gate. They are the package's first.
95
+
65
96
  ### Validation
66
97
 
67
98
  - Three tiers: errors are broken references, warnings are gaps worth filling,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hippo-digital/hippocampus",
3
- "version": "1.0.0-rc.5",
3
+ "version": "1.0.0-rc.6",
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",
@@ -14,6 +14,7 @@
14
14
  "views",
15
15
  "assets",
16
16
  "scripts",
17
+ "!scripts/__tests__",
17
18
  "skills",
18
19
  "agents",
19
20
  "instructions",
@@ -2,7 +2,6 @@ const fs = require('fs')
2
2
  const path = require('path')
3
3
  const { openWorkbook, readSheetGrid } = require('./lib/xlsx-grid')
4
4
  const { createContextOrExit } = require('../lib/context')
5
- const ctx = createContextOrExit()
6
5
 
7
6
  // Generic triage mapping from common service-blueprint swimlane vocabulary to
8
7
  // where it belongs in Hippocampus's knowledge model (see
@@ -10,6 +9,19 @@ const ctx = createContextOrExit()
10
9
  // "unmapped" and is flagged for a manual decision - this list intentionally
11
10
  // holds only generic blueprint/service-design terms, not any one project's
12
11
  // specific persona or team names, so the same rules apply to any spreadsheet.
12
+ // Generic triage mapping from service-blueprint swimlane vocabulary to where it
13
+ // belongs in Hippocampus's knowledge model (see docs/source-model.md). Anything
14
+ // that doesn't match falls through as "unmapped" and is flagged for a manual
15
+ // decision. This list intentionally holds only generic blueprint/service-design
16
+ // terms, not any one project's persona or team names.
17
+ //
18
+ // It covers BOTH dialects, because the first version covered only one and not
19
+ // the important one. Every JourneyStep field name is a lane label somebody will
20
+ // write - a blueprint authored against the schema used `Frontstage`,
21
+ // `Backstage`, `Support processes`, `Data dependencies`,
22
+ // `Security and governance`, `Exception handling` and `Future state`, and the
23
+ // table matched none of them. `frontstage` and `securityAndGovernance` had no
24
+ // destination at all, so those lanes were unreachable under any label.
13
25
  const SWIMLANE_TRIAGE = [
14
26
  // Open questions and WIP markers are checked first so they take priority
15
27
  // over the more generic keyword matches below (e.g. "Do we need a row for
@@ -17,18 +29,21 @@ const SWIMLANE_TRIAGE = [
17
29
  { match: /^do we need/i, destination: 'assumption', note: 'An open question row, not step content.' },
18
30
  { match: /unhappy path/i, destination: 'assumption', note: 'Likely deserves its own scenario/journey once detailed, rather than a lane on this one.' },
19
31
 
20
- { match: /^user groups$/i, destination: 'users', note: 'One User record per distinct persona named in this row.' },
21
- { match: /^(external )?user steps/i, destination: 'journeyStep.userAction', note: 'What the user actually does at this step.' },
22
- { match: /exception journeys/i, destination: 'journeyStep.exceptionHandling', note: '' },
23
- { match: /^back ?office/i, destination: 'journeyStep.backstage', note: '' },
24
- { match: /future steps?$/i, destination: 'journeyStep.futureState', note: 'Proposed/target-state, not current fact.' },
32
+ { match: /^user groups?$/i, destination: 'users', note: 'One User record per distinct persona named in this row.' },
33
+ { match: /^screens?$/i, destination: 'journeyStep.screenIds', note: 'Match each route to an existing Screen record, or add one.' },
34
+ { match: /^((external )?user steps|user actions?|what the user does)/i, destination: 'journeyStep.userAction', note: 'What the user actually does at this step.' },
35
+ { match: /^front ?stage|^front.of.house/i, destination: 'journeyStep.frontstage', note: 'What the user can see at this step.' },
36
+ { match: /^back ?stage|^back ?office/i, destination: 'journeyStep.backstage', note: '' },
37
+ { match: /^(support )?processes/i, destination: 'journeyStep.supportProcesses', note: '' },
38
+ { match: /^data( dependenc(y|ies))?$/i, destination: 'journeyStep.dataDependencies', note: '' },
39
+ { match: /^(security|governance|security and governance|information governance)/i, destination: 'journeyStep.securityAndGovernance', note: '' },
25
40
  { match: /^pain points/i, destination: 'journeyStep.painPoints', note: '' },
26
- { match: /^data$/i, destination: 'journeyStep.dataDependencies', note: '' },
27
- { match: /^processes/i, destination: 'journeyStep.supportProcesses', note: '' },
28
- { match: /needs? linked to (jira|a ticket)/i, destination: 'needs', note: 'Need.statement + Need.reference (ticket ID).' },
29
- { match: /^backlog status/i, destination: 'projectContext.facts', note: '' },
41
+ { match: /^exception (handling|journeys)|^edge cases/i, destination: 'journeyStep.exceptionHandling', note: '' },
42
+ { match: /^future (state|steps?)$/i, destination: 'journeyStep.futureState', note: 'Proposed/target-state, not current fact.' },
43
+ { match: /needs? linked to (jira|a ticket)/i, destination: 'needs', note: 'Ticket references, not needs - link to the existing Need records instead.' },
44
+ { match: /^backlog status/i, destination: 'unmapped', note: 'Delivery tracking, not design knowledge. Usually left out.' },
30
45
  { match: /^notes$/i, destination: 'projectContext.facts', note: '' },
31
- { match: /^opportunities/i, destination: 'assumption', note: 'One Assumption per opportunity.' },
46
+ { match: /^opportunities/i, destination: 'assumption', note: 'Proposed, not observed - record as an assumption until evidenced.' },
32
47
  { match: /^systems/i, destination: 'projectContext.channels', note: '' },
33
48
  { match: /^sources$/i, destination: 'evidence', note: '' }
34
49
  ]
@@ -43,7 +58,7 @@ async function main () {
43
58
  const workbook = openWorkbook(documentPath)
44
59
 
45
60
  const draft = {
46
- sourceDocument: path.relative(ctx.root, documentPath),
61
+ sourceDocument: path.relative(createContextOrExit().root, documentPath),
47
62
  importedAt: new Date().toISOString(),
48
63
  note: 'Review artefact only - nothing here has been written to the project source yet. Decide, sheet by sheet and row by row, whether any identifying details should be genericized before promoting content into <project>/source/*.json.',
49
64
  sheets: Object.fromEntries(
@@ -74,45 +89,86 @@ async function main () {
74
89
  * silently dropping its content.
75
90
  */
76
91
  function extractSheet (workbook, sheetName) {
77
- const grid = readSheetGrid(workbook, sheetName)
78
- const { steps, headerRowIndex } = buildSteps(grid)
79
- const swimlanes = groupIntoSwimlanes(grid, steps, headerRowIndex + 2)
92
+ return extractFromGrid(readSheetGrid(workbook, sheetName))
93
+ }
94
+
95
+ function extractFromGrid (grid) {
96
+ const { steps, laneStartRow, stepHeaderIsAboveLabels } = buildSteps(grid)
97
+ const swimlanes = groupIntoSwimlanes(grid, steps, laneStartRow)
80
98
 
81
99
  // A handful of stray column-0 values isn't enough evidence that a sheet
82
100
  // follows the swimlane convention - most of its actual content needs to
83
101
  // have landed inside a swimlane, or this isn't really a step x lane
84
102
  // blueprint and forcing that shape on it would silently drop everything
85
103
  // that came before the first (possibly late, possibly sparse) label.
86
- const contentCells = flattenCells(grid.slice(headerRowIndex + 2)).length
104
+ const contentCells = flattenCells(grid.slice(laneStartRow)).length
87
105
  const capturedCells = swimlanes.reduce(
88
106
  (sum, swimlane) => sum + Object.values(swimlane.cellsByStep).reduce((n, v) => n + asList(v).length, 0),
89
107
  0
90
108
  )
91
109
 
92
- if (swimlanes.length && contentCells > 0 && capturedCells / contentCells >= 0.5) {
110
+ // Two structural tests separate a blueprint from an ordinary table, because
111
+ // both have a populated column 0 and both passed the coverage test on their
112
+ // own - an Evidence tab came out as 74 lanes named after repeated step names,
113
+ // and a Sources tab as 8 lanes named after its ID column.
114
+ //
115
+ // 1. A blueprint's step-header row has an EMPTY column 0 - the corner above
116
+ // the lane labels. A table's header row names that column ("Source ID").
117
+ // 2. Each lane appears once. Duplicate labels mean column 0 holds data.
118
+ //
119
+ // A blueprint that does label its corner cell is read as flat, which keeps
120
+ // every cell for manual review. Wrongly flat loses nothing; wrongly blueprint
121
+ // invents a structure and buries the content.
122
+ const labels = swimlanes.map((swimlane) => swimlane.label)
123
+ const labelsAreUnique = new Set(labels).size === labels.length
124
+
125
+ if (stepHeaderIsAboveLabels && swimlanes.length && labelsAreUnique &&
126
+ contentCells > 0 && capturedCells / contentCells >= 0.5) {
93
127
  return { shape: 'blueprint', steps: steps.map((step) => step.label), swimlanes }
94
128
  }
95
129
 
96
130
  return { shape: 'flat', cells: flattenCells(grid) }
97
131
  }
98
132
 
133
+ /**
134
+ * Finds the row of step names and the row the lanes start on.
135
+ *
136
+ * A blueprint's shape is: some number of title/phase rows, then a row of step
137
+ * names with an empty column 0, then one labelled row per lane. So the step
138
+ * header is the row immediately above the first labelled row - structural, and
139
+ * true whether there are zero title rows or three.
140
+ *
141
+ * The previous version guessed the header as whichever of the first six rows
142
+ * had the most populated cells, then read the step names from the row AFTER it
143
+ * and started lanes two rows later. On a real blueprint that named the steps
144
+ * after the contents of the User action row and silently dropped the first two
145
+ * lanes entirely.
146
+ */
99
147
  function buildSteps (grid) {
100
- // The step-header row is whichever of the first few rows has the most
101
- // populated columns - generic enough to not assume a fixed row number.
102
- const candidateRows = grid.slice(0, 6).map((row, index) => ({ row: row || [], index }))
103
- const headerRowIndex = candidateRows.reduce((best, candidate) =>
104
- (candidate.row.filter(Boolean).length > (candidateRows[best]?.row.filter(Boolean).length || 0) ? candidate.index : best), 0)
148
+ // A lane row has a label AND content beside it. A title row ("Patient search
149
+ // blueprint" in A1) has the label and nothing else, and taking it as the
150
+ // first lane puts the header above the top of the sheet and finds no steps
151
+ // at all. Requiring content beside the label tells them apart.
152
+ const firstLabelRow = grid.findIndex((row) => row && row[0] && row.slice(1).filter(Boolean).length > 0)
153
+
154
+ if (firstLabelRow === -1) return { steps: [], headerRowIndex: 0, laneStartRow: grid.length, stepHeaderIsAboveLabels: false }
155
+
156
+ // Usually the header sits above the first label. A sheet that puts a corner
157
+ // label in column 0 of its header row ("Step", "Stage") has no row above to
158
+ // take, so the header is that row itself and the lanes start below it.
159
+ const above = firstLabelRow > 0 ? (grid[firstLabelRow - 1] || []) : []
160
+ const aboveHasSteps = above.slice(1).filter(Boolean).length > 0
161
+
162
+ const headerRowIndex = aboveHasSteps ? firstLabelRow - 1 : firstLabelRow
163
+ const laneStartRow = aboveHasSteps ? firstLabelRow : firstLabelRow + 1
105
164
 
106
165
  const headerRow = grid[headerRowIndex] || []
107
- const nextRow = grid[headerRowIndex + 1] || []
108
166
  const steps = []
109
-
110
- for (let col = 1; col < Math.max(headerRow.length, nextRow.length); col++) {
111
- const label = nextRow[col] || headerRow[col]
112
- if (label) steps.push({ column: col, label: String(label).trim() })
167
+ for (let col = 1; col < headerRow.length; col++) {
168
+ if (headerRow[col]) steps.push({ column: col, label: String(headerRow[col]).trim() })
113
169
  }
114
170
 
115
- return { steps, headerRowIndex }
171
+ return { steps, headerRowIndex, laneStartRow, stepHeaderIsAboveLabels: aboveHasSteps }
116
172
  }
117
173
 
118
174
  function groupIntoSwimlanes (grid, steps, startRow) {
@@ -236,7 +292,14 @@ function parseArgs (args) {
236
292
  return parsed
237
293
  }
238
294
 
239
- main().catch((error) => {
240
- console.error(error.message)
241
- process.exit(1)
242
- })
295
+ // Exported so the grid logic can be tested without a workbook or a project:
296
+ // these are the parts that were silently wrong, and they are pure functions of
297
+ // a grid.
298
+ module.exports = { buildSteps, groupIntoSwimlanes, extractFromGrid, triageFor }
299
+
300
+ if (require.main === module) {
301
+ main().catch((error) => {
302
+ console.error(error.message)
303
+ process.exit(1)
304
+ })
305
+ }