heartcode 0.1.59 → 0.1.60
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/CHANGELOG.md +28 -0
- package/README.md +14 -7
- package/SKILL.md +2 -1
- package/bin/heart.js +1 -1
- package/bin/heartcode.js +62 -48
- package/package.json +1 -1
- package/prompts/agent.md +50 -6
- package/src/acp.js +3 -3
- package/src/agent.js +116 -16
- package/src/capabilities.js +1 -1
- package/src/client.js +29 -7
- package/src/config.js +1 -1
- package/src/context.js +1 -1
- package/src/headless.js +3 -2
- package/src/importer.js +7 -7
- package/src/log.js +2 -2
- package/src/mcp.js +1 -1
- package/src/memory.js +1 -1
- package/src/oauth.js +1 -1
- package/src/probe.js +14 -4
- package/src/reset.js +2 -2
- package/src/sessions.js +2 -2
- package/src/settings.html +202 -158
- package/src/settings.js +43 -19
- package/src/telegram.js +1 -1
- package/src/tools.js +67 -13
- package/src/tree.js +1 -1
- package/src/ui.js +8 -8
- package/src/usage.js +9 -0
- package/src/voice.js +1 -1
- package/src/web.js +1 -1
package/src/importer.js
CHANGED
|
@@ -65,7 +65,7 @@ function skillBodies(root, scope) {
|
|
|
65
65
|
function skillDup(root, scope, name, body) {
|
|
66
66
|
if (taken(root, scope, name)) return `a skill named ${name} is already there`
|
|
67
67
|
const twin = skillBodies(root, scope).find(([, b]) => same(b, body))
|
|
68
|
-
return twin ? `the same as
|
|
68
|
+
return twin ? `the same as the skill ${twin[0]}` : ''
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
// A markdown command (Claude Code, Codex, OpenCode) → a HeartCode skill you type ("use: me").
|
|
@@ -109,7 +109,7 @@ function mcpDup(root, scope, name, cfg) {
|
|
|
109
109
|
const have = readJson(mcpFile(root, scope), {}).mcpServers ?? {}
|
|
110
110
|
if (have[name]) return `an MCP server named ${name} is already there`
|
|
111
111
|
const twin = Object.entries(have).find(([, c]) => serverKey(c) === serverKey(cfg))
|
|
112
|
-
return twin ? `the same server as
|
|
112
|
+
return twin ? `the same server as ${twin[0]}` : ''
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
function importMcp(root, scope, name, cfg) {
|
|
@@ -189,13 +189,13 @@ export function findImports(root, home = os.homedir()) {
|
|
|
189
189
|
for (const [rel, file] of filesIn(dir, ['.md'])) {
|
|
190
190
|
const name = safe(rel)
|
|
191
191
|
const { meta, body } = frontMatter(fs.readFileSync(file, 'utf8'))
|
|
192
|
-
add(`${tool} · ${scope === 'global' ? '
|
|
192
|
+
add(`${tool} · ${scope === 'global' ? 'global' : 'this project'} · commands`, `/${name}`, (meta.description || body.split('\n')[0]).slice(0, 90), () => importCommand(root, scope, name, file), () => skillDup(root, scope, name, body))
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
for (const [scope, dir] of [['project', path.join(root, '.gemini', 'commands')], ['global', path.join(home, '.gemini', 'commands')]]) {
|
|
196
196
|
for (const [rel, file] of filesIn(dir, ['.toml'])) {
|
|
197
197
|
const name = safe(rel)
|
|
198
|
-
add(`Gemini CLI · ${scope === 'global' ? '
|
|
198
|
+
add(`Gemini CLI · ${scope === 'global' ? 'global' : 'this project'} · commands`, `/${name}`, /^description\s*=\s*"([^"]*)"/m.exec(fs.readFileSync(file, 'utf8'))?.[1] ?? '', () => importToml(root, scope, name, file), () => (taken(root, scope, name) ? `a skill named ${name} is already there` : ''))
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
const skillSources = [
|
|
@@ -212,7 +212,7 @@ export function findImports(root, home = os.homedir()) {
|
|
|
212
212
|
const file = path.join(dir, e.name, 'SKILL.md')
|
|
213
213
|
if (!e.isDirectory() || !exists(file)) continue
|
|
214
214
|
const { meta, body } = frontMatter(fs.readFileSync(file, 'utf8'))
|
|
215
|
-
add(`${tool} · ${scope === 'global' ? '
|
|
215
|
+
add(`${tool} · ${scope === 'global' ? 'global' : 'this project'} · skills`, safe(e.name), (meta.description ?? '').slice(0, 90), () => importSkillFolder(root, scope, safe(e.name), path.join(dir, e.name)), () => skillDup(root, scope, safe(e.name), body))
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
const claudeJson = readJson(path.join(home, '.claude.json'), {})
|
|
@@ -229,11 +229,11 @@ export function findImports(root, home = os.homedir()) {
|
|
|
229
229
|
for (const [tool, scope, servers] of mcpSources) {
|
|
230
230
|
for (const [name, cfg] of Object.entries(servers ?? {})) {
|
|
231
231
|
if (!cfg?.command && !cfg?.url && !cfg?.httpUrl) continue
|
|
232
|
-
add(`${tool} · ${scope === 'global' ? '
|
|
232
|
+
add(`${tool} · ${scope === 'global' ? 'global' : 'this project'} · MCP servers`, name, (cfg.command ? `${cfg.command} ${(cfg.args ?? []).join(' ')}` : (cfg.url ?? cfg.httpUrl)).slice(0, 90), () => importMcp(root, scope, name, cfg), () => mcpDup(root, scope, name, cfg))
|
|
233
233
|
}
|
|
234
234
|
}
|
|
235
235
|
for (const [tool, file] of [['Claude Code', path.join(home, '.claude', 'CLAUDE.md')], ['Codex', path.join(home, '.codex', 'AGENTS.md')], ['Gemini CLI', path.join(home, '.gemini', 'GEMINI.md')]]) {
|
|
236
|
-
if (exists(file)) add(`${tool} ·
|
|
236
|
+
if (exists(file)) add(`${tool} · global · instructions`, path.basename(file), `${tool} instructions → ~/.heart/HEARTCODE.md`, () => importInstructions(file, tool))
|
|
237
237
|
}
|
|
238
238
|
const claudeMemory = path.join(home, '.claude', 'projects', root.replace(/[^a-zA-Z0-9]/g, '-'), 'memory')
|
|
239
239
|
const notes = filesIn(claudeMemory, ['.md']).filter(([n]) => n !== 'MEMORY')
|
package/src/log.js
CHANGED
|
@@ -24,11 +24,11 @@ export const LOG_DIR = process.env.HEART_LOG === 'off' ? null : path.resolve(pro
|
|
|
24
24
|
// The kinds of text log, what each is for, and which topics (log('topic', …)) go in it. A topic not
|
|
25
25
|
// listed goes in debug.
|
|
26
26
|
export const LOG_KINDS = {
|
|
27
|
-
tools: { label: 'Tools & commands', about: 'what HeartCode did on
|
|
27
|
+
tools: { label: 'Tools & commands', about: 'what HeartCode did on this machine: each tool call and its result, commands and background commands, MCP calls, files written', topics: ['tool', 'command', 'mcp', 'background', 'lsp', 'format', 'write', 'web', 'research', 'worktree'] },
|
|
28
28
|
models: { label: 'Model choices', about: 'why a model answered or didn\'t: fallbacks, retries and quirks found', topics: ['rotate', 'retry', 'quirk'] },
|
|
29
29
|
agent: { label: "Agent's decisions", about: 'why it did what it did: each task and its answer, plan-first, reviews, page checks, helpers and parts, compacting, lessons, the wrap-up', topics: ['task', 'look', 'review', 'compact', 'wrapup', 'learn', 'agent', 'director', 'guided', 'rewind', 'btw', 'parts'] },
|
|
30
30
|
errors: { label: 'Errors', about: 'what went wrong: errors, crashes and warnings, with where they came from', topics: ['error', 'crash', 'warn', 'exit'] },
|
|
31
|
-
conversation: { label: 'Conversation', about: 'a plain transcript:
|
|
31
|
+
conversation: { label: 'Conversation', about: 'a plain transcript: the messages typed, the answers, its questions and the replies', topics: ['input', 'ask', 'answer'] },
|
|
32
32
|
debug: { label: 'Debug', about: 'everything else, for a bug report: HTTP, settings, voice, Telegram, sign-ins, tabs, headless and ACP', topics: [] },
|
|
33
33
|
}
|
|
34
34
|
const KIND_OF = Object.fromEntries(Object.entries(LOG_KINDS).flatMap(([k, v]) => v.topics.map((t) => [t, k])))
|
package/src/mcp.js
CHANGED
|
@@ -209,7 +209,7 @@ class Server {
|
|
|
209
209
|
|
|
210
210
|
#signIn(how, signal) {
|
|
211
211
|
const open = this.hub.onSignIn
|
|
212
|
-
if (!open) throw new Error(`${this.name} needs
|
|
212
|
+
if (!open) throw new Error(`${this.name} needs a sign-in first: start heartcode and run /login_mcp ${this.name}`)
|
|
213
213
|
return signIn(this.url, how, (link) => open(this.name, link), { signal, oauth: this.cfg.oauth })
|
|
214
214
|
}
|
|
215
215
|
|
package/src/memory.js
CHANGED
|
@@ -137,7 +137,7 @@ class Notes {
|
|
|
137
137
|
// Keeps MEMORY.md in step with the notes.
|
|
138
138
|
changed() {
|
|
139
139
|
fs.mkdirSync(this.dir, { recursive: true })
|
|
140
|
-
const what = this.scope === 'global' ? 'The notes HeartCode keeps about
|
|
140
|
+
const what = this.scope === 'global' ? 'The notes HeartCode keeps about the user, for every project' : "This project's notes, kept by HeartCode"
|
|
141
141
|
fs.writeFileSync(path.join(this.dir, 'MEMORY.md'), `# Memory\n\n${what}. Each line links to a note.\n\n${this.index(Infinity) || '(no notes yet)'}\n`)
|
|
142
142
|
}
|
|
143
143
|
}
|
package/src/oauth.js
CHANGED
|
@@ -108,7 +108,7 @@ export async function signIn(url, wwwAuth, open, { signal, oauth = {} } = {}) {
|
|
|
108
108
|
const q = new URL(req.url, redirect)
|
|
109
109
|
if (q.pathname !== '/callback') return res.writeHead(404).end()
|
|
110
110
|
const ok = q.searchParams.get('state') === state && q.searchParams.get('code')
|
|
111
|
-
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8' }).end(`<!doctype html><meta charset="utf-8"><title>HeartCode</title><body style="font:16px system-ui;padding:40px">${ok ? '♥ Signed in.
|
|
111
|
+
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8' }).end(`<!doctype html><meta charset="utf-8"><title>HeartCode</title><body style="font:16px system-ui;padding:40px">${ok ? '♥ Signed in. This tab can be closed now.' : `Sign-in failed: ${String(q.searchParams.get('error_description') ?? q.searchParams.get('error') ?? 'wrong state').replace(/</g, '<')}`}</body>`)
|
|
112
112
|
clearTimeout(timer)
|
|
113
113
|
ok ? resolve(ok) : reject(new Error(`sign-in failed: ${q.searchParams.get('error_description') ?? q.searchParams.get('error') ?? 'the reply did not match'}`))
|
|
114
114
|
})
|
package/src/probe.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// A model's profile (what it can do: models.dev's word, or your settings) and how HeartCode talks to it.
|
|
2
|
+
import fs from 'node:fs'
|
|
2
3
|
import path from 'node:path'
|
|
3
4
|
import { HOME, readJson } from './config.js'
|
|
4
5
|
import { contextWindow, contextSource, ASSUMED_REMOTE, LIMIT_MS } from './context.js'
|
|
@@ -13,8 +14,17 @@ export const profilePath = (client) => {
|
|
|
13
14
|
}
|
|
14
15
|
// Bump when a profile's shape changes, so older saved ones are made again once.
|
|
15
16
|
const PROBE_VERSION = 2
|
|
17
|
+
// Kept in memory by file and its time: a page listing thousands of models reads only the ones that
|
|
18
|
+
// changed (a test, a setup, another HeartCode), not every file every time.
|
|
19
|
+
const profiles = new Map() // file → { at: its mtime, p }
|
|
16
20
|
export const loadProfile = (client) => {
|
|
17
|
-
const
|
|
21
|
+
const file = profilePath(client)
|
|
22
|
+
const st = fs.statSync(file, { throwIfNoEntry: false })
|
|
23
|
+
if (!st) return profiles.delete(file), null
|
|
24
|
+
const at = `${st.mtimeMs}:${st.size}` // the size too: a file system that keeps times to the second
|
|
25
|
+
let hit = profiles.get(file)
|
|
26
|
+
if (hit?.at !== at) profiles.set(file, (hit = { at, p: readJson(file, null) }))
|
|
27
|
+
const p = hit.p && structuredClone(hit.p) // a copy, as a read gave: a caller may change it before writing
|
|
18
28
|
// another model's (a model list switch once saved the first model's profile under the next one's name)
|
|
19
29
|
return p?.version === PROBE_VERSION && (!p.model || p.model === client.model) ? p : null
|
|
20
30
|
}
|
|
@@ -48,9 +58,9 @@ export function strategy(p, cfg = {}) {
|
|
|
48
58
|
|
|
49
59
|
export function describe(p, s) {
|
|
50
60
|
const yn = (v) => (v ? c.green('yes') : c.red('no'))
|
|
51
|
-
const context = ['context', `${s.context}${c.dim(` (${p.set?.context ? 'set
|
|
52
|
-
const from = { 'models.dev': 'models.dev', you: '
|
|
53
|
-
const mine = (k) => (p.set?.[k] !== undefined ? c.dim(' (set by
|
|
61
|
+
const context = ['context', `${s.context}${c.dim(` (${p.set?.context ? 'set on /settings' : contextSource(p)}; change it on /settings)`)}`]
|
|
62
|
+
const from = { 'models.dev': 'models.dev', you: '/settings (set by hand)', assumed: "nothing: it isn't in models.dev. Set what it can do on /settings" }[p.source] ?? 'an earlier test'
|
|
63
|
+
const mine = (k) => (p.set?.[k] !== undefined ? c.dim(' (set by hand)') : '')
|
|
54
64
|
return [['from', from], context, ['tool calls', yn(s.actions === 'tools') + mine('tools')], ['thinking', yn(s.thinking) + mine('thinking')], ['images', yn(s.vision) + (Date.now() - (p.quirks?.noImages ?? -Infinity) < LIMIT_MS ? c.dim(' (its provider refused an image today)') : mine('images'))], ['streaming', yn(s.stream) + mine('stream')]]
|
|
55
65
|
.map(([k, v]) => ` ${c.dim(k.padEnd(15))} ${v}`)
|
|
56
66
|
.join('\n')
|
package/src/reset.js
CHANGED
|
@@ -9,13 +9,13 @@ export const RESETS = [
|
|
|
9
9
|
{
|
|
10
10
|
level: 'settings',
|
|
11
11
|
label: 'Settings',
|
|
12
|
-
desc: 'permissions, theme, effort, the toggles, the model list, voice;
|
|
12
|
+
desc: 'permissions, theme, effort, the toggles, the model list, voice; keys, colors, formatters, prompts, MCP servers and hooks. Providers, keys and the model stay.',
|
|
13
13
|
files: ['keybindings.json', 'theme.json', 'format.json', 'prompts', 'mcp.json', 'hooks.json'],
|
|
14
14
|
},
|
|
15
15
|
{
|
|
16
16
|
level: 'providers',
|
|
17
17
|
label: 'Settings and providers',
|
|
18
|
-
desc: 'the above, and
|
|
18
|
+
desc: 'the above, and the providers with their API keys, MCP sign-ins, what HeartCode learned about each model, prices',
|
|
19
19
|
files: ['config.json', 'mcp-auth.json', 'models', 'prices.json'],
|
|
20
20
|
},
|
|
21
21
|
{
|
package/src/sessions.js
CHANGED
|
@@ -94,13 +94,13 @@ export function exportChat(chat, format, model = '') {
|
|
|
94
94
|
if (format === 'md') {
|
|
95
95
|
const body = list.map((e) => {
|
|
96
96
|
const tools = e.tools.map((t) => `<details><summary>${t.name} ${esc(t.args.slice(0, 120))}</summary>\n\n${fence(t.result ?? '')}\n</details>`).join('\n')
|
|
97
|
-
return [`## ${e.role === 'user' ? '
|
|
97
|
+
return [`## ${e.role === 'user' ? 'User' : 'HeartCode'}`, e.text, tools].filter(Boolean).join('\n\n')
|
|
98
98
|
})
|
|
99
99
|
return `# ${title}\n\n_${when}_\n\n${body.join('\n\n')}\n`
|
|
100
100
|
}
|
|
101
101
|
const body = list.map((e) => {
|
|
102
102
|
const tools = e.tools.map((t) => `<details><summary><b>${esc(t.name)}</b> <code>${esc(t.args.slice(0, 160))}</code></summary><pre>${esc(t.result ?? '')}</pre></details>`).join('')
|
|
103
|
-
return `<section class="${e.role}"><h2>${e.role === 'user' ? '
|
|
103
|
+
return `<section class="${e.role}"><h2>${e.role === 'user' ? 'User' : 'HeartCode'}</h2>${e.text ? `<div class="text">${esc(e.text)}</div>` : ''}${tools}</section>`
|
|
104
104
|
})
|
|
105
105
|
return `<!doctype html>
|
|
106
106
|
<html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${esc(title)}</title>
|