heartcode 0.1.36 → 0.1.40

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/src/settings.js CHANGED
@@ -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 { log, LOGS, REQUESTS, useRequestLog, listRequests, readRequest, pruneLogs, logDays, logSize, clearLogs } from './log.js'
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))
@@ -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
- 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) })),
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])), ...Object.fromEntries(LOG_SWITCHES.map((k) => [k, cfg[k] === true])), logDetail: cfg.logDetail === 'summary' ? 'summary' : 'full', logDays: logDays(cfg), testTimeout: Number(cfg.testTimeout) > 0 ? Number(cfg.testTimeout) : 10 },
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 (Get rankings / Refresh 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}`)
@@ -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 ((name in TOGGLES || LOG_SWITCHES.includes(name)) && typeof value !== 'boolean') throw new Error(`${name}: on or off`)
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 (!['permissions', 'effort', 'theme', 'context', 'logDetail', 'logDays', 'testTimeout', ...Object.keys(TOGGLES), ...LOG_SWITCHES].includes(name)) throw new Error(`no setting "${name}"`)
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 === 'logRequests' || name === 'logDetail') useRequestLog(cfg) // from the next request (a running HeartCode takes it in too: applySettings)
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),
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
- // ~/.heart/skills/ for every project
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) {