@homeostat/dashboard 0.0.0-stage → 0.1.1
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/LICENSE +202 -0
- package/README.md +4 -2
- package/dist/src/automation.d.ts +44 -0
- package/dist/src/automation.js +142 -0
- package/dist/src/charts.d.ts +33 -0
- package/dist/src/charts.js +112 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/metrics.d.ts +91 -0
- package/dist/src/metrics.js +143 -0
- package/dist/src/server.d.ts +17 -0
- package/dist/src/server.js +180 -0
- package/dist/src/settings.d.ts +32 -0
- package/dist/src/settings.js +397 -0
- package/dist/src/views.d.ts +36 -0
- package/dist/src/views.js +397 -0
- package/package.json +40 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @homeostat/dashboard
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The local dashboard for [homeostat](https://www.npmjs.com/package/homeostat): knowledge-base health, agent liveness, impact, document usage and settings forms, served on localhost. Start it with `homeostat dashboard`.
|
|
4
|
+
|
|
5
|
+
Apache-2.0. Source: <https://github.com/ysugarmen/homeostat>.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type Config, type DecisionRecord, type DecisionsFile, type Heartbeat, type RunReport } from "@homeostat/core";
|
|
2
|
+
/**
|
|
3
|
+
* The Automation page reads the `homeostat/state` branch the daily run writes. It reads the
|
|
4
|
+
* clone's copy (`origin/homeostat/state`), which every sync fetches, so the page makes no network
|
|
5
|
+
* call: it is as current as this clone's last sync.
|
|
6
|
+
*/
|
|
7
|
+
export interface AutomationState {
|
|
8
|
+
/** False when no daily run has written the state branch yet (or this clone never fetched it). */
|
|
9
|
+
present: boolean;
|
|
10
|
+
runs: RunReport[];
|
|
11
|
+
heartbeats: Heartbeat[];
|
|
12
|
+
decisions: DecisionsFile[];
|
|
13
|
+
}
|
|
14
|
+
export declare function readAutomation(kbRoot: string, maxRuns?: number): AutomationState;
|
|
15
|
+
export interface SyncHealth {
|
|
16
|
+
member: string;
|
|
17
|
+
role: string;
|
|
18
|
+
heartbeat?: Heartbeat;
|
|
19
|
+
/** "ok", "stale" (no report for STALE_HEARTBEAT_HOURS), "never" (no sync has reported) */
|
|
20
|
+
state: "ok" | "stale" | "never";
|
|
21
|
+
ageHours?: number;
|
|
22
|
+
today?: RunReport["members"][number];
|
|
23
|
+
}
|
|
24
|
+
export interface QueueItem extends DecisionRecord {
|
|
25
|
+
member: string;
|
|
26
|
+
ageDays: number;
|
|
27
|
+
overdue: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface AutomationView {
|
|
30
|
+
present: boolean;
|
|
31
|
+
lastRun?: RunReport;
|
|
32
|
+
runs: RunReport[];
|
|
33
|
+
health: SyncHealth[];
|
|
34
|
+
queue: QueueItem[];
|
|
35
|
+
/** Lessons decided per day, by outcome, over the runs on record. */
|
|
36
|
+
byDay: {
|
|
37
|
+
day: string;
|
|
38
|
+
merged: number;
|
|
39
|
+
review: number;
|
|
40
|
+
declined: number;
|
|
41
|
+
}[];
|
|
42
|
+
}
|
|
43
|
+
export declare function automationView(state: AutomationState, config: Config, now: Date): AutomationView;
|
|
44
|
+
export declare function automationPage(v: AutomationView): string;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { REVIEW_REMINDER_DAYS, STALE_HEARTBEAT_HOURS, STATE_BRANCH, } from "@homeostat/core";
|
|
3
|
+
import { columns, dataTable, esc } from "./charts.js";
|
|
4
|
+
const REF = `refs/remotes/origin/${STATE_BRANCH}`;
|
|
5
|
+
function git(dir, ...args) {
|
|
6
|
+
try {
|
|
7
|
+
return execFileSync("git", ["-C", dir, ...args], {
|
|
8
|
+
encoding: "utf8",
|
|
9
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
10
|
+
maxBuffer: 32 * 1024 * 1024,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function json(dir, path) {
|
|
18
|
+
try {
|
|
19
|
+
return JSON.parse(git(dir, "show", `${REF}:${path}`) ?? "");
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export function readAutomation(kbRoot, maxRuns = 30) {
|
|
26
|
+
const listing = git(kbRoot, "ls-tree", "-r", "--name-only", REF);
|
|
27
|
+
if (listing === undefined)
|
|
28
|
+
return { present: false, runs: [], heartbeats: [], decisions: [] };
|
|
29
|
+
const paths = listing.split("\n").filter(Boolean);
|
|
30
|
+
const under = (dir) => paths.filter((p) => p.startsWith(`${dir}/`) && p.endsWith(".json"));
|
|
31
|
+
const runs = under("runs")
|
|
32
|
+
.sort()
|
|
33
|
+
.slice(-maxRuns)
|
|
34
|
+
.flatMap((p) => json(kbRoot, p) ?? []);
|
|
35
|
+
const heartbeats = under("heartbeats").flatMap((p) => json(kbRoot, p) ?? []);
|
|
36
|
+
const decisions = under("decisions").flatMap((p) => json(kbRoot, p) ?? []);
|
|
37
|
+
return { present: true, runs, heartbeats, decisions };
|
|
38
|
+
}
|
|
39
|
+
export function automationView(state, config, now) {
|
|
40
|
+
const lastRun = state.runs.at(-1);
|
|
41
|
+
const health = config.team.members.map((m) => {
|
|
42
|
+
const heartbeat = state.heartbeats.find((h) => h.member === m.id);
|
|
43
|
+
const ageHours = heartbeat ? (now.getTime() - Date.parse(heartbeat.at)) / 3_600_000 : undefined;
|
|
44
|
+
const today = lastRun?.members.find((r) => r.member === m.id);
|
|
45
|
+
return {
|
|
46
|
+
member: m.id,
|
|
47
|
+
role: m.role,
|
|
48
|
+
...(heartbeat ? { heartbeat } : {}),
|
|
49
|
+
...(ageHours !== undefined ? { ageHours } : {}),
|
|
50
|
+
...(today ? { today } : {}),
|
|
51
|
+
state: !heartbeat ? "never" : (ageHours ?? 0) > STALE_HEARTBEAT_HOURS ? "stale" : "ok",
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
const queue = state.decisions
|
|
55
|
+
.flatMap((d) => d.decided
|
|
56
|
+
.filter((r) => r.decision === "review")
|
|
57
|
+
.map((r) => {
|
|
58
|
+
const ageDays = (now.getTime() - Date.parse(r.at)) / 86_400_000;
|
|
59
|
+
return { ...r, member: d.member, ageDays, overdue: ageDays > REVIEW_REMINDER_DAYS };
|
|
60
|
+
}))
|
|
61
|
+
.sort((a, b) => b.ageDays - a.ageDays);
|
|
62
|
+
const byDay = state.runs.map((r) => ({
|
|
63
|
+
day: r.at.slice(0, 10),
|
|
64
|
+
merged: r.members.reduce((n, m) => n + m.merged, 0),
|
|
65
|
+
review: r.members.reduce((n, m) => n + m.review, 0),
|
|
66
|
+
declined: r.members.reduce((n, m) => n + m.declined, 0),
|
|
67
|
+
}));
|
|
68
|
+
return {
|
|
69
|
+
present: state.present,
|
|
70
|
+
...(lastRun ? { lastRun } : {}),
|
|
71
|
+
runs: state.runs,
|
|
72
|
+
health,
|
|
73
|
+
queue,
|
|
74
|
+
byDay,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const age = (hours) => hours === undefined
|
|
78
|
+
? "—"
|
|
79
|
+
: hours < 1
|
|
80
|
+
? "under 1h"
|
|
81
|
+
: hours < 48
|
|
82
|
+
? `${Math.round(hours)}h`
|
|
83
|
+
: `${Math.round(hours / 24)}d`;
|
|
84
|
+
const prLink = (url, label = "PR") => url && /^https:\/\//.test(url) ? `<a href="${esc(url)}">${esc(label)}</a>` : "";
|
|
85
|
+
function healthRow(h) {
|
|
86
|
+
const lamp = h.state === "ok" ? "good" : h.state === "stale" ? "warning" : "";
|
|
87
|
+
const state = h.state === "ok"
|
|
88
|
+
? "Syncing"
|
|
89
|
+
: h.state === "stale"
|
|
90
|
+
? `Not syncing for ${age(h.ageHours)}`
|
|
91
|
+
: "No sync yet";
|
|
92
|
+
const hb = h.heartbeat;
|
|
93
|
+
const kb = !hb ? "—" : hb.behind > 0 ? `${hb.behind} behind` : "current";
|
|
94
|
+
const t = h.today;
|
|
95
|
+
const outcome = t
|
|
96
|
+
? `${t.merged} merged · ${t.review} to review · ${t.declined} declined${t.mergeError ? " · merge refused" : ""}`
|
|
97
|
+
: "—";
|
|
98
|
+
return `<tr><td class="mono">${esc(h.member)}</td><td>${esc(h.role)}</td><td><span class="lamp ${lamp}" aria-hidden="true" style="display:inline-block;vertical-align:middle;margin-right:6px"></span>${esc(state)}</td><td class="num">${age(h.ageHours)}</td><td class="mono">${esc(kb)}</td><td class="num">${hb?.pending ?? "—"}</td><td class="mono">${esc(hb?.version ?? "—")}</td><td>${esc(outcome)} ${prLink(t?.dailyPr, "daily")} ${prLink(t?.reviewPr, "review")}</td></tr>`;
|
|
99
|
+
}
|
|
100
|
+
export function automationPage(v) {
|
|
101
|
+
if (!v.present) {
|
|
102
|
+
return `<section class="panel"><h2>Automation</h2><p class="lede">No daily run on record in this clone yet. The daily run (<code>homeostat daily</code>, scheduled in the KB repo's CI) writes its decisions to the <code>${STATE_BRANCH}</code> branch, and each developer's sync fetches it. Once the first run has happened and this clone has synced, its runs, every developer's sync health and the review queue show up here.</p></section>`;
|
|
103
|
+
}
|
|
104
|
+
const r = v.lastRun;
|
|
105
|
+
const stat = (n, k) => `<div class="stat"><span class="n">${n}</span><span class="k">${k}</span></div>`;
|
|
106
|
+
const total = (k) => r?.members.reduce((n, m) => n + m[k], 0) ?? 0;
|
|
107
|
+
const notSyncing = v.health.filter((h) => h.state !== "ok");
|
|
108
|
+
const overdue = v.queue.filter((q) => q.overdue).length;
|
|
109
|
+
const daily = v.byDay.map((d) => ({
|
|
110
|
+
label: d.day.slice(5),
|
|
111
|
+
value: d.merged + d.review + d.declined,
|
|
112
|
+
title: `${d.day}: ${d.merged} merged, ${d.review} to review, ${d.declined} declined`,
|
|
113
|
+
}));
|
|
114
|
+
return `<div class="grid">
|
|
115
|
+
<section class="panel span-8" aria-labelledby="last"><h2 id="last">Last daily run</h2>
|
|
116
|
+
${r ? `<p class="lede mono">${esc(r.at.replace("T", " ").slice(0, 16))} UTC</p>` : ""}
|
|
117
|
+
<div class="stats" style="--cols: 4">${stat(total("merged"), "merged")}${stat(total("review"), "to review")}${stat(total("declined"), "declined")}${stat(r?.settled ?? 0, "settled by reviewers")}</div>
|
|
118
|
+
${daily.length > 1 ? `<div style="margin-top:14px"><span class="label">Lessons decided per run</span>${columns(daily, { title: "Lessons decided per run", labelled: "ends", tickEvery: 7 })}${dataTable(daily, ["Run", "Lessons"])}</div>` : ""}</section>
|
|
119
|
+
<section class="panel span-4" aria-labelledby="attention"><h2 id="attention">Needs attention</h2>
|
|
120
|
+
<div class="stats" style="--cols: 2">${stat(v.queue.length, "in review")}${stat(overdue, `waiting > ${REVIEW_REMINDER_DAYS} days`)}${stat(notSyncing.length, "not syncing")}${stat(r?.members.filter((m) => m.mergeError).length ?? 0, "merges refused")}</div>
|
|
121
|
+
${notSyncing.length ? `<p class="lede">Not syncing: ${notSyncing.map((h) => `<span class="mono">${esc(h.member)}</span>`).join(", ")}. Their lessons reach the daily run only after a session syncs; check that the Homeostat plugin is installed for them.</p>` : ""}</section>
|
|
122
|
+
<section class="panel span-12" aria-labelledby="queue"><h2 id="queue">Review queue</h2><p class="lede">Lessons the daily run could not decide on its own. Merging the review PR accepts them; closing it declines them. The next daily run records the outcome, and the developer's sync picks it up.</p>
|
|
123
|
+
${v.queue.length
|
|
124
|
+
? `<div class="table-wrap"><table><thead><tr><th>Lesson</th><th>Developer</th><th class="num">Confidence</th><th>Why it waits</th><th class="num">Waiting</th><th>PR branch</th></tr></thead><tbody>${v.queue
|
|
125
|
+
.map((q) => `<tr><td class="mono">${esc(q.id)}</td><td class="mono">${esc(q.member)}</td><td class="num">${q.confidence ?? "—"}</td><td>${esc(q.reason)}</td><td class="num">${q.overdue ? '<span class="chip disputed">' : ""}${Math.floor(q.ageDays)}d${q.overdue ? "</span>" : ""}</td><td class="mono">${esc(q.pr ?? "—")}</td></tr>`)
|
|
126
|
+
.join("")}</tbody></table></div>`
|
|
127
|
+
: '<p class="empty">Nothing waiting for a reviewer.</p>'}</section>
|
|
128
|
+
<section class="panel span-12" aria-labelledby="health"><h2 id="health">Developer sync</h2><p class="lede">Each developer's sessions sync their clone in the background and report a heartbeat; the daily run collects them. "Not syncing" means no report for ${STALE_HEARTBEAT_HOURS} hours: normal over a weekend, worth a look after that.</p>
|
|
129
|
+
<div class="table-wrap"><table><thead><tr><th>Member</th><th>Role</th><th>Sync</th><th class="num">Last report</th><th>KB clone</th><th class="num">Pending</th><th>Version</th><th>Last daily run</th></tr></thead><tbody>${v.health.map(healthRow).join("")}</tbody></table></div></section>
|
|
130
|
+
<section class="panel span-12" aria-labelledby="runs"><h2 id="runs">Runs</h2>
|
|
131
|
+
<div class="table-wrap"><table><thead><tr><th>Run</th><th class="num">Merged</th><th class="num">To review</th><th class="num">Declined</th><th class="num">Settled</th><th>Merge refused</th></tr></thead><tbody>${[
|
|
132
|
+
...v.runs,
|
|
133
|
+
]
|
|
134
|
+
.reverse()
|
|
135
|
+
.map((run) => {
|
|
136
|
+
const sum = (k) => run.members.reduce((n, m) => n + m[k], 0);
|
|
137
|
+
const refused = run.members.filter((m) => m.mergeError).map((m) => m.member);
|
|
138
|
+
return `<tr><td class="mono">${esc(run.at.replace("T", " ").slice(0, 16))}</td><td class="num">${sum("merged")}</td><td class="num">${sum("review")}</td><td class="num">${sum("declined")}</td><td class="num">${run.settled}</td><td class="mono">${esc(refused.join(", ") || "—")}</td></tr>`;
|
|
139
|
+
})
|
|
140
|
+
.join("")}</tbody></table></div></section>
|
|
141
|
+
</div>`;
|
|
142
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Escapes text for HTML and SVG. */
|
|
2
|
+
export declare const esc: (s: unknown) => string;
|
|
3
|
+
export interface Datum {
|
|
4
|
+
label: string;
|
|
5
|
+
value: number;
|
|
6
|
+
/** Shown in the hover tooltip; defaults to "label: value". */
|
|
7
|
+
title?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Vertical bars for one series over categories or days. Labels only the bars named in
|
|
11
|
+
* `labelled` (selective direct labels); every bar has a hover tooltip.
|
|
12
|
+
*/
|
|
13
|
+
export declare function columns(data: readonly Datum[], opts: {
|
|
14
|
+
title: string;
|
|
15
|
+
height?: number;
|
|
16
|
+
labelled?: "all" | "ends";
|
|
17
|
+
tickEvery?: number;
|
|
18
|
+
}): string;
|
|
19
|
+
/** Horizontal bars for one series, each labelled at its data end. */
|
|
20
|
+
export declare function rows(data: readonly Datum[], opts: {
|
|
21
|
+
title: string;
|
|
22
|
+
labelWidth?: number;
|
|
23
|
+
}): string;
|
|
24
|
+
/**
|
|
25
|
+
* The homeostat's dial: a half-circle meter with a needle at `value` (0..1). Ashby's machine
|
|
26
|
+
* showed each unit's state on a needle; here it is the share of the KB that is healthy.
|
|
27
|
+
*/
|
|
28
|
+
export declare function dial(value: number, opts: {
|
|
29
|
+
title: string;
|
|
30
|
+
caption: string;
|
|
31
|
+
}): string;
|
|
32
|
+
/** The table view every chart offers, for screen readers and exact numbers. */
|
|
33
|
+
export declare function dataTable(data: readonly Datum[], headers: [string, string]): string;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/** Escapes text for HTML and SVG. */
|
|
2
|
+
export const esc = (s) => String(s ?? "")
|
|
3
|
+
.replace(/&/g, "&")
|
|
4
|
+
.replace(/</g, "<")
|
|
5
|
+
.replace(/>/g, ">")
|
|
6
|
+
.replace(/"/g, """);
|
|
7
|
+
/** A bar whose data end (top) is rounded 4px and whose base sits square on the baseline. */
|
|
8
|
+
function columnPath(x, y, w, h) {
|
|
9
|
+
if (h <= 0)
|
|
10
|
+
return "";
|
|
11
|
+
const r = Math.min(4, w / 2, h);
|
|
12
|
+
return `M${x},${y + h}V${y + r}Q${x},${y} ${x + r},${y}H${x + w - r}Q${x + w},${y} ${x + w},${y + r}V${y + h}Z`;
|
|
13
|
+
}
|
|
14
|
+
/** The same, lying down: rounded on the right (data) end, square on the left baseline. */
|
|
15
|
+
function rowPath(x, y, w, h) {
|
|
16
|
+
if (w <= 0)
|
|
17
|
+
return "";
|
|
18
|
+
const r = Math.min(4, h / 2, w);
|
|
19
|
+
return `M${x},${y}H${x + w - r}Q${x + w},${y} ${x + w},${y + r}V${y + h - r}Q${x + w},${y + h} ${x + w - r},${y + h}H${x}Z`;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Vertical bars for one series over categories or days. Labels only the bars named in
|
|
23
|
+
* `labelled` (selective direct labels); every bar has a hover tooltip.
|
|
24
|
+
*/
|
|
25
|
+
export function columns(data, opts) {
|
|
26
|
+
const width = 560;
|
|
27
|
+
const height = opts.height ?? 140;
|
|
28
|
+
const pad = { top: 18, bottom: 22, left: 4, right: 4 };
|
|
29
|
+
const max = Math.max(1, ...data.map((d) => d.value));
|
|
30
|
+
const inner = height - pad.top - pad.bottom;
|
|
31
|
+
const slot = (width - pad.left - pad.right) / Math.max(data.length, 1);
|
|
32
|
+
const gap = 2;
|
|
33
|
+
const bar = Math.max(2, Math.min(36, slot - gap));
|
|
34
|
+
const maxIndex = data.findIndex((d) => d.value === max);
|
|
35
|
+
const show = (i) => opts.labelled === "all" ||
|
|
36
|
+
(opts.labelled === "ends" && (i === data.length - 1 || i === maxIndex));
|
|
37
|
+
const marks = data
|
|
38
|
+
.map((d, i) => {
|
|
39
|
+
const h = (d.value / max) * inner;
|
|
40
|
+
const x = pad.left + i * slot + (slot - bar) / 2;
|
|
41
|
+
const y = pad.top + inner - h;
|
|
42
|
+
const label = show(i) && d.value > 0
|
|
43
|
+
? `<text class="v" x="${x + bar / 2}" y="${y - 5}" text-anchor="middle">${d.value}</text>`
|
|
44
|
+
: "";
|
|
45
|
+
const tick = opts.tickEvery && i % opts.tickEvery === 0
|
|
46
|
+
? `<text class="t" x="${x + bar / 2}" y="${height - 6}" text-anchor="middle">${esc(d.label)}</text>`
|
|
47
|
+
: !opts.tickEvery
|
|
48
|
+
? `<text class="t" x="${x + bar / 2}" y="${height - 6}" text-anchor="middle">${esc(d.label)}</text>`
|
|
49
|
+
: "";
|
|
50
|
+
// The hit target spans the whole slot, taller and wider than the mark.
|
|
51
|
+
return `<g class="m"><rect class="hit" x="${pad.left + i * slot}" y="${pad.top}" width="${slot}" height="${inner}"/><path d="${columnPath(x, y, bar, h)}"/>${label}${tick}<title>${esc(d.title ?? `${d.label}: ${d.value}`)}</title></g>`;
|
|
52
|
+
})
|
|
53
|
+
.join("");
|
|
54
|
+
return `<svg class="chart" viewBox="0 0 ${width} ${height}" role="img" aria-label="${esc(opts.title)}"><line class="base" x1="0" x2="${width}" y1="${pad.top + inner}" y2="${pad.top + inner}"/>${marks}</svg>`;
|
|
55
|
+
}
|
|
56
|
+
/** Horizontal bars for one series, each labelled at its data end. */
|
|
57
|
+
export function rows(data, opts) {
|
|
58
|
+
const width = 560;
|
|
59
|
+
const rowH = 22;
|
|
60
|
+
const labelW = opts.labelWidth ?? 220;
|
|
61
|
+
const height = Math.max(rowH, data.length * rowH) + 4;
|
|
62
|
+
const max = Math.max(1, ...data.map((d) => d.value));
|
|
63
|
+
const track = width - labelW - 40;
|
|
64
|
+
const marks = data
|
|
65
|
+
.map((d, i) => {
|
|
66
|
+
const y = i * rowH + 4;
|
|
67
|
+
const w = (d.value / max) * track;
|
|
68
|
+
return `<g class="m"><rect class="hit" x="0" y="${y - 2}" width="${width}" height="${rowH}"/><text class="t" x="${labelW - 8}" y="${y + 12}" text-anchor="end">${esc(d.label)}</text><path d="${rowPath(labelW, y + 2, w, rowH - 8)}"/><text class="v" x="${labelW + w + 6}" y="${y + 12}">${d.value}</text><title>${esc(d.title ?? `${d.label}: ${d.value}`)}</title></g>`;
|
|
69
|
+
})
|
|
70
|
+
.join("");
|
|
71
|
+
return `<svg class="chart" viewBox="0 0 ${width} ${height}" role="img" aria-label="${esc(opts.title)}"><line class="base" x1="${labelW}" x2="${labelW}" y1="0" y2="${height}"/>${marks}</svg>`;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The homeostat's dial: a half-circle meter with a needle at `value` (0..1). Ashby's machine
|
|
75
|
+
* showed each unit's state on a needle; here it is the share of the KB that is healthy.
|
|
76
|
+
*/
|
|
77
|
+
export function dial(value, opts) {
|
|
78
|
+
const v = Math.max(0, Math.min(1, value));
|
|
79
|
+
const cx = 110;
|
|
80
|
+
const cy = 104;
|
|
81
|
+
const r = 86;
|
|
82
|
+
const point = (t, radius) => {
|
|
83
|
+
const a = Math.PI * (1 - t);
|
|
84
|
+
return [cx + radius * Math.cos(a), cy - radius * Math.sin(a)];
|
|
85
|
+
};
|
|
86
|
+
const ticks = Array.from({ length: 11 }, (_, i) => {
|
|
87
|
+
const [x1, y1] = point(i / 10, r - (i % 5 === 0 ? 12 : 7));
|
|
88
|
+
const [x2, y2] = point(i / 10, r);
|
|
89
|
+
return `<line class="tick${i % 5 === 0 ? " major" : ""}" x1="${x1}" y1="${y1}" x2="${x2}" y2="${y2}"/>`;
|
|
90
|
+
}).join("");
|
|
91
|
+
const [ax, ay] = point(0, r);
|
|
92
|
+
const [bx, by] = point(1, r);
|
|
93
|
+
const [nx, ny] = point(v, r - 18);
|
|
94
|
+
const [vx, vy] = point(v, r);
|
|
95
|
+
const large = 0;
|
|
96
|
+
return `<svg class="dial" viewBox="0 0 220 158" role="img" aria-label="${esc(opts.title)}: ${Math.round(v * 100)}%">
|
|
97
|
+
<path class="track" d="M${ax},${ay} A${r},${r} 0 ${large} 1 ${bx},${by}"/>
|
|
98
|
+
<path class="fill" d="M${ax},${ay} A${r},${r} 0 ${large} 1 ${vx},${vy}"/>
|
|
99
|
+
${ticks}
|
|
100
|
+
<line class="needle" x1="${cx}" y1="${cy}" x2="${nx}" y2="${ny}"/>
|
|
101
|
+
<circle class="hub" cx="${cx}" cy="${cy}" r="5"/>
|
|
102
|
+
<text class="dial-value" x="${cx}" y="${cy + 34}" text-anchor="middle">${Math.round(v * 100)}%</text>
|
|
103
|
+
<text class="dial-caption" x="${cx}" y="${cy + 52}" text-anchor="middle">${esc(opts.caption)}</text>
|
|
104
|
+
<title>${esc(opts.title)}: ${Math.round(v * 100)}%</title>
|
|
105
|
+
</svg>`;
|
|
106
|
+
}
|
|
107
|
+
/** The table view every chart offers, for screen readers and exact numbers. */
|
|
108
|
+
export function dataTable(data, headers) {
|
|
109
|
+
return `<details class="table-view"><summary>Table</summary><table><thead><tr><th>${esc(headers[0])}</th><th class="num">${esc(headers[1])}</th></tr></thead><tbody>${data
|
|
110
|
+
.map((d) => `<tr><td>${esc(d.label)}</td><td class="num">${d.value}</td></tr>`)
|
|
111
|
+
.join("")}</tbody></table></details>`;
|
|
112
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { type DashboardOptions, startDashboard } from "./server.ts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { startDashboard } from "./server.js";
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { type AgentName, type Config, type ContextDoc, type Entry, type Event, type Status } from "@homeostat/core";
|
|
2
|
+
export interface Snapshot {
|
|
3
|
+
config: Config;
|
|
4
|
+
entries: readonly Entry[];
|
|
5
|
+
/** Knowledge documents (K1); absent in older callers. */
|
|
6
|
+
docs?: readonly ContextDoc[];
|
|
7
|
+
events: readonly Event[];
|
|
8
|
+
now: Date;
|
|
9
|
+
}
|
|
10
|
+
export interface AgentLiveness {
|
|
11
|
+
agent: AgentName;
|
|
12
|
+
enabled: boolean;
|
|
13
|
+
schedule: string;
|
|
14
|
+
nextRun?: string;
|
|
15
|
+
lastRun?: {
|
|
16
|
+
ts: string;
|
|
17
|
+
ok: boolean;
|
|
18
|
+
summary: string;
|
|
19
|
+
};
|
|
20
|
+
lastSuccess?: string;
|
|
21
|
+
failures7d: number;
|
|
22
|
+
}
|
|
23
|
+
export declare function agentLiveness({ config, events, now }: Snapshot): AgentLiveness[];
|
|
24
|
+
export interface Health {
|
|
25
|
+
total: number;
|
|
26
|
+
byStatus: Record<Status, number>;
|
|
27
|
+
/** Days since last confirmed, averaged over accepted entries. */
|
|
28
|
+
averageAgeDays: number;
|
|
29
|
+
stale: string[];
|
|
30
|
+
disputed: string[];
|
|
31
|
+
flagged: string[];
|
|
32
|
+
possibleDuplicates: [string, string][];
|
|
33
|
+
/** Share of all entries that are accepted, not stale and not flagged: the dial on the overview. */
|
|
34
|
+
stability: number;
|
|
35
|
+
}
|
|
36
|
+
export declare function health({ config, entries, now }: Snapshot): Health;
|
|
37
|
+
export interface Contribution {
|
|
38
|
+
member: string;
|
|
39
|
+
role: string;
|
|
40
|
+
authored: number;
|
|
41
|
+
accepted: number;
|
|
42
|
+
/** Accepted share of what they authored; undefined with nothing authored. */
|
|
43
|
+
acceptedRatio?: number;
|
|
44
|
+
flagsRaised: number;
|
|
45
|
+
captured30d: number;
|
|
46
|
+
}
|
|
47
|
+
export declare function contributions({ config, entries, events, now }: Snapshot): Contribution[];
|
|
48
|
+
export interface AreaCoverage {
|
|
49
|
+
area: string;
|
|
50
|
+
globs: readonly string[];
|
|
51
|
+
accepted: number;
|
|
52
|
+
candidates: number;
|
|
53
|
+
}
|
|
54
|
+
export interface SourceCoverage {
|
|
55
|
+
repo: string;
|
|
56
|
+
/** Entries whose source review comment came from this repo. */
|
|
57
|
+
entries: number;
|
|
58
|
+
}
|
|
59
|
+
export declare function coverage({ config, entries }: Snapshot): {
|
|
60
|
+
areas: AreaCoverage[];
|
|
61
|
+
sources: SourceCoverage[];
|
|
62
|
+
};
|
|
63
|
+
export interface DailyCount {
|
|
64
|
+
day: string;
|
|
65
|
+
count: number;
|
|
66
|
+
}
|
|
67
|
+
export interface Impact {
|
|
68
|
+
injectionsByDay: DailyCount[];
|
|
69
|
+
mcpCallsByDay: DailyCount[];
|
|
70
|
+
sessions: number;
|
|
71
|
+
rulesPerInjection: number;
|
|
72
|
+
tokensPerInjection: number;
|
|
73
|
+
topRules: {
|
|
74
|
+
id: string;
|
|
75
|
+
injections: number;
|
|
76
|
+
}[];
|
|
77
|
+
toolUse: {
|
|
78
|
+
tool: string;
|
|
79
|
+
calls: number;
|
|
80
|
+
}[];
|
|
81
|
+
}
|
|
82
|
+
export declare function impact({ events, now }: Snapshot, days?: number): Impact;
|
|
83
|
+
export interface DesirePath {
|
|
84
|
+
name: string;
|
|
85
|
+
/** The real tool it resolved to, or undefined when nothing did. */
|
|
86
|
+
resolved?: string;
|
|
87
|
+
count: number;
|
|
88
|
+
last: string;
|
|
89
|
+
}
|
|
90
|
+
/** Tool names agents guessed: the ones to consider implementing (execution plan 3.2). */
|
|
91
|
+
export declare function desirePaths({ events }: Snapshot): DesirePath[];
|