@indigoai-us/hq-cli 5.345.248 → 5.345.251

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 (114) hide show
  1. package/CHANGELOG.md +143 -0
  2. package/contracts/host-canary-release.json +3 -3
  3. package/dist/command-catalog.generated.d.ts +288 -9
  4. package/dist/command-catalog.generated.js +355 -9
  5. package/dist/commands/bot.js +5 -1
  6. package/dist/commands/core-job-run-native.js +4 -0
  7. package/dist/commands/core-knowledge-prefs.d.ts +1 -1
  8. package/dist/commands/core-knowledge-prefs.js +1 -16
  9. package/dist/commands/core.js +0 -2
  10. package/dist/commands/daemon.js +21 -0
  11. package/dist/commands/lanes.d.ts +2 -0
  12. package/dist/commands/lanes.js +9 -4
  13. package/dist/commands/ontology-graph.d.ts +11 -3
  14. package/dist/commands/ontology-graph.js +138 -14
  15. package/dist/commands/sources.js +26 -8
  16. package/dist/commands/sync-core.js +6 -0
  17. package/dist/fast-scaffold.js +1 -3
  18. package/dist/hq-cloud-sync-runner/bin/sync-runner.js +281 -256
  19. package/dist/hq-cloud-sync-runner/package.json +1 -1
  20. package/dist/index.d.ts +8 -0
  21. package/dist/index.js +47 -0
  22. package/dist/lib/bot/fleet-cron.d.ts +2 -0
  23. package/dist/lib/bot/fleet-cron.js +5 -0
  24. package/dist/lib/daemon/installed-cli-restart.d.ts +57 -0
  25. package/dist/lib/daemon/installed-cli-restart.js +114 -0
  26. package/dist/lib/daemon/legacy-journal-gate.d.ts +32 -0
  27. package/dist/lib/daemon/legacy-journal-gate.js +102 -0
  28. package/dist/lib/daemon/machine-checks.d.ts +7 -0
  29. package/dist/lib/daemon/machine-checks.js +10 -0
  30. package/dist/lib/daemon/run.d.ts +3 -1
  31. package/dist/lib/daemon/run.js +48 -5
  32. package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
  33. package/dist/lib/flag-registry-worker-source.generated.js +1 -1
  34. package/dist/lib/hook-engine/coverage.d.ts +99 -19
  35. package/dist/lib/hook-engine/coverage.js +269 -35
  36. package/dist/lib/hook-engine/native-stop-compatibility.json +9 -4
  37. package/dist/lib/hook-engine/registration-identity.d.ts +5 -0
  38. package/dist/lib/hook-engine/registration-identity.js +1 -1
  39. package/dist/lib/hook-engine/resolve.d.ts +23 -0
  40. package/dist/lib/hook-engine/resolve.js +48 -1
  41. package/dist/lib/hook-engine/stable-heal.d.ts +87 -0
  42. package/dist/lib/hook-engine/stable-heal.js +214 -0
  43. package/dist/lib/hot-channels/graph-context.d.ts +26 -1
  44. package/dist/lib/hot-channels/graph-context.js +80 -10
  45. package/dist/lib/hot-channels/run.d.ts +1 -0
  46. package/dist/lib/hot-channels/signals-pass.js +9 -4
  47. package/dist/lib/ontology-graph/model/files.d.ts +4 -0
  48. package/dist/lib/ontology-graph/model/files.js +23 -0
  49. package/dist/lib/ontology-graph/model/index.d.ts +11 -1
  50. package/dist/lib/ontology-graph/model/index.js +42 -18
  51. package/dist/lib/ontology-graph/model/pass-tasks.d.ts +9 -1
  52. package/dist/lib/ontology-graph/model/pass-tasks.js +7 -4
  53. package/dist/lib/ontology-graph/model/pass.d.ts +5 -0
  54. package/dist/lib/ontology-graph/model/pass.js +8 -8
  55. package/dist/lib/ontology-graph/model/pending-items.d.ts +31 -0
  56. package/dist/lib/ontology-graph/model/pending-items.js +113 -0
  57. package/dist/lib/ontology-graph/model/step.d.ts +48 -1
  58. package/dist/lib/ontology-graph/model/step.js +205 -36
  59. package/dist/lib/ontology-graph/model/tasks.d.ts +17 -1
  60. package/dist/lib/ontology-graph/model/tasks.js +28 -8
  61. package/dist/lib/ontology-graph/org/derive.d.ts +2 -0
  62. package/dist/lib/ontology-graph/org/derive.js +9 -2
  63. package/dist/lib/ontology-graph/org/index.d.ts +35 -6
  64. package/dist/lib/ontology-graph/org/index.js +136 -19
  65. package/dist/lib/ontology-graph/org/text.d.ts +2 -0
  66. package/dist/lib/ontology-graph/org/text.js +6 -0
  67. package/dist/lib/ontology-graph/org/types.d.ts +5 -0
  68. package/dist/lib/ontology-graph/pages/render.d.ts +2 -0
  69. package/dist/lib/ontology-graph/pages/render.js +11 -4
  70. package/dist/lib/ontology-graph/read/brief.d.ts +13 -3
  71. package/dist/lib/ontology-graph/read/brief.js +312 -62
  72. package/dist/lib/ontology-graph/read/index.d.ts +1 -1
  73. package/dist/lib/ontology-graph/read/index.js +14 -3
  74. package/dist/lib/ontology-graph/read/names.d.ts +6 -1
  75. package/dist/lib/ontology-graph/read/names.js +8 -3
  76. package/dist/lib/ontology-graph/read/reader-setting.d.ts +2 -0
  77. package/dist/lib/ontology-graph/read/reader-setting.js +4 -1
  78. package/dist/lib/ontology-graph/remodel/index.d.ts +174 -0
  79. package/dist/lib/ontology-graph/remodel/index.js +450 -0
  80. package/dist/lib/ontology-graph/replay/engine.d.ts +47 -1
  81. package/dist/lib/ontology-graph/replay/engine.js +68 -2
  82. package/dist/lib/ontology-graph/replay/index.d.ts +2 -1
  83. package/dist/lib/ontology-graph/replay/index.js +114 -8
  84. package/dist/lib/ontology-graph/schema/authority.d.ts +43 -0
  85. package/dist/lib/ontology-graph/schema/authority.js +39 -0
  86. package/dist/lib/ontology-graph/schema/index.d.ts +1 -1
  87. package/dist/lib/ontology-graph/schema/index.js +1 -1
  88. package/dist/lib/ontology-graph/setup/index.d.ts +88 -0
  89. package/dist/lib/ontology-graph/setup/index.js +489 -0
  90. package/dist/lib/ontology-graph/types.d.ts +28 -0
  91. package/dist/lib/ontology-graph/types.js +5 -0
  92. package/dist/lib/signals/failure-alert.js +4 -5
  93. package/dist/lib/signals/steps/adapters.js +3 -0
  94. package/dist/lib/sync-core/engine-holds.d.ts +1 -1
  95. package/dist/lib/sync-core/engine-holds.js +12 -2
  96. package/dist/lib/sync-core/hand-back.d.ts +2 -1
  97. package/dist/lib/sync-core/hand-back.js +16 -2
  98. package/dist/lib/sync-core/legacy-journal-export-child.d.ts +2 -0
  99. package/dist/lib/sync-core/legacy-journal-export-child.js +24 -0
  100. package/dist/lib/sync-core/legacy-journal-export.d.ts +39 -0
  101. package/dist/lib/sync-core/legacy-journal-export.js +241 -0
  102. package/dist/lib/sync-core/legacy-journal-reader.d.ts +15 -0
  103. package/dist/lib/sync-core/legacy-journal-reader.js +56 -0
  104. package/dist/lib/sync-core/reconcile.d.ts +3 -0
  105. package/dist/lib/sync-core/reconcile.js +43 -3
  106. package/dist/utils/cli-telemetry.d.ts +1 -0
  107. package/dist/utils/cli-telemetry.js +6 -3
  108. package/dist/utils/hook-engine-rollup.d.ts +96 -0
  109. package/dist/utils/hook-engine-rollup.js +725 -0
  110. package/dist/utils/sync-person.d.ts +15 -0
  111. package/dist/utils/sync-person.js +74 -0
  112. package/package.json +8 -8
  113. package/scripts/install-hook-engine.mjs +4 -0
  114. package/assets/scaffold/core/scripts/knowledge-prefs.sh +0 -55
@@ -1,19 +1,30 @@
1
1
  /**
2
- * WP-E: `hq ontology brief` writes `brief.md`, the small summary a session
2
+ * WP-E: `hq ontology brief` writes `brief.md`, the small text a session
3
3
  * starts with (design 4.2). The SessionStart hook prints the file as is; it
4
4
  * never walks the graph, so everything a session should know up front is
5
- * decided here.
5
+ * decided here. No model is called.
6
6
  *
7
- * Sections: who the member is, their manager and teams; active projects with
8
- * owner and stage; top customers with stage; what changed in the last 7 days;
9
- * the four commands that return more. The text is kept under
10
- * `BRIEF_MAX_TOKENS` by a character estimate that overstates the count, and
11
- * by dropping list lines from the longest section until it fits.
7
+ * Two styles:
8
+ *
9
+ * - `map` (the default). What the graph holds, with a count per kind; the
10
+ * commands a session calls to look things up and when to use the graph or
11
+ * the vault; and names worth looking up (the member, active projects,
12
+ * customers, teammates), names only. It prints no fact: no role, stage,
13
+ * owner, team, reporting line or recent change. Those are behind `lookup`
14
+ * and `neighbors` (CONTRACT.md lists which command reaches each).
15
+ * - `full`. The earlier summary: who the member is and what they work on,
16
+ * active projects with owner and stage, the most active customers with
17
+ * stage, what changed in the last 7 days, the four commands.
18
+ *
19
+ * Both are kept under `BRIEF_MAX_TOKENS` by a character estimate that
20
+ * overstates the count, and by dropping the last entry of the longest list
21
+ * until the text fits. The order of the trim is fixed, so the same graph and
22
+ * the same day give the same text.
12
23
  */
13
- import { originTier } from "../schema/index.js";
24
+ import { GUESS_FIELDS, dropUnverifiedGuesses, effectiveFacts, isUnverifiedGuess, originTier } from "../schema/index.js";
14
25
  import { GRAPH_PATHS, atomicWriteFile, graphPath, openGraphStore } from "../store/index.js";
15
- import { COMPANY_AUDIENCE, } from "../types.js";
16
- import { graphExists, loadReadIndex, rowVisible, visible, } from "./graph-index.js";
26
+ import { BRIEF_STYLES, COMPANY_AUDIENCE, } from "../types.js";
27
+ import { graphExists, loadReadIndex, normalizeName, rowVisible, visible, } from "./graph-index.js";
17
28
  import { indexedFacts } from "./names.js";
18
29
  import { readReaderSetting } from "./reader-setting.js";
19
30
  export const BRIEF_MAX_TOKENS = 1500;
@@ -21,6 +32,12 @@ export const BRIEF_MAX_PROJECTS = 15;
21
32
  export const BRIEF_MAX_CUSTOMERS = 8;
22
33
  export const BRIEF_MAX_CHANGES = 12;
23
34
  export const BRIEF_WINDOW_DAYS = 7;
35
+ export const BRIEF_DEFAULT_STYLE = "map";
36
+ /** Most names the map lists per kind before the token cap trims further. */
37
+ export const MAP_MAX_PROJECTS = 30;
38
+ export const MAP_MAX_CUSTOMERS = 15;
39
+ export const MAP_MAX_TEAMMATES = 30;
40
+ export const MAP_NAME_MAX_CHARS = 60;
24
41
  /**
25
42
  * Upper estimate of the token count. English prose runs near four characters
26
43
  * a token; ids, dates and slugs run shorter, so three is used.
@@ -28,6 +45,12 @@ export const BRIEF_WINDOW_DAYS = 7;
28
45
  export function estimateTokens(text) {
29
46
  return Math.ceil(text.length / 3);
30
47
  }
48
+ /** The style a brief is built in: the caller's, else the reader setting's `brief_style`, else `map`. */
49
+ export function resolveBriefStyle(hqRoot, asked) {
50
+ if (asked !== undefined && BRIEF_STYLES.includes(asked))
51
+ return asked;
52
+ return readReaderSetting(hqRoot).briefStyle || BRIEF_DEFAULT_STYLE;
53
+ }
31
54
  const ENDED = /\b(done|complete|completed|shipped|archived|cancell?ed|closed|paused|dead|deprecated|abandoned|inactive|retired)\b/i;
32
55
  function clip(text, max) {
33
56
  const flat = text.replace(/\s+/g, " ").trim();
@@ -39,6 +62,45 @@ function isoDay(date) {
39
62
  function factValue(index, schema, entity, filter, field) {
40
63
  return indexedFacts(index, schema, entity, filter).find((stored) => stored.row.field === field)?.row.value ?? "";
41
64
  }
65
+ /**
66
+ * True for a role or an affiliation a model read out of a document, at any confidence. The brief prints a role
67
+ * with no source and no origin beside it, so it prints one only when a record, a rule, a person or the old
68
+ * entity files state it: one false sentence in a document a model read is never the member's role here.
69
+ * `lookup` and the pages still show a model's row at or above the confidence line, with its origin and source.
70
+ */
71
+ function modelReadRole(row) {
72
+ return row.kind === "F" && typeof row.by === "string" && row.by.startsWith("agent:") && GUESS_FIELDS.has(row.field ?? "");
73
+ }
74
+ /** The member's role as the brief prints it: the winner among the rows no model wrote. */
75
+ function establishedRole(index, schema, entity, filter) {
76
+ const position = index.byId.get(entity.id);
77
+ if (position === undefined)
78
+ return "";
79
+ const rows = [];
80
+ for (const at of index.factsOf.get(position) ?? []) {
81
+ const entry = index.facts[at];
82
+ if (entry && rowVisible(entry.a, filter) && !modelReadRole(entry.row))
83
+ rows.push({ id: entry.id, entity: entity.id, audience: entry.a, row: entry.row });
84
+ }
85
+ return effectiveFacts(schema, entity.type, rows).find((stored) => stored.row.field === "role_title")?.row.value ?? "";
86
+ }
87
+ /** True for a relationship a record wrote (a roster, a directory, a billing system), not a rule, a person or a model. */
88
+ function recordBacked(stored) {
89
+ return stored.row.by === "record";
90
+ }
91
+ /** The member's open role and affiliation rows a model wrote under the confidence line: left out of the brief. */
92
+ function memberFactGuesses(index, member, filter) {
93
+ const position = index.byId.get(member.id);
94
+ if (position === undefined)
95
+ return 0;
96
+ let count = 0;
97
+ for (const at of index.factsOf.get(position) ?? []) {
98
+ const entry = index.facts[at];
99
+ if (entry && rowVisible(entry.a, filter) && entry.row.valid.to === undefined && isUnverifiedGuess(entry.row))
100
+ count += 1;
101
+ }
102
+ return count;
103
+ }
42
104
  function openEdges(store, ref, filter) {
43
105
  const rows = store.readRows(ref, {
44
106
  kinds: ["E"],
@@ -77,16 +139,15 @@ function render(sections) {
77
139
  ...sections.head,
78
140
  ...block("You", sections.you),
79
141
  ...block("Active projects", sections.projects),
80
- ...block("Top customers", sections.customers),
142
+ // Ordered by activity in the graph. Nothing here knows revenue, so the heading does not say "top".
143
+ ...block("Most active customers", sections.customers),
81
144
  ...block(`Last ${String(BRIEF_WINDOW_DAYS)} days`, sections.changes),
82
145
  ...block("Ask the graph before answering about people, projects, customers or decisions", sections.commands),
83
146
  "",
84
147
  ].join("\n");
85
148
  }
86
- /** Builds the brief text. Pure apart from reads through the store. */
87
- export function buildBrief(context, extras = {}) {
149
+ function openFrame(context, extras) {
88
150
  const store = extras.store ?? openGraphStore(context.graphRoot, { company: context.company });
89
- const schema = store.schema();
90
151
  const index = loadReadIndex(context.graphRoot, { store });
91
152
  const filter = extras.audiences
92
153
  ? new Set(extras.audiences)
@@ -94,14 +155,89 @@ export function buildBrief(context, extras = {}) {
94
155
  ? new Set([COMPANY_AUDIENCE, ...context.member.audienceKeys])
95
156
  : null;
96
157
  const now = extras.now ?? new Date();
97
- const today = isoDay(now);
98
- const cutoff = isoDay(new Date(now.getTime() - BRIEF_WINDOW_DAYS * 86_400_000));
99
158
  const shown = index.entities.filter((entity) => visible(entity, filter));
159
+ return {
160
+ context,
161
+ extras,
162
+ store,
163
+ schema: store.schema(),
164
+ index,
165
+ filter,
166
+ now,
167
+ today: isoDay(now),
168
+ shown,
169
+ newest: shown.reduce((latest, entity) => (entity.last > latest ? entity.last : latest), ""),
170
+ cap: Math.min(BRIEF_MAX_TOKENS, extras.maxTokens ?? BRIEF_MAX_TOKENS),
171
+ };
172
+ }
173
+ /** Most recently touched first, then the entity with more rows, then id: the one order every list uses. */
174
+ function byActivity(a, b) {
175
+ return (a.last < b.last ? 1 : a.last > b.last ? -1 : b.rows - a.rows) || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
176
+ }
177
+ /** A raw Slack user id: U or W, then 8 to 11 capitals and digits with at least one digit (so no plain word). */
178
+ const SLACK_ID = /\b[UW](?=[A-Z0-9]*\d)[A-Z0-9]{8,11}\b/g;
179
+ const SLACK_ID_ONLY = /^[UW](?=[A-Z0-9]*\d)[A-Z0-9]{8,11}$/;
180
+ /**
181
+ * A name with each raw Slack user id replaced by the name of the one visible person who holds that id.
182
+ * `raw` is true when an id is still in the text: no visible person holds it, or that person has no name either.
183
+ */
184
+ function withNames(frame, text) {
185
+ let raw = false;
186
+ const named = text.replace(SLACK_ID, (id) => {
187
+ const holders = (frame.index.byKey.get(id.toLowerCase()) ?? [])
188
+ .map((position) => frame.index.entities[position])
189
+ .filter((entity) => entity !== undefined && entity.type === "person" && visible(entity, frame.filter));
190
+ const holder = holders.length === 1 ? holders[0] : undefined;
191
+ if (holder && !SLACK_ID_ONLY.test(holder.name.trim()))
192
+ return holder.name;
193
+ raw = true;
194
+ return id;
195
+ });
196
+ return { text: named, raw };
197
+ }
198
+ /** Projects with no ended status or stage, most recently touched first. */
199
+ function activeProjects(frame) {
200
+ const { index, schema, filter } = frame;
201
+ return frame.shown
202
+ .filter((entity) => entity.type === "project")
203
+ .map((entity) => ({
204
+ entity,
205
+ status: factValue(index, schema, entity, filter, "status"),
206
+ stage: factValue(index, schema, entity, filter, "stage"),
207
+ }))
208
+ .filter((entry) => !ENDED.test(entry.status) && !ENDED.test(entry.stage))
209
+ .sort((a, b) => byActivity(a.entity, b.entity));
210
+ }
211
+ /** Companies with a customer relation, most recently touched first. Activity in the graph, never revenue. */
212
+ function activeCustomers(frame) {
213
+ const { index, schema, filter } = frame;
214
+ return frame.shown
215
+ .filter((entity) => entity.type === "company")
216
+ .map((entity) => {
217
+ const facts = indexedFacts(index, schema, entity, filter);
218
+ return {
219
+ entity,
220
+ customer: facts.some((stored) => stored.row.field === "relation" && /customer/i.test(stored.row.value)),
221
+ stage: facts.find((stored) => stored.row.field === "stage")?.row.value ?? "",
222
+ crm: facts.find((stored) => stored.row.field === "crm_status")?.row.value ?? "",
223
+ };
224
+ })
225
+ .filter((entry) => entry.customer)
226
+ .sort((a, b) => byActivity(a.entity, b.entity));
227
+ }
228
+ /** Builds the brief text in the asked style. Pure apart from reads through the store. No model call. */
229
+ export function buildBrief(context, extras = {}) {
230
+ const frame = openFrame(context, extras);
231
+ return resolveBriefStyle(context.hqRoot, extras.style) === "full" ? buildFullBrief(frame) : buildMapBrief(frame);
232
+ }
233
+ /** The `full` style: the earlier summary, facts included. */
234
+ function buildFullBrief(frame) {
235
+ const { context, extras, store, schema, index, filter, now, today, shown, newest } = frame;
236
+ const cutoff = isoDay(new Date(now.getTime() - BRIEF_WINDOW_DAYS * 86_400_000));
100
237
  const label = (ref) => {
101
238
  const entity = index.entities[index.byId.get(ref) ?? -1];
102
- return entity && visible(entity, filter) ? `${clip(entity.name, 40)} (${ref})` : ref;
239
+ return entity && visible(entity, filter) ? `${clip(withNames(frame, entity.name).text, 40)} (${ref})` : ref;
103
240
  };
104
- const newest = shown.reduce((latest, entity) => (entity.last > latest ? entity.last : latest), "");
105
241
  const sections = {
106
242
  head: [
107
243
  `# Company graph brief: ${context.company}`,
@@ -122,67 +258,59 @@ export function buildBrief(context, extras = {}) {
122
258
  ],
123
259
  };
124
260
  // Who the member is.
261
+ let leftOutGuesses = 0;
125
262
  const member = findMember(context, index, filter, extras);
126
263
  if (member) {
127
- const role = factValue(index, schema, member, filter, "role_title");
128
- const edges = openEdges(store, member.id, filter);
129
- const targets = (verb, cap) => edges.filter((stored) => stored.row.verb === verb).slice(0, cap).map((stored) => label(stored.row.target));
130
- sections.you.push(`- ${member.name} (${member.id})${role ? `, ${clip(role, 60)}` : ""}`);
131
- const manager = targets("reports_to", 1);
132
- if (manager.length > 0)
133
- sections.you.push(`- Reports to: ${manager.join(", ")}`);
264
+ const role = establishedRole(index, schema, member, filter);
265
+ // A manager, report, team or lead a model wrote at low confidence is a guess: left out, counted below.
266
+ const kept = dropUnverifiedGuesses(openEdges(store, member.id, filter), { edges: true });
267
+ const edges = kept.rows;
268
+ leftOutGuesses += kept.leftOut + memberFactGuesses(index, member, filter);
269
+ const targets = (verb, cap, only = () => true) => edges.filter((stored) => stored.row.verb === verb && only(stored)).slice(0, cap).map((stored) => label(stored.row.target));
270
+ sections.you.push(`- ${withNames(frame, member.name).text} (${member.id})${role ? `, ${clip(role, 60)}` : ""}`);
271
+ // What the member does comes first: what they work on and own. Membership and lead lines follow.
272
+ const worksOn = targets("works_on", 4);
273
+ if (worksOn.length > 0)
274
+ sections.you.push(`- Works on: ${worksOn.join(", ")}`);
275
+ const owns = targets("owns", 4);
276
+ if (owns.length > 0)
277
+ sections.you.push(`- Owns: ${owns.join(", ")}`);
134
278
  const teams = targets("member_of", 3);
135
279
  if (teams.length > 0)
136
280
  sections.you.push(`- Teams: ${teams.join(", ")}`);
137
281
  const leads = targets("leads", 3);
138
282
  if (leads.length > 0)
139
283
  sections.you.push(`- Leads: ${leads.join(", ")}`);
140
- const reports = edges.filter((stored) => stored.row.verb === "manages");
284
+ // A reporting line is printed only when a record backs it. A rule's, a person's or a model's is not.
285
+ const manager = targets("reports_to", 1, recordBacked);
286
+ if (manager.length > 0)
287
+ sections.you.push(`- Reports to: ${manager.join(", ")}`);
288
+ const reports = edges.filter((stored) => stored.row.verb === "manages" && recordBacked(stored));
141
289
  if (reports.length > 0) {
142
290
  sections.you.push(`- Manages ${String(reports.length)}: ${reports.slice(0, 5).map((stored) => label(stored.row.target)).join(", ")}`);
143
291
  }
292
+ if (leftOutGuesses > 0) {
293
+ sections.you.push(`- Left out: ${String(leftOutGuesses)} unconfirmed model ${leftOutGuesses === 1 ? "guess" : "guesses"} at a role, team or reporting line. Read the sources.`);
294
+ }
144
295
  }
145
296
  else {
146
297
  sections.you.push("- Member not identified in the graph. Set `member: person/<slug>` in personal/settings/ontology-reader.yaml and run `hq ontology brief` again.");
147
298
  }
148
299
  // Active projects, most recently touched first.
149
- const projects = shown
150
- .filter((entity) => entity.type === "project")
151
- .map((entity) => ({
152
- entity,
153
- status: factValue(index, schema, entity, filter, "status"),
154
- stage: factValue(index, schema, entity, filter, "stage"),
155
- }))
156
- .filter((entry) => !ENDED.test(entry.status) && !ENDED.test(entry.stage))
157
- .sort((a, b) => (a.entity.last < b.entity.last ? 1 : a.entity.last > b.entity.last ? -1 : b.entity.rows - a.entity.rows))
158
- .slice(0, BRIEF_MAX_PROJECTS);
159
- for (const entry of projects) {
160
- const owner = openEdges(store, entry.entity.id, filter).find((stored) => stored.row.verb === "owned_by" || stored.row.verb === "led_by");
300
+ for (const entry of activeProjects(frame).slice(0, BRIEF_MAX_PROJECTS)) {
301
+ const ownerRows = dropUnverifiedGuesses(openEdges(store, entry.entity.id, filter), { edges: true });
302
+ const owner = ownerRows.rows.find((stored) => stored.row.verb === "owned_by" || stored.row.verb === "led_by");
161
303
  const parts = [
162
- `${clip(entry.entity.name, 48)} (${entry.entity.id})`,
304
+ `${clip(withNames(frame, entry.entity.name).text, 48)} (${entry.entity.id})`,
163
305
  ...(entry.stage ? [`stage ${clip(entry.stage, 24)}`] : entry.status ? [`status ${clip(entry.status, 24)}`] : []),
164
306
  ...(owner ? [`owner ${owner.row.target}`] : []),
165
307
  ];
166
308
  sections.projects.push(`- ${parts.join(" | ")}`);
167
309
  }
168
310
  // Customers.
169
- const customers = shown
170
- .filter((entity) => entity.type === "company")
171
- .map((entity) => {
172
- const facts = indexedFacts(index, schema, entity, filter);
173
- return {
174
- entity,
175
- customer: facts.some((stored) => stored.row.field === "relation" && /customer/i.test(stored.row.value)),
176
- stage: facts.find((stored) => stored.row.field === "stage")?.row.value ?? "",
177
- crm: facts.find((stored) => stored.row.field === "crm_status")?.row.value ?? "",
178
- };
179
- })
180
- .filter((entry) => entry.customer)
181
- .sort((a, b) => (a.entity.last < b.entity.last ? 1 : a.entity.last > b.entity.last ? -1 : b.entity.rows - a.entity.rows))
182
- .slice(0, BRIEF_MAX_CUSTOMERS);
183
- for (const entry of customers) {
311
+ for (const entry of activeCustomers(frame).slice(0, BRIEF_MAX_CUSTOMERS)) {
184
312
  const stage = entry.stage || entry.crm;
185
- sections.customers.push(`- ${clip(entry.entity.name, 48)} (${entry.entity.id})${stage ? ` | stage ${clip(stage, 24)}` : ""}`);
313
+ sections.customers.push(`- ${clip(withNames(frame, entry.entity.name).text, 48)} (${entry.entity.id})${stage ? ` | stage ${clip(stage, 24)}` : ""}`);
186
314
  }
187
315
  // What changed in the window: decisions first, then changed single-valued facts.
188
316
  const changes = [];
@@ -191,7 +319,7 @@ export function buildBrief(context, extras = {}) {
191
319
  continue;
192
320
  const day = factValue(index, schema, entity, filter, "decided_on") || entity.firstSeen;
193
321
  if (day >= cutoff && day <= today)
194
- changes.push({ day, line: `- ${day} decision: ${clip(entity.name, 90)} (${entity.id})` });
322
+ changes.push({ day, line: `- ${day} decision: ${clip(withNames(frame, entity.name).text, 90)} (${entity.id})` });
195
323
  }
196
324
  const decisions = changes.sort((a, b) => (a.day < b.day ? 1 : a.day > b.day ? -1 : 0)).slice(0, 8);
197
325
  const moved = [];
@@ -201,6 +329,9 @@ export function buildBrief(context, extras = {}) {
201
329
  continue;
202
330
  if (!rowVisible(entry.a, filter) || entry.row.by === "legacy")
203
331
  continue;
332
+ // A role or affiliation a model read is not reported as a change either, at any confidence.
333
+ if (isUnverifiedGuess(entry.row) || modelReadRole(entry.row))
334
+ continue;
204
335
  if (entry.row.valid.from < cutoff || entry.row.valid.from > today)
205
336
  continue;
206
337
  if (schema.entity_types[entity.type].facts[entry.row.field]?.cardinality !== "single")
@@ -214,7 +345,7 @@ export function buildBrief(context, extras = {}) {
214
345
  if (sections.changes.length === 0)
215
346
  sections.changes = [`- Nothing recorded since ${cutoff}.`];
216
347
  // Fit the cap: drop the last line of the longest list until the text fits.
217
- const cap = Math.min(BRIEF_MAX_TOKENS, extras.maxTokens ?? BRIEF_MAX_TOKENS);
348
+ const cap = frame.cap;
218
349
  let text = render(sections);
219
350
  while (estimateTokens(text) > cap) {
220
351
  const lists = [sections.projects, sections.changes, sections.customers, sections.you].sort((a, b) => b.length - a.length);
@@ -228,7 +359,124 @@ export function buildBrief(context, extras = {}) {
228
359
  text = `${text.slice(0, cap * 3 - 1)}\n`;
229
360
  return text;
230
361
  }
231
- /** `hq ontology brief`: writes brief.md (1,500 tokens max). */
362
+ // ---------------------------------------------------------------------------
363
+ // The `map` style
364
+ // ---------------------------------------------------------------------------
365
+ /** The company the graph belongs to: the one with an open `relation = self` fact, else `company/<slug>`. */
366
+ function selfCompany(frame) {
367
+ for (const entry of frame.index.facts) {
368
+ if (entry.row.field !== "relation" || entry.row.value !== "self" || entry.row.valid.to !== undefined)
369
+ continue;
370
+ const entity = frame.index.entities[entry.e];
371
+ if (entity && entity.type === "company" && rowVisible(entry.a, frame.filter))
372
+ return entity.id;
373
+ }
374
+ return `company/${frame.context.company}`;
375
+ }
376
+ /**
377
+ * The people who work at the company itself, most recently active first, without the member. An employer a
378
+ * model wrote under the confidence line is a guess and puts nobody on the list.
379
+ */
380
+ function teammates(frame, member) {
381
+ const self = selfCompany(frame);
382
+ return frame.shown
383
+ .filter((entity) => entity.type === "person" && entity.id !== member?.id)
384
+ .filter((entity) => dropUnverifiedGuesses(openEdges(frame.store, entity.id, frame.filter), { edges: true }).rows.some((stored) => stored.row.verb === "works_at" && stored.row.target === self))
385
+ .sort(byActivity);
386
+ }
387
+ /**
388
+ * Names for the recognition list: the name alone, no id and no detail. A raw Slack id is replaced by the
389
+ * person's name; an entity that has only a raw id for a name is left out. One entry per name.
390
+ */
391
+ function recognitionNames(frame, entities, max) {
392
+ const out = [];
393
+ const seen = new Set();
394
+ for (const entity of entities) {
395
+ if (out.length >= max)
396
+ break;
397
+ // A name stored as a wiki link, [[path|Label]] or [[Label]], is shown as its label.
398
+ const named = withNames(frame, entity.name.replace(/\[\[(?:[^\]|]*\|)?([^\]|]+)\]\]/g, "$1"));
399
+ if (named.raw)
400
+ continue;
401
+ // The list is joined with "; ", so a name keeps no semicolon of its own.
402
+ const text = clip(named.text.replace(/;/g, ","), MAP_NAME_MAX_CHARS);
403
+ const key = normalizeName(text);
404
+ if (key === "" || seen.has(key))
405
+ continue;
406
+ seen.add(key);
407
+ out.push(text);
408
+ }
409
+ return out;
410
+ }
411
+ function renderMap(frame, you, lists) {
412
+ const company = frame.context.company;
413
+ const counts = new Map();
414
+ for (const entity of frame.shown)
415
+ counts.set(entity.type, (counts.get(entity.type) ?? 0) + 1);
416
+ const kinds = [...counts.entries()]
417
+ .sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1))
418
+ .map(([type, count]) => `${type} ${String(count)}`)
419
+ .join(", ");
420
+ const list = (title, names) => (names.length > 0 ? [`- ${title}: ${names.join("; ")}`] : []);
421
+ return [
422
+ `# Company graph map: ${company}`,
423
+ `Generated ${frame.today}. This is a map of the company graph, not a summary. It states no fact about a person, project or customer: look a name up before you say anything about it.`,
424
+ "",
425
+ "## What the graph holds",
426
+ `- ${String(frame.shown.length)} entities; newest fact ${frame.newest || "none"}. By kind: ${kinds || "none"}.`,
427
+ "- Typed entities with dated facts and relationships; every fact and edge carries a source and a date. Ids look like `person/<slug>` or `project/<slug>`.",
428
+ "",
429
+ "## How to look things up",
430
+ `- \`hq ontology lookup "<name or id>" --company ${company}\`: one entity by name, id, email or Slack id: its current facts (role, status, stage), main relationships and latest dated lines.`,
431
+ `- \`hq ontology neighbors <id> [--verb V] --company ${company}\`: every relationship one step away from an id, grouped by verb; optional verb such as works_on, owns, member_of, leads, reports_to or owned_by.`,
432
+ `- \`hq ontology search "<words>" --company ${company}\`: entities by name, alias, identity key or fact text; use it when you only have a fragment.`,
433
+ `- \`hq ontology traverse <id> [<id>] [--verb V] [--depth 1-3] --company ${company}\`: follow relationships outward from an id, 1 to 3 steps; with a second id, the shortest path between the two.`,
434
+ `- \`hq ontology activity "<person>" --company ${company}\`: what a person does, from behavior in the graph: kinds of work, what they ship and own, who they work with. Inferred, never a confirmed fact.`,
435
+ `- \`hq ontology brief --style full --stdout --company ${company}\`: the earlier one-page summary: your role and projects, project stages and owners, customer stages, the last ${String(BRIEF_WINDOW_DAYS)} days of decisions and changes.`,
436
+ "",
437
+ "## Graph or vault",
438
+ "The graph is an index of the vault. It is not the record.",
439
+ "- Use the graph to orient and to find sources: it tells you which entity a name means, who and what it is tied to, and which files say so. Each line it prints ends with `file: <path>` when the source is a file on this machine.",
440
+ "- A lookup question asks for facts about one thing: who someone is, what was decided, where something stands, what changed. For a lookup question the vault is the record: after any graph call, search the vault on the words of the question itself before you answer.",
441
+ "- A relationship question asks how things are connected: who owns, leads or works on what, who reports to or works with whom. Start in the graph and stay with it: resolve every name to an entity id with lookup or search, follow the relationships with neighbors or traverse, then open the `file:` path behind each link you rely on and confirm it says so. If a source contradicts a link, the source wins.",
442
+ "- The graph lacking a fact is not evidence either way. If lookup says \"thin:\" or \"no match\", search the vault. If the sources do not state the answer, say it is not known; do not fill the gap with a related entity or a guess.",
443
+ "- \"ambiguous: ... Pick one id\" means the name matches several entities: choose an id from other context and say which you chose; never pick silently.",
444
+ "",
445
+ "## Names the graph knows",
446
+ "Names only, so you can tell a name is worth looking up. The list says nothing about who does what.",
447
+ `- You: ${you}`,
448
+ ...list("Active projects (most recently active first)", lists.projects),
449
+ ...list("Customers (most active in the graph first; activity, not revenue)", lists.customers),
450
+ ...list("Teammates (most active in the graph first)", lists.teammates),
451
+ "",
452
+ ].join("\n");
453
+ }
454
+ /** The `map` style: what the graph holds, how to look things up, and names worth looking up. No facts. */
455
+ function buildMapBrief(frame) {
456
+ const member = findMember(frame.context, frame.index, frame.filter, frame.extras);
457
+ const own = member ? withNames(frame, member.name) : null;
458
+ const you = own && !own.raw ? clip(own.text, MAP_NAME_MAX_CHARS) : "not identified. Set `member: person/<slug>` in personal/settings/ontology-reader.yaml.";
459
+ const lists = {
460
+ projects: recognitionNames(frame, activeProjects(frame).map((entry) => entry.entity), MAP_MAX_PROJECTS),
461
+ customers: recognitionNames(frame, activeCustomers(frame).map((entry) => entry.entity), MAP_MAX_CUSTOMERS),
462
+ teammates: recognitionNames(frame, teammates(frame, member), MAP_MAX_TEAMMATES),
463
+ };
464
+ // Fit the cap: drop the last name of the longest list until the text fits. On a tie the earlier list in
465
+ // this fixed order gives way first, so the same graph and day always trim the same way.
466
+ let text = renderMap(frame, you, lists);
467
+ while (estimateTokens(text) > frame.cap) {
468
+ const longest = [lists.projects, lists.teammates, lists.customers].reduce((a, b) => (b.length > a.length ? b : a));
469
+ if (longest.length === 0)
470
+ break;
471
+ longest.pop();
472
+ text = renderMap(frame, you, lists);
473
+ }
474
+ // A cap lower than the map's fixed part (the counts, the commands and the rules) cuts the text itself.
475
+ if (estimateTokens(text) > frame.cap)
476
+ text = `${text.slice(0, frame.cap * 3 - 1)}\n`;
477
+ return text;
478
+ }
479
+ /** `hq ontology brief [--style map|full]`: writes brief.md (1,500 tokens max). */
232
480
  export async function briefCommand(context, options) {
233
481
  if (!options.store && !graphExists(context.graphRoot)) {
234
482
  return {
@@ -237,15 +485,17 @@ export async function briefCommand(context, options) {
237
485
  exitCode: 1,
238
486
  };
239
487
  }
240
- const text = buildBrief(context, options);
488
+ const style = resolveBriefStyle(context.hqRoot, options.style);
489
+ const text = buildBrief(context, { ...options, style });
241
490
  const tokens = estimateTokens(text);
491
+ const size = { style, tokens, characters: text.length, cap: BRIEF_MAX_TOKENS };
242
492
  if (options.stdout)
243
- return { text, json: { status: "ok", written: false, tokens, brief: text } };
493
+ return { text, json: { status: "ok", written: false, ...size, brief: text } };
244
494
  const file = graphPath(context.graphRoot, GRAPH_PATHS.brief);
245
495
  atomicWriteFile(file, text);
246
496
  return {
247
- text: `wrote ${file} (about ${String(tokens)} tokens, cap ${String(BRIEF_MAX_TOKENS)})`,
248
- json: { status: "ok", written: true, file, tokens },
497
+ text: `wrote ${file} (${style} style, ${String(text.length)} characters, about ${String(tokens)} tokens, cap ${String(BRIEF_MAX_TOKENS)})`,
498
+ json: { status: "ok", written: true, file, ...size },
249
499
  };
250
500
  }
251
501
  //# sourceMappingURL=brief.js.map
@@ -1,6 +1,6 @@
1
1
  import { type AudienceKey, type CommandOutput, type GraphContext, type GraphStore, type LookupOptions, type NeighborsOptions, type Resolver, type SearchOptions, type TraverseOptions } from "../types.js";
2
2
  import { type AudienceFilter } from "./graph-index.js";
3
- export { briefCommand, buildBrief, estimateTokens, BRIEF_MAX_TOKENS } from "./brief.js";
3
+ export { briefCommand, buildBrief, estimateTokens, resolveBriefStyle, BRIEF_DEFAULT_STYLE, BRIEF_MAX_TOKENS } from "./brief.js";
4
4
  export type { BriefExtras } from "./brief.js";
5
5
  export { graphReaderEnabled, readReaderSetting, readerSettingFile } from "./reader-setting.js";
6
6
  export { loadReadIndex, forgetReadIndex, READ_INDEX_RELATIVE } from "./graph-index.js";
@@ -25,12 +25,12 @@
25
25
  import * as fs from "node:fs";
26
26
  import * as path from "node:path";
27
27
  import { filterPageLines } from "../pages/render.js";
28
- import { effectiveFacts, originTier } from "../schema/index.js";
28
+ import { dropUnverifiedGuesses, effectiveFacts, originTier, rowCoversDay } from "../schema/index.js";
29
29
  import { openGraphStore, pageFile } from "../store/index.js";
30
30
  import { COMPANY_AUDIENCE, } from "../types.js";
31
31
  import { graphExists, loadReadIndex, visible, } from "./graph-index.js";
32
32
  import { indexedFacts, resolveName, searchIndex } from "./names.js";
33
- export { briefCommand, buildBrief, estimateTokens, BRIEF_MAX_TOKENS } from "./brief.js";
33
+ export { briefCommand, buildBrief, estimateTokens, resolveBriefStyle, BRIEF_DEFAULT_STYLE, BRIEF_MAX_TOKENS } from "./brief.js";
34
34
  export { graphReaderEnabled, readReaderSetting, readerSettingFile } from "./reader-setting.js";
35
35
  export { loadReadIndex, forgetReadIndex, READ_INDEX_RELATIVE } from "./graph-index.js";
36
36
  export { resolveName, searchIndex } from "./names.js";
@@ -337,7 +337,14 @@ export async function lookupCommand(context, options) {
337
337
  const entity = answer.entity;
338
338
  if (options.page)
339
339
  return pageOutput(session, entity, answer);
340
- const rows = readRows(session, entity.id, options.asOf ? { asOf: options.asOf } : {});
340
+ const asOf = options.asOf;
341
+ // A role, an affiliation or an employer a model wrote at low confidence is a guess, not a fact. It is
342
+ // left out before the winner of a field is chosen, so it cannot hide an older established row, and counted below.
343
+ // Employer relationships are included here because lookup prints a relationship with no origin beside it.
344
+ const { rows, leftOut: guesses } = dropUnverifiedGuesses(readRows(session, entity.id, asOf ? { asOf } : {}), {
345
+ edges: true,
346
+ ...(asOf ? { live: (row) => rowCoversDay(row, asOf) } : {}),
347
+ });
341
348
  const facts = effectiveFacts(session.schema, entity.type, rows, options.asOf);
342
349
  const live = options.asOf ? visibleEdges(session, rows) : visibleEdges(session, rows).filter((stored) => !stored.row.valid.to);
343
350
  // Relationships only. Appearing in the same meeting or decision is counted below, not listed as an edge.
@@ -362,6 +369,9 @@ export async function lookupCommand(context, options) {
362
369
  else {
363
370
  lines.push("facts: none recorded");
364
371
  }
372
+ if (guesses > 0) {
373
+ lines.push(`left out: ${String(guesses)} unconfirmed model ${guesses === 1 ? "guess" : "guesses"} at a role or affiliation. The graph does not establish the role or employer; read the sources.`);
374
+ }
365
375
  if (shown.length > 0) {
366
376
  lines.push(`edges (${String(shown.length)} of ${String(edges.length)}):`);
367
377
  for (const stored of shown)
@@ -405,6 +415,7 @@ export async function lookupCommand(context, options) {
405
415
  recent: recent.map((stored) => ({ date: stored.row.date, type: stored.row.signalType, text: stored.row.text, src: stored.row.src, ...fileJson(session, stored.row.src), audience: stored.audience })),
406
416
  timelineTotal: timeline.length,
407
417
  thin,
418
+ ...(guesses > 0 ? { leftOutGuesses: guesses } : {}),
408
419
  },
409
420
  };
410
421
  }
@@ -39,6 +39,11 @@ export interface SearchIndexOptions {
39
39
  * somewhere on the entity (name, alias, key or one open fact) to count.
40
40
  */
41
41
  export declare function searchIndex(index: ReadIndex, _schema: GraphSchema, text: string, options: SearchIndexOptions): SearchHit[];
42
- /** The facts that answer "what is true" for one indexed entity, limited to the allowed audiences. */
42
+ /**
43
+ * The facts that answer "what is true" for one indexed entity, limited to the allowed audiences.
44
+ * A model's low-confidence guess at a role or affiliation is left out before the winner of a
45
+ * field is chosen, so every reader built on this (lookup's candidates, the brief, the signals
46
+ * graph context) shows the established row or nothing.
47
+ */
43
48
  export declare function indexedFacts(index: ReadIndex, schema: GraphSchema, entity: IndexedEntity, filter: AudienceFilter): StoredRow<FactRow>[];
44
49
  //# sourceMappingURL=names.d.ts.map
@@ -11,7 +11,7 @@
11
11
  * `searchIndex` is the keyword and fuzzy search over names, aliases, identity
12
12
  * keys and open facts.
13
13
  */
14
- import { effectiveFacts, isEntityRef, slugify } from "../schema/index.js";
14
+ import { dropUnverifiedGuesses, effectiveFacts, isEntityRef, slugify } from "../schema/index.js";
15
15
  import { createResolver } from "../resolve/index.js";
16
16
  import { GRAPH_ENTITY_TYPES, } from "../types.js";
17
17
  import { allKeys, normalizeName, rowVisible, visible, } from "./graph-index.js";
@@ -276,7 +276,12 @@ export function searchIndex(index, _schema, text, options) {
276
276
  .sort((a, b) => b.score - a.score || b.entity.rows - a.entity.rows || (a.entity.id < b.entity.id ? -1 : 1))
277
277
  .slice(0, limit);
278
278
  }
279
- /** The facts that answer "what is true" for one indexed entity, limited to the allowed audiences. */
279
+ /**
280
+ * The facts that answer "what is true" for one indexed entity, limited to the allowed audiences.
281
+ * A model's low-confidence guess at a role or affiliation is left out before the winner of a
282
+ * field is chosen, so every reader built on this (lookup's candidates, the brief, the signals
283
+ * graph context) shows the established row or nothing.
284
+ */
280
285
  export function indexedFacts(index, schema, entity, filter) {
281
286
  const position = index.byId.get(entity.id);
282
287
  if (position === undefined)
@@ -287,6 +292,6 @@ export function indexedFacts(index, schema, entity, filter) {
287
292
  if (entry && rowVisible(entry.a, filter))
288
293
  rows.push({ id: entry.id, entity: entity.id, audience: entry.a, row: entry.row });
289
294
  }
290
- return effectiveFacts(schema, entity.type, rows);
295
+ return effectiveFacts(schema, entity.type, dropUnverifiedGuesses(rows).rows);
291
296
  }
292
297
  //# sourceMappingURL=names.js.map
@@ -6,6 +6,8 @@ export interface ReaderSetting {
6
6
  company: string;
7
7
  /** `person/<slug>` of the member, or "" when absent. */
8
8
  member: string;
9
+ /** `map` or `full` when the file names one, else "" (the brief's default applies). */
10
+ briefStyle: "map" | "full" | "";
9
11
  /** False when the file is missing or unreadable (the default applies). */
10
12
  present: boolean;
11
13
  }
@@ -10,6 +10,7 @@
10
10
  * reader: entities # entities (old files) | graph (new graph)
11
11
  * company: indigo # company whose graph the session brief comes from
12
12
  * member: person/<slug> # optional: the member's own entity, for the brief
13
+ * brief_style: map # optional: map (default) | full, the shape `hq ontology brief` writes
13
14
  *
14
15
  * The file is parsed line by line on purpose: the hook reads it with shell
15
16
  * builtins and both readers must agree on what counts as a value.
@@ -17,7 +18,7 @@
17
18
  import * as fs from "node:fs";
18
19
  import * as path from "node:path";
19
20
  export const READER_SETTING_RELATIVE = "personal/settings/ontology-reader.yaml";
20
- const DEFAULT_SETTING = { reader: "entities", company: "", member: "", present: false };
21
+ const DEFAULT_SETTING = { reader: "entities", company: "", member: "", briefStyle: "", present: false };
21
22
  const MAX_SETTING_BYTES = 4096;
22
23
  export function readerSettingFile(hqRoot) {
23
24
  return path.join(hqRoot, ...READER_SETTING_RELATIVE.split("/"));
@@ -38,6 +39,8 @@ export function parseReaderSetting(text) {
38
39
  else if (key === "member") {
39
40
  out.member = /^person\/[a-z0-9][a-z0-9._-]*$/.test(value) && !value.includes("..") ? value : "";
40
41
  }
42
+ else if (key === "brief_style")
43
+ out.briefStyle = value === "map" || value === "full" ? value : "";
41
44
  }
42
45
  return out;
43
46
  }