@kitkat-vn/kitcode 0.2.0-staging.3
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/README.md +328 -0
- package/bin/kitcode.mjs +1097 -0
- package/package.json +41 -0
- package/src/api-access.mjs +119 -0
- package/src/api.mjs +165 -0
- package/src/atomic-file.mjs +85 -0
- package/src/break-progress.mjs +87 -0
- package/src/claim-bundle.mjs +37 -0
- package/src/companion-controls.mjs +40 -0
- package/src/companion-electron.mjs +87 -0
- package/src/companion-preload.cjs +10 -0
- package/src/companion-window.mjs +57 -0
- package/src/cors.mjs +51 -0
- package/src/equals-ledger.mjs +166 -0
- package/src/focus-clock.mjs +86 -0
- package/src/fonts/fira-code/OFL.txt +93 -0
- package/src/fonts/fira-code/fira-code-latin-400-normal.woff2 +0 -0
- package/src/fonts/fira-code/fira-code-latin-500-normal.woff2 +0 -0
- package/src/fonts/fira-code/fira-code-latin-700-normal.woff2 +0 -0
- package/src/fonts/vt323/OFL.txt +93 -0
- package/src/fonts/vt323/vt323-latin-400-normal.woff2 +0 -0
- package/src/git.mjs +448 -0
- package/src/hook-installers.mjs +397 -0
- package/src/hook-prompt.mjs +201 -0
- package/src/install-id.mjs +94 -0
- package/src/integration-installers.mjs +28 -0
- package/src/integration-spec.mjs +398 -0
- package/src/log-file.mjs +60 -0
- package/src/milestones-reached.mjs +130 -0
- package/src/next-break-reminder.mjs +78 -0
- package/src/onboarding-electron.mjs +240 -0
- package/src/onboarding-platform.mjs +50 -0
- package/src/onboarding-preload.cjs +19 -0
- package/src/onboarding-window.mjs +874 -0
- package/src/open-dashboard.mjs +30 -0
- package/src/reward.mjs +311 -0
- package/src/runner-installer.mjs +153 -0
- package/src/runtime.mjs +1323 -0
- package/src/scan-worker.mjs +23 -0
- package/src/scanner.mjs +84 -0
- package/src/seen-lines.mjs +148 -0
- package/src/skill-installer.mjs +76 -0
- package/src/source-snapshot.mjs +725 -0
- package/src/store.mjs +595 -0
- package/src/tracker-instance.mjs +166 -0
- package/src/tracker-problems.mjs +30 -0
- package/src/tracker-stop.mjs +73 -0
- package/src/uninstall.mjs +80 -0
- package/src/vibe.mjs +4 -0
- package/src/window-guards.mjs +7 -0
- package/src/window-page.mjs +49 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {COMPANION_HIDE_CSS, renderCompanionTitleBar} from './companion-controls.mjs';
|
|
2
|
+
import {DASHBOARD_URL} from './integration-spec.mjs';
|
|
3
|
+
import {contentSecurityPolicy, fontFaces} from './window-page.mjs';
|
|
4
|
+
|
|
5
|
+
export function renderCompanionWindow(apiBase = '') {
|
|
6
|
+
// The page's one stylesheet and one script, kept apart so that its policy allows exactly them. Served
|
|
7
|
+
// by the tracker (apiBase ''), the page reads the API from its own origin; the offline copy, from apiBase.
|
|
8
|
+
const style = `
|
|
9
|
+
${fontFaces(['vt323', 'fira-code'])}
|
|
10
|
+
:root{color-scheme:dark;--bg-color:#0c0c0c;--red-color:#f03030;--white-text:#e0e0e0;--font-mono:'Fira Code',monospace;--font-pixel:'VT323',monospace}
|
|
11
|
+
*{box-sizing:border-box;margin:0;padding:0}
|
|
12
|
+
html,body{position:relative;width:100%;height:100%;margin:0;overflow:hidden;background:transparent;color:var(--white-text);font-family:var(--font-mono)}
|
|
13
|
+
button{cursor:pointer}
|
|
14
|
+
.widget-window{position:relative;width:100%;height:100%;display:flex;flex-direction:column;background:var(--bg-color);border:2px solid var(--red-color);border-radius:8px;overflow:hidden;-webkit-app-region:drag}
|
|
15
|
+
.title-bar{padding:6px 10px 4px;display:flex;align-items:center;gap:7px;border-bottom:1px solid var(--red-color)}
|
|
16
|
+
.dot{width:12px;height:12px;border-radius:50%;border:1px solid var(--red-color);background:transparent}
|
|
17
|
+
.dot.filled{background-color:var(--red-color)}
|
|
18
|
+
.widget-body{flex:1;min-height:0;padding:8px 16px;display:flex;align-items:center;justify-content:space-between;gap:10px;min-width:0;-webkit-app-region:drag}
|
|
19
|
+
.brand-label{color:var(--red-color);font-family:var(--font-mono);font-size:10px;font-weight:700;line-height:1.15;letter-spacing:.6px;text-transform:uppercase;white-space:nowrap}
|
|
20
|
+
.percentage{font-family:var(--font-pixel),var(--font-mono);font-size:30px;letter-spacing:1px;line-height:1;color:var(--white-text);white-space:nowrap}
|
|
21
|
+
.progress-box{border-top:2px solid var(--white-text);border-bottom:2px solid var(--white-text);border-left:1px dashed var(--white-text);border-right:1px dashed var(--white-text);padding:3px 6px;width:120px;height:32px;display:flex;align-items:center;flex:0 0 120px;overflow:hidden}
|
|
22
|
+
.progress-fill{width:0;height:100%;display:flex;flex-direction:column;justify-content:center;gap:1px;overflow:hidden;transition:width .2s ease}
|
|
23
|
+
.progress-row{width:max-content;color:var(--white-text);font:700 9px/1 var(--font-mono);letter-spacing:1px;white-space:nowrap}
|
|
24
|
+
.metrics-group{display:flex;align-items:flex-end;gap:14px;min-width:0}
|
|
25
|
+
.metric-item{display:flex;flex-direction:column;align-items:center;min-width:0}
|
|
26
|
+
.metric-value{color:var(--white-text);font-family:var(--font-pixel),var(--font-mono);font-size:24px;line-height:1;margin-bottom:2px;letter-spacing:.5px;white-space:nowrap}
|
|
27
|
+
.metric-label{color:var(--red-color);font-family:var(--font-mono);font-size:7px;font-weight:500;letter-spacing:.3px;text-transform:uppercase;white-space:nowrap}
|
|
28
|
+
.claim-btn{-webkit-app-region:no-drag;background:transparent;color:var(--white-text);font-family:var(--font-mono);font-size:10px;font-weight:500;letter-spacing:1px;padding:3px 12px;cursor:pointer;text-transform:uppercase;border-top:2px solid var(--red-color);border-bottom:2px solid var(--red-color);border-left:1px dashed var(--red-color);border-right:1px dashed var(--red-color);white-space:normal;width:min-content;line-height:1.15;transition:background-color .2s ease}
|
|
29
|
+
.claim-btn[data-ready="true"]{background:rgba(240,48,48,.18)}
|
|
30
|
+
.claim-btn:hover,.claim-btn:focus-visible{background:rgba(240,48,48,.15);outline:none}
|
|
31
|
+
.offline .percentage,.offline .metric-value{color:#6f6f6f}
|
|
32
|
+
.offline .progress-row{color:#6f6f6f}
|
|
33
|
+
${COMPANION_HIDE_CSS}
|
|
34
|
+
`;
|
|
35
|
+
const script = `
|
|
36
|
+
const API_BASE=${JSON.stringify(apiBase)};const percent=document.getElementById('percent'),countValue=document.getElementById('countValue'),workedValue=document.getElementById('workedValue'),idleValue=document.getElementById('idleValue'),progressFill=document.getElementById('progressFill'),main=document.getElementById('main'),dashboardButton=document.getElementById('dashboardButton');
|
|
37
|
+
function formatDuration(seconds){const totalSeconds=Math.max(0,Math.floor(Number(seconds)||0));if(totalSeconds<60)return totalSeconds+'s';const hours=Math.floor(totalSeconds/3600),minutes=Math.floor((totalSeconds%3600)/60);if(hours>0)return minutes>0?hours+'h '+minutes+'m':hours+'h';return minutes+'m'}
|
|
38
|
+
function updateProgress(value){progressFill.style.width=Math.max(0,Math.min(100,Number(value)||0))+'%'}
|
|
39
|
+
function render(summary){const reward=summary?.reward||{},global=summary?.global||{},tiers=reward.tiers||[],ready=tiers.some((tier)=>tier.status==='ready'),value=Math.max(0,Math.min(100,Math.floor(Number(reward.progressPercent)||0)));percent.textContent=value+'%';countValue.textContent=String(Math.max(0,Math.floor(Number(reward.totalEquals)||0)));workedValue.textContent=formatDuration(global.totalActiveSeconds);idleValue.textContent=formatDuration(global.totalIdleSeconds);updateProgress(value);dashboardButton.dataset.ready=ready?'true':'false';main.classList.remove('offline')}
|
|
40
|
+
function offline(){percent.textContent='--';countValue.textContent='--';workedValue.textContent='--';idleValue.textContent='--';updateProgress(0);dashboardButton.dataset.ready='false';main.classList.add('offline')}
|
|
41
|
+
async function sync(){try{const response=await fetch(API_BASE+'/api/summary');if(!response.ok)throw new Error();render(await response.json())}catch{offline()}}
|
|
42
|
+
const hideButton=document.getElementById('hideButton');function hideCompanion(){try{const result=window.kitcodeCompanion?.hide?.();if(result&&typeof result.catch==='function')result.catch(()=>window.close());if(!result)window.close()}catch{window.close()}}
|
|
43
|
+
hideButton.addEventListener('pointerdown',(event)=>event.stopPropagation());hideButton.addEventListener('click',(event)=>{event.stopPropagation();hideCompanion()});
|
|
44
|
+
dashboardButton.addEventListener('pointerdown',(event)=>event.stopPropagation());
|
|
45
|
+
dashboardButton.addEventListener('click',()=>{if(window.kitcodeCompanion?.openDashboard){window.kitcodeCompanion.openDashboard();return}window.open(${JSON.stringify(DASHBOARD_URL)},'_blank','noopener')});
|
|
46
|
+
sync();const events=new EventSource(API_BASE+'/api/events');events.addEventListener('summary',(event)=>{try{render(JSON.parse(event.data))}catch{offline()}});events.onerror=offline;
|
|
47
|
+
`;
|
|
48
|
+
|
|
49
|
+
// The button opens the dashboard, where a ready code is shown: "Show code", not a claim (operator
|
|
50
|
+
// decision, 2026-09-24). It wraps onto two lines, as KITCODE COUNTER does on the left: on one line
|
|
51
|
+
// it took 28 px from the counters, which then ran into each other at long-campaign values
|
|
52
|
+
// (measured in the 560 x 76 window with 2500 = and 11h 48m).
|
|
53
|
+
return `<!doctype html>
|
|
54
|
+
<html lang="en"><head><meta charset="utf-8"><meta http-equiv="Content-Security-Policy" content="${contentSecurityPolicy({script, style, connect: [apiBase || "'self'"]})}"><meta name="viewport" content="width=device-width, initial-scale=1">
|
|
55
|
+
<title>KitCode Counter</title><style>${style}</style></head>
|
|
56
|
+
<body><main class="widget-window" id="main" data-testid="companion-counter-bar">${renderCompanionTitleBar()}<div class="widget-body"><div class="brand-label" aria-label="KitCode Counter">KITCODE<br>COUNTER</div><strong class="percentage" id="percent" data-testid="mini-percent">--</strong><div class="progress-box" aria-hidden="true"><div class="progress-fill" id="progressFill"><div class="progress-row">========================</div><div class="progress-row">========================</div></div></div><div class="metrics-group" aria-label="KitCode counters"><div class="metric-item"><div class="metric-value" id="countValue" data-testid="mini-count">--</div><div class="metric-label">= COUNT</div></div><div class="metric-item"><div class="metric-value" id="workedValue" data-testid="mini-worked">--</div><div class="metric-label">WORKED</div></div><div class="metric-item"><div class="metric-value" id="idleValue" data-testid="mini-idle">--</div><div class="metric-label">IDLE</div></div></div><button class="claim-btn" id="dashboardButton" data-testid="companion-dashboard" type="button" data-ready="false">Show code</button></div></main><script>${script}</script></body></html>`;
|
|
57
|
+
}
|
package/src/cors.mjs
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// The origins a tracker allows with nothing configured: the hosted dashboard's and the local development
|
|
2
|
+
// servers'. Pinned by local-api.test.mjs.
|
|
3
|
+
export const DEFAULT_ALLOWED_ORIGINS = new Set([
|
|
4
|
+
// The staging dashboard this tester build is for (scripts/tester-build.mjs in the repository).
|
|
5
|
+
"https://staging.kitcode.vn",
|
|
6
|
+
'http://localhost:8686',
|
|
7
|
+
'http://127.0.0.1:8686',
|
|
8
|
+
'http://localhost:3000',
|
|
9
|
+
'http://127.0.0.1:3000',
|
|
10
|
+
'http://localhost:5173',
|
|
11
|
+
'http://127.0.0.1:5173',
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
function configuredOrigins() {
|
|
15
|
+
if (!process.env.KITCODE_ALLOWED_ORIGINS) {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return process.env.KITCODE_ALLOWED_ORIGINS.split(',')
|
|
20
|
+
.map((origin) => origin.trim())
|
|
21
|
+
.filter(Boolean);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function isAllowedOrigin(origin) {
|
|
25
|
+
return Boolean(origin) && (DEFAULT_ALLOWED_ORIGINS.has(origin) || configuredOrigins().includes(origin));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Only an allow-listed origin is told anything: whether it may read, and whether it may reach this
|
|
29
|
+
// private-network address at all. Any other origin gets none of these headers. The one thing any page
|
|
30
|
+
// may read is a refusal, which carries fixed words only (api-access.mjs).
|
|
31
|
+
export function corsMiddleware(req, res, next) {
|
|
32
|
+
const origin = req.headers.origin;
|
|
33
|
+
|
|
34
|
+
res.setHeader('Vary', 'Origin');
|
|
35
|
+
|
|
36
|
+
if (isAllowedOrigin(origin)) {
|
|
37
|
+
res.setHeader('Access-Control-Allow-Origin', origin);
|
|
38
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
|
|
39
|
+
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
|
|
40
|
+
res.setHeader('Access-Control-Allow-Private-Network', 'true');
|
|
41
|
+
res.setHeader('Private-Network-Access-ID', '4b:69:74:43:6f:64');
|
|
42
|
+
res.setHeader('Private-Network-Access-Name', 'kitcode-local');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (req.method === 'OPTIONS') {
|
|
46
|
+
res.status(204).end();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
next();
|
|
51
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import {loadState, STORE_PATH, updateState} from './store.mjs';
|
|
2
|
+
|
|
3
|
+
export const EQUALS_LEDGER_PATH = STORE_PATH;
|
|
4
|
+
|
|
5
|
+
function createEmptyLedger() {
|
|
6
|
+
return {
|
|
7
|
+
total_equals: 0,
|
|
8
|
+
projects: {},
|
|
9
|
+
earned_tiers: [],
|
|
10
|
+
first_counted_at: null,
|
|
11
|
+
last_updated_at: null,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function isObject(value) {
|
|
16
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function normalizeCountedEntries(entries) {
|
|
20
|
+
const normalized = {};
|
|
21
|
+
|
|
22
|
+
if (!entries || typeof entries !== 'object') {
|
|
23
|
+
return normalized;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
for (const [id, entry] of Object.entries(entries)) {
|
|
27
|
+
normalized[id] = {
|
|
28
|
+
equals: Number(entry?.equals) || 0,
|
|
29
|
+
counted_at: entry?.counted_at ?? null,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return normalized;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function normalizeProjectLedger(projectId, projectLedger = {}) {
|
|
37
|
+
const countedCommits = normalizeCountedEntries(projectLedger.counted_commits);
|
|
38
|
+
const countedBatches = normalizeCountedEntries(projectLedger.counted_batches);
|
|
39
|
+
const totalEquals = Number(projectLedger.total_equals)
|
|
40
|
+
|| Object.values(countedCommits).reduce((sum, entry) => sum + entry.equals, 0)
|
|
41
|
+
+ Object.values(countedBatches).reduce((sum, entry) => sum + entry.equals, 0);
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
project_id: projectId,
|
|
45
|
+
repo_root: typeof projectLedger.repo_root === 'string' ? projectLedger.repo_root : null,
|
|
46
|
+
source_type: projectLedger.source_type === 'vibe' ? 'vibe' : 'git',
|
|
47
|
+
total_equals: totalEquals,
|
|
48
|
+
counted_commits: countedCommits,
|
|
49
|
+
counted_batches: countedBatches,
|
|
50
|
+
first_counted_at: projectLedger.first_counted_at ?? null,
|
|
51
|
+
last_updated_at: projectLedger.last_updated_at ?? null,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function normalizeLedger(ledger) {
|
|
56
|
+
const projects = {};
|
|
57
|
+
|
|
58
|
+
if (ledger?.projects && typeof ledger.projects === 'object') {
|
|
59
|
+
for (const [projectId, projectLedger] of Object.entries(ledger.projects)) {
|
|
60
|
+
projects[projectId] = normalizeProjectLedger(projectId, projectLedger);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const totalEquals = Object.values(projects).reduce((sum, project) => sum + project.total_equals, 0);
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
total_equals: totalEquals,
|
|
68
|
+
projects,
|
|
69
|
+
earned_tiers: Array.isArray(ledger?.earned_tiers) ? ledger.earned_tiers : [],
|
|
70
|
+
first_counted_at: ledger?.first_counted_at ?? null,
|
|
71
|
+
last_updated_at: ledger?.last_updated_at ?? null,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// The ledger as stored in `state`, for an updateState callback to change in place. Fields and
|
|
76
|
+
// entries this version does not know stay as they are.
|
|
77
|
+
export function storedEqualsLedger(state) {
|
|
78
|
+
if (!isObject(state.equalsLedger)) {
|
|
79
|
+
state.equalsLedger = createEmptyLedger();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const ledger = state.equalsLedger;
|
|
83
|
+
|
|
84
|
+
if (!isObject(ledger.projects)) {
|
|
85
|
+
ledger.projects = {};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (!Array.isArray(ledger.earned_tiers)) {
|
|
89
|
+
ledger.earned_tiers = [];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return ledger;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function equalsLedgerFrom(state) {
|
|
96
|
+
return normalizeLedger(state.equalsLedger);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function loadEqualsLedger() {
|
|
100
|
+
return equalsLedgerFrom(loadState());
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Counts a batch of = once. The check and the record happen in one locked update, so two
|
|
104
|
+
// processes cannot both count the same batch.
|
|
105
|
+
export function addSourceEqualsOnce(project, batchId, equals) {
|
|
106
|
+
if (equals <= 0) {
|
|
107
|
+
return loadEqualsLedger().total_equals;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return updateState((state) => {
|
|
111
|
+
const ledger = storedEqualsLedger(state);
|
|
112
|
+
const projectId = project.id ?? project.project_id;
|
|
113
|
+
const stored = isObject(ledger.projects[projectId]) ? ledger.projects[projectId] : {};
|
|
114
|
+
const current = normalizeProjectLedger(projectId, {
|
|
115
|
+
...stored,
|
|
116
|
+
repo_root: project.repoRoot ?? project.repo_root ?? stored.repo_root,
|
|
117
|
+
source_type: project.sourceType ?? project.source_type ?? stored.source_type,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
if (current.counted_batches[batchId]) {
|
|
121
|
+
return normalizeLedger(ledger).total_equals;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const countedAt = new Date().toISOString();
|
|
125
|
+
ledger.projects[projectId] = {
|
|
126
|
+
...stored,
|
|
127
|
+
project_id: current.project_id,
|
|
128
|
+
repo_root: current.repo_root,
|
|
129
|
+
source_type: current.source_type,
|
|
130
|
+
total_equals: current.total_equals + equals,
|
|
131
|
+
counted_commits: isObject(stored.counted_commits) ? stored.counted_commits : {},
|
|
132
|
+
counted_batches: {
|
|
133
|
+
...(isObject(stored.counted_batches) ? stored.counted_batches : {}),
|
|
134
|
+
[batchId]: {equals, counted_at: countedAt},
|
|
135
|
+
},
|
|
136
|
+
first_counted_at: current.first_counted_at ?? countedAt,
|
|
137
|
+
last_updated_at: countedAt,
|
|
138
|
+
};
|
|
139
|
+
ledger.total_equals = normalizeLedger(ledger).total_equals;
|
|
140
|
+
ledger.first_counted_at ??= countedAt;
|
|
141
|
+
ledger.last_updated_at = countedAt;
|
|
142
|
+
|
|
143
|
+
return ledger.total_equals;
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export const addVibeEqualsOnce = addSourceEqualsOnce;
|
|
148
|
+
|
|
149
|
+
export function getTotalEquals() {
|
|
150
|
+
return loadEqualsLedger().total_equals;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function removeProjectEquals(projectId) {
|
|
154
|
+
return updateState((state) => {
|
|
155
|
+
if (!isObject(state.equalsLedger?.projects) || !(projectId in state.equalsLedger.projects)) {
|
|
156
|
+
return normalizeLedger(state.equalsLedger);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const ledger = storedEqualsLedger(state);
|
|
160
|
+
delete ledger.projects[projectId];
|
|
161
|
+
ledger.total_equals = normalizeLedger(ledger).total_equals;
|
|
162
|
+
ledger.last_updated_at = new Date().toISOString();
|
|
163
|
+
|
|
164
|
+
return normalizeLedger(ledger);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Focus time: one clock for all projects (operator decision Q3, 2026-09-24; docs/reward-rules.md
|
|
2
|
+
// §4). A wall-clock second is active when any registered project had real activity within the idle
|
|
3
|
+
// window before it, and it counts once, however many projects were active in it. Nothing is active
|
|
4
|
+
// until the first real activity: not after a tracker starts, not after a project is added.
|
|
5
|
+
//
|
|
6
|
+
// Pure: the tracker passes in every time, so the arithmetic is tested without waiting.
|
|
7
|
+
|
|
8
|
+
export const IDLE_WINDOW_MS = 5 * 60 * 1000;
|
|
9
|
+
|
|
10
|
+
// When activity keeps a clock active. `coveredUntil` is the end of the window of the activity
|
|
11
|
+
// already counted; activity recorded since the last advance is pending until the next one.
|
|
12
|
+
export function createActivityWindow() {
|
|
13
|
+
return {coveredUntil: 0, pendingStart: null, pendingUntil: 0};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function recordActivity(window, at) {
|
|
17
|
+
window.pendingStart = window.pendingStart === null ? at : Math.min(window.pendingStart, at);
|
|
18
|
+
window.pendingUntil = Math.max(window.pendingUntil, at + IDLE_WINDOW_MS);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Splits the interval (from, to] into active and idle milliseconds, and moves the window on. An
|
|
22
|
+
// activity recorded after the interval it happened in, as a scan's result is, counts from `from`.
|
|
23
|
+
export function advanceWindow(window, from, to) {
|
|
24
|
+
// A time that is not a number would turn every counter it touches into NaN, which is written to
|
|
25
|
+
// state.json as null and read back as 0: stop here instead.
|
|
26
|
+
if (!Number.isFinite(from) || !Number.isFinite(to)) {
|
|
27
|
+
throw new TypeError(`advanceWindow needs two times, and got ${from} and ${to}`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const span = Math.max(0, to - from);
|
|
31
|
+
let activeMs = Math.max(0, Math.min(to, window.coveredUntil) - from);
|
|
32
|
+
|
|
33
|
+
if (window.pendingStart !== null) {
|
|
34
|
+
const start = Math.max(from, window.pendingStart, window.coveredUntil);
|
|
35
|
+
const end = Math.min(to, window.pendingUntil);
|
|
36
|
+
activeMs += Math.max(0, end - start);
|
|
37
|
+
window.coveredUntil = Math.max(window.coveredUntil, window.pendingUntil);
|
|
38
|
+
window.pendingStart = null;
|
|
39
|
+
window.pendingUntil = 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
activeMs = Math.min(activeMs, span);
|
|
43
|
+
return {activeMs, idleMs: span - activeMs};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function seconds(value) {
|
|
47
|
+
const number = Number(value);
|
|
48
|
+
return Number.isFinite(number) && number >= 0 ? number : null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function isObject(value) {
|
|
52
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// The shared clock as stored in state.json, or null in a file written before it existed.
|
|
56
|
+
export function storedFocusTime(state) {
|
|
57
|
+
if (!isObject(state?.focusTime)) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const activeSeconds = seconds(state.focusTime.activeSeconds);
|
|
62
|
+
return activeSeconds === null ? null : {activeSeconds, idleSeconds: seconds(state.focusTime.idleSeconds) ?? 0};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Time as a file without the shared clock counted it: summed over its projects.
|
|
66
|
+
export function summedProjectTime(state) {
|
|
67
|
+
const projects = Object.values(isObject(state?.projects) ? state.projects : {}).filter(isObject);
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
activeSeconds: projects.reduce((sum, project) => sum + (seconds(project.activeSeconds) ?? 0), 0),
|
|
71
|
+
idleSeconds: projects.reduce((sum, project) => sum + (seconds(project.idleSeconds) ?? 0), 0),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Focus time as every reader sees it: the shared clock, or, in a file that predates it, the summed
|
|
76
|
+
// total the clock will start from. So nobody's earned time goes down when the rule changes.
|
|
77
|
+
export function focusTimeFrom(state) {
|
|
78
|
+
return storedFocusTime(state) ?? summedProjectTime(state);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// A shared clock for a file that has none: it starts from the file's summed total, and records it.
|
|
82
|
+
export function startedFocusTime(state, at = new Date()) {
|
|
83
|
+
const {activeSeconds, idleSeconds} = summedProjectTime(state);
|
|
84
|
+
|
|
85
|
+
return {activeSeconds, idleSeconds, carriedOver: {activeSeconds, idleSeconds, at: at.toISOString()}};
|
|
86
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Copyright 2014-2020 The Fira Code Project Authors (https://github.com/tonsky/FiraCode)
|
|
2
|
+
|
|
3
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
4
|
+
This license is copied below, and is also available with a FAQ at:
|
|
5
|
+
https://scripts.sil.org/OFL
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
-----------------------------------------------------------
|
|
9
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
10
|
+
-----------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
PREAMBLE
|
|
13
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
14
|
+
development of collaborative font projects, to support the font creation
|
|
15
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
16
|
+
open framework in which fonts may be shared and improved in partnership
|
|
17
|
+
with others.
|
|
18
|
+
|
|
19
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
20
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
21
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
22
|
+
redistributed and/or sold with any software provided that any reserved
|
|
23
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
24
|
+
however, cannot be released under any other type of license. The
|
|
25
|
+
requirement for fonts to remain under this license does not apply
|
|
26
|
+
to any document created using the fonts or their derivatives.
|
|
27
|
+
|
|
28
|
+
DEFINITIONS
|
|
29
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
30
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
31
|
+
include source files, build scripts and documentation.
|
|
32
|
+
|
|
33
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
34
|
+
copyright statement(s).
|
|
35
|
+
|
|
36
|
+
"Original Version" refers to the collection of Font Software components as
|
|
37
|
+
distributed by the Copyright Holder(s).
|
|
38
|
+
|
|
39
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
40
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
41
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
42
|
+
new environment.
|
|
43
|
+
|
|
44
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
45
|
+
writer or other person who contributed to the Font Software.
|
|
46
|
+
|
|
47
|
+
PERMISSION & CONDITIONS
|
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
49
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
50
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
51
|
+
Software, subject to the following conditions:
|
|
52
|
+
|
|
53
|
+
1) Neither the Font Software nor any of its individual components,
|
|
54
|
+
in Original or Modified Versions, may be sold by itself.
|
|
55
|
+
|
|
56
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
57
|
+
redistributed and/or sold with any software, provided that each copy
|
|
58
|
+
contains the above copyright notice and this license. These can be
|
|
59
|
+
included either as stand-alone text files, human-readable headers or
|
|
60
|
+
in the appropriate machine-readable metadata fields within text or
|
|
61
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
62
|
+
|
|
63
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
64
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
65
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
66
|
+
presented to the users.
|
|
67
|
+
|
|
68
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
69
|
+
Software shall not be used to promote, endorse or advertise any
|
|
70
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
71
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
72
|
+
permission.
|
|
73
|
+
|
|
74
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
75
|
+
must be distributed entirely under this license, and must not be
|
|
76
|
+
distributed under any other license. The requirement for fonts to
|
|
77
|
+
remain under this license does not apply to any document created
|
|
78
|
+
using the Font Software.
|
|
79
|
+
|
|
80
|
+
TERMINATION
|
|
81
|
+
This license becomes null and void if any of the above conditions are
|
|
82
|
+
not met.
|
|
83
|
+
|
|
84
|
+
DISCLAIMER
|
|
85
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
86
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
87
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
88
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
89
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
90
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
91
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
92
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
93
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Copyright 2011, The VT323 Project Authors (peter.hull@oikoi.com)
|
|
2
|
+
|
|
3
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
4
|
+
This license is copied below, and is also available with a FAQ at:
|
|
5
|
+
http://scripts.sil.org/OFL
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
-----------------------------------------------------------
|
|
9
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
10
|
+
-----------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
PREAMBLE
|
|
13
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
14
|
+
development of collaborative font projects, to support the font creation
|
|
15
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
16
|
+
open framework in which fonts may be shared and improved in partnership
|
|
17
|
+
with others.
|
|
18
|
+
|
|
19
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
20
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
21
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
22
|
+
redistributed and/or sold with any software provided that any reserved
|
|
23
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
24
|
+
however, cannot be released under any other type of license. The
|
|
25
|
+
requirement for fonts to remain under this license does not apply
|
|
26
|
+
to any document created using the fonts or their derivatives.
|
|
27
|
+
|
|
28
|
+
DEFINITIONS
|
|
29
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
30
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
31
|
+
include source files, build scripts and documentation.
|
|
32
|
+
|
|
33
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
34
|
+
copyright statement(s).
|
|
35
|
+
|
|
36
|
+
"Original Version" refers to the collection of Font Software components as
|
|
37
|
+
distributed by the Copyright Holder(s).
|
|
38
|
+
|
|
39
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
40
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
41
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
42
|
+
new environment.
|
|
43
|
+
|
|
44
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
45
|
+
writer or other person who contributed to the Font Software.
|
|
46
|
+
|
|
47
|
+
PERMISSION & CONDITIONS
|
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
49
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
50
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
51
|
+
Software, subject to the following conditions:
|
|
52
|
+
|
|
53
|
+
1) Neither the Font Software nor any of its individual components,
|
|
54
|
+
in Original or Modified Versions, may be sold by itself.
|
|
55
|
+
|
|
56
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
57
|
+
redistributed and/or sold with any software, provided that each copy
|
|
58
|
+
contains the above copyright notice and this license. These can be
|
|
59
|
+
included either as stand-alone text files, human-readable headers or
|
|
60
|
+
in the appropriate machine-readable metadata fields within text or
|
|
61
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
62
|
+
|
|
63
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
64
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
65
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
66
|
+
presented to the users.
|
|
67
|
+
|
|
68
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
69
|
+
Software shall not be used to promote, endorse or advertise any
|
|
70
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
71
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
72
|
+
permission.
|
|
73
|
+
|
|
74
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
75
|
+
must be distributed entirely under this license, and must not be
|
|
76
|
+
distributed under any other license. The requirement for fonts to
|
|
77
|
+
remain under this license does not apply to any document created
|
|
78
|
+
using the Font Software.
|
|
79
|
+
|
|
80
|
+
TERMINATION
|
|
81
|
+
This license becomes null and void if any of the above conditions are
|
|
82
|
+
not met.
|
|
83
|
+
|
|
84
|
+
DISCLAIMER
|
|
85
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
86
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
87
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
88
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
89
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
90
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
91
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
92
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
93
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
Binary file
|