@hippo-digital/hippocampus 2.0.1 → 2.2.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 +97 -0
- package/README.md +2 -0
- package/agents/knowledge-builder.md +2 -0
- package/agents/workflow-orchestrator.md +2 -0
- package/bin/hippocampus.js +2 -0
- package/lib/consequences.js +348 -0
- package/lib/known.js +258 -0
- package/package.json +1 -1
- package/scripts/audit-provenance.js +1 -1
- package/scripts/consequences.js +147 -0
- package/scripts/known.js +118 -0
- package/skills/find-unintended-consequences/SKILL.md +124 -0
- package/skills/skills.json +59 -0
- package/skills/whats-known-about/SKILL.md +113 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,102 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.2.0
|
|
4
|
+
|
|
5
|
+
`hippocampus consequences <scenario-id>` runs a new or changed journey against the
|
|
6
|
+
users the knowledge base already knows, before the journey is designed. A
|
|
7
|
+
`find-unintended-consequences` skill ships with it, and `knowledge-builder` and
|
|
8
|
+
`workflow-orchestrator` list it.
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npx hippocampus consequences scenario-fire-safety-officer-visit-list-check
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
The case it was built for is a new persona arriving - optometrists on NCRS - and the
|
|
15
|
+
question of whether their journeys will hurt the people already using the service.
|
|
16
|
+
The input is a scenario; the output is:
|
|
17
|
+
|
|
18
|
+
- **This user in the research.** Whether any participant's role matches the new
|
|
19
|
+
persona. Matched on the words that tell this role apart from the other users, so
|
|
20
|
+
"safety" in *fire safety officer* does not match an *MRI safety officer*.
|
|
21
|
+
- **What the journey stands on.** The evidence under its own needs (their
|
|
22
|
+
`evidenceIds` and `supported-by` rows) and the insights that test them, with
|
|
23
|
+
assertion-type evidence called out.
|
|
24
|
+
- **Users who stand on the same ground.** Every other user whose needs cite the
|
|
25
|
+
same evidence or are tested by the same insights, and which they share.
|
|
26
|
+
- **Design actions and decisions already on that ground.** A decision can be
|
|
27
|
+
taken in a journey built on the same evidence, or it can resolve a design
|
|
28
|
+
action that responds to one of the journey's insights. It is reported either
|
|
29
|
+
way, with its status and which route it came by.
|
|
30
|
+
- **Weak ground.** Assumptions attached to the journey's needs or ground,
|
|
31
|
+
assertion-type or low-confidence evidence, and insights on the ground that are
|
|
32
|
+
not held at high confidence.
|
|
33
|
+
- **Screens already built on that ground** - where the journey is likely to land.
|
|
34
|
+
- **Questions every new kind of user raises:** what they may see, whether they
|
|
35
|
+
write, and whether they look at one record or many. A concern no record names is
|
|
36
|
+
reported as nobody having asked.
|
|
37
|
+
|
|
38
|
+
It walks the shared ground and never the screen. A screen's own needs belong to its
|
|
39
|
+
intended users by construction, so starting from the screens a journey touches
|
|
40
|
+
always reports that nothing is wrong. On NAER, walking out from the address screen
|
|
41
|
+
found one role; walking the evidence the same change rests on found five roles and
|
|
42
|
+
ten needs. Screens are listed but not walked for the same reason: a shared page
|
|
43
|
+
reaches every user and buries the few whose needs actually stand on the ground.
|
|
44
|
+
|
|
45
|
+
Insights count as ground because evidence alone is not enough. On NCRS each
|
|
46
|
+
persona has its own evidence record, so evidence is almost never shared between
|
|
47
|
+
users. Read that way, the safeguarding household scenario reached nobody and
|
|
48
|
+
found no decisions, which is the "nothing is wrong" answer this command exists to
|
|
49
|
+
prevent. Read through the insights, it reaches 13 needs across 6 roles, and all
|
|
50
|
+
five Round 16 decisions on location search through `da-r16-01`.
|
|
51
|
+
|
|
52
|
+
Matching participants to the new persona ignores generic job words such as
|
|
53
|
+
*practitioner*, *clinical*, *administrator* and *lead*. Without that, on NCRS
|
|
54
|
+
"Safeguarding practitioner (clinical)" was matched on *practitioner* alone, and
|
|
55
|
+
three *Clinical - Practitioner* participants from other rounds were counted as
|
|
56
|
+
research on safeguarding.
|
|
57
|
+
|
|
58
|
+
It lists candidates, not verdicts. Whether a decision is a collision or already
|
|
59
|
+
answers the question, and whether a gap needs research, are judgements, and the
|
|
60
|
+
skill is where they get made. It exits 0 whenever the scenario exists, and supports
|
|
61
|
+
`--json` and `--all`.
|
|
62
|
+
|
|
63
|
+
## 2.1.0
|
|
64
|
+
|
|
65
|
+
`hippocampus known <topic>` answers "what do we already know about this?" before
|
|
66
|
+
anyone finds it out a second time. A `whats-known-about` skill ships with it, and
|
|
67
|
+
`knowledge-builder` and `workflow-orchestrator` list it.
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
npx hippocampus known "historic resident" "previous occupant"
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Each argument is searched on its own, matching at the start of a word, so
|
|
74
|
+
`postcode` finds "postcodes" and `age` does not find "page". It reads the body of
|
|
75
|
+
every kind of record, not just the titles, because a topic is usually named in the
|
|
76
|
+
summary rather than the heading. The output keeps apart the things a summary tends
|
|
77
|
+
to merge:
|
|
78
|
+
|
|
79
|
+
- **Findings.** Insights and evidence, oldest round first. Each one keeps its own
|
|
80
|
+
round, date and confidence, because two rounds agreeing is a stronger result than
|
|
81
|
+
one sentence that hides both.
|
|
82
|
+
- **Assumptions.** These come from `assumptions.json`, plus any evidence whose
|
|
83
|
+
source type says it is an assertion. That test now lives in one place and
|
|
84
|
+
`source audit` uses it too, so the two commands cannot disagree about what counts.
|
|
85
|
+
- **Already built on these.** Screens, journeys, design actions and decisions,
|
|
86
|
+
found by following links forward up to three steps (`--hops`) and never back
|
|
87
|
+
through provenance. A need reaches a decision only through an insight and then a
|
|
88
|
+
design action. On NCRS, a single step from the need found the screens but none
|
|
89
|
+
of the five decisions, and naming what exists is what stops something being
|
|
90
|
+
built twice.
|
|
91
|
+
- **Coverage.** This covers rounds with a finding, rounds that name the topic
|
|
92
|
+
without one, rounds that produced no insights at all, and held files whose names
|
|
93
|
+
match but were never ingested. On NCRS, 7 of 14 rounds have no insights, so
|
|
94
|
+
finding nothing there means "not in the knowledge base", which is not the same as
|
|
95
|
+
"nobody asked". The output says which.
|
|
96
|
+
|
|
97
|
+
The command exits 0 when nothing matches, because finding nothing is an answer. It
|
|
98
|
+
supports `--json` for scripts and `--all` to lift the 25-item list limit.
|
|
99
|
+
|
|
3
100
|
## 2.0.1
|
|
4
101
|
|
|
5
102
|
`skills validate` says what it checked.
|
package/README.md
CHANGED
|
@@ -138,6 +138,8 @@ otherwise produce an empty knowledge base and no explanation.
|
|
|
138
138
|
npx hippocampus doctor # wiring, integrity and routes - start here
|
|
139
139
|
npx hippocampus validate # parse, check integrity, report coverage gaps
|
|
140
140
|
npx hippocampus validate --strict # and fail on warnings
|
|
141
|
+
npx hippocampus known "topic" # what is already known, what was built on it, what nobody asked
|
|
142
|
+
npx hippocampus consequences <id> # run a new journey against the users we already know
|
|
141
143
|
npx hippocampus research triage # rank a research folder before importing anything
|
|
142
144
|
npx hippocampus research sync # inbox artefacts to reviewable drafts
|
|
143
145
|
npx hippocampus source index # record what was ingested, before the copies go
|
|
@@ -18,6 +18,8 @@ Maintains the Hippocampus source model.
|
|
|
18
18
|
- `.github/skills/add-scenario/SKILL.md`
|
|
19
19
|
- `.github/skills/create-journey-from-scenario/SKILL.md`
|
|
20
20
|
- `.github/skills/audit-knowledge-source/SKILL.md`
|
|
21
|
+
- `.github/skills/whats-known-about/SKILL.md`
|
|
22
|
+
- `.github/skills/find-unintended-consequences/SKILL.md`
|
|
21
23
|
- `.github/skills/ingest-user-personas/SKILL.md`
|
|
22
24
|
- `.github/skills/record-design-decision/SKILL.md`
|
|
23
25
|
- `.github/skills/onboard-team-member/SKILL.md`
|
|
@@ -26,6 +26,8 @@ Coordinates larger Hippocampus delivery work.
|
|
|
26
26
|
- `.github/skills/review-research-import-draft/SKILL.md`
|
|
27
27
|
- `.github/skills/map-research-to-graph/SKILL.md`
|
|
28
28
|
- `.github/skills/audit-knowledge-source/SKILL.md`
|
|
29
|
+
- `.github/skills/whats-known-about/SKILL.md`
|
|
30
|
+
- `.github/skills/find-unintended-consequences/SKILL.md`
|
|
29
31
|
- `.github/skills/triage-research-corpus/SKILL.md`
|
|
30
32
|
- `.github/skills/onboard-team-member/SKILL.md`
|
|
31
33
|
|
package/bin/hippocampus.js
CHANGED
|
@@ -17,6 +17,8 @@ const COMMANDS = {
|
|
|
17
17
|
doctor: 'doctor.js',
|
|
18
18
|
eject: 'eject.js',
|
|
19
19
|
validate: 'validate-knowledge.js',
|
|
20
|
+
known: 'known.js',
|
|
21
|
+
consequences: 'consequences.js',
|
|
20
22
|
migrate: 'migrate-knowledge.js',
|
|
21
23
|
'research sync': 'sync-research-artefacts.js',
|
|
22
24
|
'research triage': 'triage-research-corpus.js',
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
// "If we add this journey, who that we already know could it hurt?" answered
|
|
2
|
+
// from the knowledge base, before the journey is designed.
|
|
3
|
+
//
|
|
4
|
+
// The input is a scenario for a new or changed journey. The output is every
|
|
5
|
+
// existing user whose needs stand on the same ground, the decisions already
|
|
6
|
+
// taken on that ground, the weak parts of it, and the questions every new kind
|
|
7
|
+
// of user raises that nobody may have asked.
|
|
8
|
+
//
|
|
9
|
+
// Two rules make the answer worth having:
|
|
10
|
+
//
|
|
11
|
+
// - Walk the shared ground, never the screen. A screen's own needs belong, by
|
|
12
|
+
// construction, to its intended users, so starting from the screens a journey
|
|
13
|
+
// touches always reports that nothing is wrong. The users a journey can hurt
|
|
14
|
+
// are the ones whose needs rest on the same evidence, the same assumptions and
|
|
15
|
+
// the same decisions.
|
|
16
|
+
// - Report candidates, not verdicts. Whether a decision is a collision, whether
|
|
17
|
+
// a finding is already handled, whether a gap needs research - those are
|
|
18
|
+
// judgements. This lists what a person or an agent has to look at, with the
|
|
19
|
+
// record behind each item, and leaves the call to them.
|
|
20
|
+
|
|
21
|
+
const { whatsKnown, ASSERTION_TYPES } = require('./known')
|
|
22
|
+
|
|
23
|
+
// Questions every new kind of user raises, whatever the service. Checked by
|
|
24
|
+
// coverage: a concern that no record names is a question nobody has asked, and
|
|
25
|
+
// is reported as that, not as a pass.
|
|
26
|
+
const STANDING_CONCERNS = [
|
|
27
|
+
{
|
|
28
|
+
id: 'disclosure',
|
|
29
|
+
question: 'What this user may see, and what they must not',
|
|
30
|
+
terms: ['privacy', 'consent', 'disclos', 'confidential', 'information governance', 'data sharing']
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: 'writes',
|
|
34
|
+
question: 'Whether this user writes to the record, and how it is attributed',
|
|
35
|
+
terms: ['write back', 'write-back', 'correction', 'attributed']
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: 'bulk-access',
|
|
39
|
+
question: 'Whether this user looks at one record or at many',
|
|
40
|
+
terms: ['bulk', 'postcode-area', 'postcode area', 'area search', 'caseload']
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
// Words too common in role names to tell one role from another. Generic grade
|
|
45
|
+
// and job-family words belong here too: on NCRS, "Safeguarding practitioner
|
|
46
|
+
// (clinical)" was otherwise matched on "practitioner" alone - the one word the
|
|
47
|
+
// other users lacked - and reported three GP participants as research on it.
|
|
48
|
+
const ROLE_NOISE = new Set([
|
|
49
|
+
'and', 'the', 'for', 'officer', 'service', 'services', 'staff', 'worker', 'team', 'home', 'person',
|
|
50
|
+
'practitioner', 'clinical', 'clinician', 'admin', 'administrator', 'user', 'users', 'manager',
|
|
51
|
+
'lead', 'senior', 'specialist', 'coordinator', 'assistant', 'general'
|
|
52
|
+
])
|
|
53
|
+
|
|
54
|
+
function roleWords (label) {
|
|
55
|
+
return String(label || '').toLowerCase().split(/[^a-z]+/).filter((w) => w.length >= 3 && !ROLE_NOISE.has(w))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function indexBy (records) {
|
|
59
|
+
const map = new Map()
|
|
60
|
+
for (const record of records || []) map.set(record.id, record)
|
|
61
|
+
return map
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Journeys reach evidence, screens and decisions through relationship rows and
|
|
65
|
+
// through the id lists on their steps. Collect both, so a journey modelled
|
|
66
|
+
// either way is found.
|
|
67
|
+
function journeyLinks (knowledge) {
|
|
68
|
+
const links = new Map()
|
|
69
|
+
const of = (id) => {
|
|
70
|
+
if (!links.has(id)) links.set(id, { evidence: new Set(), screens: new Set(), decisions: new Set() })
|
|
71
|
+
return links.get(id)
|
|
72
|
+
}
|
|
73
|
+
for (const rel of knowledge.relationships || []) {
|
|
74
|
+
if (rel.type === 'uses-evidence') of(rel.from).evidence.add(rel.to)
|
|
75
|
+
if (rel.type === 'renders-screen') of(rel.from).screens.add(rel.to)
|
|
76
|
+
if (rel.type === 'records-decision') of(rel.from).decisions.add(rel.to)
|
|
77
|
+
}
|
|
78
|
+
for (const journey of knowledge.journeys || []) {
|
|
79
|
+
for (const step of journey.steps || []) {
|
|
80
|
+
for (const id of step.evidenceIds || []) of(journey.id).evidence.add(id)
|
|
81
|
+
for (const id of step.screenIds || []) of(journey.id).screens.add(id)
|
|
82
|
+
for (const id of step.decisionIds || []) of(journey.id).decisions.add(id)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return links
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @param {object} knowledge from store.getKnowledge()
|
|
90
|
+
* @param {string} scenarioId the scenario for the new or changed journey
|
|
91
|
+
* @param {object} [options]
|
|
92
|
+
* @param {Array} [options.concerns] replaces STANDING_CONCERNS
|
|
93
|
+
*/
|
|
94
|
+
function checkConsequences (knowledge, scenarioId, { concerns = STANDING_CONCERNS } = {}) {
|
|
95
|
+
const scenarios = indexBy(knowledge.scenarios)
|
|
96
|
+
const scenario = scenarios.get(scenarioId)
|
|
97
|
+
if (!scenario) {
|
|
98
|
+
const known = [...scenarios.keys()]
|
|
99
|
+
throw new Error(`No scenario with id "${scenarioId}".` + (known.length ? ` Scenarios here: ${known.join(', ')}` : ' This knowledge base has no scenarios.'))
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const users = indexBy(knowledge.users)
|
|
103
|
+
const needs = indexBy(knowledge.needs)
|
|
104
|
+
const evidence = indexBy(knowledge.evidence)
|
|
105
|
+
const decisions = indexBy(knowledge.decisions)
|
|
106
|
+
const screens = indexBy(knowledge.screens)
|
|
107
|
+
const rounds = indexBy(knowledge.researchRounds)
|
|
108
|
+
const persona = scenario.userId
|
|
109
|
+
const personaLabel = users.get(persona)?.label || persona
|
|
110
|
+
|
|
111
|
+
// A need's evidence lives in its own evidenceIds and in supported-by rows;
|
|
112
|
+
// the insights that test it live only in tests-need rows. Read all three, so
|
|
113
|
+
// a knowledge base modelled either way has the same ground.
|
|
114
|
+
const insightById = indexBy(knowledge.insights)
|
|
115
|
+
const needEvidence = new Map()
|
|
116
|
+
const needInsights = new Map()
|
|
117
|
+
const addTo = (map, key, value) => {
|
|
118
|
+
if (!map.has(key)) map.set(key, new Set())
|
|
119
|
+
map.get(key).add(value)
|
|
120
|
+
}
|
|
121
|
+
for (const need of knowledge.needs || []) {
|
|
122
|
+
for (const id of need.evidenceIds || []) addTo(needEvidence, need.id, id)
|
|
123
|
+
}
|
|
124
|
+
for (const rel of knowledge.relationships || []) {
|
|
125
|
+
if (rel.type === 'supported-by' && needs.has(rel.from) && evidence.has(rel.to)) addTo(needEvidence, rel.from, rel.to)
|
|
126
|
+
if (rel.type === 'tests-need' && insightById.has(rel.from) && needs.has(rel.to)) addTo(needInsights, rel.to, rel.from)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// 1. The journey's own needs, and what they stand on: the evidence under them
|
|
130
|
+
// and the insights that test them. This is the ground. Insights matter as
|
|
131
|
+
// much as evidence: where each persona has its own evidence record, as on
|
|
132
|
+
// NCRS, evidence is almost never shared between users and the insights are
|
|
133
|
+
// the only common ground there is.
|
|
134
|
+
const ownNeeds = (scenario.needIds || []).map((id) => needs.get(id)).filter(Boolean)
|
|
135
|
+
const citedBy = new Map()
|
|
136
|
+
const testedBy = new Map()
|
|
137
|
+
for (const need of ownNeeds) {
|
|
138
|
+
for (const id of needEvidence.get(need.id) || []) {
|
|
139
|
+
if (!citedBy.has(id)) citedBy.set(id, [])
|
|
140
|
+
citedBy.get(id).push(need.id)
|
|
141
|
+
}
|
|
142
|
+
for (const id of needInsights.get(need.id) || []) {
|
|
143
|
+
if (!testedBy.has(id)) testedBy.set(id, [])
|
|
144
|
+
testedBy.get(id).push(need.id)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const ground = [...citedBy.entries()].map(([id, by]) => {
|
|
148
|
+
const record = evidence.get(id) || {}
|
|
149
|
+
return {
|
|
150
|
+
id,
|
|
151
|
+
label: record.title || id,
|
|
152
|
+
sourceType: record.sourceType || null,
|
|
153
|
+
confidence: record.confidence || null,
|
|
154
|
+
assertion: ASSERTION_TYPES.test(record.sourceType || ''),
|
|
155
|
+
citedBy: by
|
|
156
|
+
}
|
|
157
|
+
}).sort((a, b) => Number(b.assertion) - Number(a.assertion) || a.id.localeCompare(b.id))
|
|
158
|
+
const groundIds = new Set(citedBy.keys())
|
|
159
|
+
const groundInsightIds = new Set(testedBy.keys())
|
|
160
|
+
const groundInsights = [...testedBy.entries()].map(([id, by]) => {
|
|
161
|
+
const record = insightById.get(id) || {}
|
|
162
|
+
const round = rounds.get(record.roundId)
|
|
163
|
+
return {
|
|
164
|
+
id,
|
|
165
|
+
label: record.title || id,
|
|
166
|
+
confidence: record.confidence || null,
|
|
167
|
+
round: round ? { id: round.id, title: round.title, date: round.date } : null,
|
|
168
|
+
testsNeeds: by
|
|
169
|
+
}
|
|
170
|
+
}).sort((a, b) => a.id.localeCompare(b.id))
|
|
171
|
+
|
|
172
|
+
// 2. Other users' needs that stand on the same evidence or are tested by the
|
|
173
|
+
// same insights. These are the people the journey can hurt.
|
|
174
|
+
const reachedNeeds = new Map()
|
|
175
|
+
for (const need of knowledge.needs || []) {
|
|
176
|
+
if (need.userId === persona) continue
|
|
177
|
+
const shared = [
|
|
178
|
+
...[...(needEvidence.get(need.id) || [])].filter((id) => groundIds.has(id)),
|
|
179
|
+
...[...(needInsights.get(need.id) || [])].filter((id) => groundInsightIds.has(id))
|
|
180
|
+
].sort()
|
|
181
|
+
if (shared.length) reachedNeeds.set(need.id, { need, via: shared })
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// 3. Journeys already built on that ground, and what they carry: the decisions
|
|
185
|
+
// taken there and the screens they render.
|
|
186
|
+
const links = journeyLinks(knowledge)
|
|
187
|
+
const journeysOnGround = []
|
|
188
|
+
for (const [journeyId, link] of links) {
|
|
189
|
+
const shared = [...link.evidence].filter((id) => groundIds.has(id))
|
|
190
|
+
if (shared.length) journeysOnGround.push({ id: journeyId, via: shared, link })
|
|
191
|
+
}
|
|
192
|
+
const decisionVia = new Map()
|
|
193
|
+
const screensOnGround = new Map()
|
|
194
|
+
|
|
195
|
+
// Design actions responding to the ground's insights, and the decisions that
|
|
196
|
+
// resolve them. This is where most decisions live when research drives the
|
|
197
|
+
// design: a decision resolves an action, the action responds to an insight.
|
|
198
|
+
const actionInsights = new Map()
|
|
199
|
+
for (const action of knowledge.designActions || []) {
|
|
200
|
+
for (const id of action.insightIds || []) addTo(actionInsights, action.id, id)
|
|
201
|
+
}
|
|
202
|
+
const resolvedBy = new Map()
|
|
203
|
+
for (const rel of knowledge.relationships || []) {
|
|
204
|
+
if (rel.type === 'responds-to-insight') addTo(actionInsights, rel.from, rel.to)
|
|
205
|
+
if (rel.type === 'resolves-action') addTo(resolvedBy, rel.to, rel.from)
|
|
206
|
+
}
|
|
207
|
+
const actionsById = indexBy(knowledge.designActions)
|
|
208
|
+
const actionsOnGround = []
|
|
209
|
+
for (const [actionId, insightIds] of actionInsights) {
|
|
210
|
+
const via = [...insightIds].filter((id) => groundInsightIds.has(id)).sort()
|
|
211
|
+
if (!via.length || !actionsById.has(actionId)) continue
|
|
212
|
+
const record = actionsById.get(actionId)
|
|
213
|
+
actionsOnGround.push({ id: actionId, label: record.title, status: record.status || null, via })
|
|
214
|
+
for (const decisionId of resolvedBy.get(actionId) || []) {
|
|
215
|
+
if (!decisionVia.has(decisionId)) decisionVia.set(decisionId, new Set())
|
|
216
|
+
decisionVia.get(decisionId).add(actionId)
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
actionsOnGround.sort((a, b) => a.id.localeCompare(b.id))
|
|
220
|
+
|
|
221
|
+
for (const { id: journeyId, link } of journeysOnGround) {
|
|
222
|
+
for (const id of link.decisions) {
|
|
223
|
+
if (!decisionVia.has(id)) decisionVia.set(id, new Set())
|
|
224
|
+
decisionVia.get(id).add(journeyId)
|
|
225
|
+
}
|
|
226
|
+
for (const id of link.screens) {
|
|
227
|
+
if (!screensOnGround.has(id)) screensOnGround.set(id, new Set())
|
|
228
|
+
screensOnGround.get(id).add(journeyId)
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Screens are listed, not walked. A screen on this ground is where the new
|
|
233
|
+
// journey is likely to land, which matters to whoever builds it - but walking
|
|
234
|
+
// out from a screen to its needs reaches every user of a shared page and buries
|
|
235
|
+
// the few whose needs actually stand on this ground.
|
|
236
|
+
const screensBuilt = [...screensOnGround.entries()].map(([id, via]) => {
|
|
237
|
+
const record = screens.get(id) || {}
|
|
238
|
+
return { id, label: record.title || id, route: record.route || null, via: [...via].sort() }
|
|
239
|
+
}).sort((a, b) => a.id.localeCompare(b.id))
|
|
240
|
+
|
|
241
|
+
const priorityRank = { high: 0, medium: 1, low: 2 }
|
|
242
|
+
const byUser = new Map()
|
|
243
|
+
for (const { need, via } of reachedNeeds.values()) {
|
|
244
|
+
if (!byUser.has(need.userId)) byUser.set(need.userId, [])
|
|
245
|
+
byUser.get(need.userId).push({ id: need.id, label: need.statement, priority: need.priority, via })
|
|
246
|
+
}
|
|
247
|
+
const reaches = [...byUser.entries()].map(([userId, list]) => ({
|
|
248
|
+
userId,
|
|
249
|
+
label: users.get(userId)?.label || userId,
|
|
250
|
+
needs: list.sort((a, b) => (priorityRank[a.priority] ?? 3) - (priorityRank[b.priority] ?? 3) || a.id.localeCompare(b.id))
|
|
251
|
+
})).sort((a, b) => b.needs.length - a.needs.length || a.userId.localeCompare(b.userId))
|
|
252
|
+
|
|
253
|
+
const statusRank = { accepted: 0, proposed: 1, rejected: 2, superseded: 3 }
|
|
254
|
+
const decisionsOnGround = [...decisionVia.entries()].map(([id, via]) => {
|
|
255
|
+
const record = decisions.get(id) || {}
|
|
256
|
+
return { id, label: record.title || id, status: record.status || null, via: [...via].sort() }
|
|
257
|
+
}).sort((a, b) => (statusRank[a.status] ?? 4) - (statusRank[b.status] ?? 4) || a.id.localeCompare(b.id))
|
|
258
|
+
|
|
259
|
+
// 4. Weak ground: evidence that is an assertion or held at low confidence, and
|
|
260
|
+
// insights drawn from the ground that are not held at high confidence.
|
|
261
|
+
const weakEvidence = ground.filter((g) => g.assertion || g.confidence === 'low')
|
|
262
|
+
const weakInsights = (knowledge.insights || [])
|
|
263
|
+
.filter((insight) => insight.confidence !== 'high' &&
|
|
264
|
+
(groundInsightIds.has(insight.id) || (insight.evidenceIds || []).some((id) => groundIds.has(id))))
|
|
265
|
+
.map((insight) => {
|
|
266
|
+
const round = rounds.get(insight.roundId)
|
|
267
|
+
return {
|
|
268
|
+
id: insight.id,
|
|
269
|
+
label: insight.title,
|
|
270
|
+
confidence: insight.confidence,
|
|
271
|
+
round: round ? { id: round.id, title: round.title, date: round.date } : null
|
|
272
|
+
}
|
|
273
|
+
})
|
|
274
|
+
.sort((a, b) => (priorityRank[b.confidence] ?? 3) - (priorityRank[a.confidence] ?? 3) || a.id.localeCompare(b.id))
|
|
275
|
+
|
|
276
|
+
// Assumptions attached to the journey's own needs or to its ground - by any
|
|
277
|
+
// relationship row, or by a needIds list on the assumption. The skill tells
|
|
278
|
+
// people to record a missing-evidence gap as an assumption, so the check has
|
|
279
|
+
// to find the ones they record.
|
|
280
|
+
const touches = new Set([...ownNeeds.map((n) => n.id), ...groundIds, ...groundInsightIds])
|
|
281
|
+
const assumptionIds = new Set()
|
|
282
|
+
const assumptionsById = indexBy(knowledge.assumptions)
|
|
283
|
+
for (const rel of knowledge.relationships || []) {
|
|
284
|
+
if (assumptionsById.has(rel.from) && touches.has(rel.to)) assumptionIds.add(rel.from)
|
|
285
|
+
if (assumptionsById.has(rel.to) && touches.has(rel.from)) assumptionIds.add(rel.to)
|
|
286
|
+
}
|
|
287
|
+
for (const a of knowledge.assumptions || []) {
|
|
288
|
+
if ((a.needIds || []).some((id) => touches.has(id))) assumptionIds.add(a.id)
|
|
289
|
+
}
|
|
290
|
+
const weakAssumptions = [...assumptionIds].sort().map((id) => {
|
|
291
|
+
const a = assumptionsById.get(id)
|
|
292
|
+
return { id, label: a.statement, risk: a.risk || null }
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
// 5. Whether this kind of user has ever been in a research round. Matched on
|
|
296
|
+
// role names, so it is a heuristic, and is labelled as one.
|
|
297
|
+
// Only words that tell this role apart from the other users count: "safety"
|
|
298
|
+
// in "fire safety officer" must not match an "MRI safety officer".
|
|
299
|
+
const otherWords = new Set((knowledge.users || []).filter((u) => u.id !== persona).flatMap((u) => roleWords(u.label)))
|
|
300
|
+
const ownWords = roleWords(personaLabel)
|
|
301
|
+
const distinctive = ownWords.filter((w) => !otherWords.has(w))
|
|
302
|
+
const words = distinctive.length ? distinctive : ownWords
|
|
303
|
+
const participants = (knowledge.participants || []).filter((p) => {
|
|
304
|
+
const role = roleWords(p.role)
|
|
305
|
+
return words.some((w) => role.includes(w))
|
|
306
|
+
})
|
|
307
|
+
const personaRounds = [...new Set(participants.flatMap((p) => p.roundIds || []))]
|
|
308
|
+
.map((id) => rounds.get(id)).filter(Boolean)
|
|
309
|
+
.map((r) => ({ id: r.id, title: r.title, date: r.date }))
|
|
310
|
+
.sort((a, b) => `${a.date}`.localeCompare(`${b.date}`))
|
|
311
|
+
|
|
312
|
+
// 6. The standing concerns, checked by coverage across the whole knowledge base.
|
|
313
|
+
const concernResults = concerns.map((concern) => {
|
|
314
|
+
const known = whatsKnown(knowledge, concern.terms, { hops: 0 })
|
|
315
|
+
const namedBy = [
|
|
316
|
+
...known.design.map((d) => ({ id: d.id, label: d.label, kind: d.kind, status: d.status })),
|
|
317
|
+
...known.needs.map((n) => ({ id: n.id, label: n.label, kind: 'needs', status: null })),
|
|
318
|
+
...known.assumptions.map((a) => ({ id: a.id, label: a.label, kind: 'assumptions', status: null }))
|
|
319
|
+
]
|
|
320
|
+
return {
|
|
321
|
+
id: concern.id,
|
|
322
|
+
question: concern.question,
|
|
323
|
+
terms: concern.terms,
|
|
324
|
+
findings: known.findings.length,
|
|
325
|
+
roundsWithFindings: known.coverage.roundsWithFindings.length,
|
|
326
|
+
namedBy,
|
|
327
|
+
nobodyAsked: known.findings.length === 0 && namedBy.length === 0
|
|
328
|
+
}
|
|
329
|
+
})
|
|
330
|
+
|
|
331
|
+
return {
|
|
332
|
+
scenario: { id: scenario.id, title: scenario.title, userId: persona, userLabel: personaLabel, riskLevel: scenario.riskLevel || null },
|
|
333
|
+
persona: { id: persona, label: personaLabel, matchedOn: words, participants: participants.map((p) => ({ id: p.id, role: p.role })), rounds: personaRounds },
|
|
334
|
+
ownNeeds: ownNeeds.map((n) => ({ id: n.id, label: n.statement, priority: n.priority })),
|
|
335
|
+
ground,
|
|
336
|
+
groundInsights,
|
|
337
|
+
reaches,
|
|
338
|
+
designActions: actionsOnGround,
|
|
339
|
+
journeys: journeysOnGround.map((j) => ({ id: j.id, via: j.via })).sort((a, b) => a.id.localeCompare(b.id)),
|
|
340
|
+
screens: screensBuilt,
|
|
341
|
+
decisions: decisionsOnGround,
|
|
342
|
+
weakGround: { assumptions: weakAssumptions, evidence: weakEvidence, insights: weakInsights },
|
|
343
|
+
concerns: concernResults,
|
|
344
|
+
researchRounds: (knowledge.researchRounds || []).length
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
module.exports = { checkConsequences, STANDING_CONCERNS }
|