@indigoai-us/hq-cli 5.345.250 → 5.345.252
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 +214 -0
- package/assets/scaffold/core/scripts/hq-session.sh +9 -0
- package/contracts/host-canary-release.json +9 -3
- package/dist/command-catalog.generated.d.ts +316 -2
- package/dist/command-catalog.generated.js +389 -2
- package/dist/commands/bot.js +12 -3
- package/dist/commands/core-bucket-c-work-mesh-offer-native.js +1 -1
- package/dist/commands/core-hq-session-binding.d.ts +140 -0
- package/dist/commands/core-hq-session-binding.js +363 -0
- package/dist/commands/core-hq-session-native.d.ts +23 -0
- package/dist/commands/core-hq-session-native.js +59 -9
- package/dist/commands/core-stop-autosave.js +1 -1
- package/dist/commands/core.js +10 -0
- package/dist/commands/doctor.d.ts +5 -1
- package/dist/commands/doctor.js +42 -5
- package/dist/commands/files.js +1 -1
- package/dist/commands/install-global.js +4 -2
- package/dist/commands/lanes.d.ts +2 -0
- package/dist/commands/lanes.js +9 -4
- package/dist/commands/logout.js +4 -0
- package/dist/commands/ontology-graph.d.ts +11 -2
- package/dist/commands/ontology-graph.js +130 -4
- package/dist/commands/report.js +35 -2
- package/dist/commands/sources.js +26 -8
- package/dist/commands/storage-gate.js +1 -1
- package/dist/commands/vault-retention-flag.js +2 -1
- package/dist/commands/whoami.js +1 -1
- package/dist/hq-cloud-sync-runner/bin/sync-runner.js +238 -221
- package/dist/hq-cloud-sync-runner/package.json +1 -1
- package/dist/index.js +3 -1
- package/dist/lib/agent-kit/inbox-poll-backoff-flag.js +1 -1
- package/dist/lib/agent-kit/mcp/tools.js +48 -0
- package/dist/lib/bot/fleet-bots-update-pass.js +1 -1
- package/dist/lib/bot/fleet-cron.d.ts +37 -0
- package/dist/lib/bot/fleet-cron.js +59 -12
- package/dist/lib/bot/fleet-local.d.ts +18 -0
- package/dist/lib/bot/fleet-local.js +51 -5
- package/dist/lib/bot/inbox-poll-backoff-flag.js +1 -1
- package/dist/lib/bot/signals-engine-flag.d.ts +1 -1
- package/dist/lib/bot/signals-engine-flag.js +1 -1
- package/dist/lib/cli-invite-nudge.js +1 -1
- package/dist/lib/client-version.d.ts +2 -0
- package/dist/lib/client-version.js +24 -0
- package/dist/lib/company-flag-gate.d.ts +30 -0
- package/dist/lib/company-flag-gate.js +104 -0
- package/dist/lib/core-utils/hook-timeout-debug-context-flag.js +1 -1
- package/dist/lib/daemon/flag.js +2 -1
- package/dist/lib/daemon/legacy-journal-gate.js +3 -1
- package/dist/lib/daemon/shared-flag-reads.js +1 -1
- package/dist/lib/doctor/checks/host-core.js +22 -4
- package/dist/lib/doctor/checks/jq.d.ts +27 -6
- package/dist/lib/doctor/checks/jq.js +46 -8
- package/dist/lib/doctor/client-health-reason-codes-flag.js +1 -1
- package/dist/lib/doctor/fix/refresh-sync-handoff.d.ts +1 -1
- package/dist/lib/doctor/fix/refresh-sync-handoff.js +1 -1
- package/dist/lib/flag-client-gate-headers.d.ts +38 -0
- package/dist/lib/flag-client-gate-headers.js +62 -0
- package/dist/lib/flag-client-headers.d.ts +15 -0
- package/dist/lib/flag-client-headers.js +25 -0
- package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
- package/dist/lib/flag-registry-worker-source.generated.js +1 -1
- package/dist/lib/flag-registry-worker.js +35 -0
- package/dist/lib/flag-registry.d.ts +1 -20
- package/dist/lib/flag-registry.js +5 -81
- package/dist/lib/hook-engine/adapter-core-pin.d.ts +29 -0
- package/dist/lib/hook-engine/adapter-core-pin.js +29 -0
- package/dist/lib/hook-engine/coverage.d.ts +68 -8
- package/dist/lib/hook-engine/coverage.js +167 -25
- package/dist/lib/hook-engine/native-stop-compatibility.json +9 -4
- package/dist/lib/hook-engine/reconcile.js +3 -2
- 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/prompts/signals-pass.md +20 -0
- package/dist/lib/hot-channels/run.d.ts +1 -0
- package/dist/lib/hot-channels/signal-changes.d.ts +228 -0
- package/dist/lib/hot-channels/signal-changes.js +683 -0
- package/dist/lib/hot-channels/signals-pass.d.ts +24 -0
- package/dist/lib/hot-channels/signals-pass.js +240 -15
- package/dist/lib/lanes/outpost-worktree-pruner-flag.d.ts +1 -1
- package/dist/lib/lanes/outpost-worktree-pruner-flag.js +1 -1
- package/dist/lib/lanes/registry-flag.js +2 -1
- package/dist/lib/lanes/spawn.js +11 -1
- package/dist/lib/mesh/live/binding-intent.d.ts +61 -0
- package/dist/lib/mesh/live/binding-intent.js +201 -0
- package/dist/lib/mesh/live/binding-receipt.d.ts +157 -0
- package/dist/lib/mesh/live/binding-receipt.js +365 -0
- package/dist/lib/mesh/live/company-flag-refresh.js +1 -1
- package/dist/lib/mesh/live/daemon/doctor-telemetry.d.ts +39 -0
- package/dist/lib/mesh/live/daemon/doctor-telemetry.js +58 -0
- package/dist/lib/mesh/live/daemon/install.js +2 -1
- package/dist/lib/mesh/live/daemon/presence.js +9 -0
- package/dist/lib/mesh/live/daemon/run.d.ts +3 -0
- package/dist/lib/mesh/live/daemon/run.js +33 -1
- package/dist/lib/ontology-graph/lineage/index.d.ts +401 -0
- package/dist/lib/ontology-graph/lineage/index.js +1027 -0
- 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 +65 -1
- package/dist/lib/ontology-graph/model/index.js +154 -18
- package/dist/lib/ontology-graph/model/pass-tasks.d.ts +84 -1
- package/dist/lib/ontology-graph/model/pass-tasks.js +173 -4
- package/dist/lib/ontology-graph/model/pass.d.ts +11 -0
- package/dist/lib/ontology-graph/model/pass.js +17 -10
- package/dist/lib/ontology-graph/model/pending-items.d.ts +39 -0
- package/dist/lib/ontology-graph/model/pending-items.js +136 -0
- package/dist/lib/ontology-graph/model/step.d.ts +47 -2
- package/dist/lib/ontology-graph/model/step.js +202 -36
- package/dist/lib/ontology-graph/model/tasks.d.ts +28 -4
- package/dist/lib/ontology-graph/model/tasks.js +48 -15
- 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 +349 -67
- package/dist/lib/ontology-graph/read/index.d.ts +5 -1
- package/dist/lib/ontology-graph/read/index.js +174 -30
- package/dist/lib/ontology-graph/read/lineage.d.ts +101 -0
- package/dist/lib/ontology-graph/read/lineage.js +262 -0
- 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/buffered-store.js +17 -0
- package/dist/lib/ontology-graph/replay/engine.d.ts +32 -1
- package/dist/lib/ontology-graph/replay/engine.js +213 -8
- package/dist/lib/ontology-graph/replay/extractors.d.ts +26 -0
- package/dist/lib/ontology-graph/replay/extractors.js +25 -1
- package/dist/lib/ontology-graph/replay/index.d.ts +2 -0
- package/dist/lib/ontology-graph/replay/index.js +120 -8
- package/dist/lib/ontology-graph/replay/signal-changes.d.ts +118 -0
- package/dist/lib/ontology-graph/replay/signal-changes.js +687 -0
- 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/decision-status.d.ts +18 -0
- package/dist/lib/ontology-graph/schema/decision-status.js +20 -0
- package/dist/lib/ontology-graph/schema/index.d.ts +2 -1
- package/dist/lib/ontology-graph/schema/index.js +2 -1
- package/dist/lib/ontology-graph/setup/index.d.ts +88 -0
- package/dist/lib/ontology-graph/setup/index.js +499 -0
- package/dist/lib/ontology-graph/types.d.ts +21 -0
- package/dist/lib/ontology-graph/types.js +5 -0
- package/dist/lib/search-index/index.d.ts +33 -1
- package/dist/lib/search-index/index.js +180 -25
- package/dist/lib/search-index/qmd-exit-diagnostics.d.ts +7 -0
- package/dist/lib/search-index/qmd-exit-diagnostics.js +25 -1
- package/dist/lib/signals/adapters-catalog.js +1 -1
- package/dist/lib/signals/failure-alert.js +4 -5
- package/dist/lib/signals/steps/adapters.js +3 -0
- package/dist/lib/sync-core/engine-holds.d.ts +1 -0
- package/dist/lib/sync-core/engine-holds.js +26 -0
- package/dist/lib/sync-core/engine-home.d.ts +3 -0
- package/dist/lib/sync-core/engine-home.js +41 -1
- package/dist/lib/sync-core/flag.js +2 -1
- package/dist/lib/sync-core/legacy-journal-export-child.js +5 -3
- package/dist/lib/sync-core/legacy-journal-export.d.ts +23 -4
- package/dist/lib/sync-core/legacy-journal-export.js +120 -55
- package/dist/lib/sync-core/reconcile.d.ts +2 -1
- package/dist/lib/sync-core/reconcile.js +30 -5
- package/dist/lib/sync-invalid-entity-warning.js +2 -1
- package/dist/lib/windows/install-followup.d.ts +41 -0
- package/dist/lib/windows/install-followup.js +87 -0
- package/dist/lib/windows/jq.d.ts +59 -0
- package/dist/lib/windows/jq.js +154 -3
- package/dist/lib/windows/user-path.d.ts +5 -0
- package/dist/lib/windows/user-path.js +1 -1
- package/dist/lib/work-context/auto-bind.d.ts +12 -0
- package/dist/lib/work-context/auto-bind.js +49 -3
- package/dist/lib/work-context/organize.d.ts +4 -2
- package/dist/lib/work-context/organize.js +18 -8
- package/dist/lib/work-context/reconcile.js +16 -1
- package/dist/main.js +12 -1
- package/dist/utils/client-health-contract.d.ts +30 -0
- package/dist/utils/client-health-contract.js +111 -0
- package/dist/utils/client-health.d.ts +5 -2
- package/dist/utils/client-health.js +74 -5
- package/dist/utils/exclusive-lock.d.ts +5 -1
- package/dist/utils/exclusive-lock.js +9 -2
- package/dist/utils/host-registration.d.ts +7 -0
- package/dist/utils/host-registration.js +10 -1
- package/dist/utils/pid.d.ts +31 -0
- package/dist/utils/pid.js +65 -0
- package/dist/utils/resident-package-preload.js +12 -4
- package/dist/utils/sentry-fingerprint.js +3 -0
- package/dist/utils/sync-person.d.ts +15 -0
- package/dist/utils/sync-person.js +74 -0
- package/package.json +8 -8
- package/scripts/install-hook-engine.mjs +5 -3
|
@@ -1,19 +1,35 @@
|
|
|
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. A stage, a
|
|
18
|
+
* status and an owner are printed with the day the row is valid from, and
|
|
19
|
+
* a decision that a later decision replaced ends with
|
|
20
|
+
* ` | replaced <date> by <id> [<by> <conf>]`, the origin and confidence
|
|
21
|
+
* of the edge that says so (see lineage.ts).
|
|
22
|
+
*
|
|
23
|
+
* Both are kept under `BRIEF_MAX_TOKENS` by a character estimate that
|
|
24
|
+
* overstates the count, and by dropping the last entry of the longest list
|
|
25
|
+
* until the text fits. The order of the trim is fixed, so the same graph and
|
|
26
|
+
* the same day give the same text.
|
|
12
27
|
*/
|
|
13
|
-
import { isUnverifiedGuess, originTier } from "../schema/index.js";
|
|
28
|
+
import { GUESS_FIELDS, dropUnverifiedGuesses, effectiveFacts, isUnverifiedGuess, originTier } from "../schema/index.js";
|
|
14
29
|
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";
|
|
30
|
+
import { BRIEF_STYLES, COMPANY_AUDIENCE, } from "../types.js";
|
|
31
|
+
import { graphExists, loadReadIndex, normalizeName, rowVisible, visible, } from "./graph-index.js";
|
|
32
|
+
import { decisionLineage, replacedMarker } from "./lineage.js";
|
|
17
33
|
import { indexedFacts } from "./names.js";
|
|
18
34
|
import { readReaderSetting } from "./reader-setting.js";
|
|
19
35
|
export const BRIEF_MAX_TOKENS = 1500;
|
|
@@ -21,6 +37,12 @@ export const BRIEF_MAX_PROJECTS = 15;
|
|
|
21
37
|
export const BRIEF_MAX_CUSTOMERS = 8;
|
|
22
38
|
export const BRIEF_MAX_CHANGES = 12;
|
|
23
39
|
export const BRIEF_WINDOW_DAYS = 7;
|
|
40
|
+
export const BRIEF_DEFAULT_STYLE = "map";
|
|
41
|
+
/** Most names the map lists per kind before the token cap trims further. */
|
|
42
|
+
export const MAP_MAX_PROJECTS = 30;
|
|
43
|
+
export const MAP_MAX_CUSTOMERS = 15;
|
|
44
|
+
export const MAP_MAX_TEAMMATES = 30;
|
|
45
|
+
export const MAP_NAME_MAX_CHARS = 60;
|
|
24
46
|
/**
|
|
25
47
|
* Upper estimate of the token count. English prose runs near four characters
|
|
26
48
|
* a token; ids, dates and slugs run shorter, so three is used.
|
|
@@ -28,6 +50,12 @@ export const BRIEF_WINDOW_DAYS = 7;
|
|
|
28
50
|
export function estimateTokens(text) {
|
|
29
51
|
return Math.ceil(text.length / 3);
|
|
30
52
|
}
|
|
53
|
+
/** The style a brief is built in: the caller's, else the reader setting's `brief_style`, else `map`. */
|
|
54
|
+
export function resolveBriefStyle(hqRoot, asked) {
|
|
55
|
+
if (asked !== undefined && BRIEF_STYLES.includes(asked))
|
|
56
|
+
return asked;
|
|
57
|
+
return readReaderSetting(hqRoot).briefStyle || BRIEF_DEFAULT_STYLE;
|
|
58
|
+
}
|
|
31
59
|
const ENDED = /\b(done|complete|completed|shipped|archived|cancell?ed|closed|paused|dead|deprecated|abandoned|inactive|retired)\b/i;
|
|
32
60
|
function clip(text, max) {
|
|
33
61
|
const flat = text.replace(/\s+/g, " ").trim();
|
|
@@ -39,6 +67,53 @@ function isoDay(date) {
|
|
|
39
67
|
function factValue(index, schema, entity, filter, field) {
|
|
40
68
|
return indexedFacts(index, schema, entity, filter).find((stored) => stored.row.field === field)?.row.value ?? "";
|
|
41
69
|
}
|
|
70
|
+
/** The day the winning row of a field is valid from, or "". */
|
|
71
|
+
function factDay(index, schema, entity, filter, field) {
|
|
72
|
+
return indexedFacts(index, schema, entity, filter).find((stored) => stored.row.field === field)?.row.valid.from ?? "";
|
|
73
|
+
}
|
|
74
|
+
/** ` [<day>]` after a value, or nothing when the row has no day. */
|
|
75
|
+
function dayNote(day) {
|
|
76
|
+
return day ? ` [${day}]` : "";
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* True for a role or an affiliation a model read out of a document, at any confidence. The brief prints a role
|
|
80
|
+
* with no source and no origin beside it, so it prints one only when a record, a rule, a person or the old
|
|
81
|
+
* entity files state it: one false sentence in a document a model read is never the member's role here.
|
|
82
|
+
* `lookup` and the pages still show a model's row at or above the confidence line, with its origin and source.
|
|
83
|
+
*/
|
|
84
|
+
function modelReadRole(row) {
|
|
85
|
+
return row.kind === "F" && typeof row.by === "string" && row.by.startsWith("agent:") && GUESS_FIELDS.has(row.field ?? "");
|
|
86
|
+
}
|
|
87
|
+
/** The member's role as the brief prints it: the winner among the rows no model wrote. */
|
|
88
|
+
function establishedRole(index, schema, entity, filter) {
|
|
89
|
+
const position = index.byId.get(entity.id);
|
|
90
|
+
if (position === undefined)
|
|
91
|
+
return "";
|
|
92
|
+
const rows = [];
|
|
93
|
+
for (const at of index.factsOf.get(position) ?? []) {
|
|
94
|
+
const entry = index.facts[at];
|
|
95
|
+
if (entry && rowVisible(entry.a, filter) && !modelReadRole(entry.row))
|
|
96
|
+
rows.push({ id: entry.id, entity: entity.id, audience: entry.a, row: entry.row });
|
|
97
|
+
}
|
|
98
|
+
return effectiveFacts(schema, entity.type, rows).find((stored) => stored.row.field === "role_title")?.row.value ?? "";
|
|
99
|
+
}
|
|
100
|
+
/** True for a relationship a record wrote (a roster, a directory, a billing system), not a rule, a person or a model. */
|
|
101
|
+
function recordBacked(stored) {
|
|
102
|
+
return stored.row.by === "record";
|
|
103
|
+
}
|
|
104
|
+
/** The member's open role and affiliation rows a model wrote under the confidence line: left out of the brief. */
|
|
105
|
+
function memberFactGuesses(index, member, filter) {
|
|
106
|
+
const position = index.byId.get(member.id);
|
|
107
|
+
if (position === undefined)
|
|
108
|
+
return 0;
|
|
109
|
+
let count = 0;
|
|
110
|
+
for (const at of index.factsOf.get(position) ?? []) {
|
|
111
|
+
const entry = index.facts[at];
|
|
112
|
+
if (entry && rowVisible(entry.a, filter) && entry.row.valid.to === undefined && isUnverifiedGuess(entry.row))
|
|
113
|
+
count += 1;
|
|
114
|
+
}
|
|
115
|
+
return count;
|
|
116
|
+
}
|
|
42
117
|
function openEdges(store, ref, filter) {
|
|
43
118
|
const rows = store.readRows(ref, {
|
|
44
119
|
kinds: ["E"],
|
|
@@ -77,16 +152,15 @@ function render(sections) {
|
|
|
77
152
|
...sections.head,
|
|
78
153
|
...block("You", sections.you),
|
|
79
154
|
...block("Active projects", sections.projects),
|
|
80
|
-
|
|
155
|
+
// Ordered by activity in the graph. Nothing here knows revenue, so the heading does not say "top".
|
|
156
|
+
...block("Most active customers", sections.customers),
|
|
81
157
|
...block(`Last ${String(BRIEF_WINDOW_DAYS)} days`, sections.changes),
|
|
82
158
|
...block("Ask the graph before answering about people, projects, customers or decisions", sections.commands),
|
|
83
159
|
"",
|
|
84
160
|
].join("\n");
|
|
85
161
|
}
|
|
86
|
-
|
|
87
|
-
export function buildBrief(context, extras = {}) {
|
|
162
|
+
function openFrame(context, extras) {
|
|
88
163
|
const store = extras.store ?? openGraphStore(context.graphRoot, { company: context.company });
|
|
89
|
-
const schema = store.schema();
|
|
90
164
|
const index = loadReadIndex(context.graphRoot, { store });
|
|
91
165
|
const filter = extras.audiences
|
|
92
166
|
? new Set(extras.audiences)
|
|
@@ -94,14 +168,93 @@ export function buildBrief(context, extras = {}) {
|
|
|
94
168
|
? new Set([COMPANY_AUDIENCE, ...context.member.audienceKeys])
|
|
95
169
|
: null;
|
|
96
170
|
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
171
|
const shown = index.entities.filter((entity) => visible(entity, filter));
|
|
172
|
+
return {
|
|
173
|
+
context,
|
|
174
|
+
extras,
|
|
175
|
+
store,
|
|
176
|
+
schema: store.schema(),
|
|
177
|
+
index,
|
|
178
|
+
filter,
|
|
179
|
+
now,
|
|
180
|
+
today: isoDay(now),
|
|
181
|
+
shown,
|
|
182
|
+
newest: shown.reduce((latest, entity) => (entity.last > latest ? entity.last : latest), ""),
|
|
183
|
+
cap: Math.min(BRIEF_MAX_TOKENS, extras.maxTokens ?? BRIEF_MAX_TOKENS),
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/** Most recently touched first, then the entity with more rows, then id: the one order every list uses. */
|
|
187
|
+
function byActivity(a, b) {
|
|
188
|
+
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);
|
|
189
|
+
}
|
|
190
|
+
/** A raw Slack user id: U or W, then 8 to 11 capitals and digits with at least one digit (so no plain word). */
|
|
191
|
+
const SLACK_ID = /\b[UW](?=[A-Z0-9]*\d)[A-Z0-9]{8,11}\b/g;
|
|
192
|
+
const SLACK_ID_ONLY = /^[UW](?=[A-Z0-9]*\d)[A-Z0-9]{8,11}$/;
|
|
193
|
+
/**
|
|
194
|
+
* A name with each raw Slack user id replaced by the name of the one visible person who holds that id.
|
|
195
|
+
* `raw` is true when an id is still in the text: no visible person holds it, or that person has no name either.
|
|
196
|
+
*/
|
|
197
|
+
function withNames(frame, text) {
|
|
198
|
+
let raw = false;
|
|
199
|
+
const named = text.replace(SLACK_ID, (id) => {
|
|
200
|
+
const holders = (frame.index.byKey.get(id.toLowerCase()) ?? [])
|
|
201
|
+
.map((position) => frame.index.entities[position])
|
|
202
|
+
.filter((entity) => entity !== undefined && entity.type === "person" && visible(entity, frame.filter));
|
|
203
|
+
const holder = holders.length === 1 ? holders[0] : undefined;
|
|
204
|
+
if (holder && !SLACK_ID_ONLY.test(holder.name.trim()))
|
|
205
|
+
return holder.name;
|
|
206
|
+
raw = true;
|
|
207
|
+
return id;
|
|
208
|
+
});
|
|
209
|
+
return { text: named, raw };
|
|
210
|
+
}
|
|
211
|
+
/** Projects with no ended status or stage, most recently touched first. */
|
|
212
|
+
function activeProjects(frame) {
|
|
213
|
+
const { index, schema, filter } = frame;
|
|
214
|
+
return frame.shown
|
|
215
|
+
.filter((entity) => entity.type === "project")
|
|
216
|
+
.map((entity) => ({
|
|
217
|
+
entity,
|
|
218
|
+
status: factValue(index, schema, entity, filter, "status"),
|
|
219
|
+
stage: factValue(index, schema, entity, filter, "stage"),
|
|
220
|
+
statusDay: factDay(index, schema, entity, filter, "status"),
|
|
221
|
+
stageDay: factDay(index, schema, entity, filter, "stage"),
|
|
222
|
+
}))
|
|
223
|
+
.filter((entry) => !ENDED.test(entry.status) && !ENDED.test(entry.stage))
|
|
224
|
+
.sort((a, b) => byActivity(a.entity, b.entity));
|
|
225
|
+
}
|
|
226
|
+
/** Companies with a customer relation, most recently touched first. Activity in the graph, never revenue. */
|
|
227
|
+
function activeCustomers(frame) {
|
|
228
|
+
const { index, schema, filter } = frame;
|
|
229
|
+
return frame.shown
|
|
230
|
+
.filter((entity) => entity.type === "company")
|
|
231
|
+
.map((entity) => {
|
|
232
|
+
const facts = indexedFacts(index, schema, entity, filter);
|
|
233
|
+
return {
|
|
234
|
+
entity,
|
|
235
|
+
customer: facts.some((stored) => stored.row.field === "relation" && /customer/i.test(stored.row.value)),
|
|
236
|
+
stage: facts.find((stored) => stored.row.field === "stage")?.row.value ?? "",
|
|
237
|
+
crm: facts.find((stored) => stored.row.field === "crm_status")?.row.value ?? "",
|
|
238
|
+
stageDay: facts.find((stored) => stored.row.field === "stage")?.row.valid.from ?? "",
|
|
239
|
+
crmDay: facts.find((stored) => stored.row.field === "crm_status")?.row.valid.from ?? "",
|
|
240
|
+
};
|
|
241
|
+
})
|
|
242
|
+
.filter((entry) => entry.customer)
|
|
243
|
+
.sort((a, b) => byActivity(a.entity, b.entity));
|
|
244
|
+
}
|
|
245
|
+
/** Builds the brief text in the asked style. Pure apart from reads through the store. No model call. */
|
|
246
|
+
export function buildBrief(context, extras = {}) {
|
|
247
|
+
const frame = openFrame(context, extras);
|
|
248
|
+
return resolveBriefStyle(context.hqRoot, extras.style) === "full" ? buildFullBrief(frame) : buildMapBrief(frame);
|
|
249
|
+
}
|
|
250
|
+
/** The `full` style: the earlier summary, facts included. */
|
|
251
|
+
function buildFullBrief(frame) {
|
|
252
|
+
const { context, extras, store, schema, index, filter, now, today, shown, newest } = frame;
|
|
253
|
+
const cutoff = isoDay(new Date(now.getTime() - BRIEF_WINDOW_DAYS * 86_400_000));
|
|
100
254
|
const label = (ref) => {
|
|
101
255
|
const entity = index.entities[index.byId.get(ref) ?? -1];
|
|
102
|
-
return entity && visible(entity, filter) ? `${clip(entity.name, 40)} (${ref})` : ref;
|
|
256
|
+
return entity && visible(entity, filter) ? `${clip(withNames(frame, entity.name).text, 40)} (${ref})` : ref;
|
|
103
257
|
};
|
|
104
|
-
const newest = shown.reduce((latest, entity) => (entity.last > latest ? entity.last : latest), "");
|
|
105
258
|
const sections = {
|
|
106
259
|
head: [
|
|
107
260
|
`# Company graph brief: ${context.company}`,
|
|
@@ -122,67 +275,60 @@ export function buildBrief(context, extras = {}) {
|
|
|
122
275
|
],
|
|
123
276
|
};
|
|
124
277
|
// Who the member is.
|
|
278
|
+
let leftOutGuesses = 0;
|
|
125
279
|
const member = findMember(context, index, filter, extras);
|
|
126
280
|
if (member) {
|
|
127
|
-
const role =
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
281
|
+
const role = establishedRole(index, schema, member, filter);
|
|
282
|
+
// A manager, report, team or lead a model wrote at low confidence is a guess: left out, counted below.
|
|
283
|
+
const kept = dropUnverifiedGuesses(openEdges(store, member.id, filter), { edges: true });
|
|
284
|
+
const edges = kept.rows;
|
|
285
|
+
leftOutGuesses += kept.leftOut + memberFactGuesses(index, member, filter);
|
|
286
|
+
const targets = (verb, cap, only = () => true) => edges.filter((stored) => stored.row.verb === verb && only(stored)).slice(0, cap).map((stored) => label(stored.row.target));
|
|
287
|
+
sections.you.push(`- ${withNames(frame, member.name).text} (${member.id})${role ? `, ${clip(role, 60)}` : ""}`);
|
|
288
|
+
// What the member does comes first: what they work on and own. Membership and lead lines follow.
|
|
289
|
+
const worksOn = targets("works_on", 4);
|
|
290
|
+
if (worksOn.length > 0)
|
|
291
|
+
sections.you.push(`- Works on: ${worksOn.join(", ")}`);
|
|
292
|
+
const owns = targets("owns", 4);
|
|
293
|
+
if (owns.length > 0)
|
|
294
|
+
sections.you.push(`- Owns: ${owns.join(", ")}`);
|
|
134
295
|
const teams = targets("member_of", 3);
|
|
135
296
|
if (teams.length > 0)
|
|
136
297
|
sections.you.push(`- Teams: ${teams.join(", ")}`);
|
|
137
298
|
const leads = targets("leads", 3);
|
|
138
299
|
if (leads.length > 0)
|
|
139
300
|
sections.you.push(`- Leads: ${leads.join(", ")}`);
|
|
140
|
-
|
|
301
|
+
// A reporting line is printed only when a record backs it. A rule's, a person's or a model's is not.
|
|
302
|
+
const manager = targets("reports_to", 1, recordBacked);
|
|
303
|
+
if (manager.length > 0)
|
|
304
|
+
sections.you.push(`- Reports to: ${manager.join(", ")}`);
|
|
305
|
+
const reports = edges.filter((stored) => stored.row.verb === "manages" && recordBacked(stored));
|
|
141
306
|
if (reports.length > 0) {
|
|
142
307
|
sections.you.push(`- Manages ${String(reports.length)}: ${reports.slice(0, 5).map((stored) => label(stored.row.target)).join(", ")}`);
|
|
143
308
|
}
|
|
309
|
+
if (leftOutGuesses > 0) {
|
|
310
|
+
sections.you.push(`- Left out: ${String(leftOutGuesses)} unconfirmed model ${leftOutGuesses === 1 ? "guess" : "guesses"} at a role, team or reporting line. Read the sources.`);
|
|
311
|
+
}
|
|
144
312
|
}
|
|
145
313
|
else {
|
|
146
314
|
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
315
|
}
|
|
148
316
|
// 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");
|
|
317
|
+
for (const entry of activeProjects(frame).slice(0, BRIEF_MAX_PROJECTS)) {
|
|
318
|
+
const ownerRows = dropUnverifiedGuesses(openEdges(store, entry.entity.id, filter), { edges: true });
|
|
319
|
+
const owner = ownerRows.rows.find((stored) => stored.row.verb === "owned_by" || stored.row.verb === "led_by");
|
|
161
320
|
const parts = [
|
|
162
|
-
`${clip(entry.entity.name, 48)} (${entry.entity.id})`,
|
|
163
|
-
...(entry.stage ? [`stage ${clip(entry.stage, 24)}`] : entry.status ? [`status ${clip(entry.status, 24)}`] : []),
|
|
164
|
-
...(owner ? [`owner ${owner.row.target}`] : []),
|
|
321
|
+
`${clip(withNames(frame, entry.entity.name).text, 48)} (${entry.entity.id})`,
|
|
322
|
+
...(entry.stage ? [`stage ${clip(entry.stage, 24)}${dayNote(entry.stageDay)}`] : entry.status ? [`status ${clip(entry.status, 24)}${dayNote(entry.statusDay)}`] : []),
|
|
323
|
+
...(owner ? [`owner ${owner.row.target}${dayNote(owner.row.valid.from)}`] : []),
|
|
165
324
|
];
|
|
166
325
|
sections.projects.push(`- ${parts.join(" | ")}`);
|
|
167
326
|
}
|
|
168
327
|
// 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) {
|
|
328
|
+
for (const entry of activeCustomers(frame).slice(0, BRIEF_MAX_CUSTOMERS)) {
|
|
184
329
|
const stage = entry.stage || entry.crm;
|
|
185
|
-
|
|
330
|
+
const stageDay = entry.stage ? entry.stageDay : entry.crmDay;
|
|
331
|
+
sections.customers.push(`- ${clip(withNames(frame, entry.entity.name).text, 48)} (${entry.entity.id})${stage ? ` | stage ${clip(stage, 24)}${dayNote(stageDay)}` : ""}`);
|
|
186
332
|
}
|
|
187
333
|
// What changed in the window: decisions first, then changed single-valued facts.
|
|
188
334
|
const changes = [];
|
|
@@ -191,9 +337,26 @@ export function buildBrief(context, extras = {}) {
|
|
|
191
337
|
continue;
|
|
192
338
|
const day = factValue(index, schema, entity, filter, "decided_on") || entity.firstSeen;
|
|
193
339
|
if (day >= cutoff && day <= today)
|
|
194
|
-
changes.push({ day, line: `- ${day} decision: ${clip(entity.name, 90)} (${entity.id})` });
|
|
340
|
+
changes.push({ day, id: entity.id, line: `- ${day} decision: ${clip(withNames(frame, entity.name).text, 90)} (${entity.id})` });
|
|
195
341
|
}
|
|
196
|
-
|
|
342
|
+
// A decision a later decision replaced stays on the list, marked, so it is not read as the current one.
|
|
343
|
+
const visibleTarget = (ref) => {
|
|
344
|
+
const target = index.entities[index.byId.get(ref) ?? -1];
|
|
345
|
+
return target !== undefined && visible(target, filter);
|
|
346
|
+
};
|
|
347
|
+
const lineageEdges = (ref) => openEdges(store, ref, filter).filter((stored) => visibleTarget(stored.row.target));
|
|
348
|
+
// The status rows say whether a link was a reversal, whether the decision was withdrawn, and whether a person or a
|
|
349
|
+
// record has set its status since (then the link carries no marker).
|
|
350
|
+
const lineageFacts = {
|
|
351
|
+
statusRows: (ref) => store
|
|
352
|
+
.readRows(ref, { kinds: ["F"], ...(filter === null ? {} : { audiences: [...filter] }) })
|
|
353
|
+
.filter((stored) => stored.row.kind === "F" && stored.row.field === "status" && rowVisible(stored.audience, filter)),
|
|
354
|
+
live: (row) => !row.valid.to,
|
|
355
|
+
};
|
|
356
|
+
const decisions = changes
|
|
357
|
+
.sort((a, b) => (a.day < b.day ? 1 : a.day > b.day ? -1 : 0))
|
|
358
|
+
.slice(0, 8)
|
|
359
|
+
.map((entry) => ({ day: entry.day, line: `${entry.line}${replacedMarker(decisionLineage(lineageEdges, entry.id, lineageFacts))}` }));
|
|
197
360
|
const moved = [];
|
|
198
361
|
for (const entry of index.facts) {
|
|
199
362
|
const entity = index.entities[entry.e];
|
|
@@ -201,8 +364,8 @@ export function buildBrief(context, extras = {}) {
|
|
|
201
364
|
continue;
|
|
202
365
|
if (!rowVisible(entry.a, filter) || entry.row.by === "legacy")
|
|
203
366
|
continue;
|
|
204
|
-
// A
|
|
205
|
-
if (isUnverifiedGuess(entry.row))
|
|
367
|
+
// A role or affiliation a model read is not reported as a change either, at any confidence.
|
|
368
|
+
if (isUnverifiedGuess(entry.row) || modelReadRole(entry.row))
|
|
206
369
|
continue;
|
|
207
370
|
if (entry.row.valid.from < cutoff || entry.row.valid.from > today)
|
|
208
371
|
continue;
|
|
@@ -217,7 +380,7 @@ export function buildBrief(context, extras = {}) {
|
|
|
217
380
|
if (sections.changes.length === 0)
|
|
218
381
|
sections.changes = [`- Nothing recorded since ${cutoff}.`];
|
|
219
382
|
// Fit the cap: drop the last line of the longest list until the text fits.
|
|
220
|
-
const cap =
|
|
383
|
+
const cap = frame.cap;
|
|
221
384
|
let text = render(sections);
|
|
222
385
|
while (estimateTokens(text) > cap) {
|
|
223
386
|
const lists = [sections.projects, sections.changes, sections.customers, sections.you].sort((a, b) => b.length - a.length);
|
|
@@ -231,7 +394,124 @@ export function buildBrief(context, extras = {}) {
|
|
|
231
394
|
text = `${text.slice(0, cap * 3 - 1)}\n`;
|
|
232
395
|
return text;
|
|
233
396
|
}
|
|
234
|
-
|
|
397
|
+
// ---------------------------------------------------------------------------
|
|
398
|
+
// The `map` style
|
|
399
|
+
// ---------------------------------------------------------------------------
|
|
400
|
+
/** The company the graph belongs to: the one with an open `relation = self` fact, else `company/<slug>`. */
|
|
401
|
+
function selfCompany(frame) {
|
|
402
|
+
for (const entry of frame.index.facts) {
|
|
403
|
+
if (entry.row.field !== "relation" || entry.row.value !== "self" || entry.row.valid.to !== undefined)
|
|
404
|
+
continue;
|
|
405
|
+
const entity = frame.index.entities[entry.e];
|
|
406
|
+
if (entity && entity.type === "company" && rowVisible(entry.a, frame.filter))
|
|
407
|
+
return entity.id;
|
|
408
|
+
}
|
|
409
|
+
return `company/${frame.context.company}`;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* The people who work at the company itself, most recently active first, without the member. An employer a
|
|
413
|
+
* model wrote under the confidence line is a guess and puts nobody on the list.
|
|
414
|
+
*/
|
|
415
|
+
function teammates(frame, member) {
|
|
416
|
+
const self = selfCompany(frame);
|
|
417
|
+
return frame.shown
|
|
418
|
+
.filter((entity) => entity.type === "person" && entity.id !== member?.id)
|
|
419
|
+
.filter((entity) => dropUnverifiedGuesses(openEdges(frame.store, entity.id, frame.filter), { edges: true }).rows.some((stored) => stored.row.verb === "works_at" && stored.row.target === self))
|
|
420
|
+
.sort(byActivity);
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Names for the recognition list: the name alone, no id and no detail. A raw Slack id is replaced by the
|
|
424
|
+
* person's name; an entity that has only a raw id for a name is left out. One entry per name.
|
|
425
|
+
*/
|
|
426
|
+
function recognitionNames(frame, entities, max) {
|
|
427
|
+
const out = [];
|
|
428
|
+
const seen = new Set();
|
|
429
|
+
for (const entity of entities) {
|
|
430
|
+
if (out.length >= max)
|
|
431
|
+
break;
|
|
432
|
+
// A name stored as a wiki link, [[path|Label]] or [[Label]], is shown as its label.
|
|
433
|
+
const named = withNames(frame, entity.name.replace(/\[\[(?:[^\]|]*\|)?([^\]|]+)\]\]/g, "$1"));
|
|
434
|
+
if (named.raw)
|
|
435
|
+
continue;
|
|
436
|
+
// The list is joined with "; ", so a name keeps no semicolon of its own.
|
|
437
|
+
const text = clip(named.text.replace(/;/g, ","), MAP_NAME_MAX_CHARS);
|
|
438
|
+
const key = normalizeName(text);
|
|
439
|
+
if (key === "" || seen.has(key))
|
|
440
|
+
continue;
|
|
441
|
+
seen.add(key);
|
|
442
|
+
out.push(text);
|
|
443
|
+
}
|
|
444
|
+
return out;
|
|
445
|
+
}
|
|
446
|
+
function renderMap(frame, you, lists) {
|
|
447
|
+
const company = frame.context.company;
|
|
448
|
+
const counts = new Map();
|
|
449
|
+
for (const entity of frame.shown)
|
|
450
|
+
counts.set(entity.type, (counts.get(entity.type) ?? 0) + 1);
|
|
451
|
+
const kinds = [...counts.entries()]
|
|
452
|
+
.sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1))
|
|
453
|
+
.map(([type, count]) => `${type} ${String(count)}`)
|
|
454
|
+
.join(", ");
|
|
455
|
+
const list = (title, names) => (names.length > 0 ? [`- ${title}: ${names.join("; ")}`] : []);
|
|
456
|
+
return [
|
|
457
|
+
`# Company graph map: ${company}`,
|
|
458
|
+
`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.`,
|
|
459
|
+
"",
|
|
460
|
+
"## What the graph holds",
|
|
461
|
+
`- ${String(frame.shown.length)} entities; newest fact ${frame.newest || "none"}. By kind: ${kinds || "none"}.`,
|
|
462
|
+
"- 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>`.",
|
|
463
|
+
"",
|
|
464
|
+
"## How to look things up",
|
|
465
|
+
`- \`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.`,
|
|
466
|
+
`- \`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.`,
|
|
467
|
+
`- \`hq ontology search "<words>" --company ${company}\`: entities by name, alias, identity key or fact text; use it when you only have a fragment.`,
|
|
468
|
+
`- \`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.`,
|
|
469
|
+
`- \`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.`,
|
|
470
|
+
`- \`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.`,
|
|
471
|
+
"",
|
|
472
|
+
"## Graph or vault",
|
|
473
|
+
"The graph is an index of the vault. It is not the record.",
|
|
474
|
+
"- 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.",
|
|
475
|
+
"- 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.",
|
|
476
|
+
"- 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.",
|
|
477
|
+
"- 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.",
|
|
478
|
+
"- \"ambiguous: ... Pick one id\" means the name matches several entities: choose an id from other context and say which you chose; never pick silently.",
|
|
479
|
+
"",
|
|
480
|
+
"## Names the graph knows",
|
|
481
|
+
"Names only, so you can tell a name is worth looking up. The list says nothing about who does what.",
|
|
482
|
+
`- You: ${you}`,
|
|
483
|
+
...list("Active projects (most recently active first)", lists.projects),
|
|
484
|
+
...list("Customers (most active in the graph first; activity, not revenue)", lists.customers),
|
|
485
|
+
...list("Teammates (most active in the graph first)", lists.teammates),
|
|
486
|
+
"",
|
|
487
|
+
].join("\n");
|
|
488
|
+
}
|
|
489
|
+
/** The `map` style: what the graph holds, how to look things up, and names worth looking up. No facts. */
|
|
490
|
+
function buildMapBrief(frame) {
|
|
491
|
+
const member = findMember(frame.context, frame.index, frame.filter, frame.extras);
|
|
492
|
+
const own = member ? withNames(frame, member.name) : null;
|
|
493
|
+
const you = own && !own.raw ? clip(own.text, MAP_NAME_MAX_CHARS) : "not identified. Set `member: person/<slug>` in personal/settings/ontology-reader.yaml.";
|
|
494
|
+
const lists = {
|
|
495
|
+
projects: recognitionNames(frame, activeProjects(frame).map((entry) => entry.entity), MAP_MAX_PROJECTS),
|
|
496
|
+
customers: recognitionNames(frame, activeCustomers(frame).map((entry) => entry.entity), MAP_MAX_CUSTOMERS),
|
|
497
|
+
teammates: recognitionNames(frame, teammates(frame, member), MAP_MAX_TEAMMATES),
|
|
498
|
+
};
|
|
499
|
+
// Fit the cap: drop the last name of the longest list until the text fits. On a tie the earlier list in
|
|
500
|
+
// this fixed order gives way first, so the same graph and day always trim the same way.
|
|
501
|
+
let text = renderMap(frame, you, lists);
|
|
502
|
+
while (estimateTokens(text) > frame.cap) {
|
|
503
|
+
const longest = [lists.projects, lists.teammates, lists.customers].reduce((a, b) => (b.length > a.length ? b : a));
|
|
504
|
+
if (longest.length === 0)
|
|
505
|
+
break;
|
|
506
|
+
longest.pop();
|
|
507
|
+
text = renderMap(frame, you, lists);
|
|
508
|
+
}
|
|
509
|
+
// A cap lower than the map's fixed part (the counts, the commands and the rules) cuts the text itself.
|
|
510
|
+
if (estimateTokens(text) > frame.cap)
|
|
511
|
+
text = `${text.slice(0, frame.cap * 3 - 1)}\n`;
|
|
512
|
+
return text;
|
|
513
|
+
}
|
|
514
|
+
/** `hq ontology brief [--style map|full]`: writes brief.md (1,500 tokens max). */
|
|
235
515
|
export async function briefCommand(context, options) {
|
|
236
516
|
if (!options.store && !graphExists(context.graphRoot)) {
|
|
237
517
|
return {
|
|
@@ -240,15 +520,17 @@ export async function briefCommand(context, options) {
|
|
|
240
520
|
exitCode: 1,
|
|
241
521
|
};
|
|
242
522
|
}
|
|
243
|
-
const
|
|
523
|
+
const style = resolveBriefStyle(context.hqRoot, options.style);
|
|
524
|
+
const text = buildBrief(context, { ...options, style });
|
|
244
525
|
const tokens = estimateTokens(text);
|
|
526
|
+
const size = { style, tokens, characters: text.length, cap: BRIEF_MAX_TOKENS };
|
|
245
527
|
if (options.stdout)
|
|
246
|
-
return { text, json: { status: "ok", written: false,
|
|
528
|
+
return { text, json: { status: "ok", written: false, ...size, brief: text } };
|
|
247
529
|
const file = graphPath(context.graphRoot, GRAPH_PATHS.brief);
|
|
248
530
|
atomicWriteFile(file, text);
|
|
249
531
|
return {
|
|
250
|
-
text: `wrote ${file} (about ${String(tokens)} tokens, cap ${String(BRIEF_MAX_TOKENS)})`,
|
|
251
|
-
json: { status: "ok", written: true, file,
|
|
532
|
+
text: `wrote ${file} (${style} style, ${String(text.length)} characters, about ${String(tokens)} tokens, cap ${String(BRIEF_MAX_TOKENS)})`,
|
|
533
|
+
json: { status: "ok", written: true, file, ...size },
|
|
252
534
|
};
|
|
253
535
|
}
|
|
254
536
|
//# sourceMappingURL=brief.js.map
|
|
@@ -1,11 +1,13 @@
|
|
|
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";
|
|
7
7
|
export { resolveName, searchIndex } from "./names.js";
|
|
8
8
|
export { resolveReadMember } from "./member.js";
|
|
9
|
+
export { decisionLineage, replacedMarker, LINEAGE_MAX_STEPS } from "./lineage.js";
|
|
10
|
+
export type { Lineage, LineageLink, LineageStep } from "./lineage.js";
|
|
9
11
|
export type { ResolveReadMemberOptions } from "./member.js";
|
|
10
12
|
/** Optional inputs every read command accepts beside its contract options. */
|
|
11
13
|
export interface ReadExtras {
|
|
@@ -32,6 +34,8 @@ export declare const LOOKUP_EDGE_LIMIT = 12;
|
|
|
32
34
|
export declare const SIGNAL_LIMIT = 5;
|
|
33
35
|
export declare const LOOKUP_RECENT_LIMIT = 3;
|
|
34
36
|
export declare const WALK_NODE_LIMIT = 300;
|
|
37
|
+
/** Most characters of a decision's name on a `replaced:` or `replaces:` line. */
|
|
38
|
+
export declare const LINEAGE_NAME_MAX_CHARS = 60;
|
|
35
39
|
export declare function audienceFilterFor(context: GraphContext, extras?: ReadExtras): AudienceFilter;
|
|
36
40
|
/** `hq ontology lookup <name> [--as-of D]`. */
|
|
37
41
|
export declare function lookupCommand(context: GraphContext, options: LookupOptions & ReadExtras & {
|