heartcode 0.1.69 → 0.1.95

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.
@@ -0,0 +1,168 @@
1
+ # Guides: how to do one kind of work
2
+
3
+ <!-- Each section is the guide for one kind of project or task. The model reads one with the guide tool
4
+ (agent/tool-guide lists them), and HeartCode adds one by itself, once per conversation, when the project's
5
+ files or the message show what kind of work it is (src/guides.js). Every guide has the same parts: done
6
+ when, start, run, check, traps. Short and general on purpose: what any model, the smallest too, can follow.
7
+ Variables (all guides get all of them; use or ignore): {{page}}: the command for HeartCode's headless
8
+ browser check. {{memory}}: set when there's a memory tool. {{noUser}}: set when nobody can answer. -->
9
+
10
+ ## web
11
+
12
+ <!-- Web sites and web apps: pages, front ends, single-page apps, full-stack apps' front end. -->
13
+ Guide: web site or web app (keep it in mind for this work)
14
+ Done when: it starts with one command, the pages the user asked for show and work in a browser (checked with screenshots), no errors in the console, and it fits a phone-width screen.
15
+ 1. Start: an existing project: follow its framework and scripts (package.json). A new one: plain HTML/CSS/JS for a simple page; for an app, the framework's official create command (read its current docs first), not files written by hand.
16
+ 2. Run: start the dev server with run_command in the background (background tool), note its URL, stop it when done.
17
+ 3. Check: `{{page}} <url or file>`: it opens the page headless and gives errors and screenshots. Look at every screenshot. Click through what the user asked for. Check a narrow (phone) width too.
18
+ 4. Traps: paths that work only from one folder; a blank page from one JS error (read the console); styles not loaded; a form that does nothing; text or buttons off screen on a phone.
19
+ 5. End your answer with the command to start it and the URL to open.
20
+
21
+ ## api
22
+
23
+ <!-- Back ends: HTTP APIs, servers, webhooks, the server part of a full-stack app. -->
24
+ Guide: API or server (keep it in mind for this work)
25
+ Done when: it starts with one command, every endpoint the user asked for answers right to a real request, bad input gets a clear error with the right status code, and no secret is in the code.
26
+ 1. Start: an existing project: its framework and its patterns (routes, handlers, models). A new one: the smallest common framework for the language, set up as its docs say.
27
+ 2. Settings (port, database URL, keys) come from environment variables with a safe default for local use; secrets never in files you commit. Add a .env.example if there are any.
28
+ 3. Run: start it in the background (background tool), wait until it listens, stop it when done.
29
+ 4. Check: call every endpoint with run_command (curl or the language's own client): one normal request, one with bad or missing input, one for something that doesn't exist. Read the status code and the body.
30
+ 5. Traps: the server crashes on bad input; CORS blocks a browser front end; the port is already in use; errors that leak stack traces or secrets.
31
+
32
+ ## mobile
33
+
34
+ <!-- Mobile apps: Flutter, React Native/Expo, native Android (Kotlin) and iOS (Swift). -->
35
+ Guide: mobile app (keep it in mind for this work)
36
+ Done when: the app builds without errors, starts on an emulator or simulator (or the closest check this machine has), the screens the user asked for show and work, checked with a screenshot.
37
+ 1. Start: an existing project: its framework (pubspec.yaml: Flutter; app.json/package.json with expo or react-native; build.gradle: Android; .xcodeproj: iOS). A new one: the framework's official create command, from its current docs.
38
+ 2. Check what's installed first (find_command: flutter, npx, adb, xcrun, java). Missing: say what is needed; install only what the plan needs.
39
+ 3. Build for one platform first (Android or iOS, whichever this machine can), then the other.
40
+ 4. Check: the framework's analyzer and tests (flutter analyze, flutter test, npm test); then run on an emulator or simulator and take a screenshot (adb exec-out screencap -p, xcrun simctl io booted screenshot) and look at it. No emulator here: build it and say plainly it wasn't run.
41
+ 5. Traps: permissions missing from AndroidManifest.xml or Info.plist; a package that doesn't support one platform; hard-coded sizes that break on small screens; network calls to localhost from an emulator (Android uses 10.0.2.2).
42
+
43
+ ## desktop
44
+
45
+ <!-- Desktop apps: Electron, Tauri, native GUI (Qt, GTK, WinUI, SwiftUI, Python GUIs). -->
46
+ Guide: desktop app (keep it in mind for this work)
47
+ Done when: it starts with one command on this OS, its window shows what the user asked for (checked with a screenshot), what they asked works, and it closes cleanly.
48
+ 1. Start: an existing project: its framework (electron in package.json, src-tauri/, a .pro or CMakeLists.txt…). A new one: the framework's official create command, from its current docs.
49
+ 2. Run it in the background (background tool), give it a few seconds, take a screenshot of its window (macOS: screencapture -x; Linux: import -window root or gnome-screenshot; Windows: PowerShell), look at it, then stop it.
50
+ 3. Check what it does with real input, not only that it opens. Read its log and terminal output for errors.
51
+ 4. Package it (installer, .app, .exe) only when the user asks, and last.
52
+ 5. Traps: works in dev, fails packaged (paths to files inside the app); a blocked main thread freezes the window; Electron security settings (contextIsolation on, no nodeIntegration in pages).
53
+
54
+ ## cli
55
+
56
+ <!-- Command-line tools and terminal programs. -->
57
+ Guide: command-line tool (keep it in mind for this work)
58
+ Done when: it runs with one command, does what the user asked with real arguments, gives a clear error and a non-zero exit code on wrong input, and --help says how to use it.
59
+ 1. Start: an existing tool: its argument parser and style. A new one: the language's standard argument parsing (or the usual small library), one entry point.
60
+ 2. Output: results to stdout, errors to stderr, plain text that can be piped; colors only on a terminal.
61
+ 3. Exit codes: 0 when it worked, non-zero when it didn't.
62
+ 4. Check: run it with run_command: --help, a normal case, an edge case (empty input, a missing file), a wrong argument. Read the output and the exit code each time.
63
+ 5. Traps: paths relative to the wrong folder; hangs waiting for input that never comes; Windows vs macOS/Linux path and quoting differences.
64
+ 6. End your answer with the exact command to run it.
65
+
66
+ ## automation
67
+
68
+ <!-- Scripts and automation: bots, scraping, file processing, scheduled jobs, workflows that run unattended. -->
69
+ Guide: automation or script (keep it in mind for this work)
70
+ Done when: it runs unattended from one command, a test run on safe or sample data did the right thing, running it twice does no harm, and failures are logged with a reason.
71
+ 1. Start: one script in the language the project uses (else the one this machine has: python3 or node). Settings (paths, URLs, times, keys) at the top or in environment variables.
72
+ 2. Safe first: a dry run (--dry-run) that only says what it would do; test on a copy or sample data, never the user's real data or accounts until they say so.
73
+ 3. Robust: timeouts and a few retries for network calls; safe to run again (skip what's done, don't duplicate); a log line for each step and each failure.
74
+ 4. Scraping: read the site's terms and robots.txt; slow down between requests; prefer an official API.
75
+ 5. Scheduling: the OS's own scheduler (cron or launchd on macOS/Linux, Task Scheduler on Windows). Show the user the exact entry; install it only when they ask.
76
+ 6. Check: run it for real on the safe data and read its output and log.
77
+ 7. Traps: works from one folder only (use paths relative to the script); a secret printed in the log; an infinite loop with no stop.
78
+
79
+ ## long-task
80
+
81
+ <!-- Big or long work: many parts, many files, migrations, rewrites, work that goes on for hours. -->
82
+ Guide: long or big task (keep it in mind for this work)
83
+ Done when: every part of the plan is done and checked, one by one, and the whole works together at the end.
84
+ 1. Plan: break it into parts with the todo tool, each small enough to finish and check on its own, in an order where each part leaves things working.
85
+ 2. One part at a time: do it, check it (run it, run the tests), mark it done, then the next. Never start the next part on top of a broken one.
86
+ 3. Keep notes so you can pick up after a restart or compaction: {{#if memory}}save progress with the memory tool (what's done, what's next, how to check){{else}}keep the todo list current: what's done, what's next, how to check{{/if}}.
87
+ 4. Long commands (builds, installs, test suites, servers): run them in the background (background tool) and look at their output; don't wait idle.
88
+ 5. Don't stop to ask "want me to continue?": keep going until all parts are done. Truly blocked on one part: mark it stuck with why, and do the others.
89
+ 6. Traps: changing everything at once and then nothing works; losing track of what's done; a part "done" that was never run.
90
+
91
+ ## game
92
+
93
+ <!-- Games: browser games (canvas, WebGL), and games in engines or other languages. -->
94
+ Guide: game (keep it in mind for this work)
95
+ Done when: it starts with one command or one file, it is playable from start to end (start, play, win or lose, play again), the controls work, and it has no errors, checked with screenshots.
96
+ 1. Start: a browser game: plain HTML/JS with a canvas unless the user named an engine. Another kind: the engine or library the user named, set up from its docs.
97
+ 2. Structure: a game loop (requestAnimationFrame), input handling, update, draw; game state in one place; a start screen and a game over/restart.
98
+ 3. Check: `{{page}} <file or url>`: errors and screenshots after it starts. Look at the screenshots: is the game drawn, is the score there? Check the rules in code: collisions, scoring, winning and losing.
99
+ 4. Traps: speed that depends on the frame rate (use the time between frames); keys that scroll the page; nothing drawn because of one error; no way to restart.
100
+ 5. End your answer with how to start it and the controls.
101
+
102
+ ## data
103
+
104
+ <!-- Data work: processing files (CSV, JSON, Excel), analysis, charts, notebooks, machine learning. -->
105
+ Guide: data work (keep it in mind for this work)
106
+ Done when: the result comes from the real data, it was checked against a few values worked out another way, and the outputs (files, charts) are saved where the user can open them.
107
+ 1. Look first: read the data's first rows, its columns and types, how many rows, missing values. Never assume a column's meaning: check.
108
+ 2. Small first: try the steps on a sample, then on all of it.
109
+ 3. Tools: what the project uses; else the usual ones (Python with pandas, or plain csv/json). Install only what's needed, into the project (a virtual environment).
110
+ 4. Check: compare a few results with a hand count or a second method; look at charts (read the image) before you say they're right.
111
+ 5. Save outputs as files (CSV, PNG, HTML) and say where they are. Never change or delete the original data.
112
+ 6. Traps: wrong encoding or separator; dates and numbers read as text; dropping rows silently; a model "trained" on its own test data.
113
+
114
+ ## library
115
+
116
+ <!-- Libraries and packages others will use: npm, PyPI, crates, SDKs. -->
117
+ Guide: library or package (keep it in mind for this work)
118
+ Done when: its public functions do what the README says, tests cover them and pass, a README example runs as written, and it builds as a package.
119
+ 1. Start: an existing one: its structure and style. A new one: the language's standard package layout (package.json, pyproject.toml, Cargo.toml) from its current docs.
120
+ 2. Keep the public API small and clear; everything else private. Don't break what users already call: add, don't change, unless the user asks.
121
+ 3. Tests for every public function: normal use, edge cases, wrong input.
122
+ 4. Check: run the tests; build or pack it (npm pack, python -m build, cargo package); run a README example against the built package.
123
+ 5. Version and changelog when the user asks for a release. Never publish yourself: say the command.
124
+ 6. Traps: files missing from the package; a dependency that should be a dev dependency; types or docs that don't match the code.
125
+
126
+ ## extension
127
+
128
+ <!-- Browser extensions (Chrome, Firefox, Edge) and editor extensions (VS Code and others). -->
129
+ Guide: browser or editor extension (keep it in mind for this work)
130
+ Done when: it loads without errors in its host (unpacked or dev mode), what the user asked works in a real page or editor, and it asks only for the permissions it needs.
131
+ 1. Start: a browser extension: manifest.json with manifest_version 3, from the browser's current docs. A VS Code extension: the official generator (yo code) or its current docs; package.json declares commands and activation.
132
+ 2. Permissions: only what the features need; say why each is there.
133
+ 3. Check: browser: validate the manifest, load it unpacked in a headless browser if possible, check the background script and pages for errors; VS Code: compile and run its tests (the test runner starts an editor). Say plainly what couldn't be checked here.
134
+ 4. Traps: Manifest V2 code in a V3 extension (background pages vs service workers); content scripts that run on the wrong pages; scripts blocked by the content security policy.
135
+
136
+ ## devops
137
+
138
+ <!-- Docker, CI (GitHub Actions…), deploying, servers and infrastructure config. -->
139
+ Guide: Docker, CI or deploying (keep it in mind for this work)
140
+ Done when: the image builds and runs locally (or the config is valid and checked), the CI file follows the official docs, and nothing was deployed or pushed without the user saying so.
141
+ 1. Docker: a small official base image; copy the dependency files first, then the code (faster builds); run as a non-root user; .dockerignore. Build it and run it locally, and check the app answers.
142
+ 2. CI: start from the official template for the language; the same commands the project uses locally (install, test, build). Check the YAML is valid.
143
+ 3. Secrets: in the platform's secrets, never in files.
144
+ 4. Deploying, pushing, changing a live server or cloud account: only when the user asks, and say exactly what will happen first.
145
+ 5. Traps: works on your machine but the image misses a file; a different OS or architecture in the image; CI using a different version than local.
146
+
147
+ ## database
148
+
149
+ <!-- Databases: schemas, migrations, queries, ORMs. -->
150
+ Guide: database work (keep it in mind for this work)
151
+ Done when: the change is a migration that can be undone, it ran on a test or copy database, the queries return the right rows, and no data was lost.
152
+ 1. Start: the project's own tool for schema changes (its ORM's migrations, a migrations folder). Never change a database by hand when the project has migrations.
153
+ 2. Every migration has a way back (down/rollback). Changes that remove or rewrite data: copy or back up first, and ask the user before running them on real data.
154
+ 3. Check on a test database or a copy: run the migration, run it back, run it again; run the queries and look at the rows.
155
+ 4. Queries: parameters, never strings glued together (SQL injection); an index for what is searched often.
156
+ 5. Traps: a migration that works on an empty database but fails on real data; a column dropped that code still uses; different behavior between SQLite in tests and the real database.
157
+
158
+ ## upgrade
159
+
160
+ <!-- Upgrades and refactors: new versions of frameworks or dependencies, moving to another library, restructuring code. -->
161
+ Guide: upgrade or refactor (keep it in mind for this work)
162
+ Done when: everything that worked before still works (tests and a real run, same as before the change), and the change the user asked for is complete.
163
+ 1. First: run the tests and the app as they are, and note the result: that's what "still works" means.
164
+ 2. Upgrades: read the official migration guide and changelog for every version in between; note the breaking changes that touch this code.
165
+ 3. One step at a time (one dependency, one module, one rename), checking after each step; never everything at once.
166
+ 4. A rename or move: find every use (lsp or search) and update them all, docs and configs too.
167
+ 5. Check at the end: the same tests and run as at the start, and compare.
168
+ 6. Traps: a lock file not updated; deprecated calls left that break in the next version; behavior changed silently (dates, defaults, sorting).
package/src/acp.js CHANGED
@@ -40,7 +40,7 @@ class AcpUI extends HeadlessUI {
40
40
  async confirm(question, kind = 'edit') {
41
41
  if (kind === 'read' && this.permission === 'plan') return true
42
42
  const mode = this.permission === 'plan' ? (this.beforePlan ?? 'ask') : this.permission // plan mode asks as the mode before it did (as the full screen's)
43
- if (mode === 'all' || (mode === 'commands' && kind === 'edit')) return true
43
+ if (kind !== 'setup' && (mode === 'all' || (mode === 'commands' && kind === 'edit'))) return true // setup: always asked
44
44
  const toolCallId = runningCall.getStore() ?? this.calls[0] ?? `ask_${Date.now()}` // the call asking
45
45
  const r = await this.conn
46
46
  .request('session/request_permission', {