heartcode 0.1.37 → 0.1.41
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/.claude/scheduled_tasks.lock +1 -0
- package/CHANGELOG.md +99 -0
- package/README.md +27 -12
- package/SKILL.md +22 -7
- package/bin/heart.js +8 -21
- package/bin/heartcode.js +90 -62
- package/package.json +1 -1
- package/prompts/README.md +0 -1
- package/prompts/agent.md +114 -120
- package/src/agent.js +71 -261
- package/src/background.js +39 -12
- package/src/capabilities.js +2 -2
- package/src/client.js +41 -6
- package/src/config.js +1 -1
- package/src/fit.js +65 -0
- package/src/guided.js +12 -21
- package/src/importer.js +50 -12
- package/src/log.js +69 -18
- package/src/parquet.js +209 -0
- package/src/probe.js +20 -310
- package/src/prompts.js +1 -1
- package/src/rankings.js +122 -0
- package/src/settings.html +230 -115
- package/src/settings.js +59 -22
- package/src/skills.js +7 -3
- package/src/tools.js +189 -50
- package/src/ui.js +55 -10
- package/src/update.js +59 -0
- package/prompts/probe.md +0 -67
package/src/settings.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// The settings page: a small web server on this machine
|
|
1
|
+
// The settings page: a small web server (on this machine, and on its network address for another device) where everything but
|
|
2
2
|
// the chat can be changed: providers and their keys, the model, settings, MCP servers, hooks,
|
|
3
3
|
// keys, colors, skills. Open with `heartcode settings` or /settings. A secret token in
|
|
4
4
|
// the link guards it (another site, or another user on this machine, can't use it); API keys
|
|
@@ -8,7 +8,8 @@ import fs from 'node:fs'
|
|
|
8
8
|
import path from 'node:path'
|
|
9
9
|
import crypto from 'node:crypto'
|
|
10
10
|
import os from 'node:os'
|
|
11
|
-
import { HOME, saveConfig, readJson, writeJson, byName, takeIn, whatOf } from './config.js'
|
|
11
|
+
import { HOME, saveConfig, readJson, writeJson, byName, takeIn, whatOf, VERSION } from './config.js'
|
|
12
|
+
import { newer } from './update.js'
|
|
12
13
|
import { DEFAULT_SERVERS, mcpAuth } from './mcp.js'
|
|
13
14
|
import { sections, BUILTIN_PROMPTS } from './prompts.js'
|
|
14
15
|
import { Client } from './client.js'
|
|
@@ -16,18 +17,21 @@ import { clip } from './tools.js'
|
|
|
16
17
|
import { loadProfile, strategy, profilePath, profileFrom } from './probe.js'
|
|
17
18
|
import { loadPrices, priceOf, limitsOf } from './usage.js'
|
|
18
19
|
import { THEMES, PERMISSIONS } from './ui.js'
|
|
19
|
-
import { loadSkills, frontMatter } from './skills.js'
|
|
20
|
+
import { loadSkills, frontMatter, BUNDLED } from './skills.js'
|
|
20
21
|
import { installSkill, findImports } from './importer.js'
|
|
21
22
|
import { capabilities } from './capabilities.js'
|
|
22
23
|
import { connect, sendTelegram, tokenHint, tgReady, EVENTS } from './telegram.js'
|
|
23
24
|
import { searchSettings, testSearxng, ENGINE_NAMES } from './web.js'
|
|
24
|
-
import {
|
|
25
|
+
import { loadRankings, rankings, rankIn } from './rankings.js'
|
|
26
|
+
// a model's places in the rankings shown on Your models: { coding, web, vision } as { rank, of, as }
|
|
27
|
+
const RANKED_ON = { coding: 'text:coding', web: 'webdev:webdev', vision: 'vision:overall' }
|
|
28
|
+
const ranksOf = (model, data) => (data ? Object.fromEntries(Object.entries(RANKED_ON).map(([k, list]) => [k, rankIn(model, list, data)])) : null)
|
|
29
|
+
import { log, LOGS, REQUESTS, useRequestLog, listRequests, readRequest, pruneLogs, logDays, logSize, clearLogs, LOG_KINDS, kindsOn, listLogRuns, readLog } from './log.js'
|
|
25
30
|
|
|
26
31
|
const PAGE = new URL('./settings.html', import.meta.url)
|
|
27
32
|
const EFFORTS = ['default', 'low', 'medium', 'high']
|
|
28
|
-
const TOGGLES = { autoCompact: 'compact the conversation when it fills 85% of the model\'s context window', director: 'let the model add skills, MCP servers and change settings when asked', format: "run the project's formatter on every file HeartCode writes", lsp: "show the model a language server's errors after each edit" }
|
|
33
|
+
const TOGGLES = { autoCompact: 'compact the conversation when it fills 85% of the model\'s context window', director: 'let the model add skills, MCP servers and change settings when asked', format: "run the project's formatter on every file HeartCode writes", lsp: "show the model a language server's errors after each edit", updateCheck: 'check once a day whether a newer HeartCode is out (shown in the status bar; /update installs it)' }
|
|
29
34
|
// The Logging page's: both off unless switched on; how much of each request ("full" or "summary")
|
|
30
|
-
const LOG_SWITCHES = ['log', 'logRequests']
|
|
31
35
|
// The status-bar items the visual editor offers (id must match App.status in bin/heartcode.js).
|
|
32
36
|
// `sample` is shown in the page's live preview.
|
|
33
37
|
const STATUS_ITEMS = [
|
|
@@ -42,6 +46,7 @@ const STATUS_ITEMS = [
|
|
|
42
46
|
{ id: 'autocompact', label: 'Auto-compact off', sample: 'auto-compact off' },
|
|
43
47
|
{ id: 'worktree', label: 'Git worktree', sample: '⎇ feature' },
|
|
44
48
|
{ id: 'background', label: 'Background commands', sample: '⚙ 2 running' },
|
|
49
|
+
{ id: 'update', label: 'Update available', sample: '⬆ 0.1.38 /update' },
|
|
45
50
|
{ id: 'permissions', label: 'Permissions', sample: '⏵⏵ all allowed' },
|
|
46
51
|
]
|
|
47
52
|
const STATUS_IDS = new Set(STATUS_ITEMS.map((i) => i.id))
|
|
@@ -56,7 +61,7 @@ const FILES = [
|
|
|
56
61
|
['HEARTCODE.md', 'Your instructions for every project (like AGENTS.md, for all of them)', false, '- Answer briefly.\n- Use pnpm, not npm.'],
|
|
57
62
|
]
|
|
58
63
|
// The prompts the page edits: every section of these files (prompts/*.md); the system prompts first.
|
|
59
|
-
const PROMPT_FILES = ['agent', 'guided', 'compact'
|
|
64
|
+
const PROMPT_FILES = ['agent', 'guided', 'compact']
|
|
60
65
|
const FIRST = { 'agent/system': 'System prompt (models with tool calls)', 'guided/system': 'System prompt (guided mode: models without tool calls)' }
|
|
61
66
|
const ownPrompts = (file) => path.join(HOME, 'prompts', `${file}.md`)
|
|
62
67
|
const tilde = (p) => (p.startsWith(os.homedir() + path.sep) ? '~' + p.slice(os.homedir().length) : p)
|
|
@@ -357,15 +362,18 @@ export function startSettings({ cfg, apply = () => {}, port = 0, root = process.
|
|
|
357
362
|
}
|
|
358
363
|
}
|
|
359
364
|
|
|
360
|
-
const state = () => ({
|
|
365
|
+
const state = (ranked = loadRankings()) => ({
|
|
361
366
|
providers: Object.entries(byName(cfg.providers))
|
|
362
367
|
.filter(([n]) => n !== cfg.adhoc)
|
|
363
368
|
.map(([name, p]) => ({ name, baseUrl: p.baseUrl, key: mask(p.apiKey), list: p.list !== false, off: p.off === true, added: p.models ?? [] })),
|
|
364
369
|
provider: cfg.provider ?? null,
|
|
365
370
|
model: cfg.model ?? null,
|
|
366
|
-
|
|
371
|
+
version: VERSION,
|
|
372
|
+
update: (({ latest } = {}) => (cfg.updateCheck !== false && latest && newer(latest, VERSION) ? latest : null))(readJson(path.join(HOME, 'update-check.json'), {})), // the day's answer from npm: no request here
|
|
373
|
+
order: [...(cfg.providers[cfg.provider] && cfg.model ? [{ provider: cfg.provider, model: cfg.model }] : []), ...rotationOf(cfg).then].map((t) => ({ ...t, tested: testedOf(t), known: knownOf(t), price: priceFor(t), ranks: ranksOf(t.model, ranked) })),
|
|
374
|
+
rankings: ranked && { fetched: ranked.fetched, source: ranked.source },
|
|
367
375
|
rotation: (({ then, ...opts }) => opts)(rotationOf(cfg)),
|
|
368
|
-
settings: { permissions: cfg.permissions ?? 'all', effort: cfg.effort ?? 'default', theme: cfg.theme ?? 'dark', context: cfg.context ?? null, ...Object.fromEntries(Object.keys(TOGGLES).map((k) => [k, cfg[k] !== false])),
|
|
376
|
+
settings: { permissions: cfg.permissions ?? 'all', effort: cfg.effort ?? 'default', theme: cfg.theme ?? 'dark', context: cfg.context ?? null, ...Object.fromEntries(Object.keys(TOGGLES).map((k) => [k, cfg[k] !== false])), logs: kindsOn(cfg), logDetail: cfg.logDetail === 'summary' ? 'summary' : 'full', logDays: logDays(cfg), testTimeout: Number(cfg.testTimeout) > 0 ? Number(cfg.testTimeout) : 10, modelChoice: cfg.modelChoice === 'fit' ? 'fit' : 'order', replyStart: Number(cfg.replyStart) > 0 ? Number(cfg.replyStart) : 60 },
|
|
369
377
|
logs: { runs: tilde(path.join(LOGS, 'runs')), requests: tilde(REQUESTS) },
|
|
370
378
|
voice: cfg.voice ? JSON.stringify(cfg.voice, null, 2) : '',
|
|
371
379
|
statusBar: cfg.statusBar === undefined ? null : cfg.statusBar, // false (off), a list of lines, or null (default)
|
|
@@ -373,9 +381,9 @@ export function startSettings({ cfg, apply = () => {}, port = 0, root = process.
|
|
|
373
381
|
telegram: (({ token, bot, chatName, chatId, on, events } = {}) => ({ hint: tokenHint(token), bot: bot ?? null, chatName: chatName ?? null, connected: Boolean(token && chatId), on: on !== false, events: Object.fromEntries(Object.keys(EVENTS).map((k) => [k, events?.[k] !== false])), names: EVENTS }))(cfg.telegram),
|
|
374
382
|
search: { ...(({ searxng, order, off }) => ({ searxng, order, off }))(searchSettings()), names: ENGINE_NAMES }, // web search: your SearXNG, the engines' order and switches
|
|
375
383
|
capabilities: capabilities(cfg), // features that need outside tools, and whether they're here
|
|
376
|
-
choices: { permissions: PERMISSIONS, effort: EFFORTS, theme: Object.keys(THEMES), toggles: TOGGLES, statusItems: STATUS_ITEMS },
|
|
384
|
+
choices: { permissions: PERMISSIONS, effort: EFFORTS, theme: Object.keys(THEMES), toggles: TOGGLES, statusItems: STATUS_ITEMS, logKinds: Object.fromEntries(Object.entries(LOG_KINDS).map(([k, { label, about }]) => [k, { label, about }])) },
|
|
377
385
|
files: FILES.map(([name, about, json, example]) => ({ name, about, json, example, text: fs.existsSync(path.join(HOME, name)) ? fs.readFileSync(path.join(HOME, name), 'utf8') : '' })),
|
|
378
|
-
skills: [...loadSkills(null).values()].map((s) => ({ name: s.name, description: s.description, use: s.use, mine: s.file.startsWith(skillsDir() + path.sep), text: fs.readFileSync(s.file, 'utf8') })),
|
|
386
|
+
skills: [...loadSkills(null).values()].map((s) => ({ name: s.name, description: s.description, use: s.use, mine: s.file.startsWith(skillsDir() + path.sep), builtIn: s.file.startsWith(BUNDLED), text: fs.readFileSync(s.file, 'utf8') })),
|
|
379
387
|
mcp: mcpServers(),
|
|
380
388
|
prompts: prompts(),
|
|
381
389
|
home: tilde(HOME),
|
|
@@ -384,6 +392,11 @@ export function startSettings({ cfg, apply = () => {}, port = 0, root = process.
|
|
|
384
392
|
|
|
385
393
|
const routes = {
|
|
386
394
|
'GET /api/state': () => state(),
|
|
395
|
+
// the public rankings, fetched now (with models.dev: Update model info on Your models)
|
|
396
|
+
'POST /api/rankings': async () => {
|
|
397
|
+
if (!(await rankings({ now: true }))) throw new Error("couldn't get the rankings (huggingface.co)")
|
|
398
|
+
return state()
|
|
399
|
+
},
|
|
387
400
|
'GET /api/log-size': () => logSize(),
|
|
388
401
|
'POST /api/prefs': ({ key, value }) => {
|
|
389
402
|
if (!PREF_KEYS.includes(key)) throw new Error(`no such choice: ${key}`)
|
|
@@ -500,7 +513,7 @@ export function startSettings({ cfg, apply = () => {}, port = 0, root = process.
|
|
|
500
513
|
const profile = loadProfile(new Client({ baseUrl: p.baseUrl, apiKey: p.apiKey, model: id }))
|
|
501
514
|
return [id, {
|
|
502
515
|
...saved.details[id],
|
|
503
|
-
tested: profile ? { mode:
|
|
516
|
+
tested: profile ? ((st) => ({ mode: st.actions, context: profile.context, thinking: st.thinking, vision: st.vision }))(strategy(profile)) : undefined,
|
|
504
517
|
known: limitsOf(name, p.baseUrl, id) ?? undefined,
|
|
505
518
|
}]
|
|
506
519
|
}))
|
|
@@ -644,17 +657,36 @@ export function startSettings({ cfg, apply = () => {}, port = 0, root = process.
|
|
|
644
657
|
if (name === 'effort' && !EFFORTS.includes(value)) throw new Error(`effort: ${EFFORTS.join(', ')}`)
|
|
645
658
|
if (name === 'theme' && !THEMES[value]) throw new Error(`theme: ${Object.keys(THEMES).join(', ')}`)
|
|
646
659
|
if (name === 'context' && value !== null && !(Number(value) > 0)) throw new Error('context: a number of tokens, or empty for what the model says')
|
|
647
|
-
if (
|
|
660
|
+
if (name in TOGGLES && typeof value !== 'boolean') throw new Error(`${name}: on or off`)
|
|
648
661
|
if (name === 'logDays' && !(Number.isInteger(value) && value >= 1 && value <= 3650)) throw new Error('logDays: a whole number of days, 1 to 3650')
|
|
649
662
|
if (name === 'logDetail' && !DETAILS.includes(value)) throw new Error(`logDetail: ${DETAILS.join(' or ')}`)
|
|
650
663
|
if (name === 'testTimeout' && !(Number.isInteger(value) && value >= 1 && value <= 600)) throw new Error('test timeout: a whole number of seconds, 1 to 600')
|
|
651
|
-
if (
|
|
664
|
+
if (name === 'replyStart' && !(Number.isInteger(value) && value >= 5 && value <= 600)) throw new Error('a reply must start within: a whole number of seconds, 5 to 600')
|
|
665
|
+
if (!['permissions', 'effort', 'theme', 'context', 'logDetail', 'logDays', 'testTimeout', 'modelChoice', 'replyStart', ...Object.keys(TOGGLES)].includes(name)) throw new Error(`no setting "${name}"`)
|
|
666
|
+
if (name === 'modelChoice' && !['order', 'fit'].includes(value)) throw new Error('modelChoice: order or fit')
|
|
652
667
|
cfg[name] = name === 'effort' && value === 'default' ? undefined : name === 'context' ? (value === null ? undefined : Number(value)) : value
|
|
653
668
|
save(`setting:${name}`)
|
|
654
|
-
if (name === '
|
|
669
|
+
if (name === 'logDetail') useRequestLog(cfg) // from the next request (a running HeartCode takes it in too: applySettings)
|
|
655
670
|
if (name === 'logDays') pruneLogs(value) // older ones go now
|
|
656
671
|
return state()
|
|
657
672
|
},
|
|
673
|
+
// Each kind of log on or off ({ kind, on }), or all of them off ({ all: false }): written as
|
|
674
|
+
// config.json's "logs" (the older "log" and "logRequests" go), taken in at once by a running HeartCode
|
|
675
|
+
'POST /api/log-kind': ({ kind, on, all }) => {
|
|
676
|
+
const now = kindsOn(cfg)
|
|
677
|
+
if (all === false) for (const k of Object.keys(now)) now[k] = false
|
|
678
|
+
else if (kind in now && typeof on === 'boolean') now[kind] = on
|
|
679
|
+
else throw new Error(`no kind of log "${kind}"`)
|
|
680
|
+
cfg.logs = now
|
|
681
|
+
delete cfg.log
|
|
682
|
+
delete cfg.logRequests
|
|
683
|
+
save('setting:logs')
|
|
684
|
+
useRequestLog(cfg)
|
|
685
|
+
return state()
|
|
686
|
+
},
|
|
687
|
+
// The text logs: the runs that have some, and one kind of one run (its last megabyte)
|
|
688
|
+
'GET /api/log-runs': () => ({ runs: listLogRuns() }),
|
|
689
|
+
'POST /api/log-read': ({ run, kind }) => readLog(run, kind),
|
|
658
690
|
// The requests log: the newest first; one in full
|
|
659
691
|
'GET /api/requests': () => ({ items: listRequests() }),
|
|
660
692
|
'POST /api/request': ({ run, file }) => readRequest(run, file),
|
|
@@ -905,9 +937,9 @@ export function startSettings({ cfg, apply = () => {}, port = 0, root = process.
|
|
|
905
937
|
res.end(type === 'application/json' ? JSON.stringify(body) : body)
|
|
906
938
|
}
|
|
907
939
|
try {
|
|
908
|
-
// only
|
|
940
|
+
// only by this machine's own names and addresses (a site renamed to this address can't reach it), and only with the token
|
|
909
941
|
const { port: p } = server.address()
|
|
910
|
-
if (![
|
|
942
|
+
if (!['127.0.0.1', 'localhost', ...addresses()].map((h) => `${h}:${p}`).includes(req.headers.host)) return send(403, { error: 'wrong host' })
|
|
911
943
|
const url = new URL(req.url, `http://${req.headers.host}`)
|
|
912
944
|
if (url.pathname === '/favicon.ico') return res.writeHead(204).end() // the browser asks, without the token
|
|
913
945
|
const given = url.pathname === '/' || url.pathname === '/api/events' ? url.searchParams.get('t') : req.headers['x-heart-token']
|
|
@@ -940,20 +972,25 @@ export function startSettings({ cfg, apply = () => {}, port = 0, root = process.
|
|
|
940
972
|
return new Promise((resolve, reject) => {
|
|
941
973
|
server.on('error', reject)
|
|
942
974
|
forgetTests() // results of models no longer yours, left from before
|
|
943
|
-
server.listen(port, '
|
|
944
|
-
const
|
|
945
|
-
|
|
975
|
+
server.listen(port, '0.0.0.0', () => {
|
|
976
|
+
const at = (host) => `http://${host}:${server.address().port}/?t=${token}`
|
|
977
|
+
const local = at('127.0.0.1') // for a browser on this machine
|
|
978
|
+
const url = at(addresses()[0] ?? '127.0.0.1') // its network address when it has one: works from another device too
|
|
979
|
+
log('web', `settings page at ${new URL(url).host}`)
|
|
946
980
|
// models.dev's list (its sizes for your models, whether their providers' lists are on or not):
|
|
947
981
|
// loaded now, and your models' lines brought up to date when it's in
|
|
948
982
|
loadPrices().then(() => {
|
|
949
983
|
for (const t of state().order) testNews(`${t.provider}/${t.model}`, t)
|
|
950
984
|
test(state().order) // any without a profile yet
|
|
951
985
|
})
|
|
952
|
-
resolve({ url, server, close: () => (watcher?.close(), server.closeAllConnections?.(), server.close()) })
|
|
986
|
+
resolve({ url, local, server, close: () => (watcher?.close(), server.closeAllConnections?.(), server.close()) })
|
|
953
987
|
})
|
|
954
988
|
})
|
|
955
989
|
}
|
|
956
990
|
|
|
991
|
+
// This machine's IPv4 addresses on its networks (Wi-Fi, Ethernet, a VPN), not the loopback one
|
|
992
|
+
const addresses = () => Object.values(os.networkInterfaces()).flat().filter((n) => n && n.family === 'IPv4' && !n.internal).map((n) => n.address)
|
|
993
|
+
|
|
957
994
|
// What a model costs at this provider, per million tokens, as its own model list says: { input,
|
|
958
995
|
// output } (either may be missing), or undefined. Not models.dev's: the same model costs differently
|
|
959
996
|
// at different providers. The forms lists use: pricing.prompt/completion (per token, OpenRouter's);
|
package/src/skills.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
// Skills: reusable prompts that you can type as /name and/or the model can load when a task
|
|
2
2
|
// matches. One file (<name>.md) or a folder (<name>/SKILL.md, for extra files), in
|
|
3
|
-
//
|
|
3
|
+
// skills/ in HeartCode the ones it comes with
|
|
4
|
+
// ~/.heart/skills/ for every project (wins over those on the same name)
|
|
4
5
|
// .heartcode/skills/ for one project (wins on the same name)
|
|
5
6
|
// ---
|
|
6
7
|
// description: Review my changes before committing (what the model sees; also in the / menu)
|
|
7
8
|
// use: both me (only typed: costs nothing until used) · model (only the model) · both
|
|
9
|
+
// · always (in every system prompt: how to work, not a task)
|
|
8
10
|
// ---
|
|
9
11
|
// Review the uncommitted changes, focusing on {{args}}.
|
|
10
12
|
// !`git diff HEAD`
|
|
@@ -12,9 +14,11 @@
|
|
|
12
14
|
// other CLIs), @path/to/file (its contents), !`command` (its output).
|
|
13
15
|
import fs from 'node:fs'
|
|
14
16
|
import path from 'node:path'
|
|
17
|
+
import { fileURLToPath } from 'node:url'
|
|
15
18
|
import { HOME } from './config.js'
|
|
16
19
|
|
|
17
|
-
export const USES = ['me', 'model', 'both']
|
|
20
|
+
export const USES = ['me', 'model', 'both', 'always']
|
|
21
|
+
export const BUNDLED = fileURLToPath(new URL('../skills/', import.meta.url))
|
|
18
22
|
|
|
19
23
|
export function frontMatter(text) {
|
|
20
24
|
const m = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/.exec(text)
|
|
@@ -53,7 +57,7 @@ function useOf(meta, fallback = 'both') {
|
|
|
53
57
|
export const extraSkillDirs = []
|
|
54
58
|
|
|
55
59
|
export function skillDirs(root) {
|
|
56
|
-
return [path.join(HOME, 'skills'), root && path.join(root, '.heartcode', 'skills'), ...extraSkillDirs].filter(Boolean)
|
|
60
|
+
return [BUNDLED, path.join(HOME, 'skills'), root && path.join(root, '.heartcode', 'skills'), ...extraSkillDirs].filter(Boolean)
|
|
57
61
|
}
|
|
58
62
|
|
|
59
63
|
export function loadSkills(root) {
|