@indigoai-us/hq-cli 5.345.250 → 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.
- package/CHANGELOG.md +102 -0
- package/contracts/host-canary-release.json +3 -3
- package/dist/command-catalog.generated.d.ts +195 -1
- package/dist/command-catalog.generated.js +241 -1
- package/dist/commands/bot.js +5 -1
- package/dist/commands/lanes.d.ts +2 -0
- package/dist/commands/lanes.js +9 -4
- package/dist/commands/ontology-graph.d.ts +9 -2
- package/dist/commands/ontology-graph.js +97 -4
- package/dist/commands/sources.js +26 -8
- package/dist/lib/bot/fleet-cron.d.ts +2 -0
- package/dist/lib/bot/fleet-cron.js +5 -0
- package/dist/lib/hook-engine/coverage.d.ts +18 -7
- package/dist/lib/hook-engine/coverage.js +58 -20
- package/dist/lib/hook-engine/native-stop-compatibility.json +9 -4
- package/dist/lib/hot-channels/graph-context.d.ts +26 -1
- package/dist/lib/hot-channels/graph-context.js +76 -9
- package/dist/lib/hot-channels/run.d.ts +1 -0
- package/dist/lib/hot-channels/signals-pass.js +9 -4
- package/dist/lib/ontology-graph/model/files.d.ts +4 -0
- package/dist/lib/ontology-graph/model/files.js +23 -0
- package/dist/lib/ontology-graph/model/index.d.ts +11 -1
- package/dist/lib/ontology-graph/model/index.js +42 -18
- package/dist/lib/ontology-graph/model/pass-tasks.d.ts +9 -1
- package/dist/lib/ontology-graph/model/pass-tasks.js +7 -4
- package/dist/lib/ontology-graph/model/pass.d.ts +5 -0
- package/dist/lib/ontology-graph/model/pass.js +8 -8
- package/dist/lib/ontology-graph/model/pending-items.d.ts +31 -0
- package/dist/lib/ontology-graph/model/pending-items.js +113 -0
- package/dist/lib/ontology-graph/model/step.d.ts +46 -1
- package/dist/lib/ontology-graph/model/step.js +202 -36
- package/dist/lib/ontology-graph/model/tasks.d.ts +17 -1
- package/dist/lib/ontology-graph/model/tasks.js +28 -8
- package/dist/lib/ontology-graph/pages/render.d.ts +1 -1
- package/dist/lib/ontology-graph/pages/render.js +4 -3
- package/dist/lib/ontology-graph/read/brief.d.ts +13 -3
- package/dist/lib/ontology-graph/read/brief.js +311 -64
- package/dist/lib/ontology-graph/read/index.d.ts +1 -1
- package/dist/lib/ontology-graph/read/index.js +1 -1
- package/dist/lib/ontology-graph/read/reader-setting.d.ts +2 -0
- package/dist/lib/ontology-graph/read/reader-setting.js +4 -1
- package/dist/lib/ontology-graph/remodel/index.d.ts +174 -0
- package/dist/lib/ontology-graph/remodel/index.js +450 -0
- package/dist/lib/ontology-graph/replay/index.js +113 -7
- package/dist/lib/ontology-graph/schema/authority.d.ts +14 -5
- package/dist/lib/ontology-graph/schema/authority.js +13 -3
- package/dist/lib/ontology-graph/schema/index.d.ts +1 -1
- package/dist/lib/ontology-graph/schema/index.js +1 -1
- package/dist/lib/ontology-graph/setup/index.d.ts +88 -0
- package/dist/lib/ontology-graph/setup/index.js +489 -0
- package/dist/lib/ontology-graph/types.d.ts +21 -0
- package/dist/lib/ontology-graph/types.js +5 -0
- package/dist/lib/signals/failure-alert.js +4 -5
- package/dist/lib/signals/steps/adapters.js +3 -0
- package/dist/utils/sync-person.d.ts +15 -0
- package/dist/utils/sync-person.js +74 -0
- package/package.json +7 -7
|
@@ -12,6 +12,21 @@ function conf(value, fallback) {
|
|
|
12
12
|
return fallback;
|
|
13
13
|
return Math.min(1, Math.max(0, Math.round(n * 100) / 100));
|
|
14
14
|
}
|
|
15
|
+
/** Confidence an extraction falls back to when the model gave none it can use. Below the readers' unverified-guess line on purpose. */
|
|
16
|
+
export const DEFAULT_EXTRACTED_CONF = 0.6;
|
|
17
|
+
/**
|
|
18
|
+
* A confidence the model stated for one fact: a number from 0 to 1, kept to two
|
|
19
|
+
* decimals. Anything else (missing, text, not finite, outside the range) is not
|
|
20
|
+
* a statement of confidence and gets the default; a 7 is never read as 1.
|
|
21
|
+
*/
|
|
22
|
+
export function statedConf(value, fallback = DEFAULT_EXTRACTED_CONF) {
|
|
23
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1)
|
|
24
|
+
return fallback;
|
|
25
|
+
return Math.round(value * 100) / 100;
|
|
26
|
+
}
|
|
27
|
+
/** The rubric every extracting prompt gives for its confidence field, so the numbers mean the same thing across tasks. */
|
|
28
|
+
export const CONF_RUBRIC = "0.9 to 1 when the text says it outright in so many words; 0.7 to 0.85 when the text states it but you had to work out who or what is meant; " +
|
|
29
|
+
"0.4 to 0.65 when you inferred it (a signature, a passing mention, who was present, what someone seems to do). An inferred entry is still useful; an overstated one is not.";
|
|
15
30
|
function typeOf(ref) {
|
|
16
31
|
const parsed = parseEntityRef(ref);
|
|
17
32
|
if (!parsed)
|
|
@@ -163,11 +178,13 @@ export function extractSourcePrompt(schema) {
|
|
|
163
178
|
"Edges: {s: subject id, verb, o: object id}. Allowed verbs with subject types -> object types:",
|
|
164
179
|
JSON.stringify(vocab.verbs),
|
|
165
180
|
`Events: {e: entity id, type: one of ${EVENT_TYPES.join(", ")}, text: one line under 160 characters}. At most 6 per item.`,
|
|
181
|
+
`Every fact and every edge also carries \`conf\`, your confidence from 0 to 1: ${CONF_RUBRIC}`,
|
|
166
182
|
"Leave a list empty when the text states nothing of that kind. Do not restate the entity list.",
|
|
167
183
|
DATA_RULE,
|
|
168
|
-
'Reply shape: {"results":[{"id":"i1","facts":[{"e":"person/a","field":"role_title","value":"CTO","quote":"..."}],"edges":[{"s":"person/a","verb":"works_on","o":"project/b","quote":"..."}],"events":[{"e":"project/b","type":"decision","text":"...","quote":"..."}]}]}',
|
|
184
|
+
'Reply shape: {"results":[{"id":"i1","facts":[{"e":"person/a","field":"role_title","value":"CTO","quote":"...","conf":0.95}],"edges":[{"s":"person/a","verb":"works_on","o":"project/b","quote":"...","conf":0.6}],"events":[{"e":"project/b","type":"decision","text":"...","quote":"..."}]}]}',
|
|
169
185
|
].join("\n");
|
|
170
|
-
|
|
186
|
+
// v2: every fact and edge carries the model's own confidence (v1 stamped a flat 0.60).
|
|
187
|
+
return { prompt, promptVersion: `extract-source.v2+${sha256Hex(stableStringify(vocab)).slice(0, 8)}` };
|
|
171
188
|
}
|
|
172
189
|
function squash(text) {
|
|
173
190
|
return text.replace(/\s+/g, " ").trim().toLowerCase();
|
|
@@ -211,7 +228,7 @@ export function extractSourceSpec(schema, day) {
|
|
|
211
228
|
out.dropped += 1;
|
|
212
229
|
continue;
|
|
213
230
|
}
|
|
214
|
-
out.facts.push({ entity, field, value, quote });
|
|
231
|
+
out.facts.push({ entity, field, value, quote, conf: statedConf(fact.conf) });
|
|
215
232
|
}
|
|
216
233
|
for (const entry of raw.edges) {
|
|
217
234
|
const edge = entry && typeof entry === "object" ? entry : {};
|
|
@@ -223,7 +240,7 @@ export function extractSourceSpec(schema, day) {
|
|
|
223
240
|
out.dropped += 1;
|
|
224
241
|
continue;
|
|
225
242
|
}
|
|
226
|
-
out.edges.push({ subject, verb, target, quote });
|
|
243
|
+
out.edges.push({ subject, verb, target, quote, conf: statedConf(edge.conf) });
|
|
227
244
|
}
|
|
228
245
|
for (const entry of raw.events.slice(0, 6)) {
|
|
229
246
|
const event = entry && typeof entry === "object" ? entry : {};
|
|
@@ -246,17 +263,20 @@ export async function extractFromSources(step, schema, items, options) {
|
|
|
246
263
|
const sendable = items.filter((item) => isSourceRef(item.src) && item.entities.length > 0 && item.text.trim() !== "");
|
|
247
264
|
return step.runBatch(extractSourceSpec(schema, options.day), sendable);
|
|
248
265
|
}
|
|
249
|
-
/**
|
|
266
|
+
/**
|
|
267
|
+
* Forward rows for one extraction. Every row cites the source; `by` is `agent:<model>`. Each fact and
|
|
268
|
+
* edge keeps the confidence the model gave it; `stamp.conf` replaces them all when a caller sets it.
|
|
269
|
+
*/
|
|
250
270
|
export function extractionRows(extraction, stamp) {
|
|
251
271
|
const by = `agent:${stamp.model}`;
|
|
252
|
-
const
|
|
272
|
+
const confOf = (own) => stamp.conf ?? statedConf(own);
|
|
253
273
|
const rows = [];
|
|
254
274
|
for (const fact of extraction.facts) {
|
|
255
|
-
const row = { kind: "F", field: fact.field, value: fact.value, valid: { from: extraction.date }, src: extraction.src, learned: stamp.learned, by, conf:
|
|
275
|
+
const row = { kind: "F", field: fact.field, value: fact.value, valid: { from: extraction.date }, src: extraction.src, learned: stamp.learned, by, conf: confOf(fact.conf) };
|
|
256
276
|
rows.push({ entity: fact.entity, audience: stamp.audience, row });
|
|
257
277
|
}
|
|
258
278
|
for (const edge of extraction.edges) {
|
|
259
|
-
const row = { kind: "E", verb: edge.verb, target: edge.target, valid: { from: extraction.date }, src: extraction.src, learned: stamp.learned, by, conf:
|
|
279
|
+
const row = { kind: "E", verb: edge.verb, target: edge.target, valid: { from: extraction.date }, src: extraction.src, learned: stamp.learned, by, conf: confOf(edge.conf) };
|
|
260
280
|
rows.push({ entity: edge.subject, audience: stamp.audience, row });
|
|
261
281
|
}
|
|
262
282
|
for (const event of extraction.events) {
|
|
@@ -77,7 +77,7 @@ export interface PageModel {
|
|
|
77
77
|
};
|
|
78
78
|
/** Open legacy reference edges (`related_to`, `mentions`) left off the page. */
|
|
79
79
|
hiddenEdges: number;
|
|
80
|
-
/** Open role and affiliation facts a model wrote under the confidence line, left off the page. */
|
|
80
|
+
/** Open role and affiliation facts, and hierarchy relationships, a model wrote under the confidence line, left off the page. */
|
|
81
81
|
leftOutGuesses: number;
|
|
82
82
|
/** Closed F and E rows, hidden unless `showClosed`. */
|
|
83
83
|
closedHidden: number;
|
|
@@ -146,10 +146,11 @@ export function buildPageModel(schema, entity, storedRows, nameOf, limits = DEFA
|
|
|
146
146
|
unique.set(stored.id, stored);
|
|
147
147
|
}
|
|
148
148
|
// An open role or affiliation a model wrote at low confidence is left off the page before any winner or
|
|
149
|
-
// conflict is worked out, and counted in the frontmatter. Row counts still count every row.
|
|
150
|
-
//
|
|
149
|
+
// conflict is worked out, and counted in the frontmatter. Row counts still count every row. So is a
|
|
150
|
+
// model's low-confidence manager, report, team or lead. Employer relationships stay: a customer's
|
|
151
|
+
// contact list is built from model-written `employs` rows, and each line names who wrote it.
|
|
151
152
|
const everyRow = [...unique.values()];
|
|
152
|
-
const { rows, leftOut: leftOutGuesses } = dropUnverifiedGuesses(everyRow);
|
|
153
|
+
const { rows, leftOut: leftOutGuesses } = dropUnverifiedGuesses(everyRow, { edges: "hierarchy" });
|
|
153
154
|
const audiences = [...new Set(storedRows.map((stored) => stored.audience))].sort();
|
|
154
155
|
const type = entity.type;
|
|
155
156
|
const name = entity.canonical_name;
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import { type AudienceKey, type BriefOptions, type CommandOutput, type GraphContext, type GraphStore } from "../types.js";
|
|
1
|
+
import { type AudienceKey, type BriefOptions, type BriefStyle, type CommandOutput, type GraphContext, type GraphStore } from "../types.js";
|
|
2
2
|
export declare const BRIEF_MAX_TOKENS = 1500;
|
|
3
3
|
export declare const BRIEF_MAX_PROJECTS = 15;
|
|
4
4
|
export declare const BRIEF_MAX_CUSTOMERS = 8;
|
|
5
5
|
export declare const BRIEF_MAX_CHANGES = 12;
|
|
6
6
|
export declare const BRIEF_WINDOW_DAYS = 7;
|
|
7
|
+
export declare const BRIEF_DEFAULT_STYLE: BriefStyle;
|
|
8
|
+
/** Most names the map lists per kind before the token cap trims further. */
|
|
9
|
+
export declare const MAP_MAX_PROJECTS = 30;
|
|
10
|
+
export declare const MAP_MAX_CUSTOMERS = 15;
|
|
11
|
+
export declare const MAP_MAX_TEAMMATES = 30;
|
|
12
|
+
export declare const MAP_NAME_MAX_CHARS = 60;
|
|
7
13
|
/**
|
|
8
14
|
* Upper estimate of the token count. English prose runs near four characters
|
|
9
15
|
* a token; ids, dates and slugs run shorter, so three is used.
|
|
@@ -18,9 +24,13 @@ export interface BriefExtras {
|
|
|
18
24
|
store?: GraphStore;
|
|
19
25
|
/** Token cap. Default `BRIEF_MAX_TOKENS`; a caller may only lower it. */
|
|
20
26
|
maxTokens?: number;
|
|
27
|
+
/** `map` or `full`. Default: `brief_style` in the reader setting, else `map`. */
|
|
28
|
+
style?: BriefStyle;
|
|
21
29
|
}
|
|
22
|
-
/**
|
|
30
|
+
/** The style a brief is built in: the caller's, else the reader setting's `brief_style`, else `map`. */
|
|
31
|
+
export declare function resolveBriefStyle(hqRoot: string, asked?: BriefStyle): BriefStyle;
|
|
32
|
+
/** Builds the brief text in the asked style. Pure apart from reads through the store. No model call. */
|
|
23
33
|
export declare function buildBrief(context: GraphContext, extras?: BriefExtras): string;
|
|
24
|
-
/** `hq ontology brief`: writes brief.md (1,500 tokens max). */
|
|
34
|
+
/** `hq ontology brief [--style map|full]`: writes brief.md (1,500 tokens max). */
|
|
25
35
|
export declare function briefCommand(context: GraphContext, options: BriefOptions & BriefExtras): Promise<CommandOutput>;
|
|
26
36
|
//# sourceMappingURL=brief.d.ts.map
|
|
@@ -1,19 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* WP-E: `hq ontology brief` writes `brief.md`, the small
|
|
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
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* the
|
|
10
|
-
*
|
|
11
|
-
*
|
|
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 { isUnverifiedGuess, 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
|
-
|
|
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
|
-
|
|
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 =
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
-
|
|
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
|
|
150
|
-
|
|
151
|
-
.
|
|
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
|
|
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,8 +329,8 @@ export function buildBrief(context, extras = {}) {
|
|
|
201
329
|
continue;
|
|
202
330
|
if (!rowVisible(entry.a, filter) || entry.row.by === "legacy")
|
|
203
331
|
continue;
|
|
204
|
-
// A
|
|
205
|
-
if (isUnverifiedGuess(entry.row))
|
|
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))
|
|
206
334
|
continue;
|
|
207
335
|
if (entry.row.valid.from < cutoff || entry.row.valid.from > today)
|
|
208
336
|
continue;
|
|
@@ -217,7 +345,7 @@ export function buildBrief(context, extras = {}) {
|
|
|
217
345
|
if (sections.changes.length === 0)
|
|
218
346
|
sections.changes = [`- Nothing recorded since ${cutoff}.`];
|
|
219
347
|
// Fit the cap: drop the last line of the longest list until the text fits.
|
|
220
|
-
const cap =
|
|
348
|
+
const cap = frame.cap;
|
|
221
349
|
let text = render(sections);
|
|
222
350
|
while (estimateTokens(text) > cap) {
|
|
223
351
|
const lists = [sections.projects, sections.changes, sections.customers, sections.you].sort((a, b) => b.length - a.length);
|
|
@@ -231,7 +359,124 @@ export function buildBrief(context, extras = {}) {
|
|
|
231
359
|
text = `${text.slice(0, cap * 3 - 1)}\n`;
|
|
232
360
|
return text;
|
|
233
361
|
}
|
|
234
|
-
|
|
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). */
|
|
235
480
|
export async function briefCommand(context, options) {
|
|
236
481
|
if (!options.store && !graphExists(context.graphRoot)) {
|
|
237
482
|
return {
|
|
@@ -240,15 +485,17 @@ export async function briefCommand(context, options) {
|
|
|
240
485
|
exitCode: 1,
|
|
241
486
|
};
|
|
242
487
|
}
|
|
243
|
-
const
|
|
488
|
+
const style = resolveBriefStyle(context.hqRoot, options.style);
|
|
489
|
+
const text = buildBrief(context, { ...options, style });
|
|
244
490
|
const tokens = estimateTokens(text);
|
|
491
|
+
const size = { style, tokens, characters: text.length, cap: BRIEF_MAX_TOKENS };
|
|
245
492
|
if (options.stdout)
|
|
246
|
-
return { text, json: { status: "ok", written: false,
|
|
493
|
+
return { text, json: { status: "ok", written: false, ...size, brief: text } };
|
|
247
494
|
const file = graphPath(context.graphRoot, GRAPH_PATHS.brief);
|
|
248
495
|
atomicWriteFile(file, text);
|
|
249
496
|
return {
|
|
250
|
-
text: `wrote ${file} (about ${String(tokens)} tokens, cap ${String(BRIEF_MAX_TOKENS)})`,
|
|
251
|
-
json: { status: "ok", written: true, file,
|
|
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 },
|
|
252
499
|
};
|
|
253
500
|
}
|
|
254
501
|
//# sourceMappingURL=brief.js.map
|