@nanocollective/roster 0.1.0-beta.19 → 0.1.0-beta.21
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/README.md +8 -0
- package/dist/{agents-Q2DSTLOQ.js → agents-POITEZRI.js} +1 -1
- package/dist/{chunk-JH3LQ34C.js → chunk-FF2WBNNW.js} +18 -1
- package/dist/{chunk-UEZPQ5PV.js → chunk-GDAJPOHK.js} +2 -2
- package/dist/cli.js +1089 -211
- package/dist/{compose-H43W3QI5.js → compose-5DBEHSEV.js} +1 -1
- package/dist/{connectors-U5VT5W2I.js → connectors-5E5ZMGZV.js} +1 -1
- package/dist/worker/assets/assets/css/routines.css +40 -0
- package/dist/worker/assets/assets/js/app.js +4 -1
- package/dist/worker/assets/assets/js/icons.js +2 -0
- package/dist/worker/assets/assets/js/state.js +1 -0
- package/dist/worker/assets/assets/js/views/home.js +1 -0
- package/dist/worker/assets/assets/js/views/routines.js +378 -0
- package/dist/worker/assets/index.html +4 -0
- package/dist/worker/index.js +415 -50
- package/docs/README.md +1 -0
- package/docs/commands.md +45 -0
- package/docs/concepts.md +1 -0
- package/docs/getting-started.md +14 -0
- package/docs/hosting.md +2 -2
- package/docs/portal.md +11 -0
- package/docs/routines.md +65 -0
- package/docs/security.md +5 -3
- package/docs/session-workflow.md +2 -1
- package/docs/staff-yaml.md +1 -0
- package/package.json +1 -1
- package/templates/brain/.gitattributes +3 -0
- package/templates/brain/.github/workflows/%%STAFF%%-daily.yaml +16 -9
- package/templates/brain/staff.yaml +3 -0
- package/templates/ops/.gitattributes +3 -0
- package/templates/ops/.github/workflows/session.yaml +8 -1
- package/templates/ops/compose.mjs +20 -0
- package/templates/ops/prompts/daily.md +21 -0
- package/templates/portal/css/routines.css +40 -0
- package/templates/portal/index.html +4 -0
- package/templates/portal/js/app.js +4 -1
- package/templates/portal/js/icons.js +2 -0
- package/templates/portal/js/state.js +1 -0
- package/templates/portal/js/views/home.js +1 -0
- package/templates/portal/js/views/routines.js +378 -0
- package/templates/skill/SKILL.md +115 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/* Routines: each staff member's daily round and routines, as rows, and the editor sheet. */
|
|
2
|
+
|
|
3
|
+
.routhead{display:flex;align-items:center;justify-content:space-between;gap:12px;max-width:880px}
|
|
4
|
+
.routhead h1{margin:0}
|
|
5
|
+
.routlist{margin-bottom:6px}
|
|
6
|
+
.routrow{grid-template-columns:32px minmax(0,1fr) auto}
|
|
7
|
+
.routwhen{font-size:13px;color:var(--ink-dim)}
|
|
8
|
+
.routbody{font-size:13px;color:var(--ink-faint);display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;
|
|
9
|
+
overflow:hidden;white-space:pre-line}
|
|
10
|
+
.routadd{display:flex;align-items:center;gap:8px;padding:11px 16px;border:0;border-top:1px solid var(--line);
|
|
11
|
+
background:none;color:var(--accent);font:500 13px var(--sans);cursor:pointer;text-align:left;--ic:14px}
|
|
12
|
+
.routadd:hover{background:var(--accent-soft)}
|
|
13
|
+
|
|
14
|
+
.routform{display:flex;flex-direction:column;gap:16px}
|
|
15
|
+
.routform .sheettitle{margin-bottom:0}
|
|
16
|
+
.routfield{display:flex;flex-direction:column;gap:7px}
|
|
17
|
+
.routfield input[type=text]{width:100%;box-sizing:border-box}
|
|
18
|
+
.routtodo{min-height:160px;font:14px/1.55 var(--sans)}
|
|
19
|
+
.routwho,.routdays{display:flex;flex-wrap:wrap;gap:6px}
|
|
20
|
+
.routchip{padding:6px 12px;border:1px solid var(--border-strong);border-radius:999px;background:var(--bg-elev);
|
|
21
|
+
color:var(--ink);font:500 13px var(--sans);cursor:pointer;transition:background .12s var(--ease),border-color .12s var(--ease)}
|
|
22
|
+
.routchip:hover{border-color:var(--accent)}
|
|
23
|
+
.routchip.on{background:var(--accent);border-color:var(--accent);color:var(--accent-ink)}
|
|
24
|
+
.routwhenpick{display:flex;flex-direction:column;gap:10px;align-items:flex-start}
|
|
25
|
+
.routwhenpick [hidden]{display:none}
|
|
26
|
+
.routsaid{color:var(--ink-dim);font-size:12.5px}
|
|
27
|
+
|
|
28
|
+
/* The sentence the routine will be, as it is typed. */
|
|
29
|
+
.routpreview{display:grid;grid-template-columns:32px minmax(0,1fr);gap:12px;padding:14px 16px;
|
|
30
|
+
border:1px solid var(--line);border-radius:var(--r-lg);background:var(--panel);box-shadow:var(--shadow-sm)}
|
|
31
|
+
.routpreview b{font:600 14px var(--sans);letter-spacing:-.01em}
|
|
32
|
+
.routpreview p{margin:6px 0 0;font-size:13.5px;line-height:1.55;color:var(--ink-dim);white-space:pre-wrap;
|
|
33
|
+
max-height:9em;overflow:hidden}
|
|
34
|
+
|
|
35
|
+
@media (max-width:640px){
|
|
36
|
+
.routrow{grid-template-columns:32px minmax(0,1fr)}
|
|
37
|
+
.routrow .connacts{grid-column:1 / -1;flex-wrap:wrap}
|
|
38
|
+
}
|
|
39
|
+
.routwhenpick select{width:auto}
|
|
40
|
+
.routhead + div > .connhead:first-child{margin-top:20px}
|
|
@@ -19,6 +19,7 @@ import { ORG_WIDE, S, VIEWS, applyHash, humanLabel, readHash, writeHash } from "
|
|
|
19
19
|
import { viewBrain } from "./views/brain.js";
|
|
20
20
|
import { viewChanged } from "./views/changed.js";
|
|
21
21
|
import { viewConnectors } from "./views/connectors.js";
|
|
22
|
+
import { viewRoutines } from "./views/routines.js";
|
|
22
23
|
import { viewDocs } from "./views/docs.js";
|
|
23
24
|
import { viewGraph } from "./views/graph.js";
|
|
24
25
|
import { viewHealth } from "./views/health.js";
|
|
@@ -41,6 +42,7 @@ const SCREEN = {
|
|
|
41
42
|
org: viewOrg,
|
|
42
43
|
staff: viewStaff,
|
|
43
44
|
connectors: viewConnectors,
|
|
45
|
+
routines: viewRoutines,
|
|
44
46
|
docs: viewDocs,
|
|
45
47
|
brain: viewBrain,
|
|
46
48
|
memory: viewBrain,
|
|
@@ -67,6 +69,7 @@ const NAV = [
|
|
|
67
69
|
["#inboxnav", "inbox"],
|
|
68
70
|
["#runsnav", "runs"],
|
|
69
71
|
["#staffnav", "staff"],
|
|
72
|
+
["#routinesnav", "routines"],
|
|
70
73
|
["#connectorsnav", "connectors"],
|
|
71
74
|
["#orgnav", "org"],
|
|
72
75
|
["#docsnav", "docs"],
|
|
@@ -111,7 +114,7 @@ export async function boot() {
|
|
|
111
114
|
/* Every one of these reads a tenant, so during setup they answer 409 and the sidebar is a
|
|
112
115
|
row of four dead ends beside an empty Staff heading. There is one thing to do on this
|
|
113
116
|
screen; the navigation comes back with the org. */
|
|
114
|
-
for (const el of document.querySelectorAll("#sidesearch, #homenav, #inboxnav, #runsnav, #orgnav, #staffnav, #connectorsnav, #docsnav, #refreshall, .sect, #stafflist")) {
|
|
117
|
+
for (const el of document.querySelectorAll("#sidesearch, #homenav, #inboxnav, #runsnav, #orgnav, #staffnav, #routinesnav, #connectorsnav, #docsnav, #refreshall, .sect, #stafflist")) {
|
|
115
118
|
el.hidden = true;
|
|
116
119
|
}
|
|
117
120
|
for (const slot of document.querySelectorAll("[data-icon]")) {
|
|
@@ -83,6 +83,8 @@ const PATHS = {
|
|
|
83
83
|
"<path d=\"m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48\" />",
|
|
84
84
|
"person":
|
|
85
85
|
"<circle cx=\"12\" cy=\"8\" r=\"5\" /> <path d=\"M20 21a8 8 0 0 0-16 0\" />",
|
|
86
|
+
"clock":
|
|
87
|
+
"<circle cx=\"12\" cy=\"12\" r=\"10\" /> <path d=\"M12 6v6l4 2\" />",
|
|
86
88
|
"play":
|
|
87
89
|
"<path d=\"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z\" />",
|
|
88
90
|
// The pair for the lightbox's zoom controls. `dash` above is the other half.
|
|
@@ -489,6 +489,7 @@ function whatRun(r) {
|
|
|
489
489
|
const on = r.issue ? titleOn(r) : "";
|
|
490
490
|
if (r.trigger === "mention") return r.issue ? `Answering #${r.issue}${on}` : "Answering a message";
|
|
491
491
|
if (r.trigger === "peer") return r.issue ? `Helping a colleague with #${r.issue}${on}` : "Helping a colleague";
|
|
492
|
+
if (r.trigger === "routine") return r.routine ? `Running the ${r.routine} routine` : "Running a routine";
|
|
492
493
|
return (
|
|
493
494
|
{
|
|
494
495
|
daily: "Doing their daily work",
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
/* The Routines screen: when each staff member wakes, and what they do then.
|
|
2
|
+
*
|
|
3
|
+
* Every staff member has a daily round. A routine is one more wake-up with its own job: a time,
|
|
4
|
+
* a name, and what to do in the person's own words. Saving writes the staff member's
|
|
5
|
+
* staff.yaml, routines/<id>.md and the daily caller in one commit, as you.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { post } from "../api.js";
|
|
9
|
+
import { sheet } from "../dialog.js";
|
|
10
|
+
import { el, grow } from "../dom.js";
|
|
11
|
+
import { icon } from "../icons.js";
|
|
12
|
+
import { render } from "../router.js";
|
|
13
|
+
|
|
14
|
+
/* The last answer, so a repaint after Save does not flash an empty screen. */
|
|
15
|
+
let last = null;
|
|
16
|
+
|
|
17
|
+
export function viewRoutines(m) {
|
|
18
|
+
const add = el("button", { className: "ghbtn primary", textContent: "New routine" });
|
|
19
|
+
m.append(el("div", { className: "routhead" }, [el("h1", { textContent: "Routines" }), add]));
|
|
20
|
+
const body = el("div");
|
|
21
|
+
m.append(body);
|
|
22
|
+
if (last) draw(body, last, add);
|
|
23
|
+
else body.append(el("p", { className: "sub", textContent: "Loading…" }));
|
|
24
|
+
fetch("/api/routines")
|
|
25
|
+
.then((r) => r.json())
|
|
26
|
+
.then((d) => {
|
|
27
|
+
if (d.error) throw new Error(d.error);
|
|
28
|
+
last = d;
|
|
29
|
+
body.replaceChildren();
|
|
30
|
+
draw(body, d, add);
|
|
31
|
+
})
|
|
32
|
+
.catch((err) => body.replaceChildren(el("p", { className: "err", textContent: String(err.message || err) })));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function draw(body, d, add) {
|
|
36
|
+
add.onclick = () => edit(d, null, null);
|
|
37
|
+
add.disabled = !d.staff.length;
|
|
38
|
+
if (!d.staff.length) {
|
|
39
|
+
body.append(el("p", { className: "sub", textContent: "Hire a staff member first." }));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
for (const s of d.staff) {
|
|
43
|
+
const list = el("div", { className: "connlist routlist" });
|
|
44
|
+
list.append(dailyRow(s, d));
|
|
45
|
+
for (const r of s.routines) list.append(routineRow(s, r, d));
|
|
46
|
+
const more = el("button", { className: "routadd" }, [icon("plus"), el("span", { textContent: "Add a routine for " + s.name })]);
|
|
47
|
+
more.onclick = () => edit(d, s, null);
|
|
48
|
+
list.append(more);
|
|
49
|
+
body.append(el("h2", { className: "connhead", textContent: s.name }), list);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function dailyRow(s, d) {
|
|
54
|
+
const change = el("button", { className: "ghbtn", textContent: "Change time" });
|
|
55
|
+
change.onclick = () => editDaily(d, s);
|
|
56
|
+
return el("div", { className: "connrow routrow" }, [
|
|
57
|
+
el("span", { className: "connicon" }, [icon("refresh")]),
|
|
58
|
+
el("div", { className: "conntext" }, [
|
|
59
|
+
el("b", { textContent: "Daily round" }),
|
|
60
|
+
el("span", { className: "routwhen", textContent: s.dailyWhen }),
|
|
61
|
+
]),
|
|
62
|
+
el("div", { className: "row connacts" }, [change]),
|
|
63
|
+
]);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function routineRow(s, r, d) {
|
|
67
|
+
const run = el("button", { className: "ghbtn", textContent: "Run now" });
|
|
68
|
+
run.onclick = () => runNow(s, r, run);
|
|
69
|
+
const change = el("button", { className: "ghbtn", textContent: "Edit" });
|
|
70
|
+
change.onclick = () => edit(d, s, r);
|
|
71
|
+
const remove = el("button", { className: "ghbtn", textContent: "Remove" });
|
|
72
|
+
remove.onclick = () => confirmRemove(s, r, remove);
|
|
73
|
+
return el("div", { className: "connrow routrow" }, [
|
|
74
|
+
el("span", { className: "connicon" }, [icon("clock")]),
|
|
75
|
+
el("div", { className: "conntext" }, [
|
|
76
|
+
el("b", { textContent: r.title }),
|
|
77
|
+
el("span", { className: "routwhen", textContent: r.when }),
|
|
78
|
+
r.body ? el("span", { className: "routbody", textContent: r.body }) : null,
|
|
79
|
+
].filter(Boolean)),
|
|
80
|
+
el("div", { className: "row connacts" }, [run, change, remove]),
|
|
81
|
+
]);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async function runNow(s, r, btn) {
|
|
85
|
+
btn.disabled = true;
|
|
86
|
+
btn.textContent = "Starting…";
|
|
87
|
+
try {
|
|
88
|
+
const res = await post({ staff: s.handle, routine: r.id }, "/api/run/start");
|
|
89
|
+
btn.replaceWith(el("a", { className: "ghbtn", href: res.url, target: "_blank", rel: "noopener", textContent: "Started" }));
|
|
90
|
+
} catch (err) {
|
|
91
|
+
btn.disabled = false;
|
|
92
|
+
btn.textContent = "Run now";
|
|
93
|
+
btn.title = String(err.message || err);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function confirmRemove(s, r, btn) {
|
|
98
|
+
if (btn.dataset.sure !== "1") {
|
|
99
|
+
btn.dataset.sure = "1";
|
|
100
|
+
btn.textContent = "Remove " + r.title + "?";
|
|
101
|
+
btn.classList.add("danger");
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
btn.disabled = true;
|
|
105
|
+
btn.textContent = "Removing…";
|
|
106
|
+
try {
|
|
107
|
+
await save(s, s.daily, s.routines.filter((x) => x.id !== r.id));
|
|
108
|
+
last = null;
|
|
109
|
+
render();
|
|
110
|
+
} catch (err) {
|
|
111
|
+
btn.textContent = String(err.message || err);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** One staff member's whole schedule, as the server wants it. */
|
|
116
|
+
function save(s, daily, routines) {
|
|
117
|
+
return post(
|
|
118
|
+
{
|
|
119
|
+
staff: s.handle,
|
|
120
|
+
daily,
|
|
121
|
+
routines: routines.map((r) => ({ id: r.id, title: r.title, body: r.body, schedule: r.schedule })),
|
|
122
|
+
},
|
|
123
|
+
"/api/routines/save",
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/* --------------------------------- editors --------------------------------- */
|
|
128
|
+
|
|
129
|
+
function edit(d, s, r) {
|
|
130
|
+
let box = null;
|
|
131
|
+
const node = routineForm(d, s, r, () => box?.close());
|
|
132
|
+
box = sheet({ node, onClose: () => {} });
|
|
133
|
+
if (!box) document.querySelector("#main")?.append(node);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function editDaily(d, s) {
|
|
137
|
+
let box = null;
|
|
138
|
+
const close = () => box?.close();
|
|
139
|
+
const out = el("div", { className: "routform" });
|
|
140
|
+
out.append(el("h2", { className: "sheettitle", textContent: s.name + "'s daily round" }));
|
|
141
|
+
const when = whenField(s.daily);
|
|
142
|
+
out.append(when.node);
|
|
143
|
+
const status = el("div");
|
|
144
|
+
const ok = el("button", { className: "ghbtn primary", textContent: "Save" });
|
|
145
|
+
const cancel = el("button", { className: "ghbtn", textContent: "Cancel" });
|
|
146
|
+
cancel.onclick = close;
|
|
147
|
+
ok.onclick = async () => {
|
|
148
|
+
ok.disabled = true;
|
|
149
|
+
ok.textContent = "Saving…";
|
|
150
|
+
try {
|
|
151
|
+
await save(s, when.value(), s.routines);
|
|
152
|
+
last = null;
|
|
153
|
+
close();
|
|
154
|
+
render();
|
|
155
|
+
} catch (err) {
|
|
156
|
+
ok.disabled = false;
|
|
157
|
+
ok.textContent = "Save";
|
|
158
|
+
status.replaceChildren(el("p", { className: "err", textContent: String(err.message || err) }));
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
out.append(status, el("div", { className: "row connfoot" }, [ok, cancel]));
|
|
162
|
+
box = sheet({ node: out, onClose: () => {} });
|
|
163
|
+
if (!box) document.querySelector("#main")?.append(out);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function routineForm(d, s, r, close) {
|
|
167
|
+
const out = el("div", { className: "routform" });
|
|
168
|
+
out.append(el("h2", { className: "sheettitle", textContent: r ? r.title : "New routine" }));
|
|
169
|
+
|
|
170
|
+
let who = s ?? d.staff[0];
|
|
171
|
+
const pick = el("div", { className: "routwho" });
|
|
172
|
+
if (!r) {
|
|
173
|
+
for (const p of d.staff) {
|
|
174
|
+
const chip = el("button", { className: "routchip" + (p === who ? " on" : ""), textContent: p.name, type: "button" });
|
|
175
|
+
chip.onclick = () => {
|
|
176
|
+
who = p;
|
|
177
|
+
for (const c of pick.children) c.classList.toggle("on", c === chip);
|
|
178
|
+
say();
|
|
179
|
+
};
|
|
180
|
+
pick.append(chip);
|
|
181
|
+
}
|
|
182
|
+
out.append(field("Who", pick));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const name = el("input", { type: "text", value: r?.title ?? "", placeholder: "Monday plan", spellcheck: true });
|
|
186
|
+
out.append(field("Name", name));
|
|
187
|
+
|
|
188
|
+
const when = whenField(r?.schedule ?? "0 9 * * 1");
|
|
189
|
+
out.append(when.node);
|
|
190
|
+
|
|
191
|
+
const todo = el("textarea", {
|
|
192
|
+
className: "routtodo",
|
|
193
|
+
value: r?.body ?? "",
|
|
194
|
+
rows: 8,
|
|
195
|
+
placeholder: "Plan the week. Read last week's status issue and this month's priorities, then open one issue per thing to ship this week, ranked.",
|
|
196
|
+
});
|
|
197
|
+
out.append(field("What to do", todo));
|
|
198
|
+
|
|
199
|
+
const preview = el("div", { className: "routpreview" });
|
|
200
|
+
out.append(preview);
|
|
201
|
+
const say = () => {
|
|
202
|
+
const text = todo.value.trim();
|
|
203
|
+
preview.replaceChildren(
|
|
204
|
+
el("span", { className: "connicon" }, [icon("clock")]),
|
|
205
|
+
el("div", {}, [
|
|
206
|
+
el("b", { textContent: describe(when.value()) + ", " + who.name + " wakes up and:" }),
|
|
207
|
+
el("p", { textContent: text || "…" }),
|
|
208
|
+
]),
|
|
209
|
+
);
|
|
210
|
+
};
|
|
211
|
+
name.oninput = say;
|
|
212
|
+
todo.oninput = () => {
|
|
213
|
+
grow(todo);
|
|
214
|
+
say();
|
|
215
|
+
};
|
|
216
|
+
when.onchange(say);
|
|
217
|
+
say();
|
|
218
|
+
|
|
219
|
+
const status = el("div");
|
|
220
|
+
const ok = el("button", { className: "ghbtn primary", textContent: "Save" });
|
|
221
|
+
const cancel = el("button", { className: "ghbtn", textContent: "Cancel" });
|
|
222
|
+
cancel.onclick = close;
|
|
223
|
+
ok.onclick = async () => {
|
|
224
|
+
const next = { id: r?.id, title: name.value.trim(), body: todo.value, schedule: when.value() };
|
|
225
|
+
if (!next.title) return status.replaceChildren(el("p", { className: "err", textContent: "Give it a name." }));
|
|
226
|
+
if (!next.body.trim()) return status.replaceChildren(el("p", { className: "err", textContent: "Say what to do." }));
|
|
227
|
+
ok.disabled = true;
|
|
228
|
+
ok.textContent = "Saving…";
|
|
229
|
+
try {
|
|
230
|
+
const routines = r ? who.routines.map((x) => (x.id === r.id ? next : x)) : [...who.routines, next];
|
|
231
|
+
await save(who, who.daily, routines);
|
|
232
|
+
last = null;
|
|
233
|
+
close();
|
|
234
|
+
render();
|
|
235
|
+
} catch (err) {
|
|
236
|
+
ok.disabled = false;
|
|
237
|
+
ok.textContent = "Save";
|
|
238
|
+
status.replaceChildren(el("p", { className: "err", textContent: String(err.message || err) }));
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
out.append(status, el("div", { className: "row connfoot" }, [ok, cancel]));
|
|
242
|
+
return out;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function field(label, control) {
|
|
246
|
+
return el("div", { className: "field routfield" }, [el("span", { textContent: label }), control]);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/* --------------------------------- the time --------------------------------- */
|
|
250
|
+
|
|
251
|
+
const DAYS = [
|
|
252
|
+
["1", "Mon"],
|
|
253
|
+
["2", "Tue"],
|
|
254
|
+
["3", "Wed"],
|
|
255
|
+
["4", "Thu"],
|
|
256
|
+
["5", "Fri"],
|
|
257
|
+
["6", "Sat"],
|
|
258
|
+
["0", "Sun"],
|
|
259
|
+
];
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* When, as days and a time, or a day of the month, rather than as cron. The value is still a
|
|
263
|
+
* cron, because that is what goes in the workflow. A cron the picker cannot show is kept as
|
|
264
|
+
* typed, in a box of its own.
|
|
265
|
+
*/
|
|
266
|
+
function whenField(cron) {
|
|
267
|
+
const parsed = parseCron(cron);
|
|
268
|
+
const listeners = [];
|
|
269
|
+
const changed = () => {
|
|
270
|
+
for (const f of listeners) f();
|
|
271
|
+
said.textContent = describe(value()) + local(time.value);
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const repeat = el("select");
|
|
275
|
+
repeat.append(
|
|
276
|
+
el("option", { value: "week", textContent: "Days of the week" }),
|
|
277
|
+
el("option", { value: "month", textContent: "Day of the month" }),
|
|
278
|
+
el("option", { value: "cron", textContent: "Cron" }),
|
|
279
|
+
);
|
|
280
|
+
repeat.value = parsed.kind;
|
|
281
|
+
|
|
282
|
+
const days = new Set(parsed.days);
|
|
283
|
+
const dayRow = el("div", { className: "routdays" });
|
|
284
|
+
for (const [v, label] of DAYS) {
|
|
285
|
+
const chip = el("button", { className: "routchip" + (days.has(v) ? " on" : ""), textContent: label, type: "button" });
|
|
286
|
+
chip.onclick = () => {
|
|
287
|
+
days.has(v) ? days.delete(v) : days.add(v);
|
|
288
|
+
chip.classList.toggle("on", days.has(v));
|
|
289
|
+
changed();
|
|
290
|
+
};
|
|
291
|
+
dayRow.append(chip);
|
|
292
|
+
}
|
|
293
|
+
const dom = el("input", { type: "number", min: "1", max: "28", value: String(parsed.dom), style: "width:80px" });
|
|
294
|
+
const time = el("input", { type: "time", step: "60", value: parsed.time, style: "width:130px" });
|
|
295
|
+
const raw = el("input", { type: "text", value: cron, spellcheck: false, placeholder: "0 9 * * 1" });
|
|
296
|
+
const said = el("small", { className: "routsaid" });
|
|
297
|
+
|
|
298
|
+
const domRow = el("div", { className: "row" }, [el("span", { className: "meta", textContent: "Day" }), dom]);
|
|
299
|
+
const timeRow = el("div", { className: "row" }, [time, el("span", { className: "meta", textContent: "UTC" })]);
|
|
300
|
+
const show = () => {
|
|
301
|
+
dayRow.hidden = repeat.value !== "week";
|
|
302
|
+
domRow.hidden = repeat.value !== "month";
|
|
303
|
+
timeRow.hidden = repeat.value === "cron";
|
|
304
|
+
raw.hidden = repeat.value !== "cron";
|
|
305
|
+
};
|
|
306
|
+
repeat.onchange = () => {
|
|
307
|
+
show();
|
|
308
|
+
changed();
|
|
309
|
+
};
|
|
310
|
+
for (const input of [dom, time, raw]) input.oninput = changed;
|
|
311
|
+
|
|
312
|
+
function value() {
|
|
313
|
+
if (repeat.value === "cron") return raw.value.trim();
|
|
314
|
+
const [h, m] = (time.value || "09:00").split(":").map(Number);
|
|
315
|
+
if (repeat.value === "month") return `${m} ${h} ${Math.min(28, Math.max(1, Number(dom.value) || 1))} * *`;
|
|
316
|
+
const picked = DAYS.map(([v]) => v).filter((v) => days.has(v));
|
|
317
|
+
return `${m} ${h} * * ${dayList(picked)}`;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
show();
|
|
321
|
+
said.textContent = describe(value()) + local(time.value);
|
|
322
|
+
const node = el("div", { className: "field routfield" }, [
|
|
323
|
+
el("span", { textContent: "When" }),
|
|
324
|
+
el("div", { className: "routwhenpick" }, [repeat, dayRow, domRow, timeRow, raw, said]),
|
|
325
|
+
]);
|
|
326
|
+
return { node, value, onchange: (f) => listeners.push(f) };
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** Days for cron, in its own short forms where there is one. */
|
|
330
|
+
function dayList(picked) {
|
|
331
|
+
const set = new Set(picked);
|
|
332
|
+
if (set.size === 0 || set.size === 7) return "*";
|
|
333
|
+
if (set.size === 5 && ["1", "2", "3", "4", "5"].every((d) => set.has(d))) return "1-5";
|
|
334
|
+
return [...set].map(Number).sort((a, b) => a - b).join(",");
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export function parseCron(cron) {
|
|
338
|
+
const [min, hour, dom, mon, dow] = String(cron).trim().split(/\s+/);
|
|
339
|
+
const plain = /^\d+$/.test(min ?? "") && /^\d+$/.test(hour ?? "") && mon === "*";
|
|
340
|
+
const time = plain ? `${hour.padStart(2, "0")}:${min.padStart(2, "0")}` : "09:00";
|
|
341
|
+
if (plain && dom === "*") {
|
|
342
|
+
const days =
|
|
343
|
+
dow === "*" ? ["0", "1", "2", "3", "4", "5", "6"] : dow === "1-5" ? ["1", "2", "3", "4", "5"] : /^[0-6](,[0-6])*$/.test(dow) ? dow.split(",") : null;
|
|
344
|
+
if (days) return { kind: "week", days, time, dom: 1 };
|
|
345
|
+
}
|
|
346
|
+
if (plain && /^\d+$/.test(dom ?? "") && dow === "*") return { kind: "month", days: ["1"], time, dom: Number(dom) };
|
|
347
|
+
return { kind: "cron", days: ["1"], time, dom: 1 };
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
const DAY_NAME = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
|
351
|
+
|
|
352
|
+
/** The same words the server gives a schedule, so the preview and the list agree. */
|
|
353
|
+
export function describe(cron) {
|
|
354
|
+
const p = parseCron(cron);
|
|
355
|
+
const at = "at " + p.time + " UTC";
|
|
356
|
+
if (p.kind === "month") return `On the ${ordinal(p.dom)} of each month ${at}`;
|
|
357
|
+
if (p.kind === "cron") return cron || "No time yet";
|
|
358
|
+
const d = cron.trim().split(/\s+/)[4];
|
|
359
|
+
if (d === "*") return "Every day " + at;
|
|
360
|
+
if (d === "1-5") return "Weekdays " + at;
|
|
361
|
+
if (d === "0,6" || d === "6,0") return "Weekends " + at;
|
|
362
|
+
const names = p.days.map((x) => DAY_NAME[Number(x)] + "s");
|
|
363
|
+
return (names.length > 1 ? names.slice(0, -1).join(", ") + " and " + names.at(-1) : names[0]) + " " + at;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function ordinal(n) {
|
|
367
|
+
const tens = n % 100;
|
|
368
|
+
return n + (tens >= 11 && tens <= 13 ? "th" : (["th", "st", "nd", "rd"][n % 10] ?? "th"));
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/** What that UTC time is where the person reading it is, when the two differ. */
|
|
372
|
+
function local(hhmm) {
|
|
373
|
+
if (!hhmm) return "";
|
|
374
|
+
const [h, m] = hhmm.split(":").map(Number);
|
|
375
|
+
const at = new Date(Date.UTC(2026, 0, 5, h, m));
|
|
376
|
+
const here = at.toLocaleTimeString(undefined, { hour: "2-digit", minute: "2-digit" });
|
|
377
|
+
return here === hhmm ? "" : " · " + here + " where you are";
|
|
378
|
+
}
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
<link rel="stylesheet" href="/assets/css/runs.css">
|
|
22
22
|
<link rel="stylesheet" href="/assets/css/setup.css">
|
|
23
23
|
<link rel="stylesheet" href="/assets/css/connectors.css">
|
|
24
|
+
<link rel="stylesheet" href="/assets/css/routines.css">
|
|
24
25
|
</head>
|
|
25
26
|
<body>
|
|
26
27
|
<div class="app">
|
|
@@ -57,6 +58,9 @@
|
|
|
57
58
|
<button class="nav" id="staffnav" data-view="staff">
|
|
58
59
|
<span class="ic" data-icon="person"></span> Staff
|
|
59
60
|
</button>
|
|
61
|
+
<button class="nav" id="routinesnav" data-view="routines" title="When the staff wake up, and what they do then">
|
|
62
|
+
<span class="ic" data-icon="clock"></span> Routines
|
|
63
|
+
</button>
|
|
60
64
|
<button class="nav" id="connectorsnav" data-view="connectors" title="Outside services the staff can use">
|
|
61
65
|
<span class="ic" data-icon="plug"></span> Connectors
|
|
62
66
|
</button>
|