coauthored 0.0.0-stage → 1.0.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 +21 -0
- package/PRIVACY.md +107 -0
- package/README.md +113 -3
- package/THIRD_PARTY_LICENSES.md +105 -0
- package/dist/cli/analytics/anchors.js +39 -0
- package/dist/cli/analytics/archetypes.js +193 -0
- package/dist/cli/analytics/content/analyzer.js +945 -0
- package/dist/cli/analytics/content/classify.js +115 -0
- package/dist/cli/analytics/content/demo-corpus.js +301 -0
- package/dist/cli/analytics/content/sketch.js +54 -0
- package/dist/cli/analytics/dataset.js +321 -0
- package/dist/cli/analytics/demo-fixtures.js +531 -0
- package/dist/cli/analytics/fdr.js +183 -0
- package/dist/cli/analytics/helicorder.js +66 -0
- package/dist/cli/analytics/insights.js +589 -0
- package/dist/cli/analytics/models.js +75 -0
- package/dist/cli/analytics/pricing.js +121 -0
- package/dist/cli/analytics/probable-cause.js +115 -0
- package/dist/cli/analytics/report-builder.js +162 -0
- package/dist/cli/analytics/statistics.js +91 -0
- package/dist/cli/analytics/time.js +252 -0
- package/dist/cli/cli/args.js +105 -0
- package/dist/cli/cli/browser.js +71 -0
- package/dist/cli/cli/index.js +20 -0
- package/dist/cli/cli/main.js +520 -0
- package/dist/cli/cli/phrase-review.js +78 -0
- package/dist/cli/cli/server.js +481 -0
- package/dist/cli/cli/terminal.js +363 -0
- package/dist/cli/ingest/adapters/aider.js +116 -0
- package/dist/cli/ingest/adapters/claude-code.js +139 -0
- package/dist/cli/ingest/adapters/cline-roo.js +89 -0
- package/dist/cli/ingest/adapters/codex-cli.js +240 -0
- package/dist/cli/ingest/adapters/content.js +99 -0
- package/dist/cli/ingest/adapters/cursor-ide.js +149 -0
- package/dist/cli/ingest/adapters/gemini-cli.js +208 -0
- package/dist/cli/ingest/adapters/index.js +18 -0
- package/dist/cli/ingest/adapters/opencode.js +203 -0
- package/dist/cli/ingest/adapters/pi-agent.js +85 -0
- package/dist/cli/ingest/adapters/shared.js +484 -0
- package/dist/cli/ingest/content-sink.js +31 -0
- package/dist/cli/ingest/discovery.js +50 -0
- package/dist/cli/ingest/message-digests.js +61 -0
- package/dist/cli/ingest/pipeline.js +155 -0
- package/dist/cli/ingest/safe-fs.js +284 -0
- package/dist/cli/ingest/sqlite-stage.js +139 -0
- package/dist/cli/ingest/time-window.js +34 -0
- package/dist/cli/ingest/tool-map.js +24 -0
- package/dist/cli/ingest/types.js +1 -0
- package/dist/cli/ingest/worker.js +97 -0
- package/dist/cli/report/content/emoji-names.js +3956 -0
- package/dist/cli/report/content/insights.js +41 -0
- package/dist/cli/report/content/lexicons.js +112 -0
- package/dist/cli/report/content/policy.js +77 -0
- package/dist/cli/report/content/redact.js +164 -0
- package/dist/cli/report/content/stopwords.js +8848 -0
- package/dist/cli/report/content/suppression.js +2617 -0
- package/dist/cli/report/content/validate.js +152 -0
- package/dist/cli/report/copy-lint.js +105 -0
- package/dist/cli/report/share.js +132 -0
- package/dist/cli/report/types.js +1 -0
- package/dist/cli/report/validators.js +334 -0
- package/dist/web/assets/Archivo-VF-BohoA-Sn.woff2 +0 -0
- package/dist/web/assets/DelaGothicOne-subset-CpoJGhTq.woff2 +0 -0
- package/dist/web/assets/Film-BkhZFxG9.css +1 -0
- package/dist/web/assets/MartianMono-VF-CmJ1nXx9.woff2 +0 -0
- package/dist/web/assets/app-Dw1a5h5V.js +38 -0
- package/dist/web/assets/bricolage-grotesque-latin-700-normal-gtcctNPv.woff2 +0 -0
- package/dist/web/assets/bricolage-grotesque-latin-800-normal-J50vIsBe.woff2 +0 -0
- package/dist/web/assets/chorus-D7bfON5Z.ogg +0 -0
- package/dist/web/assets/chorus-bass-CBTKpMv_.ogg +0 -0
- package/dist/web/assets/chorus-drums-BOzgLSoq.ogg +0 -0
- package/dist/web/assets/chorus-harmony-DnJYs_tp.ogg +0 -0
- package/dist/web/assets/chorus-lead-CFpg5DC1.ogg +0 -0
- package/dist/web/assets/chunk-BNfsY4o8.js +1 -0
- package/dist/web/assets/chunk-BSm8IhPY.js +1 -0
- package/dist/web/assets/chunk-Bi6EQAkf.js +1 -0
- package/dist/web/assets/chunk-D6HyoJCB.js +46 -0
- package/dist/web/assets/chunk-DrEayQLY.js +1 -0
- package/dist/web/assets/chunk-V3YGpFIw.js +1 -0
- package/dist/web/assets/chunk-XGhNFWse.js +1 -0
- package/dist/web/assets/dialogue-card-A5zmbNhu.ogg +0 -0
- package/dist/web/assets/groove-bass-BFNelLKi.ogg +0 -0
- package/dist/web/assets/groove-drums-BY1SBntR.ogg +0 -0
- package/dist/web/assets/groove-harmony-C0CrBzu3.ogg +0 -0
- package/dist/web/assets/groove-lead-CEYPzm5U.ogg +0 -0
- package/dist/web/assets/groove-ln-zQmTb.ogg +0 -0
- package/dist/web/assets/guess-high-CL6mF18x.ogg +0 -0
- package/dist/web/assets/guess-low-C3UnKayZ.ogg +0 -0
- package/dist/web/assets/higher-BevsMIWl.ogg +0 -0
- package/dist/web/assets/identity-0EPS3msD.ogg +0 -0
- package/dist/web/assets/index-DpT0dtHc.css +1 -0
- package/dist/web/assets/intro-DeRh6kUx.ogg +0 -0
- package/dist/web/assets/intro-bass-D63IPU0H.ogg +0 -0
- package/dist/web/assets/intro-drums-Dt9QO534.ogg +0 -0
- package/dist/web/assets/intro-harmony-DBsMG9jJ.ogg +0 -0
- package/dist/web/assets/intro-lead-DWcWS1ia.ogg +0 -0
- package/dist/web/assets/jar-coin-rtCvspuq.ogg +0 -0
- package/dist/web/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
- package/dist/web/assets/ledger-tick-C1rQgQGX.ogg +0 -0
- package/dist/web/assets/night-B_bMOZcf.ogg +0 -0
- package/dist/web/assets/night-bass-B-7Ay9ME.ogg +0 -0
- package/dist/web/assets/night-drums-zEtqWXX3.ogg +0 -0
- package/dist/web/assets/night-harmony-C5Ix2yce.ogg +0 -0
- package/dist/web/assets/night-lead-B7KMlRyj.ogg +0 -0
- package/dist/web/assets/ourturn-DX78hTEz.ogg +0 -0
- package/dist/web/assets/plus-jakarta-sans-latin-400-normal-Dhut76fR.woff2 +0 -0
- package/dist/web/assets/plus-jakarta-sans-latin-500-normal-Bf-nb4oT.woff2 +0 -0
- package/dist/web/assets/plus-jakarta-sans-latin-600-normal-DLTa1BUW.woff2 +0 -0
- package/dist/web/assets/plus-jakarta-sans-latin-700-normal-CfpNZvy6.woff2 +0 -0
- package/dist/web/assets/reveal-BmWAGHih.ogg +0 -0
- package/dist/web/assets/review-split-Dac4zagw.ogg +0 -0
- package/dist/web/assets/shutter-uhz2Y9S9.ogg +0 -0
- package/dist/web/assets/soclose-CiUFR5St.ogg +0 -0
- package/dist/web/assets/stinger-TnnzHAMN.ogg +0 -0
- package/dist/web/assets/stomp-mzIk4cGm.ogg +0 -0
- package/dist/web/assets/syne-latin-700-normal-AF3Rs61n.woff2 +0 -0
- package/dist/web/assets/syne-latin-800-normal-EehdNYzx.woff2 +0 -0
- package/dist/web/assets/tension-BHvWG5ru.ogg +0 -0
- package/dist/web/assets/tension-bass-4G-2qA9W.ogg +0 -0
- package/dist/web/assets/tension-drums-D7sdehJr.ogg +0 -0
- package/dist/web/assets/tension-harmony-FyPldmLb.ogg +0 -0
- package/dist/web/assets/tension-lead-C5uoFMR8.ogg +0 -0
- package/dist/web/assets/why-clock-Dzs1A_ym.ogg +0 -0
- package/dist/web/favicon.svg +1 -0
- package/dist/web/index.html +16 -0
- package/dist/web/licenses/OFL-Archivo.txt +93 -0
- package/dist/web/licenses/OFL-DelaGothic.txt +93 -0
- package/dist/web/licenses/OFL-MartianMono.txt +93 -0
- package/package.json +63 -6
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
export const MINUTE_MS = 60_000;
|
|
2
|
+
export const DAY_MS = 86_400_000;
|
|
3
|
+
export const ACTIVE_GAP_MINUTES = 10;
|
|
4
|
+
const formatters = new Map();
|
|
5
|
+
const QUARTER_HOUR_MS = 900_000;
|
|
6
|
+
const UTC_FAST_START = Date.UTC(100, 0, 1);
|
|
7
|
+
const UTC_FAST_END = Date.UTC(10_000, 0, 1);
|
|
8
|
+
const dateLabels = new Map();
|
|
9
|
+
// Cache verified constant UTC offset (in ms) per 15-minute UTC bucket; null marks a bucket straddling a DST transition.
|
|
10
|
+
const offsetCaches = new Map();
|
|
11
|
+
function formatPartsSlow(tsMs, timezone) {
|
|
12
|
+
let formatter = formatters.get(timezone);
|
|
13
|
+
if (!formatter) {
|
|
14
|
+
formatter = new Intl.DateTimeFormat('en-GB', {
|
|
15
|
+
timeZone: timezone, calendar: 'iso8601', numberingSystem: 'latn',
|
|
16
|
+
year: 'numeric', month: '2-digit', day: '2-digit',
|
|
17
|
+
hour: '2-digit', minute: '2-digit', second: '2-digit', hourCycle: 'h23',
|
|
18
|
+
});
|
|
19
|
+
formatters.set(timezone, formatter);
|
|
20
|
+
}
|
|
21
|
+
const parts = formatter.formatToParts(tsMs);
|
|
22
|
+
let y = '', m = '', d = '', h = '', min = '', s = '';
|
|
23
|
+
for (let i = 0; i < parts.length; i++) {
|
|
24
|
+
const p = parts[i];
|
|
25
|
+
if (p.type === 'year')
|
|
26
|
+
y = p.value;
|
|
27
|
+
else if (p.type === 'month')
|
|
28
|
+
m = p.value;
|
|
29
|
+
else if (p.type === 'day')
|
|
30
|
+
d = p.value;
|
|
31
|
+
else if (p.type === 'hour')
|
|
32
|
+
h = p.value;
|
|
33
|
+
else if (p.type === 'minute')
|
|
34
|
+
min = p.value;
|
|
35
|
+
else if (p.type === 'second')
|
|
36
|
+
s = p.value;
|
|
37
|
+
}
|
|
38
|
+
const yearNum = Number(y);
|
|
39
|
+
const monthNum = Number(m);
|
|
40
|
+
const dayNum = Number(d);
|
|
41
|
+
const hourNum = Number(h);
|
|
42
|
+
const minuteNum = Number(min);
|
|
43
|
+
const secondNum = Number(s);
|
|
44
|
+
const date = `${y.padStart(4, '0')}-${m}-${d}`;
|
|
45
|
+
const civilMs = Date.UTC(yearNum, monthNum - 1, dayNum, hourNum, minuteNum, secondNum);
|
|
46
|
+
return {
|
|
47
|
+
date,
|
|
48
|
+
hour: hourNum,
|
|
49
|
+
minuteOfDay: hourNum * 60 + minuteNum,
|
|
50
|
+
second: secondNum,
|
|
51
|
+
dayOfWeek: new Date(Date.UTC(yearNum, monthNum - 1, dayNum)).getUTCDay(),
|
|
52
|
+
offsetMs: civilMs - Math.floor(tsMs / 1000) * 1000,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export function localParts(tsMs, timezone) {
|
|
56
|
+
if (timezone === 'UTC' && tsMs >= UTC_FAST_START && tsMs < UTC_FAST_END)
|
|
57
|
+
return shiftedParts(tsMs);
|
|
58
|
+
let cache = offsetCaches.get(timezone);
|
|
59
|
+
if (!cache) {
|
|
60
|
+
cache = new Map();
|
|
61
|
+
offsetCaches.set(timezone, cache);
|
|
62
|
+
}
|
|
63
|
+
const bucket = Math.floor(tsMs / QUARTER_HOUR_MS);
|
|
64
|
+
let offsetMs = cache.get(bucket);
|
|
65
|
+
if (offsetMs === undefined) {
|
|
66
|
+
const startMs = bucket * QUARTER_HOUR_MS;
|
|
67
|
+
const endMs = startMs + QUARTER_HOUR_MS - 1000;
|
|
68
|
+
const a = formatPartsSlow(startMs, timezone).offsetMs;
|
|
69
|
+
const b = formatPartsSlow(endMs, timezone).offsetMs;
|
|
70
|
+
offsetMs = a === b ? a : null;
|
|
71
|
+
if (cache.size > 40_000)
|
|
72
|
+
cache.clear();
|
|
73
|
+
cache.set(bucket, offsetMs);
|
|
74
|
+
}
|
|
75
|
+
if (offsetMs === null) {
|
|
76
|
+
const slow = formatPartsSlow(tsMs, timezone);
|
|
77
|
+
return {
|
|
78
|
+
date: slow.date,
|
|
79
|
+
hour: slow.hour,
|
|
80
|
+
minuteOfDay: slow.minuteOfDay,
|
|
81
|
+
second: slow.second,
|
|
82
|
+
dayOfWeek: slow.dayOfWeek,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return shiftedParts(tsMs + offsetMs);
|
|
86
|
+
}
|
|
87
|
+
function shiftedParts(shiftedMs) {
|
|
88
|
+
const shifted = new Date(shiftedMs);
|
|
89
|
+
const civilDay = Math.floor(shifted.getTime() / DAY_MS);
|
|
90
|
+
let date = dateLabels.get(civilDay);
|
|
91
|
+
if (date === undefined) {
|
|
92
|
+
const year = String(shifted.getUTCFullYear()).padStart(4, '0');
|
|
93
|
+
const month = String(shifted.getUTCMonth() + 1).padStart(2, '0');
|
|
94
|
+
const day = String(shifted.getUTCDate()).padStart(2, '0');
|
|
95
|
+
date = `${year}-${month}-${day}`;
|
|
96
|
+
if (dateLabels.size >= 1024)
|
|
97
|
+
dateLabels.clear();
|
|
98
|
+
dateLabels.set(civilDay, date);
|
|
99
|
+
}
|
|
100
|
+
const hour = shifted.getUTCHours();
|
|
101
|
+
const minute = shifted.getUTCMinutes();
|
|
102
|
+
const second = shifted.getUTCSeconds();
|
|
103
|
+
return {
|
|
104
|
+
date,
|
|
105
|
+
hour,
|
|
106
|
+
minuteOfDay: hour * 60 + minute,
|
|
107
|
+
second,
|
|
108
|
+
dayOfWeek: shifted.getUTCDay(),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const dateMs = (date) => Date.parse(date + 'T00:00:00Z');
|
|
112
|
+
export const addDays = (date, days) => new Date(dateMs(date) + days * DAY_MS).toISOString().slice(0, 10);
|
|
113
|
+
export const dayDistance = (start, end) => (dateMs(end) - dateMs(start)) / DAY_MS;
|
|
114
|
+
export const monday = (date) => addDays(date, -((new Date(dateMs(date)).getUTCDay() + 6) % 7));
|
|
115
|
+
export function datesBetween(start, end, step = 1) {
|
|
116
|
+
return Array.from({ length: Math.max(0, Math.floor(dayDistance(start, end) / step) + 1) }, (_, i) => addDays(start, i * step));
|
|
117
|
+
}
|
|
118
|
+
export function codingDate(parts) {
|
|
119
|
+
return parts.minuteOfDay < 240 ? addDays(parts.date, -1) : parts.date;
|
|
120
|
+
}
|
|
121
|
+
/** Resolve a civil boundary against the offsets on both sides of a zone transition. */
|
|
122
|
+
export function localTimestamp(date, minute, timezone) {
|
|
123
|
+
const target = dateMs(date) + minute * MINUTE_MS;
|
|
124
|
+
const asCivil = (instant) => {
|
|
125
|
+
const local = localParts(instant, timezone);
|
|
126
|
+
return dateMs(local.date) + local.minuteOfDay * MINUTE_MS + local.second * 1000;
|
|
127
|
+
};
|
|
128
|
+
const candidates = [-DAY_MS * 2, 0, DAY_MS * 2].map((delta) => {
|
|
129
|
+
const sample = target + delta;
|
|
130
|
+
return target - (asCivil(sample) - sample);
|
|
131
|
+
}).sort((a, b) => a - b);
|
|
132
|
+
const exact = candidates.find((instant) => asCivil(instant) === target);
|
|
133
|
+
if (exact !== undefined)
|
|
134
|
+
return exact;
|
|
135
|
+
// A skipped civil time starts at the transition, including a skipped calendar day.
|
|
136
|
+
let lo = candidates[0], hi = candidates.at(-1);
|
|
137
|
+
while (hi - lo > 1) {
|
|
138
|
+
const mid = Math.floor((lo + hi) / 2);
|
|
139
|
+
if (asCivil(mid) >= target)
|
|
140
|
+
hi = mid;
|
|
141
|
+
else
|
|
142
|
+
lo = mid;
|
|
143
|
+
}
|
|
144
|
+
return hi;
|
|
145
|
+
}
|
|
146
|
+
export function calendarWindow(year, timezone) {
|
|
147
|
+
return {
|
|
148
|
+
start: localTimestamp(`${year}-01-01`, 0, timezone),
|
|
149
|
+
end: localTimestamp(`${year + 1}-01-01`, 0, timezone),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
export function formatClock(minute) {
|
|
153
|
+
return `${String(Math.floor(minute / 60)).padStart(2, '0')}:${String(minute % 60).padStart(2, '0')}`;
|
|
154
|
+
}
|
|
155
|
+
export function makeActiveSpans(timestamps, gapMinutes = ACTIVE_GAP_MINUTES, bounds) {
|
|
156
|
+
const sorted = [...new Set(timestamps)].sort((a, b) => a - b);
|
|
157
|
+
const spans = [];
|
|
158
|
+
let first = sorted[0];
|
|
159
|
+
let last = first;
|
|
160
|
+
for (const ts of [...sorted.slice(1), Infinity]) {
|
|
161
|
+
if (first === undefined || last === undefined)
|
|
162
|
+
break;
|
|
163
|
+
if (ts - last <= gapMinutes * MINUTE_MS) {
|
|
164
|
+
last = ts;
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const start = Math.max(first, bounds?.start ?? -Infinity);
|
|
168
|
+
const end = Math.min(first === last ? last + MINUTE_MS : last, bounds?.end ?? Infinity);
|
|
169
|
+
if (start < end)
|
|
170
|
+
spans.push({ start, end });
|
|
171
|
+
first = last = ts;
|
|
172
|
+
}
|
|
173
|
+
return spans;
|
|
174
|
+
}
|
|
175
|
+
export function unionSpans(spans) {
|
|
176
|
+
const merged = [];
|
|
177
|
+
for (const span of [...spans].sort((a, b) => a.start - b.start || a.end - b.end)) {
|
|
178
|
+
const last = merged.at(-1);
|
|
179
|
+
if (last && span.start <= last.end)
|
|
180
|
+
last.end = Math.max(last.end, span.end);
|
|
181
|
+
else
|
|
182
|
+
merged.push({ ...span });
|
|
183
|
+
}
|
|
184
|
+
return merged;
|
|
185
|
+
}
|
|
186
|
+
export const spanMinutes = (spans) => spans.reduce((sum, { start, end }) => sum + (end - start) / MINUTE_MS, 0);
|
|
187
|
+
export function computeActiveTime(events, bounds) {
|
|
188
|
+
const times = new Map();
|
|
189
|
+
for (const { sessionId, tsMs } of events) {
|
|
190
|
+
const list = times.get(sessionId) ?? [];
|
|
191
|
+
list.push(tsMs);
|
|
192
|
+
times.set(sessionId, list);
|
|
193
|
+
}
|
|
194
|
+
const perSession = new Map([...times].map(([id, stamps]) => [id, makeActiveSpans(stamps, ACTIVE_GAP_MINUTES, bounds)]));
|
|
195
|
+
const wallSpans = unionSpans([...perSession.values()].flat());
|
|
196
|
+
const wallClockActiveMinutes = spanMinutes(wallSpans);
|
|
197
|
+
const agentActiveMinutes = [...perSession.values()].reduce((sum, spans) => sum + spanMinutes(spans), 0);
|
|
198
|
+
const sensitivity = (gap) => spanMinutes(unionSpans([...times.values()].flatMap((stamps) => makeActiveSpans(stamps, gap, bounds))));
|
|
199
|
+
return {
|
|
200
|
+
perSession, wallSpans, wallClockActiveMinutes, agentActiveMinutes,
|
|
201
|
+
wallClockSensitivity5m: sensitivity(5),
|
|
202
|
+
wallClockSensitivity15m: sensitivity(15),
|
|
203
|
+
parallelismFactor: wallClockActiveMinutes ? agentActiveMinutes / wallClockActiveMinutes : null,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
export function dailyActiveMinutes(spans, timezone, boundary = 0) {
|
|
207
|
+
const totals = new Map();
|
|
208
|
+
const boundaries = new Map();
|
|
209
|
+
for (const span of spans) {
|
|
210
|
+
const local = localParts(span.start, timezone);
|
|
211
|
+
let date = local.minuteOfDay < boundary ? addDays(local.date, -1) : local.date;
|
|
212
|
+
let start = span.start;
|
|
213
|
+
while (start < span.end) {
|
|
214
|
+
const next = addDays(date, 1);
|
|
215
|
+
let cut = boundaries.get(next);
|
|
216
|
+
if (cut === undefined) {
|
|
217
|
+
cut = localTimestamp(next, boundary, timezone);
|
|
218
|
+
boundaries.set(next, cut);
|
|
219
|
+
}
|
|
220
|
+
const end = Math.min(cut, span.end);
|
|
221
|
+
if (end > start)
|
|
222
|
+
totals.set(date, (totals.get(date) ?? 0) + (end - start) / MINUTE_MS);
|
|
223
|
+
start = Math.max(start, end);
|
|
224
|
+
date = next;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return totals;
|
|
228
|
+
}
|
|
229
|
+
export function circularMean(minutes) {
|
|
230
|
+
if (!minutes.length)
|
|
231
|
+
return { minute: null, resultantR: 0 };
|
|
232
|
+
const angle = Math.PI / 720;
|
|
233
|
+
let x = 0, y = 0;
|
|
234
|
+
for (const minute of minutes) {
|
|
235
|
+
x += Math.cos(minute * angle);
|
|
236
|
+
y += Math.sin(minute * angle);
|
|
237
|
+
}
|
|
238
|
+
const resultantR = Math.min(1, Math.hypot(x, y) / minutes.length);
|
|
239
|
+
const minute = resultantR < 1e-12 ? null : (Math.round(Math.atan2(y, x) / angle) + 1440) % 1440;
|
|
240
|
+
return { minute, resultantR };
|
|
241
|
+
}
|
|
242
|
+
export function chronotypeFor(minute, resultantR) {
|
|
243
|
+
if (minute === null || resultantR < 0.25)
|
|
244
|
+
return 'Round-the-Clock';
|
|
245
|
+
if (minute < 300 || minute >= 1320)
|
|
246
|
+
return 'Nocturnal';
|
|
247
|
+
if (minute < 600)
|
|
248
|
+
return 'Dawn';
|
|
249
|
+
if (minute < 1020)
|
|
250
|
+
return 'Daylight';
|
|
251
|
+
return 'Twilight';
|
|
252
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { parseArgs } from 'node:util';
|
|
2
|
+
const DEMO_PROFILES = ['night-owl', 'polyglot', 'starter', 'specialist', 'partial'];
|
|
3
|
+
const DEFAULT_DEMO = DEMO_PROFILES[0];
|
|
4
|
+
export const HELP_TEXT = `coauthored · flight recorder 2026
|
|
5
|
+
|
|
6
|
+
Usage: coauthored [options]
|
|
7
|
+
|
|
8
|
+
--demo [profile] Replay a fictional recorder. Default profile is night-owl.
|
|
9
|
+
Profiles: ${DEMO_PROFILES.join(', ')}
|
|
10
|
+
--dry-run List exact source paths and the field policy. Zero content reads.
|
|
11
|
+
--terminal Review the plan and read the report in the terminal.
|
|
12
|
+
--no-browser Alias for --terminal.
|
|
13
|
+
--no-open Start the local UI for manual navigation.
|
|
14
|
+
--inspect-report Write export-safe report JSON to stdout.
|
|
15
|
+
--export-json <path> Save the browser-safe report JSON to a file.
|
|
16
|
+
--privacy-receipt Include the exact source ledger in the terminal.
|
|
17
|
+
--input <dir> Discover recorders in an explicit directory.
|
|
18
|
+
--analytics-log <path> Include an explicit Aider analytics JSONL file.
|
|
19
|
+
--year <YYYY> Set the reporting year. Default is 2026.
|
|
20
|
+
--tz <IANA> Set the reporting timezone. Default is the local timezone.
|
|
21
|
+
--port <n> Set the loopback port. Default is chosen by the OS.
|
|
22
|
+
--confirm Explicitly release the plan for a terminal scan.
|
|
23
|
+
--content Ask to count prompt and reply words in the terminal.
|
|
24
|
+
--confirm-content Confirm word counting with --content in automation.
|
|
25
|
+
--include-private-phrases Review phrases in a terminal and include the ones you keep in JSON output.
|
|
26
|
+
--force Replace an existing JSON export.
|
|
27
|
+
--help Print this field guide.
|
|
28
|
+
--version Print the recorder version.`;
|
|
29
|
+
export function parseCliArgs(argv = process.argv.slice(2)) {
|
|
30
|
+
// parseArgs supports string options but has no optional-value form.
|
|
31
|
+
const args = argv.map((arg, i) => arg === '--demo' && (argv[i + 1] === undefined || argv[i + 1]?.startsWith('-'))
|
|
32
|
+
? `--demo=${DEFAULT_DEMO}`
|
|
33
|
+
: arg);
|
|
34
|
+
const { values } = parseArgs({
|
|
35
|
+
args,
|
|
36
|
+
options: {
|
|
37
|
+
demo: { type: 'string' },
|
|
38
|
+
'dry-run': { type: 'boolean' },
|
|
39
|
+
terminal: { type: 'boolean' },
|
|
40
|
+
'no-browser': { type: 'boolean' },
|
|
41
|
+
'no-open': { type: 'boolean' },
|
|
42
|
+
'inspect-report': { type: 'boolean' },
|
|
43
|
+
'export-json': { type: 'string' },
|
|
44
|
+
'privacy-receipt': { type: 'boolean' },
|
|
45
|
+
input: { type: 'string' },
|
|
46
|
+
'analytics-log': { type: 'string' },
|
|
47
|
+
year: { type: 'string', default: '2026' },
|
|
48
|
+
tz: { type: 'string', default: Intl.DateTimeFormat().resolvedOptions().timeZone },
|
|
49
|
+
port: { type: 'string' },
|
|
50
|
+
confirm: { type: 'boolean' },
|
|
51
|
+
content: { type: 'boolean' },
|
|
52
|
+
'confirm-content': { type: 'boolean' },
|
|
53
|
+
'include-private-phrases': { type: 'boolean' },
|
|
54
|
+
force: { type: 'boolean' },
|
|
55
|
+
help: { type: 'boolean' },
|
|
56
|
+
version: { type: 'boolean' },
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
const demo = DEMO_PROFILES.find((profile) => profile === values.demo);
|
|
60
|
+
if (values.demo !== undefined && !demo)
|
|
61
|
+
throw new Error(`Choose a demo profile from ${DEMO_PROFILES.join(', ')}.`);
|
|
62
|
+
const year = Number(values.year);
|
|
63
|
+
if (!/^\d{4}$/.test(values.year) || year < 2020 || year > 2035)
|
|
64
|
+
throw new Error('--year must be between 2020 and 2035.');
|
|
65
|
+
try {
|
|
66
|
+
if (/^[+-]/.test(values.tz))
|
|
67
|
+
throw new Error();
|
|
68
|
+
new Intl.DateTimeFormat('en', { timeZone: values.tz });
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
throw new Error('--tz must be an IANA timezone, such as America/New_York or UTC.');
|
|
72
|
+
}
|
|
73
|
+
const port = values.port === undefined ? undefined : Number(values.port);
|
|
74
|
+
if (values.port !== undefined && (!/^\d{1,5}$/.test(values.port) || port > 65_535)) {
|
|
75
|
+
throw new Error('--port must be an integer from 0 to 65535.');
|
|
76
|
+
}
|
|
77
|
+
if (values.input === '')
|
|
78
|
+
throw new Error('--input requires a directory.');
|
|
79
|
+
if (values['analytics-log'] === '')
|
|
80
|
+
throw new Error('--analytics-log requires a file path.');
|
|
81
|
+
if (values['export-json'] === '')
|
|
82
|
+
throw new Error('--export-json requires a file path.');
|
|
83
|
+
return {
|
|
84
|
+
demo,
|
|
85
|
+
dryRun: values['dry-run'] ?? false,
|
|
86
|
+
terminal: values.terminal === true || values['no-browser'] === true,
|
|
87
|
+
noBrowser: values['no-browser'] ?? false,
|
|
88
|
+
noOpen: values['no-open'] ?? false,
|
|
89
|
+
inspectReport: values['inspect-report'] ?? false,
|
|
90
|
+
exportJson: values['export-json'],
|
|
91
|
+
privacyReceipt: values['privacy-receipt'] ?? false,
|
|
92
|
+
input: values.input,
|
|
93
|
+
analyticsLog: values['analytics-log'],
|
|
94
|
+
year,
|
|
95
|
+
timezone: values.tz,
|
|
96
|
+
port,
|
|
97
|
+
confirm: values.confirm ?? false,
|
|
98
|
+
content: values.content === true,
|
|
99
|
+
confirmContent: values['confirm-content'] === true,
|
|
100
|
+
includePrivatePhrases: values['include-private-phrases'] === true,
|
|
101
|
+
force: values.force ?? false,
|
|
102
|
+
help: values.help ?? false,
|
|
103
|
+
version: values.version ?? false,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
function launch(command, args, windowsVerbatimArguments = false) {
|
|
5
|
+
return new Promise((resolve) => {
|
|
6
|
+
try {
|
|
7
|
+
const child = spawn(command, args, {
|
|
8
|
+
detached: true,
|
|
9
|
+
stdio: 'ignore',
|
|
10
|
+
windowsHide: true,
|
|
11
|
+
windowsVerbatimArguments,
|
|
12
|
+
});
|
|
13
|
+
// Some desktop launchers stay alive for the lifetime of the browser.
|
|
14
|
+
const timer = setTimeout(() => resolve(child.pid !== undefined), 2_000);
|
|
15
|
+
child.once('error', () => {
|
|
16
|
+
clearTimeout(timer);
|
|
17
|
+
resolve(false);
|
|
18
|
+
});
|
|
19
|
+
child.once('exit', (code) => {
|
|
20
|
+
clearTimeout(timer);
|
|
21
|
+
resolve(code === 0);
|
|
22
|
+
});
|
|
23
|
+
child.unref();
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
resolve(false);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function isWsl() {
|
|
31
|
+
if (process.env.WSL_DISTRO_NAME)
|
|
32
|
+
return true;
|
|
33
|
+
try {
|
|
34
|
+
return /microsoft/i.test(readFileSync('/proc/version', 'utf8'));
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export async function openBrowserUrl(url) {
|
|
41
|
+
const match = /^http:\/\/127\.0\.0\.1:(\d{1,5})\/#token=[A-Za-z0-9_-]{32,128}$/.exec(url);
|
|
42
|
+
if (!match || Number(match[1]) < 1 || Number(match[1]) > 65_535) {
|
|
43
|
+
return { opened: false, reason: 'Invalid loopback launch URL.' };
|
|
44
|
+
}
|
|
45
|
+
const windowsArgs = ['/d', '/c', 'start', '""', url];
|
|
46
|
+
let opened = false;
|
|
47
|
+
switch (process.platform) {
|
|
48
|
+
case 'darwin':
|
|
49
|
+
opened = await launch('/usr/bin/open', [url]);
|
|
50
|
+
break;
|
|
51
|
+
case 'win32':
|
|
52
|
+
opened = await launch(join(process.env.SystemRoot ?? 'C:\\Windows', 'System32', 'cmd.exe'), windowsArgs, true);
|
|
53
|
+
break;
|
|
54
|
+
case 'linux':
|
|
55
|
+
if (isWsl()) {
|
|
56
|
+
opened = await launch('wslview', [url]) ||
|
|
57
|
+
await launch('/mnt/c/Windows/System32/cmd.exe', windowsArgs) ||
|
|
58
|
+
await launch('xdg-open', [url]);
|
|
59
|
+
}
|
|
60
|
+
else if (process.env.DISPLAY || process.env.WAYLAND_DISPLAY) {
|
|
61
|
+
opened = await launch('xdg-open', [url]);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
return { opened: false, reason: 'No graphical session detected.' };
|
|
65
|
+
}
|
|
66
|
+
break;
|
|
67
|
+
default:
|
|
68
|
+
return { opened: false, reason: 'No launcher for this platform.' };
|
|
69
|
+
}
|
|
70
|
+
return opened ? { opened } : { opened, reason: 'The browser launcher did not complete successfully.' };
|
|
71
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const MIN_NODE = [24, 15, 0];
|
|
3
|
+
const [maj = 0, min = 0, pat = 0] = process.versions.node.split('.').map((n) => Number(n));
|
|
4
|
+
const ok = maj > MIN_NODE[0] ||
|
|
5
|
+
(maj === MIN_NODE[0] && min > MIN_NODE[1]) ||
|
|
6
|
+
(maj === MIN_NODE[0] && min === MIN_NODE[1] && pat >= MIN_NODE[2]);
|
|
7
|
+
if (!ok) {
|
|
8
|
+
process.stderr.write(`coauthored requires Node.js >= ${MIN_NODE.join('.')} (detected ${process.versions.node}) for hardened built-in node:sqlite.\n` +
|
|
9
|
+
`Please upgrade to Node.js ${MIN_NODE.join('.')} or newer and try again.\n`);
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
const { runCli } = await import('./main.js');
|
|
14
|
+
await runCli();
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
process.stderr.write(`coauthored failed: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
export {};
|