@hippo-digital/hippocampus 1.0.0-rc.6 → 1.0.0-rc.8
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 +84 -0
- package/lib/schema-version.js +1 -1
- package/package.json +2 -1
- package/scripts/import-design-actions.js +2 -2
- package/scripts/import-project-context.js +87 -12
- package/scripts/import-research-batch.js +1 -1
- package/scripts/import-research-deck.js +1 -1
- package/scripts/lib/project-context-workbook.js +111 -0
- package/scripts/promote-project-context-draft.js +22 -3
- package/scripts/promote-research-draft.js +7 -2
- package/scripts/sync-project-context.js +9 -5
- package/scripts/sync-research-artefacts.js +9 -5
- package/skills/ingest-project-context.skill.md +5 -0
- package/templates/project-context.xlsx +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -93,6 +93,82 @@ four sheets, with nothing unmapped.
|
|
|
93
93
|
The grid logic is exported and covered by unit tests - `npm run test:unit`, also
|
|
94
94
|
run by the release gate. They are the package's first.
|
|
95
95
|
|
|
96
|
+
### Unit tests where end-to-end cannot reach
|
|
97
|
+
|
|
98
|
+
35 tests covering the two places where being wrong damages something the team
|
|
99
|
+
owns, and where the install test structurally cannot help: it wires one
|
|
100
|
+
well-formed Prototype Kit, and every branch below needs a differently-malformed
|
|
101
|
+
file or directory tree.
|
|
102
|
+
|
|
103
|
+
- **`host-edit.js`** - the seven paths where it refuses to edit `app.js`. A block
|
|
104
|
+
with no end marker, a block the team has edited since it was written, two
|
|
105
|
+
`viewsPath` arrays, an array holding something other than string literals, no
|
|
106
|
+
safe insertion point. The install test reached none of them, and those
|
|
107
|
+
refusals are the whole safety design: half-editing a file leaves its owner
|
|
108
|
+
worse off than not editing it. Also that add-then-remove and
|
|
109
|
+
insert-then-remove restore the file byte for byte.
|
|
110
|
+
- **`resolve-root.js`** - the precedence chain and its two hard errors. A wrong
|
|
111
|
+
root does not fail; it produces an empty knowledge base and no explanation.
|
|
112
|
+
|
|
113
|
+
Not added elsewhere on purpose: `schema.js` and `lint-knowledge.js` are covered
|
|
114
|
+
by `validate` against both a real and an empty knowledge base, the router and
|
|
115
|
+
docs by `doctor` hitting every route, and `skills install` end-to-end. Tests
|
|
116
|
+
there would restate what already runs.
|
|
117
|
+
|
|
118
|
+
### Project context from a filled-in template
|
|
119
|
+
|
|
120
|
+
`templates/project-context.xlsx` ships with the package: a tab per collection,
|
|
121
|
+
one row per record, and the column headers are the schema's field names.
|
|
122
|
+
`import project-context` accepts it alongside the decks and PDFs it already took.
|
|
123
|
+
|
|
124
|
+
The difference is what the importer has to do. A deck is prose written for
|
|
125
|
+
another purpose, so the importer guesses at structure and reports how well it
|
|
126
|
+
fitted. A filled-in template already is the structure, so nothing is inferred
|
|
127
|
+
and nothing can be inferred wrongly. Both produce the same draft, reviewed and
|
|
128
|
+
promoted the same way - nothing reaches the knowledge base without a dry run.
|
|
129
|
+
|
|
130
|
+
Three rules keep a half-filled template harmless: a row with no id is skipped,
|
|
131
|
+
the shipped guidance row is skipped, and the worked example is skipped. The
|
|
132
|
+
Overview tab keeps its examples in a column of their own rather than in the
|
|
133
|
+
value cells, because an example sitting in a value cell imports as though
|
|
134
|
+
somebody had written it - which is how invented content gets into a knowledge
|
|
135
|
+
base, and it did on the first cut of this.
|
|
136
|
+
|
|
137
|
+
A test asserts every tab's columns against the schema, so a field added to the
|
|
138
|
+
model and not to the workbook fails the build rather than quietly becoming
|
|
139
|
+
unfillable.
|
|
140
|
+
|
|
141
|
+
The workbook reading lives in `scripts/lib/project-context-workbook.js` rather
|
|
142
|
+
than inside the importer, which loads a PDF parser, a zip reader and an XML
|
|
143
|
+
parser for the deck path. Reading a spreadsheet needs none of them, and a test
|
|
144
|
+
that loaded them inherited every way they can fail on a given Node version.
|
|
145
|
+
|
|
146
|
+
### Promotion in a host
|
|
147
|
+
|
|
148
|
+
`promote` wrote its data and then reported that validation had failed, when
|
|
149
|
+
validation had never run. Both promote commands, and both sync commands,
|
|
150
|
+
shelled out to `npm run validate:knowledge` - a script this repo and the demo
|
|
151
|
+
define and **no host does**. They now run the sibling script directly, which
|
|
152
|
+
needs nothing of the host but node.
|
|
153
|
+
|
|
154
|
+
`promote project-context` also failed outright on a project that had never
|
|
155
|
+
recorded context, because it merged into a `project-context.json` that `init`
|
|
156
|
+
cannot create: the schema requires a non-empty id, title and summary, and
|
|
157
|
+
inventing those is worse than leaving the file out. The first promotion into a
|
|
158
|
+
fresh project is now a create rather than a merge - which is the case that
|
|
159
|
+
matters, since it is how every project's context begins.
|
|
160
|
+
|
|
161
|
+
The install test now runs `promote project-context` against the scratch host.
|
|
162
|
+
It is the only command that writes to `hippocampus/source/` and it was the one
|
|
163
|
+
command the gate never exercised, which is how both of these shipped.
|
|
164
|
+
|
|
165
|
+
Every remaining `npm run ...` in an error message became its `npx hippocampus`
|
|
166
|
+
equivalent. They named scripts no host has.
|
|
167
|
+
|
|
168
|
+
The install test also removes its scratch project on success. Each run is a
|
|
169
|
+
full `node_modules`; fifty-seven of them filled a disk before anybody noticed.
|
|
170
|
+
A failing run still leaves its tree behind, and now says where.
|
|
171
|
+
|
|
96
172
|
### Validation
|
|
97
173
|
|
|
98
174
|
- Three tiers: errors are broken references, warnings are gaps worth filling,
|
|
@@ -105,6 +181,14 @@ run by the release gate. They are the package's first.
|
|
|
105
181
|
pointed at `<host>/node_modules/apps/demo` and failed every check. The
|
|
106
182
|
release gate now runs shipped commands against a real install rather than
|
|
107
183
|
only checking that they load, which is what let this through.
|
|
184
|
+
- The gate runs the unit tests by spawning node rather than shelling out to
|
|
185
|
+
`npm run`. It executes as `prepublishOnly`, so `npm publish --workspace=<pkg>`
|
|
186
|
+
has already set `npm_config_workspace`; an inner `npm run` inherited it,
|
|
187
|
+
looked for the script in the workspace rather than the root, and failed with
|
|
188
|
+
"Missing script" while the tests were green.
|
|
189
|
+
- It no longer claims a failure it cannot name. The fallback printed the first
|
|
190
|
+
lines of output, which on a green run are passing tests - so it reported
|
|
191
|
+
"unit tests fail" and offered three ticks as the evidence.
|
|
108
192
|
|
|
109
193
|
### Data contract
|
|
110
194
|
|
package/lib/schema-version.js
CHANGED
|
@@ -68,7 +68,7 @@ function migrateInMemory (knowledge, meta) {
|
|
|
68
68
|
version += 1
|
|
69
69
|
warnings.push(
|
|
70
70
|
`Knowledge base read as schemaVersion ${version - 1} and migrated to ${version} in memory. ` +
|
|
71
|
-
'Run `
|
|
71
|
+
'Run `npx hippocampus migrate` to write the upgrade back.'
|
|
72
72
|
)
|
|
73
73
|
}
|
|
74
74
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hippo-digital/hippocampus",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.8",
|
|
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",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"index.js",
|
|
12
12
|
"bin",
|
|
13
13
|
"lib",
|
|
14
|
+
"!lib/__tests__",
|
|
14
15
|
"views",
|
|
15
16
|
"assets",
|
|
16
17
|
"scripts",
|
|
@@ -34,7 +34,7 @@ const EXAMPLE_IDS = /^(R17-05|R17-10|DA-R17-|DEC-R17-)/i
|
|
|
34
34
|
|
|
35
35
|
function main () {
|
|
36
36
|
const args = parseArgs(process.argv.slice(2))
|
|
37
|
-
if (!args.workbook) throw new Error('Usage:
|
|
37
|
+
if (!args.workbook) throw new Error('Usage: npx hippocampus import design-actions -- --workbook path/to/tracker.xlsx [--dry-run]')
|
|
38
38
|
|
|
39
39
|
const workbook = openWorkbook(path.resolve(args.workbook))
|
|
40
40
|
const actionRows = rows(workbook, 'Design Actions')
|
|
@@ -174,7 +174,7 @@ function main () {
|
|
|
174
174
|
for (const [file, data] of Object.entries(proposed)) {
|
|
175
175
|
fs.writeFileSync(path.join(knowledgeSourceDir, file), `${JSON.stringify(data, null, 2)}\n`)
|
|
176
176
|
}
|
|
177
|
-
console.log(`\nImported from ${path.relative(ctx.root, path.resolve(args.workbook))}. Run
|
|
177
|
+
console.log(`\nImported from ${path.relative(ctx.root, path.resolve(args.workbook))}. Run `npx hippocampus validate` to confirm.`)
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
function rows (workbook, sheetName) {
|
|
@@ -5,20 +5,35 @@ const { PDFParse } = require('pdf-parse')
|
|
|
5
5
|
const { XMLParser } = require('fast-xml-parser')
|
|
6
6
|
const { ProjectContextImportDraftSchema } = require('../lib/schema')
|
|
7
7
|
const { createContextOrExit } = require('../lib/context')
|
|
8
|
-
const
|
|
9
|
-
const {
|
|
8
|
+
const { openWorkbook, readSheetGrid } = require('./lib/xlsx-grid')
|
|
9
|
+
const {
|
|
10
|
+
WORKBOOK_TABS, OVERVIEW_FIELDS, readWorkbookSections, readOverview, readRecordTab
|
|
11
|
+
} = require('./lib/project-context-workbook')
|
|
12
|
+
let cachedContext = null
|
|
13
|
+
function ctx () {
|
|
14
|
+
if (!cachedContext) cachedContext = createContextOrExit()
|
|
15
|
+
return cachedContext
|
|
16
|
+
}
|
|
10
17
|
|
|
11
18
|
async function main () {
|
|
12
19
|
const args = parseArgs(process.argv.slice(2))
|
|
13
20
|
if (!args.document || !args.contextId || !args.title) {
|
|
14
|
-
throw new Error('Usage:
|
|
21
|
+
throw new Error('Usage: npx hippocampus import project-context -- --document path/to/overview.pdf --context-id context-id --title "Project overview"\n' +
|
|
22
|
+
'A filled-in copy of templates/project-context.xlsx works too, and needs no guessing.')
|
|
15
23
|
}
|
|
16
24
|
|
|
17
|
-
|
|
18
|
-
|
|
25
|
+
// A spreadsheet is a different kind of input from a deck or a PDF. Those are
|
|
26
|
+
// prose somebody wrote for another purpose, so the importer guesses at
|
|
27
|
+
// structure and flags how well it fitted. A filled-in template already IS the
|
|
28
|
+
// structure - the columns are the schema - so nothing is inferred and nothing
|
|
29
|
+
// can be inferred wrongly. It still produces the same draft, reviewed and
|
|
30
|
+
// promoted the same way.
|
|
31
|
+
const isWorkbook = path.extname(args.document).toLowerCase() === '.xlsx'
|
|
32
|
+
const sections = isWorkbook ? readWorkbookSections(args.document) : await extractSections(args.document)
|
|
33
|
+
const draft = isWorkbook ? buildDraftFromWorkbook(args, sections) : buildDraft(args, sections)
|
|
19
34
|
validateDraft(draft)
|
|
20
35
|
|
|
21
|
-
const outputDir = args.outputDir ? path.resolve(args.outputDir) : projectImportsDir
|
|
36
|
+
const outputDir = args.outputDir ? path.resolve(args.outputDir) : ctx().paths.projectImportsDir
|
|
22
37
|
fs.mkdirSync(outputDir, { recursive: true })
|
|
23
38
|
|
|
24
39
|
const outputPath = path.join(outputDir, `${args.contextId}.json`)
|
|
@@ -26,7 +41,9 @@ async function main () {
|
|
|
26
41
|
fs.writeFileSync(outputPath, `${JSON.stringify(draft, null, 2)}\n`)
|
|
27
42
|
fs.writeFileSync(reviewPath, buildReviewMarkdown(draft))
|
|
28
43
|
|
|
29
|
-
console.log(
|
|
44
|
+
console.log(isWorkbook
|
|
45
|
+
? `Read ${sections.length} tabs`
|
|
46
|
+
: `Imported ${sections.length} ${sectionLabel(args.document).toLowerCase()}`)
|
|
30
47
|
reportFit(draft)
|
|
31
48
|
console.log(`Draft written to ${outputPath}`)
|
|
32
49
|
console.log(`Review written to ${reviewPath}`)
|
|
@@ -99,7 +116,7 @@ async function extractPdfPages (pdfPath) {
|
|
|
99
116
|
}
|
|
100
117
|
|
|
101
118
|
function buildDraft (args, sections) {
|
|
102
|
-
const sourceDocument = path.relative(ctx.root, path.resolve(args.document))
|
|
119
|
+
const sourceDocument = path.relative(ctx().root, path.resolve(args.document))
|
|
103
120
|
const lines = sections.flatMap((section) => section.text)
|
|
104
121
|
const context = {
|
|
105
122
|
id: args.contextId,
|
|
@@ -136,6 +153,60 @@ function buildDraft (args, sections) {
|
|
|
136
153
|
}
|
|
137
154
|
}
|
|
138
155
|
|
|
156
|
+
function buildDraftFromWorkbook (args, sections) {
|
|
157
|
+
const documentPath = path.resolve(args.document)
|
|
158
|
+
const workbook = openWorkbook(documentPath)
|
|
159
|
+
const present = new Set([...workbook.sheetFiles.keys()])
|
|
160
|
+
const sourceDocument = path.relative(ctx().root, documentPath)
|
|
161
|
+
|
|
162
|
+
const overview = present.has('Overview') ? readOverview(readSheetGrid(workbook, 'Overview')) : {}
|
|
163
|
+
const warnings = []
|
|
164
|
+
|
|
165
|
+
const context = {
|
|
166
|
+
id: overview.id || args.contextId,
|
|
167
|
+
title: overview.title || args.title,
|
|
168
|
+
summary: overview.summary || args.summary || `Project context from ${path.basename(args.document)}.`
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (!overview.summary && !args.summary) {
|
|
172
|
+
warnings.push('The Overview tab has no summary. Add one - it is the first thing anybody reads.')
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
for (const field of ['purpose', 'vision', 'problemStatement', 'serviceProposition']) {
|
|
176
|
+
if (overview[field]) context[field] = overview[field]
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const narrativeGaps = ['purpose', 'vision', 'problemStatement', 'serviceProposition'].filter((f) => !context[f])
|
|
180
|
+
if (narrativeGaps.length) {
|
|
181
|
+
warnings.push(`Overview left blank: ${narrativeGaps.join(', ')}. Blank is fine if nobody has written it down - say so rather than inventing it.`)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
for (const [tab, collection] of Object.entries(WORKBOOK_TABS)) {
|
|
185
|
+
const rows = present.has(tab) ? readRecordTab(readSheetGrid(workbook, tab), tab) : []
|
|
186
|
+
context[collection] = rows
|
|
187
|
+
if (!rows.length) warnings.push(`${tab} is empty.`)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const selfId = kebab(`${context.id} workbook`)
|
|
191
|
+
if (!context.sourceArtefacts.some((artefact) => artefact.id === selfId)) {
|
|
192
|
+
context.sourceArtefacts.push({
|
|
193
|
+
id: selfId,
|
|
194
|
+
title: context.title,
|
|
195
|
+
sourcePath: sourceDocument,
|
|
196
|
+
sourceType: 'filled-in template',
|
|
197
|
+
importedAt: new Date().toISOString()
|
|
198
|
+
})
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return {
|
|
202
|
+
sourceDocument,
|
|
203
|
+
importedAt: new Date().toISOString(),
|
|
204
|
+
warnings,
|
|
205
|
+
projectContext: context,
|
|
206
|
+
sections
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
139
210
|
function extractPurpose (lines) {
|
|
140
211
|
const purposeLines = lines.filter((line) => {
|
|
141
212
|
const lower = line.toLowerCase()
|
|
@@ -421,7 +492,11 @@ function camelCase (value) {
|
|
|
421
492
|
return value.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase())
|
|
422
493
|
}
|
|
423
494
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
495
|
+
module.exports = { buildDraftFromWorkbook }
|
|
496
|
+
|
|
497
|
+
if (require.main === module) {
|
|
498
|
+
main().catch((error) => {
|
|
499
|
+
console.error(error.message)
|
|
500
|
+
process.exit(1)
|
|
501
|
+
})
|
|
502
|
+
}
|
|
@@ -10,7 +10,7 @@ const supportedExtensions = new Set(['.pptx', '.pdf'])
|
|
|
10
10
|
async function main () {
|
|
11
11
|
const args = parseArgs(process.argv.slice(2))
|
|
12
12
|
if (!args.source || !args.batchId) {
|
|
13
|
-
throw new Error('Usage:
|
|
13
|
+
throw new Error('Usage: npx hippocampus research batch -- --source path/to/files --batch-id batch-id [--date YYYY-MM-DD] [--concurrency 4]')
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
const sourceDir = path.resolve(args.source)
|
|
@@ -16,7 +16,7 @@ async function main () {
|
|
|
16
16
|
args.artefactId = kebab(args.artefactId || args.roundId || '')
|
|
17
17
|
|
|
18
18
|
if (!args.deck || !args.roundId || !args.title || !args.date) {
|
|
19
|
-
throw new Error('Usage:
|
|
19
|
+
throw new Error('Usage: npx hippocampus import research-deck -- --deck path/to/artefact --round-id round-id [--artefact-id artefact-id] --title "Round title" --date YYYY-MM-DD')
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
const slides = await extractSlides(args.deck)
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
const { openWorkbook, readSheetGrid } = require('./xlsx-grid')
|
|
3
|
+
|
|
4
|
+
// Reading a filled-in project-context template. Kept apart from the importer
|
|
5
|
+
// because that module loads a PDF parser, a zip reader and an XML parser to
|
|
6
|
+
// handle decks - none of which a spreadsheet needs, and all of which a test of
|
|
7
|
+
// this logic would otherwise have to load too.
|
|
8
|
+
|
|
9
|
+
const WORKBOOK_TABS = {
|
|
10
|
+
Users: 'users',
|
|
11
|
+
Channels: 'channels',
|
|
12
|
+
Policies: 'policies',
|
|
13
|
+
Constraints: 'constraints',
|
|
14
|
+
Risks: 'risks',
|
|
15
|
+
Milestones: 'milestones',
|
|
16
|
+
Facts: 'facts',
|
|
17
|
+
Sources: 'sourceArtefacts'
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
const OVERVIEW_FIELDS = ['id', 'title', 'summary', 'purpose', 'vision', 'problemStatement', 'serviceProposition']
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
function readWorkbookSections (documentPath) {
|
|
25
|
+
const workbook = openWorkbook(path.resolve(documentPath))
|
|
26
|
+
const present = new Set([...workbook.sheetFiles.keys()])
|
|
27
|
+
|
|
28
|
+
const sections = []
|
|
29
|
+
let number = 1
|
|
30
|
+
|
|
31
|
+
for (const tab of ['Overview', ...Object.keys(WORKBOOK_TABS)]) {
|
|
32
|
+
if (!present.has(tab)) continue
|
|
33
|
+
const grid = readSheetGrid(workbook, tab)
|
|
34
|
+
const text = []
|
|
35
|
+
for (const row of grid) {
|
|
36
|
+
if (!row) continue
|
|
37
|
+
const line = row.map((cell) => String(cell == null ? '' : cell).trim()).filter(Boolean).join(' | ')
|
|
38
|
+
if (line) text.push(line)
|
|
39
|
+
}
|
|
40
|
+
// The draft schema wants at least one line per section, and an empty tab is
|
|
41
|
+
// worth recording as empty rather than omitting - the review note is how
|
|
42
|
+
// somebody notices they left a tab blank.
|
|
43
|
+
sections.push({ number: number++, title: tab, text: text.length ? text : ['(no rows)'] })
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!sections.length) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
`${path.basename(documentPath)} has none of the expected tabs.\n` +
|
|
49
|
+
`Expected: Overview, ${Object.keys(WORKBOOK_TABS).join(', ')}.\n` +
|
|
50
|
+
'Start from templates/project-context.xlsx in the installed package.'
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return sections
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function readOverview (grid) {
|
|
58
|
+
const values = {}
|
|
59
|
+
for (const row of grid) {
|
|
60
|
+
if (!row) continue
|
|
61
|
+
const field = String(row[0] == null ? '' : row[0]).trim()
|
|
62
|
+
const value = String(row[1] == null ? '' : row[1]).trim()
|
|
63
|
+
if (OVERVIEW_FIELDS.includes(field) && value) values[field] = value
|
|
64
|
+
}
|
|
65
|
+
return values
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
function readRecordTab (grid, tab) {
|
|
70
|
+
const headerIndex = grid.findIndex((row) => row && String(row[0] || '').trim() === 'id')
|
|
71
|
+
if (headerIndex === -1) {
|
|
72
|
+
throw new Error(`The ${tab} tab has no "id" column header. Start from templates/project-context.xlsx.`)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const headers = (grid[headerIndex] || []).map((cell) => String(cell == null ? '' : cell).trim())
|
|
76
|
+
const records = []
|
|
77
|
+
const seen = new Set()
|
|
78
|
+
|
|
79
|
+
for (let rowIndex = headerIndex + 1; rowIndex < grid.length; rowIndex++) {
|
|
80
|
+
const row = grid[rowIndex]
|
|
81
|
+
if (!row) continue
|
|
82
|
+
|
|
83
|
+
const id = String(row[0] == null ? '' : row[0]).trim()
|
|
84
|
+
|
|
85
|
+
// Three kinds of row are not records: an empty one, the guidance row the
|
|
86
|
+
// template ships (every cell parenthesised), and the worked example. All
|
|
87
|
+
// three are skipped so a template used exactly as shipped imports cleanly
|
|
88
|
+
// and an id that is genuinely malformed still reaches the validator, where
|
|
89
|
+
// it is reported rather than quietly dropped.
|
|
90
|
+
if (!id || id.startsWith('(') || id.startsWith('example-')) continue
|
|
91
|
+
|
|
92
|
+
const record = {}
|
|
93
|
+
for (let col = 0; col < headers.length; col++) {
|
|
94
|
+
const field = headers[col]
|
|
95
|
+
if (!field) continue
|
|
96
|
+
const value = String(row[col] == null ? '' : row[col]).trim()
|
|
97
|
+
if (value) record[field] = value
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (seen.has(id)) {
|
|
101
|
+
throw new Error(`The ${tab} tab uses the id "${id}" more than once (row ${rowIndex + 1}). Ids must be unique within a tab.`)
|
|
102
|
+
}
|
|
103
|
+
seen.add(id)
|
|
104
|
+
records.push(record)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return records
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
module.exports = { WORKBOOK_TABS, OVERVIEW_FIELDS, readWorkbookSections, readOverview, readRecordTab }
|
|
@@ -11,11 +11,25 @@ const projectContextPath = path.join(knowledgeSourceDir, 'project-context.json')
|
|
|
11
11
|
function main () {
|
|
12
12
|
const args = parseArgs(process.argv.slice(2))
|
|
13
13
|
if (!args.draft) {
|
|
14
|
-
throw new Error(`Usage:
|
|
14
|
+
throw new Error(`Usage: npx hippocampus promote project-context -- --draft ${path.relative(ctx.root, path.join(projectImportsDir, 'context-id.json'))} [--dry-run]`)
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
const draft = validateDraft(readJson(path.resolve(args.draft)))
|
|
18
|
-
|
|
18
|
+
// A project that has never recorded context has no project-context.json at
|
|
19
|
+
// all: `init` cannot write one, because the schema requires a non-empty id,
|
|
20
|
+
// title and summary and inventing those is worse than leaving the file out.
|
|
21
|
+
// So the first promotion into a fresh project is a create, not a merge -
|
|
22
|
+
// which is exactly the case that matters, since it is how every project's
|
|
23
|
+
// context starts.
|
|
24
|
+
const current = fs.existsSync(projectContextPath)
|
|
25
|
+
? readJson(projectContextPath)
|
|
26
|
+
: {
|
|
27
|
+
id: draft.projectContext.id,
|
|
28
|
+
title: draft.projectContext.title,
|
|
29
|
+
summary: draft.projectContext.summary,
|
|
30
|
+
users: [], channels: [], policies: [], constraints: [],
|
|
31
|
+
risks: [], milestones: [], facts: [], sourceArtefacts: []
|
|
32
|
+
}
|
|
19
33
|
const proposed = mergeProjectContext(current, draft.projectContext)
|
|
20
34
|
|
|
21
35
|
console.log([
|
|
@@ -36,7 +50,12 @@ function main () {
|
|
|
36
50
|
|
|
37
51
|
writeJson(projectContextPath, proposed)
|
|
38
52
|
|
|
39
|
-
|
|
53
|
+
// Run the sibling script directly rather than `npm run <script>`. Those npm
|
|
54
|
+
// scripts exist in this repo and in the demo, and in no host that installs the
|
|
55
|
+
// package - so this step failed with "Missing script" on a promotion that had
|
|
56
|
+
// already written its data correctly. Spawning node needs nothing of the host
|
|
57
|
+
// but node itself.
|
|
58
|
+
const validation = spawnSync(process.execPath, [path.join(__dirname, 'validate-knowledge.js'), '--root', ctx.root], {
|
|
40
59
|
cwd: ctx.root,
|
|
41
60
|
stdio: 'inherit'
|
|
42
61
|
})
|
|
@@ -19,7 +19,7 @@ const collections = {
|
|
|
19
19
|
function main () {
|
|
20
20
|
const args = parseArgs(process.argv.slice(2))
|
|
21
21
|
if (!args.draft) {
|
|
22
|
-
throw new Error(`Usage:
|
|
22
|
+
throw new Error(`Usage: npx hippocampus promote research -- --draft ${path.relative(ctx.root, path.join(researchImportsDir, 'round-id.json'))} [--dry-run]`)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const draft = validateDraft(readJson(path.resolve(args.draft)))
|
|
@@ -43,7 +43,12 @@ function main () {
|
|
|
43
43
|
writeJson(path.join(dataDir, filename), proposed[key])
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
// Run the sibling script directly rather than `npm run <script>`. Those npm
|
|
47
|
+
// scripts exist in this repo and in the demo, and in no host that installs the
|
|
48
|
+
// package - so this step failed with "Missing script" on a promotion that had
|
|
49
|
+
// already written its data correctly. Spawning node needs nothing of the host
|
|
50
|
+
// but node itself.
|
|
51
|
+
const validation = spawnSync(process.execPath, [path.join(__dirname, 'validate-knowledge.js'), '--root', ctx.root], {
|
|
47
52
|
cwd: ctx.root,
|
|
48
53
|
stdio: 'inherit'
|
|
49
54
|
})
|
|
@@ -98,11 +98,15 @@ async function main () {
|
|
|
98
98
|
if (!shouldPromote) return
|
|
99
99
|
|
|
100
100
|
for (const item of promotable) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
101
|
+
// Run the sibling script directly rather than `npm run <script>`. Those npm
|
|
102
|
+
// scripts exist in this repo and in the demo, and in no host that installs the
|
|
103
|
+
// package - so this step failed with "Missing script" on a promotion that had
|
|
104
|
+
// already written its data correctly. Spawning node needs nothing of the host
|
|
105
|
+
// but node itself.
|
|
106
|
+
const result = spawnSync(process.execPath, [
|
|
107
|
+
path.join(__dirname, 'promote-project-context-draft.js'),
|
|
108
|
+
`--draft=${item.draftPath}`,
|
|
109
|
+
'--root', ctx.root
|
|
106
110
|
], {
|
|
107
111
|
cwd: ctx.root,
|
|
108
112
|
stdio: 'inherit'
|
|
@@ -108,11 +108,15 @@ async function main () {
|
|
|
108
108
|
if (!shouldPromote) return
|
|
109
109
|
|
|
110
110
|
for (const item of promotable) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
// Run the sibling script directly rather than `npm run <script>`. Those npm
|
|
112
|
+
// scripts exist in this repo and in the demo, and in no host that installs the
|
|
113
|
+
// package - so this step failed with "Missing script" on a promotion that had
|
|
114
|
+
// already written its data correctly. Spawning node needs nothing of the host
|
|
115
|
+
// but node itself.
|
|
116
|
+
const result = spawnSync(process.execPath, [
|
|
117
|
+
path.join(__dirname, 'promote-research-draft.js'),
|
|
118
|
+
`--draft=${item.draftPath}`,
|
|
119
|
+
'--root', ctx.root
|
|
116
120
|
], {
|
|
117
121
|
cwd: ctx.root,
|
|
118
122
|
stdio: 'inherit'
|
|
@@ -11,6 +11,7 @@ reads:
|
|
|
11
11
|
- node_modules/@hippo-digital/hippocampus/docs/repeatable-research-round-ingestion.md
|
|
12
12
|
- node_modules/@hippo-digital/hippocampus/docs/hippocampus-technical.md
|
|
13
13
|
- node_modules/@hippo-digital/hippocampus/docs/source-model.md
|
|
14
|
+
- node_modules/@hippo-digital/hippocampus/templates/project-context.xlsx
|
|
14
15
|
- hippocampus/inbox/project/
|
|
15
16
|
- hippocampus/imports/project/[draft-id].review.md
|
|
16
17
|
- hippocampus/imports/project/[draft-id].json
|
|
@@ -37,6 +38,10 @@ acceptance:
|
|
|
37
38
|
|
|
38
39
|
## Use when
|
|
39
40
|
- A project overview deck or PDF needs to become a review-ready project-context draft.
|
|
41
|
+
- A filled-in copy of `templates/project-context.xlsx` needs importing. Prefer this
|
|
42
|
+
when the team is gathering context rather than working from one existing document:
|
|
43
|
+
the columns are the schema, so nothing has to be inferred from prose and the
|
|
44
|
+
structuring step below is already done.
|
|
40
45
|
- You want one entrypoint for the no-promote import, draft structuring, and dry-run validation flow.
|
|
41
46
|
|
|
42
47
|
## Workflow
|
|
Binary file
|