crewly 1.20.449 → 1.20.450
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/config/skills/agent/checkup-report/SKILL.md +96 -0
- package/config/skills/agent/checkup-report/app/index.html +265 -0
- package/config/skills/agent/checkup-report/execute.sh +37 -0
- package/config/skills/agent/checkup-report/execute.test.sh +137 -0
- package/config/skills/agent/checkup-report/report.mjs +194 -0
- package/dist/backend/build-info.json +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Check-up Report
|
|
3
|
+
description: The intake and report steps of the small-business check-up as one Crewly App. Copies the bundled App page (five intake questions, the report with the top 3 breaks and what an agent could do, a 7-day daily summary) into the project for publish-app, turns checkup-analyse's breaks.json into the App's report document (with the number the owner asked to see first), and writes daily-summary documents for app-data.
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
category: productivity
|
|
6
|
+
skillType: claude-skill
|
|
7
|
+
assignableRoles:
|
|
8
|
+
- "*"
|
|
9
|
+
triggers:
|
|
10
|
+
- check-up report
|
|
11
|
+
- checkup app
|
|
12
|
+
- publish the check-up
|
|
13
|
+
- intake questions
|
|
14
|
+
- daily check-up summary
|
|
15
|
+
tags:
|
|
16
|
+
- check-up
|
|
17
|
+
- small-business
|
|
18
|
+
- apps
|
|
19
|
+
- report
|
|
20
|
+
execution:
|
|
21
|
+
type: script
|
|
22
|
+
script:
|
|
23
|
+
file: execute.sh
|
|
24
|
+
interpreter: bash
|
|
25
|
+
timeoutMs: 60000
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
# Check-up Report
|
|
29
|
+
|
|
30
|
+
Steps 1 and 4 of the small-business check-up (crewly#1062), on one Crewly
|
|
31
|
+
App the owner opens on their phone: **Your answers** (five intake questions),
|
|
32
|
+
**Report** (the top 3 breaks with estimate, formula, examples and what an agent
|
|
33
|
+
could do; every break; files; assumptions) and **Daily** (a line a day for the
|
|
34
|
+
7 free days after the report). The page is built once; the data is per
|
|
35
|
+
business.
|
|
36
|
+
|
|
37
|
+
## 1. Intake — publish the App and get the five answers
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
bash execute.sh --app-dir ./checkup-app # copies the page into the project (publish-app needs a project path)
|
|
41
|
+
bash publish-app --dir ./checkup-app --name "<Business> check-up" --notify
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The owner lands on **Your answers** (no report yet): which apps, the slowest
|
|
45
|
+
weekly task, what they fear slipping through, how many apps one customer
|
|
46
|
+
passes through, which number they want to see first. Saving writes
|
|
47
|
+
`intake/answers` and sends you a message. Read it:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
bash app-data --app <appId> --get intake answers > ./intake.json
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Use `apps` to decide the connect path per app (connector, `ingest-exports`,
|
|
54
|
+
or the browser as last resort) and `firstNumber` for the report.
|
|
55
|
+
|
|
56
|
+
## 2. Connect and analyse
|
|
57
|
+
|
|
58
|
+
`ingest-exports` (exports → common schema) then `checkup-analyse`
|
|
59
|
+
(breaks + estimates → `breaks.json`). See those skills.
|
|
60
|
+
|
|
61
|
+
## 3. Report — put the result in the App
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
bash execute.sh --breaks <analysis>/breaks.json --business "<Business>" --intake ./intake.json --out ./checkup-data
|
|
65
|
+
bash app-data --app <appId> --set report current --data-file ./checkup-data/report-doc.json
|
|
66
|
+
bash publish-app --app <appId> --share # a fresh one-tap link to the owner
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`report-doc.json` holds the top 3, every break with its estimate and formula,
|
|
70
|
+
up to three short examples per break (none when the exports were hashed),
|
|
71
|
+
notes for checks the data could not support, the files and the assumptions.
|
|
72
|
+
When the intake said which number to see first, the report leads with it
|
|
73
|
+
(`firstNumber`): money owed (overdue invoices + unpaid sign-ups), missed
|
|
74
|
+
inquiries, hours lost to double entry, or lapsed customers. The whole list of
|
|
75
|
+
people never goes into the App; it stays in `breaks.json` on this machine.
|
|
76
|
+
|
|
77
|
+
## 4. Daily — one line a day for 7 days
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
bash execute.sh --daily "Replied to 3 open inquiries; 1 booked. Sent 2 invoice reminders." --out ./checkup-data
|
|
81
|
+
bash app-data --app <appId> --set daily 2026-10-27 --data-file ./checkup-data/daily-2026-10-27.json
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Say what changed and what was done, in the owner's language, under 300
|
|
85
|
+
characters. Seven entries, then stop unless the owner asks for more.
|
|
86
|
+
|
|
87
|
+
## Time log
|
|
88
|
+
|
|
89
|
+
Record the start and end of each step (intake, connect, analyse, report) in
|
|
90
|
+
your work notes; the check-up is measured by how long it really takes.
|
|
91
|
+
|
|
92
|
+
## Report back
|
|
93
|
+
|
|
94
|
+
Tell the owner in plain words: the App is ready (the card has the link), the
|
|
95
|
+
top 3 with count and estimate, that the dollars are estimates from listed
|
|
96
|
+
assumptions, and the one thing you would start on. Do not paste the document.
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en"><head>
|
|
3
|
+
<meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
|
|
4
|
+
<title>Business check-up</title>
|
|
5
|
+
<style>
|
|
6
|
+
:root { --ink: #1c1c1e; --muted: #6b6b70; --line: #e4e4e8; --accent: #1f6feb; --bg: #fff; --card: #f6f7f9; --warn: #b4540a; }
|
|
7
|
+
* { box-sizing: border-box; }
|
|
8
|
+
body { font: 16px/1.45 system-ui, -apple-system, sans-serif; margin: 0; padding: 16px 16px 48px; max-width: 640px; color: var(--ink); background: var(--bg); }
|
|
9
|
+
h1 { font-size: 22px; margin: 0 0 4px; }
|
|
10
|
+
h2 { font-size: 18px; margin: 28px 0 8px; }
|
|
11
|
+
h3 { font-size: 16px; margin: 0 0 6px; }
|
|
12
|
+
p { margin: 0 0 10px; }
|
|
13
|
+
.muted { color: var(--muted); font-size: 14px; }
|
|
14
|
+
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin: 0 0 12px; }
|
|
15
|
+
.rank { display: inline-block; min-width: 28px; height: 28px; line-height: 28px; text-align: center; border-radius: 14px; background: var(--accent); color: #fff; font-weight: 600; margin-right: 8px; }
|
|
16
|
+
.num { font-size: 20px; font-weight: 600; }
|
|
17
|
+
.est { margin: 8px 0 4px; }
|
|
18
|
+
.formula { font-size: 13px; color: var(--muted); border-left: 3px solid var(--line); padding-left: 8px; margin: 6px 0; }
|
|
19
|
+
.agent { background: #eef4ff; border-radius: 8px; padding: 8px 10px; margin-top: 8px; font-size: 15px; }
|
|
20
|
+
table { width: 100%; border-collapse: collapse; font-size: 15px; }
|
|
21
|
+
th, td { text-align: left; padding: 8px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
|
|
22
|
+
td.r, th.r { text-align: right; white-space: nowrap; }
|
|
23
|
+
label { display: block; font-weight: 600; margin: 16px 0 6px; }
|
|
24
|
+
input, textarea, select, button { font: inherit; font-size: 16px; width: 100%; min-height: 44px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); }
|
|
25
|
+
textarea { min-height: 72px; resize: vertical; }
|
|
26
|
+
button { background: var(--accent); color: #fff; border: 0; font-weight: 600; margin-top: 16px; }
|
|
27
|
+
button.secondary { background: var(--card); color: var(--ink); border: 1px solid var(--line); margin-top: 8px; }
|
|
28
|
+
.chips { margin: 0 -4px; }
|
|
29
|
+
.chip { display: inline-block; margin: 4px; padding: 8px 12px; min-height: 44px; line-height: 28px; border: 1px solid var(--line); border-radius: 22px; background: #fff; cursor: pointer; }
|
|
30
|
+
.chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }
|
|
31
|
+
#msg { min-height: 20px; color: var(--warn); margin-top: 8px; }
|
|
32
|
+
.ok { color: #1a7f37; }
|
|
33
|
+
.hidden { display: none; }
|
|
34
|
+
.tabs { display: flex; margin: 0 0 16px; border-bottom: 1px solid var(--line); }
|
|
35
|
+
.tab { flex: 1; text-align: center; padding: 12px 4px; min-height: 44px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
|
|
36
|
+
.tab.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
|
|
37
|
+
ul.plain { list-style: none; padding: 0; margin: 0; }
|
|
38
|
+
ul.plain li { padding: 8px 0; border-bottom: 1px solid var(--line); }
|
|
39
|
+
.note { font-size: 14px; color: var(--muted); }
|
|
40
|
+
</style>
|
|
41
|
+
</head><body>
|
|
42
|
+
<h1 id="title" data-crewly-id="title">Business check-up</h1>
|
|
43
|
+
<p class="muted" id="subtitle" data-crewly-id="subtitle">Loading…</p>
|
|
44
|
+
|
|
45
|
+
<div class="tabs" id="tabs">
|
|
46
|
+
<div class="tab on" id="tab-report" data-crewly-id="tab-report">Report</div>
|
|
47
|
+
<div class="tab" id="tab-intake" data-crewly-id="tab-intake">Your answers</div>
|
|
48
|
+
<div class="tab" id="tab-daily" data-crewly-id="tab-daily">Daily</div>
|
|
49
|
+
</div>
|
|
50
|
+
|
|
51
|
+
<!-- ───────── Report ───────── -->
|
|
52
|
+
<section id="report" data-crewly-id="report">
|
|
53
|
+
<div id="report-empty" class="card hidden" data-crewly-id="report-empty">
|
|
54
|
+
<h3>No report yet</h3>
|
|
55
|
+
<p class="muted">Answer the five questions under "Your answers" and share your exports. The report appears here when the check-up is done.</p>
|
|
56
|
+
</div>
|
|
57
|
+
<div id="report-body" class="hidden">
|
|
58
|
+
<div class="card" id="headline" data-crewly-id="headline">
|
|
59
|
+
<div class="muted" id="asof"></div>
|
|
60
|
+
<p class="est"><span class="num" id="total-hours"></span> h/week · <span class="num" id="total-dollars"></span>/month</p>
|
|
61
|
+
<p class="note">Estimates from the assumptions at the end. Change an assumption and the numbers follow.</p>
|
|
62
|
+
</div>
|
|
63
|
+
<div id="first-number" class="card hidden" data-crewly-id="first-number"></div>
|
|
64
|
+
<h2>Top 3</h2>
|
|
65
|
+
<div id="top3" data-crewly-id="top3"></div>
|
|
66
|
+
<h2>Every break</h2>
|
|
67
|
+
<table data-crewly-id="all-breaks"><thead><tr><th>Break</th><th class="r">Count</th><th class="r">h/wk</th><th class="r">$/mo</th></tr></thead><tbody id="all-rows"></tbody></table>
|
|
68
|
+
<div id="notes-wrap" class="hidden"><h2>Could not check</h2><ul class="plain" id="notes" data-crewly-id="notes"></ul></div>
|
|
69
|
+
<h2>Files</h2>
|
|
70
|
+
<ul class="plain" id="files" data-crewly-id="files"></ul>
|
|
71
|
+
<h2>Assumptions</h2>
|
|
72
|
+
<ul class="plain" id="assumptions" data-crewly-id="assumptions"></ul>
|
|
73
|
+
<button class="secondary" id="ask" data-crewly-id="ask">Ask about this report</button>
|
|
74
|
+
</div>
|
|
75
|
+
</section>
|
|
76
|
+
|
|
77
|
+
<!-- ───────── Intake ───────── -->
|
|
78
|
+
<section id="intake" class="hidden" data-crewly-id="intake">
|
|
79
|
+
<p class="muted">Five questions, two minutes. Your answers tell the check-up where to look first.</p>
|
|
80
|
+
<label for="q-apps">1. Which apps does the business run on?</label>
|
|
81
|
+
<div class="chips" id="q-apps-chips" data-crewly-id="q-apps"></div>
|
|
82
|
+
<input id="q-apps" placeholder="Others, comma-separated">
|
|
83
|
+
<label for="q-task">2. Which weekly task takes the most time?</label>
|
|
84
|
+
<textarea id="q-task" data-crewly-id="q-task" placeholder="e.g. copying new sign-ups from the form into the roster and the mailing list"></textarea>
|
|
85
|
+
<label>3. What do you fear slipping through?</label>
|
|
86
|
+
<div class="chips" id="q-fear-chips" data-crewly-id="q-fear"></div>
|
|
87
|
+
<input id="q-fear" placeholder="Anything else">
|
|
88
|
+
<label for="q-hops">4. How many apps does one customer pass through, from first contact to payment?</label>
|
|
89
|
+
<select id="q-hops" data-crewly-id="q-hops"><option value="">Pick one</option><option>1</option><option>2</option><option>3</option><option>4</option><option>5 or more</option></select>
|
|
90
|
+
<label for="q-first">5. Which number do you want to see first?</label>
|
|
91
|
+
<div class="chips" id="q-first-chips" data-crewly-id="q-first"></div>
|
|
92
|
+
<input id="q-first" placeholder="Or say it in your words">
|
|
93
|
+
<button id="save" data-crewly-id="save">Save answers</button>
|
|
94
|
+
<div id="msg" data-crewly-id="msg"></div>
|
|
95
|
+
</section>
|
|
96
|
+
|
|
97
|
+
<!-- ───────── Daily ───────── -->
|
|
98
|
+
<section id="daily" class="hidden" data-crewly-id="daily">
|
|
99
|
+
<p class="muted">A short summary each day for 7 days after the report: what changed, what was done.</p>
|
|
100
|
+
<ul class="plain" id="daily-list" data-crewly-id="daily-list"></ul>
|
|
101
|
+
<p class="muted hidden" id="daily-empty">Nothing yet.</p>
|
|
102
|
+
</section>
|
|
103
|
+
|
|
104
|
+
<script>
|
|
105
|
+
// Old Safari (iOS 12) has no replaceChildren; the owner's family iPad must still render this.
|
|
106
|
+
if (!Element.prototype.replaceChildren) {
|
|
107
|
+
Element.prototype.replaceChildren = function () {
|
|
108
|
+
while (this.firstChild) this.removeChild(this.firstChild);
|
|
109
|
+
for (var i = 0; i < arguments.length; i += 1) this.appendChild(arguments[i]);
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
var $ = function (id) { return document.getElementById(id); };
|
|
113
|
+
var APP_CHIPS = ['Square', 'Stripe', 'QuickBooks', 'Mailchimp', 'Jotform', 'Jackrabbit', 'Mindbody', 'Calendly', 'HubSpot', 'Google Sheets', 'Gmail'];
|
|
114
|
+
var FEAR_CHIPS = ['Unanswered inquiries', 'Signed up but never paid', 'Customers who stopped coming', 'Unpaid invoices', 'Typing the same person twice'];
|
|
115
|
+
var FIRST_CHIPS = ['Money owed to me', 'Inquiries I missed', 'Hours lost to double entry', 'Customers who lapsed'];
|
|
116
|
+
var state = { report: null, intake: null, tab: 'report' };
|
|
117
|
+
|
|
118
|
+
function text(el, s) { el.textContent = s == null ? '' : String(s); }
|
|
119
|
+
function el(tag, cls, s) { var e = document.createElement(tag); if (cls) e.className = cls; if (s != null) e.textContent = String(s); return e; }
|
|
120
|
+
function money(n) { return '$' + Math.round(Number(n) || 0).toLocaleString(); }
|
|
121
|
+
function chips(container, options, picked) {
|
|
122
|
+
container.replaceChildren();
|
|
123
|
+
options.forEach(function (opt) {
|
|
124
|
+
var c = el('span', 'chip' + (picked.indexOf(opt) >= 0 ? ' on' : ''), opt);
|
|
125
|
+
c.setAttribute('role', 'button');
|
|
126
|
+
c.onclick = function () { c.classList.toggle('on'); };
|
|
127
|
+
container.appendChild(c);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
function pickedChips(container) {
|
|
131
|
+
return Array.prototype.map.call(container.querySelectorAll('.chip.on'), function (c) { return c.textContent; });
|
|
132
|
+
}
|
|
133
|
+
function splitList(s) { return String(s || '').split(',').map(function (x) { return x.trim(); }).filter(Boolean); }
|
|
134
|
+
|
|
135
|
+
// ── tabs ──
|
|
136
|
+
function showTab(name) {
|
|
137
|
+
state.tab = name;
|
|
138
|
+
['report', 'intake', 'daily'].forEach(function (t) {
|
|
139
|
+
$(t).classList.toggle('hidden', t !== name);
|
|
140
|
+
$('tab-' + t).classList.toggle('on', t === name);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
$('tab-report').onclick = function () { showTab('report'); };
|
|
144
|
+
$('tab-intake').onclick = function () { showTab('intake'); };
|
|
145
|
+
$('tab-daily').onclick = function () { showTab('daily'); };
|
|
146
|
+
|
|
147
|
+
// ── report ──
|
|
148
|
+
function renderReport() {
|
|
149
|
+
var r = state.report;
|
|
150
|
+
var hasReport = r && Array.isArray(r.breaks) && r.breaks.length;
|
|
151
|
+
$('report-empty').classList.toggle('hidden', !!hasReport);
|
|
152
|
+
$('report-body').classList.toggle('hidden', !hasReport);
|
|
153
|
+
text($('title'), (r && r.business) ? r.business + ' check-up' : 'Business check-up');
|
|
154
|
+
if (!hasReport) { text($('subtitle'), 'The report is not ready yet.'); return; }
|
|
155
|
+
text($('subtitle'), 'Where your apps disagree, and what it costs.');
|
|
156
|
+
text($('asof'), 'As of ' + r.asOf + ' · data ' + r.period.from + ' to ' + r.period.to + ' · ' + r.stats.people + ' people across ' + r.stats.systems.join(', '));
|
|
157
|
+
text($('total-hours'), r.totals.hoursPerWeek);
|
|
158
|
+
text($('total-dollars'), money(r.totals.dollarsPerMonth));
|
|
159
|
+
|
|
160
|
+
var fn = $('first-number');
|
|
161
|
+
if (r.firstNumber) {
|
|
162
|
+
fn.classList.remove('hidden'); fn.replaceChildren();
|
|
163
|
+
fn.appendChild(el('div', 'muted', 'The number you asked to see first'));
|
|
164
|
+
fn.appendChild(el('div', 'num', r.firstNumber.value));
|
|
165
|
+
fn.appendChild(el('div', 'note', r.firstNumber.label));
|
|
166
|
+
} else { fn.classList.add('hidden'); }
|
|
167
|
+
|
|
168
|
+
var byType = {}; r.breaks.forEach(function (b) { byType[b.type] = b; });
|
|
169
|
+
var top = $('top3'); top.replaceChildren();
|
|
170
|
+
(r.top3 || []).forEach(function (t, i) {
|
|
171
|
+
var b = byType[t]; if (!b) return;
|
|
172
|
+
var card = el('div', 'card'); card.setAttribute('data-crewly-id', 'top-' + (i + 1));
|
|
173
|
+
var h = el('h3'); h.appendChild(el('span', 'rank', i + 1)); h.appendChild(document.createTextNode(b.label + ' — ' + b.count)); card.appendChild(h);
|
|
174
|
+
card.appendChild(el('p', 'est', b.estimate.hoursPerWeek + ' h/week · ' + money(b.estimate.dollarsPerMonth) + '/month (estimate)'));
|
|
175
|
+
card.appendChild(el('div', 'formula', b.estimate.formula));
|
|
176
|
+
if (b.examples && b.examples.length) {
|
|
177
|
+
var ul = el('ul', 'plain'); b.examples.forEach(function (x) { ul.appendChild(el('li', 'note', x)); }); card.appendChild(ul);
|
|
178
|
+
}
|
|
179
|
+
card.appendChild(el('div', 'agent', 'What an agent could do: ' + b.whatAnAgentCouldDo));
|
|
180
|
+
top.appendChild(card);
|
|
181
|
+
});
|
|
182
|
+
if (!top.children.length) top.appendChild(el('p', 'muted', 'No breaks found in this data.'));
|
|
183
|
+
|
|
184
|
+
var rows = $('all-rows'); rows.replaceChildren();
|
|
185
|
+
r.breaks.forEach(function (b) {
|
|
186
|
+
var tr = el('tr'); tr.appendChild(el('td', null, b.label)); tr.appendChild(el('td', 'r', b.count));
|
|
187
|
+
tr.appendChild(el('td', 'r', b.estimate.hoursPerWeek)); tr.appendChild(el('td', 'r', money(b.estimate.dollarsPerMonth))); rows.appendChild(tr);
|
|
188
|
+
});
|
|
189
|
+
var notes = $('notes'); notes.replaceChildren();
|
|
190
|
+
(r.notes || []).forEach(function (n) { notes.appendChild(el('li', null, n)); });
|
|
191
|
+
$('notes-wrap').classList.toggle('hidden', !(r.notes && r.notes.length));
|
|
192
|
+
var files = $('files'); files.replaceChildren();
|
|
193
|
+
(r.files || []).forEach(function (f) { files.appendChild(el('li', null, f.file + ' — ' + f.source + ' ' + f.kind + ', ' + f.rows + ' rows')); });
|
|
194
|
+
var as = $('assumptions'); as.replaceChildren();
|
|
195
|
+
Object.keys(r.assumptions || {}).forEach(function (k) { as.appendChild(el('li', null, k + ': ' + r.assumptions[k])); });
|
|
196
|
+
}
|
|
197
|
+
$('ask').onclick = function () {
|
|
198
|
+
crewly.notify('The owner opened the check-up report and tapped "Ask about this report". Reply in their DM with a one-line offer to walk through the top 3.').then(function () {
|
|
199
|
+
text($('ask'), 'Sent — your agent will reply in chat'); $('ask').disabled = true;
|
|
200
|
+
}).catch(function (e) { text($('ask'), 'Could not send: ' + e.message); });
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
// ── intake ──
|
|
204
|
+
function renderIntake() {
|
|
205
|
+
var a = state.intake || {};
|
|
206
|
+
chips($('q-apps-chips'), APP_CHIPS, a.apps || []);
|
|
207
|
+
$('q-apps').value = (a.apps || []).filter(function (x) { return APP_CHIPS.indexOf(x) < 0; }).join(', ');
|
|
208
|
+
$('q-task').value = a.slowestTask || '';
|
|
209
|
+
chips($('q-fear-chips'), FEAR_CHIPS, a.fears || []);
|
|
210
|
+
$('q-fear').value = (a.fears || []).filter(function (x) { return FEAR_CHIPS.indexOf(x) < 0; }).join(', ');
|
|
211
|
+
$('q-hops').value = a.appsPerCustomer || '';
|
|
212
|
+
chips($('q-first-chips'), FIRST_CHIPS, a.firstNumber ? [a.firstNumber] : []);
|
|
213
|
+
$('q-first').value = (a.firstNumber && FIRST_CHIPS.indexOf(a.firstNumber) < 0) ? a.firstNumber : '';
|
|
214
|
+
if (a.savedAt) { $('msg').className = 'ok'; text($('msg'), 'Saved ' + a.savedAt.slice(0, 16).replace('T', ' ')); }
|
|
215
|
+
}
|
|
216
|
+
$('save').onclick = function () {
|
|
217
|
+
var first = pickedChips($('q-first-chips'))[0] || $('q-first').value.trim() || null;
|
|
218
|
+
var answers = {
|
|
219
|
+
apps: pickedChips($('q-apps-chips')).concat(splitList($('q-apps').value)),
|
|
220
|
+
slowestTask: $('q-task').value.trim(),
|
|
221
|
+
fears: pickedChips($('q-fear-chips')).concat(splitList($('q-fear').value)),
|
|
222
|
+
appsPerCustomer: $('q-hops').value,
|
|
223
|
+
firstNumber: first,
|
|
224
|
+
savedAt: new Date().toISOString()
|
|
225
|
+
};
|
|
226
|
+
if (!answers.apps.length && !answers.slowestTask) { $('msg').className = ''; text($('msg'), 'Tell us at least which apps you use.'); return; }
|
|
227
|
+
$('save').disabled = true;
|
|
228
|
+
crewly.db.set('intake', 'answers', answers).then(function () {
|
|
229
|
+
state.intake = answers; $('msg').className = 'ok'; text($('msg'), 'Saved. Your agent will take it from here.'); $('save').disabled = false;
|
|
230
|
+
return crewly.notify('The owner saved their check-up answers (intake/answers). Read them with app-data and start the connect step.');
|
|
231
|
+
}).catch(function (e) { $('msg').className = ''; text($('msg'), 'Could not save: ' + e.message); $('save').disabled = false; });
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
// ── daily ──
|
|
235
|
+
function renderDaily(docs) {
|
|
236
|
+
var list = $('daily-list'); list.replaceChildren();
|
|
237
|
+
docs.sort(function (a, b) { return String(b.data.date).localeCompare(String(a.data.date)); });
|
|
238
|
+
docs.forEach(function (d) {
|
|
239
|
+
var li = el('li'); li.appendChild(el('div', 'muted', d.data.date)); li.appendChild(el('div', null, d.data.summary)); list.appendChild(li);
|
|
240
|
+
});
|
|
241
|
+
$('daily-empty').classList.toggle('hidden', docs.length > 0);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// ── load ──
|
|
245
|
+
function notFoundAsNull(e) { if (e && e.code === 'not_found') return null; throw e; }
|
|
246
|
+
function loadAll() {
|
|
247
|
+
return Promise.all([
|
|
248
|
+
crewly.db.get('report', 'current').then(function (d) { return d.data; }, notFoundAsNull),
|
|
249
|
+
crewly.db.get('intake', 'answers').then(function (d) { return d.data; }, notFoundAsNull),
|
|
250
|
+
crewly.db.list('daily', { limit: 30 }).then(function (r) { return r.docs; })
|
|
251
|
+
]).then(function (res) {
|
|
252
|
+
state.report = res[0]; state.intake = res[1];
|
|
253
|
+
renderReport(); renderIntake(); renderDaily(res[2]);
|
|
254
|
+
if (!state.report && !state.intake) showTab('intake');
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
crewly.ready.then(function () {
|
|
258
|
+
return loadAll().then(function () {
|
|
259
|
+
crewly.db.subscribe('report', function () { loadAll().catch(fail); });
|
|
260
|
+
crewly.db.subscribe('daily', function () { loadAll().catch(fail); });
|
|
261
|
+
});
|
|
262
|
+
}).catch(fail);
|
|
263
|
+
function fail(e) { text($('subtitle'), 'Could not load: ' + (e && e.message ? e.message : e)); }
|
|
264
|
+
</script>
|
|
265
|
+
</body></html>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# =============================================================================
|
|
3
|
+
# checkup-report — the report step of the small-business check-up
|
|
4
|
+
# (crewly#1062): copy the bundled report App into the project for publish-app,
|
|
5
|
+
# turn checkup-analyse's breaks.json into the App's report document, and
|
|
6
|
+
# write daily-summary documents for app-data.
|
|
7
|
+
#
|
|
8
|
+
# Usage:
|
|
9
|
+
# bash execute.sh --app-dir ./checkup-app # copy the App page
|
|
10
|
+
# bash execute.sh --breaks …/analysis/breaks.json --business "Oak Pottery" --intake ./intake.json --out ./checkup-data
|
|
11
|
+
# bash execute.sh --daily "Replied to 3 open inquiries; 1 booked." --out ./checkup-data
|
|
12
|
+
# bash execute.sh '{"breaks":"…/breaks.json","business":"Oak Pottery","out":"./checkup-data"}'
|
|
13
|
+
#
|
|
14
|
+
# Output: one JSON line with the files written and the exact next command
|
|
15
|
+
# (publish-app or app-data). Exit 0 = done, 2 = an input could not be read, 1 = usage.
|
|
16
|
+
# =============================================================================
|
|
17
|
+
set -euo pipefail
|
|
18
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
19
|
+
REPORT="${SCRIPT_DIR}/report.mjs"
|
|
20
|
+
|
|
21
|
+
command -v node >/dev/null 2>&1 || { printf '{"success":false,"error":"node is required but not on PATH"}\n'; exit 1; }
|
|
22
|
+
|
|
23
|
+
ARGS=()
|
|
24
|
+
if [[ $# -gt 0 && ${1:0:1} == '{' ]]; then
|
|
25
|
+
command -v jq >/dev/null 2>&1 || { printf '{"success":false,"error":"jq is required to read JSON input"}\n'; exit 1; }
|
|
26
|
+
for key in appDir breaks business intake examples out daily date; do
|
|
27
|
+
v=$(printf '%s' "$1" | jq -r --arg k "$key" '.[$k] // empty')
|
|
28
|
+
if [ -n "$v" ]; then
|
|
29
|
+
case "$key" in appDir) flag=--app-dir ;; *) flag="--$key" ;; esac
|
|
30
|
+
ARGS+=("$flag" "$v")
|
|
31
|
+
fi
|
|
32
|
+
done
|
|
33
|
+
shift
|
|
34
|
+
fi
|
|
35
|
+
ARGS+=("$@")
|
|
36
|
+
|
|
37
|
+
exec node "$REPORT" ${ARGS[@]+"${ARGS[@]}"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Tests for checkup-report — run with: bash execute.test.sh
|
|
3
|
+
# Offline: runs ingest-exports + checkup-analyse on the ingest fixtures first. Needs node and jq.
|
|
4
|
+
set -u
|
|
5
|
+
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
6
|
+
EXEC="$HERE/execute.sh"
|
|
7
|
+
INGEST="$HERE/../ingest-exports/execute.sh"
|
|
8
|
+
ANALYSE="$HERE/../checkup-analyse/execute.sh"
|
|
9
|
+
FX="$HERE/../ingest-exports/fixtures"
|
|
10
|
+
PASS=0; FAIL=0
|
|
11
|
+
check() {
|
|
12
|
+
local name="$1"; local got="$2"; local want="$3"
|
|
13
|
+
if [ "$got" = "$want" ]; then PASS=$((PASS+1)); else FAIL=$((FAIL+1)); echo "FAIL: $name"; echo " want: $want"; echo " got: $got"; fi
|
|
14
|
+
}
|
|
15
|
+
T="$(mktemp -d)"; trap 'rm -rf "$T"' EXIT
|
|
16
|
+
bash "$INGEST" --in "$FX" --out "$T/ingest" >/dev/null || { echo "ingest-exports failed"; exit 1; }
|
|
17
|
+
bash "$INGEST" --in "$FX" --out "$T/ingest-hashed" --hash-names >/dev/null
|
|
18
|
+
bash "$ANALYSE" --in "$T/ingest" --as-of 2026-10-26 --out "$T/an" >/dev/null || { echo "checkup-analyse failed"; exit 1; }
|
|
19
|
+
bash "$ANALYSE" --in "$T/ingest-hashed" --as-of 2026-10-26 --out "$T/anh" >/dev/null
|
|
20
|
+
|
|
21
|
+
# 1. The App page follows the Crewly Apps rules (sandbox: no network, no storage, old Safari)
|
|
22
|
+
PAGE="$HERE/app/index.html"
|
|
23
|
+
check "page exists" "$([ -f "$PAGE" ] && echo yes || echo no)" "yes"
|
|
24
|
+
check "viewport meta" "$(grep -c 'name="viewport"' "$PAGE")" "1"
|
|
25
|
+
check "no external script" "$(grep -c -E '<script[^>]+src=' "$PAGE")" "0"
|
|
26
|
+
check "no fetch/XHR" "$(grep -c -E '\bfetch\(|XMLHttpRequest|WebSocket' "$PAGE")" "0"
|
|
27
|
+
check "no localStorage/cookies" "$(grep -c -E 'localStorage|sessionStorage|document\.cookie' "$PAGE")" "0"
|
|
28
|
+
check "no alert/confirm/prompt" "$(grep -c -E '\b(alert|confirm|prompt)\(' "$PAGE")" "0"
|
|
29
|
+
check "no innerHTML with data" "$(grep -c 'innerHTML' "$PAGE")" "0"
|
|
30
|
+
check "no optional chaining / nullish (iOS 12)" "$(grep -c -E '\?\.[a-zA-Z(]|\?\?' "$PAGE")" "0"
|
|
31
|
+
check "no arrow functions / class fields (iOS 12)" "$(grep -c -E '=>' "$PAGE")" "0"
|
|
32
|
+
check "replaceChildren polyfilled" "$(grep -c 'Element.prototype.replaceChildren = ' "$PAGE")" "1"
|
|
33
|
+
check "reads report/current" "$(grep -c "crewly.db.get('report', 'current')" "$PAGE")" "1"
|
|
34
|
+
check "writes intake/answers" "$(grep -c "crewly.db.set('intake', 'answers'" "$PAGE")" "1"
|
|
35
|
+
check "lists daily" "$(grep -c "crewly.db.list('daily'" "$PAGE")" "1"
|
|
36
|
+
check "subscribes to report changes" "$(grep -c "crewly.db.subscribe('report'" "$PAGE")" "1"
|
|
37
|
+
check "data-crewly-id on the key elements" "$(grep -o 'data-crewly-id="[^"]*"' "$PAGE" | sort -u | wc -l | tr -d ' ' | awk '{print ($1>=15)?"enough":"few"}')" "enough"
|
|
38
|
+
check "page JS parses (node)" "$(node -e '
|
|
39
|
+
const fs=require("fs");const html=fs.readFileSync(process.argv[1],"utf8");
|
|
40
|
+
const m=html.match(/<script>([\s\S]*?)<\/script>/);try{new Function(m[1]);console.log("ok")}catch(e){console.log("syntax: "+e.message)}' "$PAGE")" "ok"
|
|
41
|
+
|
|
42
|
+
# 2. --app-dir copies the page into the project for publish-app
|
|
43
|
+
OUT="$(bash "$EXEC" --app-dir "$T/checkup-app")"; RC=$?
|
|
44
|
+
check "app-dir exits 0" "$RC" "0"
|
|
45
|
+
check "index.html copied" "$([ -f "$T/checkup-app/index.html" ] && echo yes || echo no)" "yes"
|
|
46
|
+
check "copied list" "$(printf '%s' "$OUT" | jq -c '.copied')" '["index.html"]'
|
|
47
|
+
check "next says publish-app" "$(printf '%s' "$OUT" | jq -r '.next' | cut -c1-11)" "publish-app"
|
|
48
|
+
check "copy is identical" "$(cmp -s "$PAGE" "$T/checkup-app/index.html" && echo same || echo differs)" "same"
|
|
49
|
+
|
|
50
|
+
# 3. --breaks builds the report document
|
|
51
|
+
cat > "$T/intake.json" <<'EOF'
|
|
52
|
+
{"apps":["Square","Jotform","Jackrabbit","Mailchimp","QuickBooks"],"slowestTask":"copying sign-ups into the roster","fears":["Unpaid invoices"],"appsPerCustomer":"3","firstNumber":"Money owed to me","savedAt":"2026-10-26T10:00:00.000Z"}
|
|
53
|
+
EOF
|
|
54
|
+
ROUT="$(bash "$EXEC" --breaks "$T/an/breaks.json" --business "Oak Pottery" --intake "$T/intake.json" --out "$T/data")"; RC=$?
|
|
55
|
+
check "breaks exits 0" "$RC" "0"
|
|
56
|
+
check "report-doc written" "$([ -f "$T/data/report-doc.json" ] && echo yes || echo no)" "yes"
|
|
57
|
+
D="$T/data/report-doc.json"
|
|
58
|
+
check "business" "$(jq -r '.business' "$D")" "Oak Pottery"
|
|
59
|
+
check "as-of carried" "$(jq -r '.asOf' "$D")" "2026-10-26"
|
|
60
|
+
check "top3 carried" "$(jq -c '.top3' "$D")" "$(jq -c '.top3' "$T/an/breaks.json")"
|
|
61
|
+
check "totals carried" "$(jq -c '.totals' "$D")" "$(jq -c '.totals' "$T/an/breaks.json")"
|
|
62
|
+
check "8 breaks" "$(jq -r '.breaks | length' "$D")" "8"
|
|
63
|
+
check "no raw items in the doc" "$(jq -r '[.breaks[] | has("items")] | any' "$D")" "false"
|
|
64
|
+
check "estimate keeps the formula" "$(jq -r '.breaks[] | select(.type=="overdue_invoices") | .estimate.formula | length > 20' "$D")" "true"
|
|
65
|
+
check "examples for overdue invoices" "$(jq -r '.breaks[] | select(.type=="overdue_invoices") | .examples | length' "$D")" "2"
|
|
66
|
+
check " example text" "$(jq -r '.breaks[] | select(.type=="overdue_invoices") | .examples[0]' "$D")" "Harbor Dental: invoice 1042 \$1250, 26 days overdue"
|
|
67
|
+
check "example for unpaid sign-up" "$(jq -r '.breaks[] | select(.type=="signed_up_unpaid") | .examples[0]' "$D")" "Sam Rivera: Kids Pottery Sat 10am on 2026-09-10, \$180 unpaid"
|
|
68
|
+
check "example for double entry" "$(jq -r '.breaks[] | select(.type=="double_entry") | .examples[0]' "$D")" "Maria Lopez is in jackrabbit, mailchimp, square"
|
|
69
|
+
check "examples capped at 3 by default" "$(jq -r '.breaks[] | select(.type=="double_entry") | .examples | length' "$D")" "3"
|
|
70
|
+
check "first number: money owed" "$(jq -r '.firstNumber.key' "$D")" "money_owed"
|
|
71
|
+
check " value = overdue + unpaid sign-ups" "$(jq -r '.firstNumber.value' "$D")" "\$3,571"
|
|
72
|
+
check " asked text kept" "$(jq -r '.firstNumber.asked' "$D")" "Money owed to me"
|
|
73
|
+
check "summary line has top3" "$(printf '%s' "$ROUT" | jq -r '.top3[0]')" "overdue_invoices"
|
|
74
|
+
check "summary line next = app-data set" "$(printf '%s' "$ROUT" | jq -r '.next' | grep -c '^app-data --app <appId> --set report current --data-file ')" "1"
|
|
75
|
+
check "files carried" "$(jq -r '.files | length' "$D")" "7"
|
|
76
|
+
check "assumptions carried" "$(jq -r '.assumptions.hourlyValue' "$D")" "30"
|
|
77
|
+
check "doc small" "$(wc -c < "$D" | awk '{print ($1<20000)?"small":"big"}')" "small"
|
|
78
|
+
|
|
79
|
+
# 4. Examples cap, other first-number choices, intake in app-data output shape, free-text first number
|
|
80
|
+
bash "$EXEC" --breaks "$T/an/breaks.json" --examples 1 --out "$T/data1" >/dev/null
|
|
81
|
+
check "--examples 1" "$(jq -r '.breaks[] | select(.type=="double_entry") | .examples | length' "$T/data1/report-doc.json")" "1"
|
|
82
|
+
bash "$EXEC" --breaks "$T/an/breaks.json" --examples 4 --out "$T/data4x" >/dev/null
|
|
83
|
+
check "--examples 4 reaches the conflict example" "$(jq -r '.breaks[] | select(.type=="double_entry") | .examples[3]' "$T/data4x/report-doc.json")" "Tom Baker is in jotform, mailchimp (phone missing in mailchimp)"
|
|
84
|
+
bash "$EXEC" --breaks "$T/an/breaks.json" --examples 0 --out "$T/data0" >/dev/null
|
|
85
|
+
check "--examples 0 → none" "$(jq -r '[.breaks[].examples | length] | add' "$T/data0/report-doc.json")" "0"
|
|
86
|
+
printf '{"success":true,"id":"answers","data":{"apps":["Square"],"firstNumber":"Inquiries I missed"},"rev":1}' > "$T/intake-appdata.json"
|
|
87
|
+
bash "$EXEC" --breaks "$T/an/breaks.json" --intake "$T/intake-appdata.json" --out "$T/data2" >/dev/null
|
|
88
|
+
check "intake from app-data output shape" "$(jq -r '.firstNumber.key' "$T/data2/report-doc.json")" "missed_inquiries"
|
|
89
|
+
check " value" "$(jq -r '.firstNumber.value' "$T/data2/report-doc.json")" "1"
|
|
90
|
+
printf '{"firstNumber":"how many hours we lose typing things twice"}' > "$T/intake-free.json"
|
|
91
|
+
bash "$EXEC" --breaks "$T/an/breaks.json" --intake "$T/intake-free.json" --out "$T/data3" >/dev/null
|
|
92
|
+
check "free-text first number mapped" "$(jq -r '.firstNumber.key' "$T/data3/report-doc.json")" "double_entry_hours"
|
|
93
|
+
printf '{"firstNumber":"Customers who lapsed"}' > "$T/intake-lapsed.json"
|
|
94
|
+
bash "$EXEC" --breaks "$T/an/breaks.json" --intake "$T/intake-lapsed.json" --out "$T/data4" >/dev/null
|
|
95
|
+
check "lapsed first number" "$(jq -r '.firstNumber.key' "$T/data4/report-doc.json")" "lapsed"
|
|
96
|
+
printf '{"firstNumber":"the weather"}' > "$T/intake-odd.json"
|
|
97
|
+
bash "$EXEC" --breaks "$T/an/breaks.json" --intake "$T/intake-odd.json" --out "$T/data5" >/dev/null
|
|
98
|
+
check "unmappable first number → no firstNumber" "$(jq -r 'has("firstNumber")' "$T/data5/report-doc.json")" "false"
|
|
99
|
+
check " but a note" "$(jq -r '.notes | map(select(test("the weather"))) | length' "$T/data5/report-doc.json")" "1"
|
|
100
|
+
bash "$EXEC" --breaks "$T/an/breaks.json" --out "$T/data6" >/dev/null
|
|
101
|
+
check "no intake → no firstNumber, no note" "$(jq -r 'has("firstNumber"), (.notes|length)' "$T/data6/report-doc.json" | tr '\n' ' ')" "false 0 "
|
|
102
|
+
|
|
103
|
+
# 5. Hashed data: no names, examples say "names hashed"
|
|
104
|
+
bash "$EXEC" --breaks "$T/anh/breaks.json" --out "$T/datah" >/dev/null
|
|
105
|
+
check "hashed: no plain names in the doc" "$(grep -c -E "Lopez|Rivera|Baker|Chen|Natarajan|example\.test" "$T/datah/report-doc.json")" "0"
|
|
106
|
+
check "hashed: no hashes leak either" "$(grep -c '"h:' "$T/datah/report-doc.json")" "0"
|
|
107
|
+
check "hashed: example says names hashed" "$(jq -r '.breaks[] | select(.type=="signed_up_unpaid") | .examples[0]' "$T/datah/report-doc.json")" "1 person (names hashed)"
|
|
108
|
+
check "hashed: invoice customers hashed too → count only" "$(jq -r '.breaks[] | select(.type=="overdue_invoices") | .examples[0]' "$T/datah/report-doc.json")" "2 people (names hashed)"
|
|
109
|
+
|
|
110
|
+
# 6. --daily
|
|
111
|
+
DOUT="$(bash "$EXEC" --daily "Replied to 3 open inquiries; 1 booked." --date 2026-10-27 --out "$T/data")"
|
|
112
|
+
check "daily exits 0" "$?" "0"
|
|
113
|
+
check "daily file" "$([ -f "$T/data/daily-2026-10-27.json" ] && echo yes || echo no)" "yes"
|
|
114
|
+
check "daily doc" "$(jq -c '{date,summary}' "$T/data/daily-2026-10-27.json")" '{"date":"2026-10-27","summary":"Replied to 3 open inquiries; 1 booked."}'
|
|
115
|
+
check "daily next = app-data set daily <date>" "$(printf '%s' "$DOUT" | jq -r '.next' | grep -c '^app-data --app <appId> --set daily 2026-10-27 --data-file ')" "1"
|
|
116
|
+
check "daily default date = today" "$(bash "$EXEC" --daily "x" --out "$T/data" | jq -r '.dailyDoc' | grep -c "daily-$(date -u +%F).json")" "1"
|
|
117
|
+
|
|
118
|
+
# 7. JSON input and combined calls
|
|
119
|
+
JOUT="$(bash "$EXEC" "{\"appDir\":\"$T/japp\",\"breaks\":\"$T/an/breaks.json\",\"business\":\"Oak\",\"out\":\"$T/jdata\"}")"
|
|
120
|
+
check "json input: app copied" "$([ -f "$T/japp/index.html" ] && echo yes || echo no)" "yes"
|
|
121
|
+
check "json input: report written" "$(jq -r '.business' "$T/jdata/report-doc.json")" "Oak"
|
|
122
|
+
check "json input: summary has both" "$(printf '%s' "$JOUT" | jq -r '(.copied|length), (.top3|length)' | tr '\n' ' ')" "1 3 "
|
|
123
|
+
|
|
124
|
+
# 8. Errors
|
|
125
|
+
bash "$EXEC" >/dev/null 2>&1; check "no args exits 1" "$?" "1"
|
|
126
|
+
bash "$EXEC" --breaks "$T/an/breaks.json" >/dev/null 2>&1; check "breaks without --out exits 1" "$?" "1"
|
|
127
|
+
bash "$EXEC" --breaks "$T/nope.json" --out "$T/x" >/dev/null 2>&1; check "missing breaks exits 2" "$?" "2"
|
|
128
|
+
printf '{"foo":1}' > "$T/notbreaks.json"
|
|
129
|
+
bash "$EXEC" --breaks "$T/notbreaks.json" --out "$T/x" >/dev/null 2>&1; check "wrong file exits 2" "$?" "2"
|
|
130
|
+
bash "$EXEC" --breaks "$T/an/breaks.json" --intake "$T/nope.json" --out "$T/x" >/dev/null 2>&1; check "missing intake exits 2" "$?" "2"
|
|
131
|
+
bash "$EXEC" --daily "x" --date 27/10/2026 --out "$T/x" >/dev/null 2>&1; check "bad date exits 1" "$?" "1"
|
|
132
|
+
bash "$EXEC" --daily " " --out "$T/x" >/dev/null 2>&1; check "empty daily exits 1" "$?" "1"
|
|
133
|
+
bash "$EXEC" --breaks "$T/an/breaks.json" --examples lots --out "$T/x" >/dev/null 2>&1; check "bad examples exits 1" "$?" "1"
|
|
134
|
+
bash "$EXEC" --bogus >/dev/null 2>&1; check "unknown flag exits 1" "$?" "1"
|
|
135
|
+
|
|
136
|
+
echo "checkup-report: $PASS passed, $FAIL failed"
|
|
137
|
+
[ "$FAIL" -eq 0 ]
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// =============================================================================
|
|
3
|
+
// checkup-report — the report step of the small-business check-up
|
|
4
|
+
// (crewly#1062). Turns `breaks.json` from checkup-analyse into the document
|
|
5
|
+
// the bundled report App renders (report/current), optionally places the
|
|
6
|
+
// number the owner asked to see first (from the intake answers), writes
|
|
7
|
+
// daily-summary documents, and copies the App's files into the project so
|
|
8
|
+
// publish-app can upload them.
|
|
9
|
+
//
|
|
10
|
+
// node report.mjs --app-dir ./checkup-app # copy the App page to publish
|
|
11
|
+
// node report.mjs --breaks …/breaks.json --business "Oak Pottery" [--intake answers.json] --out ./checkup-data
|
|
12
|
+
// node report.mjs --daily "Replied to 3 open inquiries; 1 booked." [--date 2026-10-27] --out ./checkup-data
|
|
13
|
+
// =============================================================================
|
|
14
|
+
import { readFileSync, writeFileSync, mkdirSync, existsSync, copyFileSync, readdirSync, statSync } from 'node:fs';
|
|
15
|
+
import { join, resolve, dirname } from 'node:path';
|
|
16
|
+
import { fileURLToPath } from 'node:url';
|
|
17
|
+
|
|
18
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
19
|
+
const APP_SRC = join(HERE, 'app');
|
|
20
|
+
const DEFAULT_EXAMPLES = 3;
|
|
21
|
+
/** Crewly App documents are capped at 256 KB; stay well under it. */
|
|
22
|
+
const MAX_DOC_BYTES = 200 * 1024;
|
|
23
|
+
|
|
24
|
+
/** The "which number first" choices offered by the intake form, with how each is read off the breaks. */
|
|
25
|
+
const FIRST_NUMBER_RULES = [
|
|
26
|
+
{ key: 'money_owed', match: /owed|owe|invoice|unpaid|money|cash|balance/i, label: 'Owed to you: overdue invoices plus unpaid sign-ups',
|
|
27
|
+
value: (by) => '$' + Math.round((by.overdue_invoices?.estimate.outstanding || 0) + (by.signed_up_unpaid?.estimate.outstanding || 0)).toLocaleString('en-US') },
|
|
28
|
+
{ key: 'missed_inquiries', match: /inquir|lead|enquir|missed|unanswered/i, label: 'Inquiries with no sign-up or payment after them',
|
|
29
|
+
value: (by) => String(by.inquiry_no_follow_through?.count || 0) },
|
|
30
|
+
{ key: 'double_entry_hours', match: /double|entry|typing|hours|time|twice/i, label: 'Hours a week spent keying the same people into more than one system (estimate)',
|
|
31
|
+
value: (by) => `${by.double_entry?.estimate.hoursPerWeek || 0} h/week` },
|
|
32
|
+
{ key: 'lapsed', match: /laps|stopped|churn|left|came back|coming/i, label: 'Customers with no activity for a while',
|
|
33
|
+
value: (by) => String(by.lapsed?.count || 0) },
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
/** Short, owner-readable examples for a break's first items; none when the data is hashed. */
|
|
37
|
+
function examplesFor(b, limit) {
|
|
38
|
+
const out = [];
|
|
39
|
+
for (const it of b.items.slice(0, limit)) {
|
|
40
|
+
const who = it.person || it.customer || '';
|
|
41
|
+
if (!who || String(who).startsWith('h:')) continue;
|
|
42
|
+
switch (b.type) {
|
|
43
|
+
case 'inquiry_no_follow_through': out.push(`${who} asked about ${it.item || 'a class'} on ${it.inquiredAt}`); break;
|
|
44
|
+
case 'signed_up_unpaid': out.push(`${who}: ${it.item || 'sign-up'} on ${it.signedUpAt}, $${it.fee} unpaid`); break;
|
|
45
|
+
case 'paid_not_listed': out.push(`${who} paid $${it.amount} on ${it.paidAt} (${it.item || 'no item'}) and is on no roster`); break;
|
|
46
|
+
case 'dropped': out.push(`${who}: ${it.item || 'sign-up'} dropped${it.droppedAt ? ` on ${it.droppedAt}` : ''}`); break;
|
|
47
|
+
case 'lapsed': out.push(`${who}: last seen ${it.lastActivity}, ${it.daysSince} days ago`); break;
|
|
48
|
+
case 'overdue_invoices': out.push(`${who}: invoice ${it.number || ''} $${it.balance}, ${it.daysOverdue} days overdue`); break;
|
|
49
|
+
case 'double_entry': out.push(`${who} is in ${it.systems.join(', ')}${it.conflicts.length ? ` (${it.conflicts.join('; ')})` : ''}`); break;
|
|
50
|
+
case 'not_on_mailing_list': out.push(`${who}`); break;
|
|
51
|
+
default: out.push(who);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (!out.length && b.items.length && String(b.items[0].person || b.items[0].customer || '').startsWith('h:')) {
|
|
55
|
+
out.push(`${b.count} ${b.count === 1 ? 'person' : 'people'} (names hashed)`);
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Build the report document the App renders from checkup-analyse output.
|
|
62
|
+
* Items are summarised into a few examples per break so the document stays small
|
|
63
|
+
* and no full list of people lands in the App's data.
|
|
64
|
+
*/
|
|
65
|
+
export function buildReportDoc(breaks, opts = {}) {
|
|
66
|
+
const by = Object.fromEntries(breaks.breaks.map((b) => [b.type, b]));
|
|
67
|
+
const limit = Number.isFinite(opts.examples) ? opts.examples : DEFAULT_EXAMPLES;
|
|
68
|
+
const doc = {
|
|
69
|
+
business: opts.business || null,
|
|
70
|
+
generatedAt: new Date().toISOString(),
|
|
71
|
+
asOf: breaks.asOf,
|
|
72
|
+
period: breaks.period,
|
|
73
|
+
stats: { people: breaks.stats.people, systems: breaks.stats.systems, records: breaks.stats.records },
|
|
74
|
+
totals: breaks.totals,
|
|
75
|
+
breaks: breaks.breaks.map((b) => ({
|
|
76
|
+
type: b.type,
|
|
77
|
+
label: b.label,
|
|
78
|
+
count: b.count,
|
|
79
|
+
estimate: { hoursPerWeek: b.estimate.hoursPerWeek, dollarsPerMonth: b.estimate.dollarsPerMonth, formula: b.estimate.formula, isEstimate: true },
|
|
80
|
+
whatAnAgentCouldDo: b.whatAnAgentCouldDo,
|
|
81
|
+
examples: examplesFor(b, limit),
|
|
82
|
+
})),
|
|
83
|
+
top3: breaks.top3,
|
|
84
|
+
notes: breaks.notes || [],
|
|
85
|
+
files: (breaks.files || []).map((f) => ({ file: f.file, source: f.source, kind: f.kind, rows: f.rows })),
|
|
86
|
+
assumptions: breaks.assumptions,
|
|
87
|
+
};
|
|
88
|
+
const want = opts.intake && opts.intake.firstNumber ? String(opts.intake.firstNumber) : '';
|
|
89
|
+
if (want) {
|
|
90
|
+
const rule = FIRST_NUMBER_RULES.find((r) => r.match.test(want));
|
|
91
|
+
if (rule) doc.firstNumber = { asked: want, key: rule.key, label: rule.label, value: rule.value(by) };
|
|
92
|
+
else doc.notes = [...doc.notes, `The owner asked to see "${want}" first; no break maps to it, so the top 3 lead.`];
|
|
93
|
+
}
|
|
94
|
+
return doc;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Read intake answers from a plain document or from app-data's `{ success, data }` output. */
|
|
98
|
+
function readIntake(path) {
|
|
99
|
+
const raw = JSON.parse(readFileSync(path, 'utf8'));
|
|
100
|
+
return raw && raw.data && typeof raw.data === 'object' && !raw.apps ? raw.data : raw;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Copy the App page into a directory inside the project so publish-app can upload it. */
|
|
104
|
+
function copyApp(dir) {
|
|
105
|
+
mkdirSync(dir, { recursive: true });
|
|
106
|
+
const copied = [];
|
|
107
|
+
for (const f of readdirSync(APP_SRC)) {
|
|
108
|
+
const src = join(APP_SRC, f);
|
|
109
|
+
if (!statSync(src).isFile()) continue;
|
|
110
|
+
copyFileSync(src, join(dir, f));
|
|
111
|
+
copied.push(f);
|
|
112
|
+
}
|
|
113
|
+
return copied;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function out(obj, code) {
|
|
117
|
+
process.stdout.write(JSON.stringify(obj) + '\n');
|
|
118
|
+
process.exit(code);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function usage() {
|
|
122
|
+
out({ success: false, error: 'usage: report.mjs --app-dir <dir> | --breaks <breaks.json> [--business <name>] [--intake <answers.json>] [--examples N] --out <dir> | --daily "<summary>" [--date YYYY-MM-DD] --out <dir>' }, 1);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function main(argv) {
|
|
126
|
+
const o = { examples: DEFAULT_EXAMPLES };
|
|
127
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
128
|
+
const a = argv[i];
|
|
129
|
+
const next = () => { i += 1; if (i >= argv.length) usage(); return argv[i]; };
|
|
130
|
+
if (a === '--app-dir') o.appDir = next();
|
|
131
|
+
else if (a === '--breaks') o.breaks = next();
|
|
132
|
+
else if (a === '--business') o.business = next();
|
|
133
|
+
else if (a === '--intake') o.intake = next();
|
|
134
|
+
else if (a === '--examples') o.examples = Number(next());
|
|
135
|
+
else if (a === '--out') o.out = next();
|
|
136
|
+
else if (a === '--daily') o.daily = next();
|
|
137
|
+
else if (a === '--date') o.date = next();
|
|
138
|
+
else usage();
|
|
139
|
+
}
|
|
140
|
+
if (!o.appDir && !o.breaks && !o.daily) usage();
|
|
141
|
+
if ((o.breaks || o.daily) && !o.out) usage();
|
|
142
|
+
if (o.date && !/^\d{4}-\d{2}-\d{2}$/.test(o.date)) out({ success: false, error: `--date must be YYYY-MM-DD, got "${o.date}"` }, 1);
|
|
143
|
+
if (!Number.isFinite(o.examples) || o.examples < 0) out({ success: false, error: '--examples needs a number >= 0' }, 1);
|
|
144
|
+
|
|
145
|
+
const result = { success: true };
|
|
146
|
+
if (o.appDir) {
|
|
147
|
+
result.appDir = resolve(o.appDir);
|
|
148
|
+
result.copied = copyApp(o.appDir);
|
|
149
|
+
result.next = `publish-app --dir ${o.appDir} --name "<business> check-up" --notify`;
|
|
150
|
+
}
|
|
151
|
+
if (o.breaks) {
|
|
152
|
+
if (!existsSync(o.breaks)) out({ success: false, error: `${o.breaks}: not found (run checkup-analyse with --out first)` }, 2);
|
|
153
|
+
let breaks;
|
|
154
|
+
try {
|
|
155
|
+
breaks = JSON.parse(readFileSync(o.breaks, 'utf8'));
|
|
156
|
+
} catch (e) {
|
|
157
|
+
out({ success: false, error: `${o.breaks}: ${e.message}` }, 2);
|
|
158
|
+
}
|
|
159
|
+
if (!Array.isArray(breaks.breaks) || !breaks.totals) out({ success: false, error: `${o.breaks}: not a checkup-analyse breaks.json` }, 2);
|
|
160
|
+
let intake = null;
|
|
161
|
+
if (o.intake) {
|
|
162
|
+
if (!existsSync(o.intake)) out({ success: false, error: `${o.intake}: not found` }, 2);
|
|
163
|
+
try {
|
|
164
|
+
intake = readIntake(o.intake);
|
|
165
|
+
} catch (e) {
|
|
166
|
+
out({ success: false, error: `${o.intake}: ${e.message}` }, 2);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const doc = buildReportDoc(breaks, { business: o.business, intake, examples: o.examples });
|
|
170
|
+
const json = JSON.stringify(doc, null, 2);
|
|
171
|
+
if (Buffer.byteLength(json) > MAX_DOC_BYTES) out({ success: false, error: `report document is ${Buffer.byteLength(json)} bytes; lower --examples` }, 2);
|
|
172
|
+
mkdirSync(o.out, { recursive: true });
|
|
173
|
+
writeFileSync(join(o.out, 'report-doc.json'), json);
|
|
174
|
+
result.reportDoc = resolve(join(o.out, 'report-doc.json'));
|
|
175
|
+
result.top3 = doc.top3;
|
|
176
|
+
result.totals = doc.totals;
|
|
177
|
+
result.firstNumber = doc.firstNumber || null;
|
|
178
|
+
result.next = `app-data --app <appId> --set report current --data-file ${join(o.out, 'report-doc.json')}`;
|
|
179
|
+
}
|
|
180
|
+
if (o.daily) {
|
|
181
|
+
const summary = String(o.daily).trim();
|
|
182
|
+
if (!summary) out({ success: false, error: '--daily needs text' }, 1);
|
|
183
|
+
const date = o.date || new Date().toISOString().slice(0, 10);
|
|
184
|
+
const doc = { date, summary, postedAt: new Date().toISOString() };
|
|
185
|
+
mkdirSync(o.out, { recursive: true });
|
|
186
|
+
const file = join(o.out, `daily-${date}.json`);
|
|
187
|
+
writeFileSync(file, JSON.stringify(doc, null, 2));
|
|
188
|
+
result.dailyDoc = resolve(file);
|
|
189
|
+
result.next = `app-data --app <appId> --set daily ${date} --data-file ${file}`;
|
|
190
|
+
}
|
|
191
|
+
out(result, 0);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (import.meta.url === `file://${process.argv[1]}`) main(process.argv.slice(2));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "crewly",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.450",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Multi-agent orchestration platform for AI coding teams — coordinates Claude Code, Gemini CLI, and Codex agents with a real-time web dashboard",
|
|
6
6
|
"workspaces": [
|