@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.
Files changed (52) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +328 -0
  3. package/bin/kitcode.mjs +1097 -0
  4. package/package.json +41 -0
  5. package/src/api-access.mjs +119 -0
  6. package/src/api.mjs +165 -0
  7. package/src/atomic-file.mjs +85 -0
  8. package/src/break-progress.mjs +87 -0
  9. package/src/claim-bundle.mjs +37 -0
  10. package/src/companion-controls.mjs +40 -0
  11. package/src/companion-electron.mjs +87 -0
  12. package/src/companion-preload.cjs +10 -0
  13. package/src/companion-window.mjs +57 -0
  14. package/src/cors.mjs +51 -0
  15. package/src/equals-ledger.mjs +166 -0
  16. package/src/focus-clock.mjs +86 -0
  17. package/src/fonts/fira-code/OFL.txt +93 -0
  18. package/src/fonts/fira-code/fira-code-latin-400-normal.woff2 +0 -0
  19. package/src/fonts/fira-code/fira-code-latin-500-normal.woff2 +0 -0
  20. package/src/fonts/fira-code/fira-code-latin-700-normal.woff2 +0 -0
  21. package/src/fonts/vt323/OFL.txt +93 -0
  22. package/src/fonts/vt323/vt323-latin-400-normal.woff2 +0 -0
  23. package/src/git.mjs +448 -0
  24. package/src/hook-installers.mjs +397 -0
  25. package/src/hook-prompt.mjs +201 -0
  26. package/src/install-id.mjs +94 -0
  27. package/src/integration-installers.mjs +28 -0
  28. package/src/integration-spec.mjs +398 -0
  29. package/src/log-file.mjs +60 -0
  30. package/src/milestones-reached.mjs +130 -0
  31. package/src/next-break-reminder.mjs +78 -0
  32. package/src/onboarding-electron.mjs +240 -0
  33. package/src/onboarding-platform.mjs +50 -0
  34. package/src/onboarding-preload.cjs +19 -0
  35. package/src/onboarding-window.mjs +874 -0
  36. package/src/open-dashboard.mjs +30 -0
  37. package/src/reward.mjs +311 -0
  38. package/src/runner-installer.mjs +153 -0
  39. package/src/runtime.mjs +1323 -0
  40. package/src/scan-worker.mjs +23 -0
  41. package/src/scanner.mjs +84 -0
  42. package/src/seen-lines.mjs +148 -0
  43. package/src/skill-installer.mjs +76 -0
  44. package/src/source-snapshot.mjs +725 -0
  45. package/src/store.mjs +595 -0
  46. package/src/tracker-instance.mjs +166 -0
  47. package/src/tracker-problems.mjs +30 -0
  48. package/src/tracker-stop.mjs +73 -0
  49. package/src/uninstall.mjs +80 -0
  50. package/src/vibe.mjs +4 -0
  51. package/src/window-guards.mjs +7 -0
  52. package/src/window-page.mjs +49 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 KitCode Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,328 @@
1
+ # @kitkat-vn/kitcode
2
+
3
+ Local break companion for coding campaigns. This package is the **source of truth** for tracking, reward eligibility, redeem state, hooks, and the local Mini companion.
4
+
5
+ Published package: `@kitkat-vn/kitcode`
6
+
7
+ ---
8
+
9
+ ## For people
10
+
11
+ ### Before you set up
12
+
13
+ Setup only works when an assistant can run commands on your machine.
14
+
15
+ | Tool | What works | What does not work |
16
+ | --- | --- | --- |
17
+ | **Codex** | **Codex Task** or **project chat** (Desktop, Go+) | Regular chat |
18
+ | **Claude** | **Claude Code** on Claude Desktop (Pro+) | Cloud-only browser chat |
19
+
20
+ **Minimum requirements:**
21
+
22
+ | | **Codex** | **Claude Code** |
23
+ | --- | --- | --- |
24
+ | App | ChatGPT desktop app | Claude Desktop (Code tab) |
25
+ | Permission control | Approve for me or Full access | Auto or Bypass permissions |
26
+ | Account plan | Go (or higher) | Pro (or higher) |
27
+
28
+ Use the permission setting that lets setup commands run without stopping between steps.
29
+
30
+ ### Quick Start
31
+
32
+ Install KitCode first, from the dist-tag meant for you (see Releases, below): no `latest` release exists yet, and `staging` is for the invited testers of the staging round.
33
+
34
+ <table>
35
+ <tr>
36
+ <th>Command</th>
37
+ <th>What it opens or enables</th>
38
+ </tr>
39
+ <tr>
40
+ <td>
41
+ <pre><code>kitcode codex on
42
+ kitcode claude on</code></pre>
43
+ </td>
44
+ <td>
45
+ Codex / Claude integration plus Welcome when onboarding is incomplete.
46
+ </td>
47
+ </tr>
48
+ <tr>
49
+ <td>
50
+ <pre><code>Save Welcome with at least one project</code></pre>
51
+ </td>
52
+ <td>
53
+ Opens the Mini companion and can start background tracking when you chose YES in Welcome.
54
+ </td>
55
+ </tr>
56
+ <tr>
57
+ <td>
58
+ <pre><code>kitcode track
59
+ kitcode dashboard</code></pre>
60
+ </td>
61
+ <td>
62
+ Starts tracking or opens the hosted dashboard.
63
+ </td>
64
+ </tr>
65
+ </table>
66
+
67
+ Local API: `http://127.0.0.1:4747`
68
+
69
+ Finish **Welcome** with at least one project folder before expecting tracking to work.
70
+
71
+ ---
72
+
73
+ ## For agents / developers
74
+
75
+ ### Hard rules
76
+
77
+ 1. Use Codex Task or a project chat (Desktop, Go+), or Claude Code on Claude Desktop (Pro+).
78
+ 2. Set permission control before setup: Codex **Approve for me** or **Full access**; Claude Code **Auto** or **Bypass permissions**.
79
+ 3. Execute commands yourself. Do not stop after printing shell instructions.
80
+ 4. Never calculate or mutate rewards. Use `kitcode status`, `kitcode summary`, and `kitcode awards`.
81
+
82
+ ### Daily commands
83
+
84
+ | Command | What it does |
85
+ | --- | --- |
86
+ | `kitcode add [path]` | Add a project. Defaults to current folder. Existing code becomes baseline. |
87
+ | `kitcode remove [path]` | Remove a project, its snapshot and its counted `=`. Focus time already earned stays. |
88
+ | `kitcode track` | Start the background tracker. Can run before projects are added. |
89
+ | `kitcode untrack` | Stop the tracker. Added projects remain registered. |
90
+ | `kitcode list` | Show how many projects are added. |
91
+ | `kitcode status` | Tracker state, project count, compact reward progress. |
92
+ | `kitcode summary` | Total counted `=`, active time, next milestone progress. |
93
+ | `kitcode awards` | Reward and milestone readiness. Aliases: `award`, `rewards`. |
94
+ | `kitcode setup` | Welcome: projects and auto-track preference. |
95
+ | `kitcode uninstall` | Remove hooks, skills, tracker, and all `~/.kitcode` data. |
96
+ | `kitcode dashboard` | Open the hosted dashboard for the running tracker. |
97
+ | `kitcode codex on/off/status` | Install, remove, or inspect the Codex hook and skill. |
98
+ | `kitcode claude on/off/status` | Install, remove, or inspect the Claude hook and skill. |
99
+
100
+ Simplest flow:
101
+
102
+ ```bash
103
+ kitcode track
104
+ cd your-project
105
+ kitcode add .
106
+ kitcode dashboard
107
+ ```
108
+
109
+ Or add first, track later:
110
+
111
+ ```bash
112
+ cd your-project
113
+ kitcode add .
114
+ kitcode track
115
+ ```
116
+
117
+ `dashboard` and the Mini companion require a running tracker.
118
+
119
+ During first-time `codex on` / `claude on`, do **not** run `add` or `track` for the user. Welcome owns first project selection.
120
+
121
+ ## Surfaces
122
+
123
+ ### Mini companion
124
+
125
+ A successful Welcome save opens the Mini companion, which shows the page the tracker serves at `/companion`, or a copy of that page when no tracker answers as it opens. `kitcode setup` opens Welcome.
126
+
127
+ The Mini is a compact metrics bar beside your work. There is **no** standalone `kitcode mini` command.
128
+
129
+ ### Setup / Welcome
130
+
131
+ `kitcode setup` and first-time `codex on` / `claude on` can open Welcome so the user can:
132
+
133
+ - pick one or more project folders
134
+ - choose whether background tracking should start after save
135
+
136
+ Welcome no longer asks for a companion preference. Saving Welcome opens the Mini companion.
137
+
138
+ Setup needs the optional Electron dependency.
139
+
140
+ ### Dashboard
141
+
142
+ `kitcode dashboard` opens the hosted dashboard, which reads the local tracker API.
143
+
144
+ Use `--no-open` or `KITCODE_NO_OPEN=1` to skip auto-opening the browser.
145
+
146
+ ## What KitCode counts
147
+
148
+ ### Focus time
149
+
150
+ Focus time is one clock for all your projects: a second is active when any added project had real activity in the 5 minutes before it, and it counts once, however many projects were active. Real activity is a change to the lines KitCode counts in a file it reads (below). Touching a file, a save that changes no line, re-indenting, and a git operation on its own (a pull, a merge, a checkout of another branch, a stash) are not. After **5 quiet minutes**, new time is recorded as idle. No time is earned while the tracker is stopped.
151
+
152
+ ### Equal count
153
+
154
+ KitCode scans local source snapshots and counts `=` on **real code lines** added after the project baseline.
155
+
156
+ Rules:
157
+
158
+ - `kitcode add` creates the baseline.
159
+ - Existing lines at add time do not earn reward by themselves.
160
+ - Only lines with enough alphanumeric content count as real code lines.
161
+ - A line is compared without its whitespace, with `"` and `` ` `` read as `'`, and without one trailing `;` or `,`: re-indenting, re-spacing or re-quoting a line does not make it new.
162
+ - A line earns at most 3 `=`, and once per user, ever: a line KitCode has seen before, in any file of any of your projects, earns nothing, whether it was moved, copied, pasted, or deleted and added back.
163
+ - Ignored paths include `.git`, `node_modules`, `dist`, `build`, `.next`, `out`, and `coverage`.
164
+ - Lockfiles, minified files (`*.min.js`, `*.min.css`) and source maps (`*.map`) are not counted. Secret files (a name that starts with `.env`, ends in `.pem` or `.key`, or is an SSH key's) are never read.
165
+ - Files larger than 1 MiB and binary files are skipped.
166
+ - In both modes, the `=` a scan adds are recorded as one source-change batch.
167
+
168
+ Example:
169
+
170
+ ```js
171
+ const total = price + tax
172
+ ```
173
+
174
+ If that line is new after `kitcode add .`, KitCode has not seen it before, and it passes the real-code-line check, its `=` counts toward the ledger.
175
+
176
+ ## Git Mode and Vibe Mode
177
+
178
+ | Mode | When | What KitCode tracks |
179
+ | --- | --- | --- |
180
+ | Git Mode | Folder is inside a Git repository | Commit count, focus time, source-change batches |
181
+ | Vibe Mode | Folder is not inside a Git repository | Focus time and source-change batches |
182
+
183
+ Both modes count `=` by the same line rules. In Git Mode, KitCode reads only the files git lists (tracked, or untracked and not ignored), and code that arrives through git as it moves HEAD earns nothing and is not activity: a pull, a merge, a checkout of another branch, a rebase, a cherry-pick. Code git writes without moving HEAD, such as `git stash pop` or `git restore`, counts as yours. Your own new lines earn whether you commit them or not. The commit count is only reported: no reward depends on it.
184
+
185
+ ## Reward model
186
+
187
+ The time target is fixed at `3600` active seconds: no flag or variable changes it.
188
+
189
+ Each milestone needs both enough active time and enough counted `=`:
190
+
191
+ - time target for a percent = `ceil(3600 * percent / 100)` seconds: 360 for 10%, 720 for 20%, 1080 for 30%, 1800 for 50%, and 3600 for 100%
192
+ - equals target comes from the tier table below
193
+
194
+ ### Local reward tiers
195
+
196
+ Their break codes are shown in the dashboard, which records a code as shown through `POST /api/reward/redeem`, on this machine only.
197
+
198
+ | Tier | Code | Required counted `=` |
199
+ | ---: | --- | ---: |
200
+ | `10%` | `if(tired){return 10;}` | 3 |
201
+ | `20%` | `takeBreak(20);` | 6 |
202
+ | `30%` | `while(working)break(30);` | 9 |
203
+
204
+ ### Display milestones
205
+
206
+ Shown in summary/awards/dashboard, but not redeemable unless backed by campaign flow.
207
+
208
+ | Milestone | Code | Required counted `=` |
209
+ | ---: | --- | ---: |
210
+ | `50%` | `mediumStake.unlock(50);` | 12 |
211
+ | `100%` | `finalBreak.claim(100);` | 15 |
212
+
213
+ ## Codex and Claude integrations
214
+
215
+ The hosted gateway copies **agent-specific** setup prompts: Codex prompts mention only Codex; Claude prompts mention only Claude Code.
216
+
217
+ `kitcode codex on` and `kitcode claude on` install:
218
+
219
+ - a KitCode skill file
220
+ - a `UserPromptSubmit` hook whose command runs the runner below: `~/.kitcode/bin/kitcode hook prompt --source <agent>` (on Windows, `node` with the runner's `kitcode.mjs`)
221
+ - a durable local runner at `~/.kitcode/bin/kitcode`
222
+
223
+ The hook:
224
+
225
+ - runs after each submitted prompt
226
+ - fails open and never blocks prompts
227
+ - can add compact context: counted `=`, active time, next milestone progress, reward readiness
228
+ - can announce newly ready tiers once per agent source
229
+
230
+ Disable hooks with:
231
+
232
+ ```bash
233
+ KITCODE_HOOKS_OFF=1
234
+ ```
235
+
236
+ ## Local state
237
+
238
+ ```txt
239
+ ~/.kitcode/state.json Projects and their snapshots, onboarding prefs, focus time, equals ledger
240
+ ~/.kitcode/seen-lines Every line KitCode has seen, as hashes: a line earns once
241
+ ~/.kitcode/install-id A random id the claim bundle carries, made by the tracker
242
+ ~/.kitcode/tracker.json Background tracker PID/host/port metadata
243
+ ~/.kitcode/tracker.log The background tracker's log
244
+ ~/.kitcode/hook.log Hook errors, when logging succeeds
245
+ ~/.kitcode/bin/kitcode Durable runner used by agent hooks
246
+ ```
247
+
248
+ ## Privacy
249
+
250
+ By default KitCode does not send:
251
+
252
+ - source code
253
+ - raw diffs
254
+ - arbitrary file contents
255
+ - full local paths
256
+ - project names
257
+ - commit metadata
258
+
259
+ The local API returns totals only: active/idle time, project count, commit count, change batches, counted `=`, and reward progress, with the tracker's health. The claim bundle, which it gives an allowed origin alone, adds when each milestone was reached, the CLI's and the counting rules' versions, and the install id, which names no person, machine or project.
260
+
261
+ ## API
262
+
263
+ ```txt
264
+ GET /api/health
265
+ GET /api/summary
266
+ GET /api/projects
267
+ GET /api/events
268
+ GET /api/claim/bundle
269
+ GET /companion
270
+ POST /api/reward/redeem
271
+ ```
272
+
273
+ The API answers only requests addressed to `127.0.0.1` or `localhost` on its port, and web pages only from an allowed origin (below) or its own. `GET /api/claim/bundle` and `POST /api/reward/redeem` need an allowed origin, and the POST a JSON body.
274
+
275
+ `/api/events` is SSE and emits `summary` every second.
276
+
277
+ `POST /api/reward/redeem` accepts optional `{ "tier": 10 }`. If `tier` is omitted, all ready local tiers are redeemed.
278
+
279
+ Legacy endpoints return `410 Gone`:
280
+
281
+ ```txt
282
+ GET /api/projects/:id/commits
283
+ POST /api/projects/:id/start
284
+ POST /api/projects/:id/stop
285
+ POST /api/projects/selection
286
+ ```
287
+
288
+ ## Options and environment
289
+
290
+ ```bash
291
+ kitcode track --host 127.0.0.1
292
+ kitcode track --port 4757
293
+ kitcode dashboard --no-open
294
+ ```
295
+
296
+ | Variable | Effect |
297
+ | --- | --- |
298
+ | `KITCODE_ALLOWED_ORIGINS` | Extra CORS origins for the local API |
299
+ | `KITCODE_NO_OPEN` | Skip auto-opening the hosted dashboard |
300
+ | `KITCODE_HOOKS_OFF` | Disable prompt hook side effects |
301
+ | `KITCODE_DAEMON` | Internal flag used by the background tracker |
302
+
303
+ With nothing configured, the local API allows the origin of the dashboard `kitcode dashboard` opens, and local development servers on ports `3000`, `5173`, and `8686`, on `localhost` and `127.0.0.1`.
304
+
305
+ ## Requirements
306
+
307
+ - Node.js 22.12 or later
308
+ - Git optional (enables Git Mode)
309
+ - Electron optional (required for native Mini and Welcome)
310
+
311
+ ## Releases
312
+
313
+ Nobody runs `npm publish` for this package. A release comes from a pushed tag, `cli-v<version>`: the project's CI runs
314
+ its checks on the tagged commit, packs the tarball from that commit, and stages it on npm with `npm stage publish`. A
315
+ staged version becomes public only when a maintainer approves it with two-factor authentication. The package's first
316
+ version is the one exception to CI's staging: a maintainer stages CI's tarball by hand, once, since npm lets CI stage
317
+ only for a package that exists.
318
+
319
+ Two dist-tags:
320
+
321
+ | Dist-tag | Versions | Install |
322
+ | --- | --- | --- |
323
+ | `latest` | `<x>.<y>.<z>`, the version in `package.json` | `npm install -g @kitkat-vn/kitcode` |
324
+ | `staging` | `<x>.<y>.<z>-staging.<N>`, the tester build of a tagged commit, for the invited testers of the staging round. Its dashboard is KitCode's protected staging site, which only they can open | `npm install -g @kitkat-vn/kitcode@staging` |
325
+
326
+ No `latest` release exists yet.
327
+
328
+ What each dist-tag points at now: `npm view @kitkat-vn/kitcode dist-tags`.