@indigoai-us/hq-cli 5.345.247 → 5.345.250

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 (284) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/assets/lanes-hooks/hq-lanes-drain.sh +1 -1
  3. package/contracts/host-canary-release.json +14 -0
  4. package/dist/command-catalog.generated.d.ts +1198 -0
  5. package/dist/command-catalog.generated.js +1476 -0
  6. package/dist/command-registration-plan.d.ts +6 -0
  7. package/dist/command-registration-plan.js +1 -0
  8. package/dist/commands/core-job-run-native.js +4 -0
  9. package/dist/commands/core-knowledge-prefs.d.ts +1 -1
  10. package/dist/commands/core-knowledge-prefs.js +1 -16
  11. package/dist/commands/core.js +0 -2
  12. package/dist/commands/daemon.js +21 -0
  13. package/dist/commands/lanes-hold.js +7 -7
  14. package/dist/commands/lanes-resume.js +2 -2
  15. package/dist/commands/lanes-review.js +1 -1
  16. package/dist/commands/lanes-session-start.d.ts +1 -1
  17. package/dist/commands/lanes-session-start.js +3 -3
  18. package/dist/commands/lanes-shared.d.ts +1 -1
  19. package/dist/commands/lanes.d.ts +2 -2
  20. package/dist/commands/lanes.js +50 -50
  21. package/dist/commands/mesh.d.ts +25 -0
  22. package/dist/commands/mesh.js +48 -8
  23. package/dist/commands/ontology-graph.d.ts +63 -0
  24. package/dist/commands/ontology-graph.js +470 -0
  25. package/dist/commands/sync-core.js +6 -0
  26. package/dist/fast-scaffold.js +1 -3
  27. package/dist/hq-cloud-sync-runner/bin/sync-runner.js +281 -256
  28. package/dist/hq-cloud-sync-runner/package.json +1 -1
  29. package/dist/index.d.ts +8 -0
  30. package/dist/index.js +48 -1
  31. package/dist/lanes-monitor-check-argv.d.ts +1 -1
  32. package/dist/lanes-monitor-check-argv.js +1 -1
  33. package/dist/lanes-monitor-check-fast.d.ts +1 -1
  34. package/dist/lanes-monitor-check-fast.js +1 -1
  35. package/dist/lanes-session-start-argv.d.ts +1 -1
  36. package/dist/lanes-session-start-argv.js +1 -1
  37. package/dist/lib/capacity/sign-in.d.ts +1 -1
  38. package/dist/lib/capacity/sign-in.js +1 -1
  39. package/dist/lib/daemon/hook-requests-conduct-link.js +2 -2
  40. package/dist/lib/daemon/installed-cli-restart.d.ts +57 -0
  41. package/dist/lib/daemon/installed-cli-restart.js +114 -0
  42. package/dist/lib/daemon/lanes-monitor-state.d.ts +2 -2
  43. package/dist/lib/daemon/lanes-monitor-state.js +2 -2
  44. package/dist/lib/daemon/legacy-journal-gate.d.ts +32 -0
  45. package/dist/lib/daemon/legacy-journal-gate.js +102 -0
  46. package/dist/lib/daemon/machine-checks.d.ts +7 -0
  47. package/dist/lib/daemon/machine-checks.js +10 -0
  48. package/dist/lib/daemon/merge-sections.d.ts +3 -3
  49. package/dist/lib/daemon/merge-sections.js +7 -7
  50. package/dist/lib/daemon/remote-control-pools.js +1 -1
  51. package/dist/lib/daemon/run.d.ts +3 -1
  52. package/dist/lib/daemon/run.js +49 -6
  53. package/dist/lib/daemon/state-file.d.ts +1 -1
  54. package/dist/lib/daemon/state-file.js +1 -1
  55. package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
  56. package/dist/lib/flag-registry-worker-source.generated.js +1 -1
  57. package/dist/lib/flag-snapshot-file.d.ts +2 -0
  58. package/dist/lib/flag-snapshot-file.js +118 -48
  59. package/dist/lib/hook-engine/canary-gate.d.ts +57 -3
  60. package/dist/lib/hook-engine/canary-gate.js +138 -6
  61. package/dist/lib/hook-engine/coverage.d.ts +82 -13
  62. package/dist/lib/hook-engine/coverage.js +214 -18
  63. package/dist/lib/hook-engine/registration-identity.d.ts +5 -0
  64. package/dist/lib/hook-engine/registration-identity.js +1 -1
  65. package/dist/lib/hook-engine/resolve.d.ts +23 -0
  66. package/dist/lib/hook-engine/resolve.js +48 -1
  67. package/dist/lib/hook-engine/stable-heal.d.ts +87 -0
  68. package/dist/lib/hook-engine/stable-heal.js +214 -0
  69. package/dist/lib/hot-channels/graph-context.d.ts +105 -0
  70. package/dist/lib/hot-channels/graph-context.js +380 -0
  71. package/dist/lib/hot-channels/signals-pass.js +27 -1
  72. package/dist/lib/lanes/claude-credential.d.ts +1 -1
  73. package/dist/lib/lanes/claude-credential.js +1 -1
  74. package/dist/lib/lanes/delivery-core.d.ts +1 -1
  75. package/dist/lib/lanes/delivery-core.js +1 -1
  76. package/dist/lib/lanes/delivery.d.ts +10 -10
  77. package/dist/lib/lanes/delivery.js +8 -8
  78. package/dist/lib/lanes/dropbox.d.ts +1 -1
  79. package/dist/lib/lanes/dropbox.js +1 -1
  80. package/dist/lib/lanes/hooks-install.js +2 -2
  81. package/dist/lib/lanes/index.d.ts +1 -1
  82. package/dist/lib/lanes/index.js +1 -1
  83. package/dist/lib/lanes/monitor.js +1 -1
  84. package/dist/lib/lanes/quota-notice.js +1 -1
  85. package/dist/lib/lanes/quota.d.ts +1 -1
  86. package/dist/lib/lanes/quota.js +1 -1
  87. package/dist/lib/lanes/repo-merge-hold.d.ts +2 -2
  88. package/dist/lib/lanes/repo-merge-hold.js +2 -2
  89. package/dist/lib/lanes/spawn.d.ts +4 -4
  90. package/dist/lib/lanes/spawn.js +5 -5
  91. package/dist/lib/mesh/live/company-flag-refresh.d.ts +61 -0
  92. package/dist/lib/mesh/live/company-flag-refresh.js +159 -0
  93. package/dist/lib/mesh/live/company-reporting-gaps.d.ts +61 -0
  94. package/dist/lib/mesh/live/company-reporting-gaps.js +238 -0
  95. package/dist/lib/mesh/live/daemon/duplicate-unit.d.ts +156 -0
  96. package/dist/lib/mesh/live/daemon/duplicate-unit.js +616 -0
  97. package/dist/lib/mesh/live/daemon/run.d.ts +13 -0
  98. package/dist/lib/mesh/live/daemon/run.js +35 -2
  99. package/dist/lib/mesh/live/direct-drain.js +1 -1
  100. package/dist/lib/mesh/live/emit.d.ts +3 -0
  101. package/dist/lib/mesh/live/emit.js +32 -9
  102. package/dist/lib/mesh/live/flush.d.ts +3 -0
  103. package/dist/lib/mesh/live/flush.js +115 -32
  104. package/dist/lib/mesh/live/liveness-carry.d.ts +1 -1
  105. package/dist/lib/mesh/live/liveness-carry.js +1 -1
  106. package/dist/lib/mesh/live/reporting-privacy.d.ts +119 -3
  107. package/dist/lib/mesh/live/reporting-privacy.js +235 -11
  108. package/dist/lib/mesh/live/spool.d.ts +17 -2
  109. package/dist/lib/mesh/live/spool.js +22 -6
  110. package/dist/lib/ontology-graph/legacy/coverage.d.ts +67 -0
  111. package/dist/lib/ontology-graph/legacy/coverage.js +192 -0
  112. package/dist/lib/ontology-graph/legacy/index.d.ts +199 -0
  113. package/dist/lib/ontology-graph/legacy/index.js +1150 -0
  114. package/dist/lib/ontology-graph/legacy/parse.d.ts +49 -0
  115. package/dist/lib/ontology-graph/legacy/parse.js +126 -0
  116. package/dist/lib/ontology-graph/legacy/report.d.ts +14 -0
  117. package/dist/lib/ontology-graph/legacy/report.js +254 -0
  118. package/dist/lib/ontology-graph/legacy/verb-map.d.ts +35 -0
  119. package/dist/lib/ontology-graph/legacy/verb-map.js +84 -0
  120. package/dist/lib/ontology-graph/lint/checks.d.ts +140 -0
  121. package/dist/lib/ontology-graph/lint/checks.js +717 -0
  122. package/dist/lib/ontology-graph/lint/coverage.d.ts +106 -0
  123. package/dist/lib/ontology-graph/lint/coverage.js +241 -0
  124. package/dist/lib/ontology-graph/lint/daily-job.d.ts +259 -0
  125. package/dist/lib/ontology-graph/lint/daily-job.js +595 -0
  126. package/dist/lib/ontology-graph/lint/index.d.ts +65 -0
  127. package/dist/lib/ontology-graph/lint/index.js +176 -0
  128. package/dist/lib/ontology-graph/model/files.d.ts +20 -0
  129. package/dist/lib/ontology-graph/model/files.js +89 -0
  130. package/dist/lib/ontology-graph/model/index.d.ts +65 -0
  131. package/dist/lib/ontology-graph/model/index.js +100 -0
  132. package/dist/lib/ontology-graph/model/pass-tasks.d.ts +156 -0
  133. package/dist/lib/ontology-graph/model/pass-tasks.js +345 -0
  134. package/dist/lib/ontology-graph/model/pass.d.ts +109 -0
  135. package/dist/lib/ontology-graph/model/pass.js +958 -0
  136. package/dist/lib/ontology-graph/model/runner.d.ts +50 -0
  137. package/dist/lib/ontology-graph/model/runner.js +160 -0
  138. package/dist/lib/ontology-graph/model/step.d.ts +197 -0
  139. package/dist/lib/ontology-graph/model/step.js +526 -0
  140. package/dist/lib/ontology-graph/model/tasks.d.ts +183 -0
  141. package/dist/lib/ontology-graph/model/tasks.js +349 -0
  142. package/dist/lib/ontology-graph/not-implemented.d.ts +5 -0
  143. package/dist/lib/ontology-graph/not-implemented.js +8 -0
  144. package/dist/lib/ontology-graph/org/compare.d.ts +28 -0
  145. package/dist/lib/ontology-graph/org/compare.js +239 -0
  146. package/dist/lib/ontology-graph/org/derive.d.ts +67 -0
  147. package/dist/lib/ontology-graph/org/derive.js +359 -0
  148. package/dist/lib/ontology-graph/org/index.d.ts +102 -0
  149. package/dist/lib/ontology-graph/org/index.js +630 -0
  150. package/dist/lib/ontology-graph/org/load.d.ts +31 -0
  151. package/dist/lib/ontology-graph/org/load.js +476 -0
  152. package/dist/lib/ontology-graph/org/role.d.ts +38 -0
  153. package/dist/lib/ontology-graph/org/role.js +268 -0
  154. package/dist/lib/ontology-graph/org/structure.d.ts +63 -0
  155. package/dist/lib/ontology-graph/org/structure.js +437 -0
  156. package/dist/lib/ontology-graph/org/text.d.ts +97 -0
  157. package/dist/lib/ontology-graph/org/text.js +321 -0
  158. package/dist/lib/ontology-graph/org/types.d.ts +457 -0
  159. package/dist/lib/ontology-graph/org/types.js +80 -0
  160. package/dist/lib/ontology-graph/pages/index.d.ts +64 -0
  161. package/dist/lib/ontology-graph/pages/index.js +193 -0
  162. package/dist/lib/ontology-graph/pages/render.d.ts +144 -0
  163. package/dist/lib/ontology-graph/pages/render.js +688 -0
  164. package/dist/lib/ontology-graph/proposals/apply.d.ts +109 -0
  165. package/dist/lib/ontology-graph/proposals/apply.js +468 -0
  166. package/dist/lib/ontology-graph/proposals/group.d.ts +63 -0
  167. package/dist/lib/ontology-graph/proposals/group.js +232 -0
  168. package/dist/lib/ontology-graph/proposals/index.d.ts +173 -0
  169. package/dist/lib/ontology-graph/proposals/index.js +474 -0
  170. package/dist/lib/ontology-graph/proposals/model.d.ts +162 -0
  171. package/dist/lib/ontology-graph/proposals/model.js +196 -0
  172. package/dist/lib/ontology-graph/proposals/org-chart.d.ts +82 -0
  173. package/dist/lib/ontology-graph/proposals/org-chart.js +340 -0
  174. package/dist/lib/ontology-graph/read/brief.d.ts +26 -0
  175. package/dist/lib/ontology-graph/read/brief.js +254 -0
  176. package/dist/lib/ontology-graph/read/graph-index.d.ts +76 -0
  177. package/dist/lib/ontology-graph/read/graph-index.js +198 -0
  178. package/dist/lib/ontology-graph/read/index.d.ts +59 -0
  179. package/dist/lib/ontology-graph/read/index.js +803 -0
  180. package/dist/lib/ontology-graph/read/member.d.ts +7 -0
  181. package/dist/lib/ontology-graph/read/member.js +34 -0
  182. package/dist/lib/ontology-graph/read/names.d.ts +49 -0
  183. package/dist/lib/ontology-graph/read/names.js +297 -0
  184. package/dist/lib/ontology-graph/read/reader-setting.d.ts +19 -0
  185. package/dist/lib/ontology-graph/read/reader-setting.js +62 -0
  186. package/dist/lib/ontology-graph/read/test-graph.d.ts +37 -0
  187. package/dist/lib/ontology-graph/read/test-graph.js +150 -0
  188. package/dist/lib/ontology-graph/replay/buffered-store.d.ts +33 -0
  189. package/dist/lib/ontology-graph/replay/buffered-store.js +50 -0
  190. package/dist/lib/ontology-graph/replay/config.d.ts +41 -0
  191. package/dist/lib/ontology-graph/replay/config.js +105 -0
  192. package/dist/lib/ontology-graph/replay/engine.d.ts +146 -0
  193. package/dist/lib/ontology-graph/replay/engine.js +1240 -0
  194. package/dist/lib/ontology-graph/replay/extractors.d.ts +59 -0
  195. package/dist/lib/ontology-graph/replay/extractors.js +1555 -0
  196. package/dist/lib/ontology-graph/replay/index.d.ts +91 -0
  197. package/dist/lib/ontology-graph/replay/index.js +220 -0
  198. package/dist/lib/ontology-graph/replay/listing-manifest.d.ts +66 -0
  199. package/dist/lib/ontology-graph/replay/listing-manifest.js +242 -0
  200. package/dist/lib/ontology-graph/replay/member.d.ts +19 -0
  201. package/dist/lib/ontology-graph/replay/member.js +65 -0
  202. package/dist/lib/ontology-graph/replay/mentions.d.ts +58 -0
  203. package/dist/lib/ontology-graph/replay/mentions.js +239 -0
  204. package/dist/lib/ontology-graph/replay/readers.d.ts +98 -0
  205. package/dist/lib/ontology-graph/replay/readers.js +1251 -0
  206. package/dist/lib/ontology-graph/replay/rules.d.ts +127 -0
  207. package/dist/lib/ontology-graph/replay/rules.js +374 -0
  208. package/dist/lib/ontology-graph/replay/scope.d.ts +35 -0
  209. package/dist/lib/ontology-graph/replay/scope.js +115 -0
  210. package/dist/lib/ontology-graph/replay/transcripts.d.ts +39 -0
  211. package/dist/lib/ontology-graph/replay/transcripts.js +224 -0
  212. package/dist/lib/ontology-graph/replay/util.d.ts +55 -0
  213. package/dist/lib/ontology-graph/replay/util.js +256 -0
  214. package/dist/lib/ontology-graph/resolve/entity-index.d.ts +159 -0
  215. package/dist/lib/ontology-graph/resolve/entity-index.js +652 -0
  216. package/dist/lib/ontology-graph/resolve/index.d.ts +113 -0
  217. package/dist/lib/ontology-graph/resolve/index.js +214 -0
  218. package/dist/lib/ontology-graph/resolve/machine.d.ts +34 -0
  219. package/dist/lib/ontology-graph/resolve/machine.js +95 -0
  220. package/dist/lib/ontology-graph/resolve/normalize.d.ts +35 -0
  221. package/dist/lib/ontology-graph/resolve/normalize.js +124 -0
  222. package/dist/lib/ontology-graph/resolve/org-chart.d.ts +107 -0
  223. package/dist/lib/ontology-graph/resolve/org-chart.js +578 -0
  224. package/dist/lib/ontology-graph/resolve/org-layer.d.ts +78 -0
  225. package/dist/lib/ontology-graph/resolve/org-layer.js +159 -0
  226. package/dist/lib/ontology-graph/resolve/org-seed.d.ts +141 -0
  227. package/dist/lib/ontology-graph/resolve/org-seed.js +631 -0
  228. package/dist/lib/ontology-graph/resolve/org-sources.d.ts +165 -0
  229. package/dist/lib/ontology-graph/resolve/org-sources.js +634 -0
  230. package/dist/lib/ontology-graph/resolve/roster.d.ts +76 -0
  231. package/dist/lib/ontology-graph/resolve/roster.js +226 -0
  232. package/dist/lib/ontology-graph/resolve/seed.d.ts +267 -0
  233. package/dist/lib/ontology-graph/resolve/seed.js +1198 -0
  234. package/dist/lib/ontology-graph/resolve/upsert.d.ts +58 -0
  235. package/dist/lib/ontology-graph/resolve/upsert.js +139 -0
  236. package/dist/lib/ontology-graph/resolve/writer.d.ts +128 -0
  237. package/dist/lib/ontology-graph/resolve/writer.js +351 -0
  238. package/dist/lib/ontology-graph/schema/authority.d.ts +107 -0
  239. package/dist/lib/ontology-graph/schema/authority.js +186 -0
  240. package/dist/lib/ontology-graph/schema/default-schema.d.ts +10 -0
  241. package/dist/lib/ontology-graph/schema/default-schema.js +242 -0
  242. package/dist/lib/ontology-graph/schema/grammar.d.ts +57 -0
  243. package/dist/lib/ontology-graph/schema/grammar.js +409 -0
  244. package/dist/lib/ontology-graph/schema/index.d.ts +12 -0
  245. package/dist/lib/ontology-graph/schema/index.js +10 -0
  246. package/dist/lib/ontology-graph/schema/validate.d.ts +13 -0
  247. package/dist/lib/ontology-graph/schema/validate.js +132 -0
  248. package/dist/lib/ontology-graph/store/files.d.ts +34 -0
  249. package/dist/lib/ontology-graph/store/files.js +207 -0
  250. package/dist/lib/ontology-graph/store/fs.d.ts +30 -0
  251. package/dist/lib/ontology-graph/store/fs.js +101 -0
  252. package/dist/lib/ontology-graph/store/graph-store.d.ts +14 -0
  253. package/dist/lib/ontology-graph/store/graph-store.js +520 -0
  254. package/dist/lib/ontology-graph/store/index.d.ts +18 -0
  255. package/dist/lib/ontology-graph/store/index.js +15 -0
  256. package/dist/lib/ontology-graph/store/ingest.d.ts +37 -0
  257. package/dist/lib/ontology-graph/store/ingest.js +323 -0
  258. package/dist/lib/ontology-graph/store/paths.d.ts +114 -0
  259. package/dist/lib/ontology-graph/store/paths.js +232 -0
  260. package/dist/lib/ontology-graph/types.d.ts +1190 -0
  261. package/dist/lib/ontology-graph/types.js +131 -0
  262. package/dist/lib/secret-scan/gitleaks-rules.generated.js +1 -1
  263. package/dist/lib/sync-core/engine-holds.d.ts +1 -1
  264. package/dist/lib/sync-core/engine-holds.js +12 -2
  265. package/dist/lib/sync-core/hand-back.d.ts +2 -1
  266. package/dist/lib/sync-core/hand-back.js +16 -2
  267. package/dist/lib/sync-core/legacy-journal-export-child.d.ts +2 -0
  268. package/dist/lib/sync-core/legacy-journal-export-child.js +24 -0
  269. package/dist/lib/sync-core/legacy-journal-export.d.ts +39 -0
  270. package/dist/lib/sync-core/legacy-journal-export.js +241 -0
  271. package/dist/lib/sync-core/legacy-journal-reader.d.ts +15 -0
  272. package/dist/lib/sync-core/legacy-journal-reader.js +56 -0
  273. package/dist/lib/sync-core/reconcile.d.ts +3 -0
  274. package/dist/lib/sync-core/reconcile.js +43 -3
  275. package/dist/utils/cli-telemetry.d.ts +1 -0
  276. package/dist/utils/cli-telemetry.js +6 -3
  277. package/dist/utils/frontmatter.d.ts +14 -0
  278. package/dist/utils/frontmatter.js +18 -0
  279. package/dist/utils/hook-engine-rollup.d.ts +96 -0
  280. package/dist/utils/hook-engine-rollup.js +725 -0
  281. package/dist/utils/interactive-caller.js +1 -1
  282. package/package.json +9 -9
  283. package/scripts/install-hook-engine.mjs +4 -0
  284. package/assets/scaffold/core/scripts/knowledge-prefs.sh +0 -55
@@ -0,0 +1,268 @@
1
+ /**
2
+ * Observed org chart: the observed role.
3
+ *
4
+ * A short plain description of what a person visibly does, built by rules
5
+ * from the activity profile: the area mix by share of activity, the kinds of
6
+ * act that dominate, the subjects they act on, and how that changed between
7
+ * the earlier and the recent window. Every sentence cites rows. It never names
8
+ * a title.
9
+ *
10
+ * One small model call per active person may rephrase the rule sentences. The
11
+ * reply is used only when every sentence cites ids it was given and no
12
+ * sentence awards a title; otherwise the rule text stands.
13
+ */
14
+ import { parseStrictJsonObject } from "../model/step.js";
15
+ import { actInWindow, buildExamples, profileWeight } from "./derive.js";
16
+ import { confidenceFrom } from "./structure.js";
17
+ import { TITLE_WORDS, addDays, clip } from "./text.js";
18
+ import { AREAS, AREA_LABEL, ORG_ORIGIN, } from "./types.js";
19
+ /** The role is described from the most recent window that holds this much evidence. */
20
+ export const ROLE_MIN_EVIDENCE = 5;
21
+ const ROLE_WINDOWS = ["90d", "365d", "all"];
22
+ const WINDOW_WORDS = { "30d": "the last 30 days", "90d": "the last 90 days", "365d": "the last 365 days", all: "all the time on record" };
23
+ export function roleWindow(windows) {
24
+ return ROLE_WINDOWS.find((window) => windows[window].evidence >= ROLE_MIN_EVIDENCE) ?? "all";
25
+ }
26
+ const percent = (share) => `${Math.round(share * 100)}%`;
27
+ const names = (items, limit) => items.slice(0, limit).map((item) => item.name).join(", ");
28
+ const cites = (examples, limit = 3) => [...new Set((examples ?? []).slice(0, limit).map((example) => example.src))];
29
+ export function mainAreas(profile) {
30
+ return AREAS.map((area) => ({ area, share: Math.round(profile.areas[area] * 100) / 100 }))
31
+ .filter((item) => item.share >= 0.1)
32
+ .sort((a, b) => b.share - a.share || (a.area < b.area ? -1 : 1))
33
+ .slice(0, 3);
34
+ }
35
+ export function buildRuleRole(input) {
36
+ const { graph, person, acts, windows } = input;
37
+ const window = roleWindow(windows);
38
+ const profile = windows[window];
39
+ const words = WINDOW_WORDS[window];
40
+ const recent = acts.filter((item) => actInWindow(item, window, graph.asOf) && profileWeight(item.cls, person, graph.member) > 0);
41
+ const examples = buildExamples(recent);
42
+ const areas = mainAreas(profile);
43
+ if (profile.evidence < 3) {
44
+ const total = windows.all.evidence;
45
+ return {
46
+ line: total > 0 ? `Little visible activity (${Math.round(total)} pieces of evidence on record)` : "No visible activity in the rows this view may read",
47
+ sentences: total > 0 ? [{ text: `Only ${Math.round(total)} pieces of evidence name this person as acting, too few to describe a role.`, cites: cites(Object.values(examples).flat(), 3) }] : [],
48
+ change: null,
49
+ mainAreas: areas,
50
+ by: ORG_ORIGIN,
51
+ conf: 0.2,
52
+ };
53
+ }
54
+ const counts = profile.counts;
55
+ const behaviors = [];
56
+ const add = (kind, weight, phrase, sentence, cited) => {
57
+ if (weight > 0 && cited.length > 0)
58
+ behaviors.push({ kind, weight, phrase, sentence, cites: cited });
59
+ };
60
+ if (counts.commits >= 3) {
61
+ const repos = names(profile.repos, 3);
62
+ add("commits", counts.commits * 0.2, `ships code (${repos})`, `Made ${counts.commits} commits in ${words}, most to ${repos}.`, cites(examples.commits));
63
+ }
64
+ if (counts.decisions >= 2) {
65
+ const subjects = names([...profile.projects, ...profile.customers].sort((a, b) => b.count - a.count), 3);
66
+ add("decisions", counts.decisions * 1.5, subjects ? `makes decisions (${subjects})` : "makes decisions", `Is named as deciding ${counts.decisions} things in ${words}.`, cites(examples.decisions));
67
+ }
68
+ if (counts.external_meetings >= 2) {
69
+ const customers = names(profile.customers, 3);
70
+ add("external_meetings", counts.external_meetings, customers ? `takes calls with outside companies (${customers})` : "takes calls with people outside the company", `Was in ${counts.external_meetings} meetings with people outside the company in ${words}.`, cites(examples.external_meetings));
71
+ }
72
+ if (counts.meetings_led >= 2)
73
+ add("meetings_led", counts.meetings_led * 1.2, "leads meetings", `Is described as leading ${counts.meetings_led} meetings in ${words}.`, cites(examples.meetings_led));
74
+ if (counts.action_items >= 3)
75
+ add("action_items", counts.action_items, "takes on action items", `Took on ${counts.action_items} action items in ${words}.`, cites(examples.action_items));
76
+ if (counts.commitments >= 3)
77
+ add("commitments", counts.commitments * 0.8, "makes commitments to others", `Made ${counts.commitments} commitments in ${words}.`, cites(examples.commitments));
78
+ if (counts.threads_started >= 3)
79
+ add("threads_started", counts.threads_started * 0.6, "starts channel threads", `Started ${counts.threads_started} channel threads in ${words}.`, cites(examples.threads_started));
80
+ if (counts.presented >= 2)
81
+ add("presented", counts.presented, "presents and demos", `Presented or demoed in ${counts.presented} meetings in ${words}.`, cites(examples.presented));
82
+ if (counts.own_sessions >= 3)
83
+ add("own_sessions", counts.own_sessions * 0.1, "runs agent sessions", `Ran ${counts.own_sessions} recorded sessions in ${words} (seen only because this is the member's own machine).`, cites(examples.own_sessions));
84
+ const directed = input.directs.filter((edge) => edge.counts[window] > 0).slice(0, 3);
85
+ if (directed.length > 0) {
86
+ const who = directed.map((edge) => graph.people.get(edge.to)?.name ?? edge.to).join(", ");
87
+ const total = directed.reduce((sum, edge) => sum + edge.counts[window], 0);
88
+ add("directs", total * 1.5, `hands work to ${who}`, `Assigns, approves or decides work for ${who} (${total} observed instances in ${words}).`, [...new Set(directed.flatMap((edge) => edge.examples.slice(0, 1).map((example) => example.src)))]);
89
+ }
90
+ if (counts.meetings_attended >= 5 && behaviors.length === 0) {
91
+ add("meetings_attended", counts.meetings_attended * 0.2, "attends meetings", `Attended ${counts.meetings_attended} meetings in ${words}; no row names them as deciding, committing code or taking an action.`, cites(examples.meetings_attended));
92
+ }
93
+ behaviors.sort((a, b) => b.weight - a.weight || (a.kind < b.kind ? -1 : 1));
94
+ const topArea = areas[0];
95
+ const areaLead = !topArea
96
+ ? "No clear area"
97
+ : topArea.share >= 0.5
98
+ ? `Mostly ${AREA_LABEL[topArea.area]}`
99
+ : `Mix of ${areas.slice(0, 2).map((item) => AREA_LABEL[item.area]).join(" and ")}`;
100
+ const line = clip(`${areaLead}${behaviors.length > 0 ? `: ${behaviors.slice(0, 3).map((item) => item.phrase).join("; ")}` : ""}`, 200);
101
+ const sentences = [];
102
+ if (topArea) {
103
+ const areaActs = recent.filter((item) => Object.keys(item.areas).includes(topArea.area)).sort((a, b) => (a.date > b.date ? -1 : 1));
104
+ const mix = areas.map((item) => `${AREA_LABEL[item.area]} ${percent(item.share)}`).join(", ");
105
+ sentences.push({ text: `In ${words} the visible work is ${mix}, from ${Math.round(profile.evidence)} pieces of evidence.`, cites: [...new Set(areaActs.slice(0, 3).map((item) => item.src))] });
106
+ }
107
+ for (const behavior of behaviors.slice(0, 4))
108
+ sentences.push({ text: behavior.sentence, cites: behavior.cites });
109
+ return {
110
+ line,
111
+ sentences: sentences.filter((sentence) => sentence.cites.length > 0),
112
+ change: describeChange(input),
113
+ mainAreas: areas,
114
+ by: ORG_ORIGIN,
115
+ conf: confidenceFrom(profile.evidence, 20),
116
+ };
117
+ }
118
+ function span(input, from, to, days) {
119
+ const sums = Object.fromEntries(AREAS.map((area) => [area, 0]));
120
+ let weightSum = 0;
121
+ let evidence = 0;
122
+ let commits = 0;
123
+ let lastCommit = null;
124
+ let last = null;
125
+ for (const item of input.acts) {
126
+ if (item.date > to || (from !== null && (item.spanFrom ?? item.date) <= from))
127
+ continue;
128
+ const weight = profileWeight(item.cls, input.person, input.graph.member);
129
+ if (weight <= 0)
130
+ continue;
131
+ evidence += weight;
132
+ if (last === null || item.date > last.date)
133
+ last = item;
134
+ if (item.kind === "commits") {
135
+ commits += item.count;
136
+ if (lastCommit === null || item.date > lastCommit)
137
+ lastCommit = item.date;
138
+ }
139
+ for (const area of AREAS) {
140
+ const share = item.areas[area];
141
+ if (share === undefined)
142
+ continue;
143
+ sums[area] += share * item.areaWeight * weight;
144
+ weightSum += share * item.areaWeight * weight;
145
+ }
146
+ }
147
+ if (weightSum > 0)
148
+ for (const area of AREAS)
149
+ sums[area] /= weightSum;
150
+ return { evidence, days, areas: sums, commits, lastCommit, last };
151
+ }
152
+ /** Compares the last 90 days with the nine months before. Null when there is too little on either side or nothing moved. */
153
+ export function describeChange(input) {
154
+ const asOf = input.graph.asOf;
155
+ const recent = span(input, addDays(asOf, -90), asOf, 90);
156
+ const earlier = span(input, addDays(asOf, -365), addDays(asOf, -90), 275);
157
+ if (earlier.evidence < ROLE_MIN_EVIDENCE)
158
+ return null;
159
+ const earlierCites = () => (earlier.last ? [earlier.last.src] : []);
160
+ if (recent.evidence < 1) {
161
+ return { text: `Nothing visible in the last 90 days; the nine months before hold ${Math.round(earlier.evidence)} pieces of evidence, the last on ${earlier.last?.date ?? "an unknown day"}.`, cites: earlierCites() };
162
+ }
163
+ const parts = [];
164
+ const top = (areas) => {
165
+ const best = AREAS.map((area) => ({ area, share: areas[area] })).sort((a, b) => b.share - a.share)[0];
166
+ return best && best.share > 0 ? best.area : null;
167
+ };
168
+ const before = top(earlier.areas);
169
+ const after = top(recent.areas);
170
+ if (before && after && recent.evidence >= ROLE_MIN_EVIDENCE) {
171
+ const moved = AREAS.map((area) => ({ area, delta: recent.areas[area] - earlier.areas[area] })).sort((a, b) => Math.abs(b.delta) - Math.abs(a.delta))[0];
172
+ if (before !== after)
173
+ parts.push(`the main area moved from ${AREA_LABEL[before]} (${percent(earlier.areas[before])} then, ${percent(recent.areas[before])} now) to ${AREA_LABEL[after]} (${percent(earlier.areas[after])} then, ${percent(recent.areas[after])} now)`);
174
+ else if (moved && Math.abs(moved.delta) >= 0.25)
175
+ parts.push(`${AREA_LABEL[moved.area]} went from ${percent(earlier.areas[moved.area])} to ${percent(recent.areas[moved.area])} of the visible work`);
176
+ }
177
+ const rateBefore = earlier.evidence / earlier.days;
178
+ const rateNow = recent.evidence / recent.days;
179
+ if (rateBefore > 0 && rateNow / rateBefore <= 1 / 3)
180
+ parts.push(`visible activity fell to about ${percent(rateNow / rateBefore)} of its earlier rate`);
181
+ else if (rateBefore > 0 && rateNow / rateBefore >= 3)
182
+ parts.push(`visible activity rose to about ${Math.round(rateNow / rateBefore)} times its earlier rate`);
183
+ if (earlier.commits >= 10 && recent.commits === 0)
184
+ parts.push(`no commits since ${earlier.lastCommit ?? "the earlier period"} (${earlier.commits} in the nine months before)`);
185
+ if (parts.length === 0)
186
+ return null;
187
+ const text = `Compared with the nine months before the last 90 days: ${parts.join("; ")}.`;
188
+ const cited = [...new Set([...(recent.last ? [recent.last.src] : []), ...earlierCites()])];
189
+ return cited.length > 0 ? { text, cites: cited } : null;
190
+ }
191
+ // ---------------------------------------------------------------------------
192
+ // Model phrasing (optional, one call per active person)
193
+ // ---------------------------------------------------------------------------
194
+ export const ROLE_PROMPT_VERSION = "org-observed-role-v1";
195
+ export const ROLE_PROMPT = [
196
+ "You are given evidence about what one person visibly does at work. Rewrite it as a short, plain description.",
197
+ "Reply with one JSON object and nothing else:",
198
+ '{"line": "<one line, at most 110 characters, starts with a verb>", "sentences": [{"text": "<one sentence>", "cites": ["<id>", ...]}], "change": {"text": "<one sentence>", "cites": ["<id>", ...]} or null}',
199
+ "Rules:",
200
+ "- Use only what the evidence says. Do not add a fact, a reason or a guess.",
201
+ "- Never give the person a job title, a rank or a seniority (no CEO, founder, head of, lead, manager, senior). Describe actions.",
202
+ "- At most 3 sentences. Every sentence cites at least one id from the evidence. Use only ids that appear in the input.",
203
+ "- `change` restates the input's change sentence when there is one, else null.",
204
+ "- Flat factual prose. No praise, no adjectives of quality, no metaphors, no contrast constructions.",
205
+ ].join("\n");
206
+ /** Asks the model to rephrase a rule-built role. Returns the rule role unchanged unless the reply passes every check. */
207
+ export async function phraseRole(step, name, rule, examples, day) {
208
+ const ids = new Map();
209
+ const facts = rule.sentences.map((sentence, i) => {
210
+ ids.set(`f${i + 1}`, sentence.cites);
211
+ return { id: `f${i + 1}`, text: sentence.text };
212
+ });
213
+ const rows = [];
214
+ for (const [kind, list] of Object.entries(examples)) {
215
+ for (const example of list ?? []) {
216
+ const id = `e${rows.length + 1}`;
217
+ ids.set(id, [example.src]);
218
+ rows.push({ id, kind, date: example.date, text: clip(example.text, 160) });
219
+ }
220
+ }
221
+ if (rule.change)
222
+ ids.set("c1", rule.change.cites);
223
+ const input = JSON.stringify({ person: name, summary: rule.line, facts, change: rule.change ? { id: "c1", text: rule.change.text } : null, examples: rows.slice(0, 18) });
224
+ const result = await step.run({ kind: "summarize-page", promptVersion: ROLE_PROMPT_VERSION, prompt: ROLE_PROMPT, input, day, maxOutputTokens: 500 });
225
+ if (result.status === "pending" || result.status === "error" || result.output === undefined)
226
+ return { role: rule, status: result.status === "ok" || result.status === "cached" ? "rejected" : result.status };
227
+ const parsed = parseStrictJsonObject(result.output);
228
+ const checked = parsed ? checkPhrasing(parsed, ids) : null;
229
+ if (!checked)
230
+ return { role: rule, status: "rejected" };
231
+ const by = `agent:${step.model ?? "model"}`;
232
+ return { role: { ...rule, line: checked.line, sentences: checked.sentences, change: rule.change ? (checked.change ?? rule.change) : null, by }, status: result.status };
233
+ }
234
+ /** The checks a model reply must pass. Exported for tests. */
235
+ export function checkPhrasing(raw, ids) {
236
+ const line = typeof raw.line === "string" ? raw.line.replace(/\s+/g, " ").trim() : "";
237
+ if (line === "" || line.length > 140 || TITLE_WORDS.test(line))
238
+ return null;
239
+ const one = (value) => {
240
+ if (!value || typeof value !== "object")
241
+ return null;
242
+ const record = value;
243
+ const text = typeof record.text === "string" ? record.text.replace(/\s+/g, " ").trim() : "";
244
+ const cited = Array.isArray(record.cites) ? record.cites.filter((id) => typeof id === "string") : [];
245
+ if (text === "" || cited.length === 0 || TITLE_WORDS.test(text))
246
+ return null;
247
+ if (cited.some((id) => !ids.has(id)))
248
+ return null;
249
+ return { text, cites: [...new Set(cited.flatMap((id) => ids.get(id) ?? []))] };
250
+ };
251
+ if (!Array.isArray(raw.sentences) || raw.sentences.length === 0 || raw.sentences.length > 3)
252
+ return null;
253
+ const sentences = [];
254
+ for (const item of raw.sentences) {
255
+ const sentence = one(item);
256
+ if (!sentence || sentence.cites.length === 0)
257
+ return null;
258
+ sentences.push(sentence);
259
+ }
260
+ let change = null;
261
+ if (raw.change !== null && raw.change !== undefined) {
262
+ change = one(raw.change);
263
+ if (!change)
264
+ return null;
265
+ }
266
+ return { line, sentences, change };
267
+ }
268
+ //# sourceMappingURL=role.js.map
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Observed org chart: structure.
3
+ *
4
+ * Who directs whom, who works with whom, working groups, de facto owners and
5
+ * bridges. Every edge carries counts per window, a recency-weighted score and
6
+ * a confidence. Nothing here reads a title, a listed owner or a stated
7
+ * manager: those are compared afterwards (compare.ts).
8
+ *
9
+ * Skew: an edge between two people is never built from the member's own
10
+ * sessions or trackers (weight 0), and the member's direct messages count
11
+ * half, because only the member's side of anyone's messages is on this
12
+ * machine.
13
+ */
14
+ import type { EntityRef } from "../types.js";
15
+ import { type Act } from "./derive.js";
16
+ import { type Bridge, type CollabEdge, type DeFactoOwner, type DirectEvidence, type DirectsEdge, type OrgGraph, type OrgWindow, type WorkingGroup } from "./types.js";
17
+ /** Confidence from an amount of evidence: 0.2 with almost none, approaching 0.9. */
18
+ export declare function confidenceFrom(amount: number, scale: number): number;
19
+ export declare const ACTS_INTERNAL: {
20
+ commits: number;
21
+ meetings: number;
22
+ actions: number;
23
+ };
24
+ /**
25
+ * People on the roster, plus people who behave like team members without being
26
+ * on it: they commit to the company's repos, or they sit in the team's
27
+ * meetings and take actions there and no row places them at another company.
28
+ */
29
+ export declare function orgSet(graph: OrgGraph, actsByPerson: ReadonlyMap<EntityRef, readonly Act[]>): {
30
+ members: Set<EntityRef>;
31
+ actsInternal: Set<EntityRef>;
32
+ };
33
+ /** The score one direction needs over the other before it is called a line and not two peers. */
34
+ export declare const DIRECTS_ASYMMETRY = 2;
35
+ export declare const DIRECTS_MIN_WEIGHT = 2;
36
+ export declare function buildDirects(graph: OrgGraph, evidence: readonly DirectEvidence[], members: ReadonlySet<EntityRef>): DirectsEdge[];
37
+ export declare function buildCollaboration(graph: OrgGraph, members: ReadonlySet<EntityRef>): CollabEdge[];
38
+ /** A bridge carries at least this share of all collaboration between two groups, and at least this much weight. */
39
+ export declare const BRIDGE_MIN_SHARE = 0.3;
40
+ export declare const BRIDGE_MIN_WEIGHT = 1;
41
+ /** Edges below this recency-weighted score are too thin to place anyone in a group. */
42
+ export declare const GROUP_MIN_EDGE = 0.5;
43
+ /**
44
+ * Greedy modularity clustering (Clauset, Newman, Moore): start with every
45
+ * person alone, repeatedly merge the two clusters whose merge raises
46
+ * modularity most, stop when no merge raises it. Deterministic: ties break on
47
+ * the smaller member name.
48
+ */
49
+ export declare function cluster(nodes: readonly string[], edges: readonly {
50
+ a: string;
51
+ b: string;
52
+ weight: number;
53
+ }[]): string[][];
54
+ export declare function buildGroups(graph: OrgGraph, collaboration: readonly CollabEdge[], actsByPerson: ReadonlyMap<EntityRef, readonly Act[]>, members: ReadonlySet<EntityRef>): {
55
+ groups: WorkingGroup[];
56
+ bridges: Bridge[];
57
+ };
58
+ /** How decisive one act is for "who runs this". Attendance alone barely counts. */
59
+ export declare const OWNER_WEIGHT: Readonly<Record<string, number>>;
60
+ export declare const OWNER_MIN_EVENTS = 4;
61
+ export declare const OWNER_CLEAR_SHARE = 0.5;
62
+ export declare function buildOwners(graph: OrgGraph, acts: readonly Act[], members: ReadonlySet<EntityRef>, window?: OrgWindow): DeFactoOwner[];
63
+ //# sourceMappingURL=structure.d.ts.map