@kitkat-vn/kitcode 0.2.0-staging.10

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.
Files changed (56) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +321 -0
  3. package/bin/kitcode.mjs +1266 -0
  4. package/package.json +41 -0
  5. package/src/api-access.mjs +119 -0
  6. package/src/api.mjs +175 -0
  7. package/src/app-identity.mjs +29 -0
  8. package/src/assets/kitcode-icon.png +0 -0
  9. package/src/atomic-file.mjs +85 -0
  10. package/src/break-progress.mjs +87 -0
  11. package/src/claim-bundle.mjs +38 -0
  12. package/src/companion-controls.mjs +40 -0
  13. package/src/companion-electron.mjs +85 -0
  14. package/src/companion-preload.cjs +10 -0
  15. package/src/companion-window-options.mjs +16 -0
  16. package/src/companion-window.mjs +59 -0
  17. package/src/cors.mjs +51 -0
  18. package/src/diagnostics.mjs +872 -0
  19. package/src/equals-ledger.mjs +166 -0
  20. package/src/focus-clock.mjs +86 -0
  21. package/src/fonts/fira-code/OFL.txt +93 -0
  22. package/src/fonts/fira-code/fira-code-latin-400-normal.woff2 +0 -0
  23. package/src/fonts/fira-code/fira-code-latin-500-normal.woff2 +0 -0
  24. package/src/fonts/fira-code/fira-code-latin-700-normal.woff2 +0 -0
  25. package/src/fonts/vt323/OFL.txt +93 -0
  26. package/src/fonts/vt323/vt323-latin-400-normal.woff2 +0 -0
  27. package/src/git.mjs +488 -0
  28. package/src/hook-installers.mjs +397 -0
  29. package/src/hook-prompt.mjs +217 -0
  30. package/src/install-id.mjs +94 -0
  31. package/src/integration-installers.mjs +28 -0
  32. package/src/integration-spec.mjs +410 -0
  33. package/src/log-file.mjs +60 -0
  34. package/src/milestones-reached.mjs +133 -0
  35. package/src/next-break-reminder.mjs +78 -0
  36. package/src/onboarding-electron.mjs +252 -0
  37. package/src/onboarding-platform.mjs +50 -0
  38. package/src/onboarding-preload.cjs +19 -0
  39. package/src/onboarding-window.mjs +914 -0
  40. package/src/open-dashboard.mjs +30 -0
  41. package/src/reward.mjs +274 -0
  42. package/src/runner-installer.mjs +153 -0
  43. package/src/runtime.mjs +1340 -0
  44. package/src/scan-worker.mjs +23 -0
  45. package/src/scanner.mjs +84 -0
  46. package/src/seen-lines.mjs +148 -0
  47. package/src/skill-installer.mjs +76 -0
  48. package/src/source-snapshot.mjs +733 -0
  49. package/src/store.mjs +595 -0
  50. package/src/tracker-instance.mjs +166 -0
  51. package/src/tracker-problems.mjs +31 -0
  52. package/src/tracker-stop.mjs +73 -0
  53. package/src/uninstall.mjs +80 -0
  54. package/src/vibe.mjs +4 -0
  55. package/src/window-guards.mjs +7 -0
  56. package/src/window-page.mjs +49 -0
@@ -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.
@@ -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.