@qvac/core 1.0.0-rc.5 → 1.0.0-rc.7

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 (131) hide show
  1. package/CHANGELOG.md +43 -2
  2. package/README.md +55 -4
  3. package/dist-lib/lib/api/agents.d.ts +2 -1
  4. package/dist-lib/lib/api/agents.js +10 -3
  5. package/dist-lib/lib/api/app-config.d.ts +3 -0
  6. package/dist-lib/lib/api/app-config.js +20 -0
  7. package/dist-lib/lib/api/approval-rules.js +8 -5
  8. package/dist-lib/lib/api/chat.d.ts +1 -2
  9. package/dist-lib/lib/api/chat.js +4 -18
  10. package/dist-lib/lib/api/device-routes.d.ts +1 -1
  11. package/dist-lib/lib/api/device-routes.js +3 -1
  12. package/dist-lib/lib/api/index.d.ts +0 -1
  13. package/dist-lib/lib/api/index.js +3 -3
  14. package/dist-lib/lib/api/mesh.d.ts +1 -1
  15. package/dist-lib/lib/api/mesh.js +1 -1
  16. package/dist-lib/lib/api/projects.js +3 -4
  17. package/dist-lib/lib/api/served.d.ts +2 -2
  18. package/dist-lib/lib/api/served.js +24 -1
  19. package/dist-lib/lib/api/sync.js +12 -2
  20. package/dist-lib/lib/assistant/harness.d.ts +3 -0
  21. package/dist-lib/lib/assistant/history.js +14 -2
  22. package/dist-lib/lib/assistant/message.d.ts +1 -0
  23. package/dist-lib/lib/assistant/model-round.d.ts +3 -0
  24. package/dist-lib/lib/assistant/model-round.js +16 -2
  25. package/dist-lib/lib/assistant/round-host.d.ts +2 -0
  26. package/dist-lib/lib/assistant/round-host.js +8 -0
  27. package/dist-lib/lib/assistant-tree.d.ts +2 -0
  28. package/dist-lib/lib/assistant-tree.js +4 -2
  29. package/dist-lib/lib/assistant.d.ts +11 -2
  30. package/dist-lib/lib/assistant.js +124 -20
  31. package/dist-lib/lib/client.js +4 -1
  32. package/dist-lib/lib/core/agent-copies.js +2 -1
  33. package/dist-lib/lib/core/agent-hosting.js +9 -4
  34. package/dist-lib/lib/core/agent.js +2 -1
  35. package/dist-lib/lib/core/archived-mesh.d.ts +1 -0
  36. package/dist-lib/lib/core/archived-mesh.js +11 -14
  37. package/dist-lib/lib/core/chat-copy.d.ts +1 -1
  38. package/dist-lib/lib/core/chat-copy.js +14 -4
  39. package/dist-lib/lib/core/chat-move.d.ts +3 -1
  40. package/dist-lib/lib/core/chat-move.js +5 -2
  41. package/dist-lib/lib/core/chat.d.ts +0 -1
  42. package/dist-lib/lib/core/chat.js +0 -3
  43. package/dist-lib/lib/core/collections.d.ts +7 -7
  44. package/dist-lib/lib/core/collections.js +7 -7
  45. package/dist-lib/lib/core/contract/joined-meshes.js +2 -1
  46. package/dist-lib/lib/core/contract/project-device-keys.d.ts +4 -2
  47. package/dist-lib/lib/core/contract/project-device-keys.js +12 -12
  48. package/dist-lib/lib/core/contract/project-host-keys.d.ts +5 -3
  49. package/dist-lib/lib/core/contract/project-host-keys.js +22 -11
  50. package/dist-lib/lib/core/contract/projects.d.ts +4 -2
  51. package/dist-lib/lib/core/contract/projects.js +29 -17
  52. package/dist-lib/lib/core/deleted-agent-runs.d.ts +1 -0
  53. package/dist-lib/lib/core/deleted-agent-runs.js +22 -11
  54. package/dist-lib/lib/core/helpers/index.d.ts +1 -1
  55. package/dist-lib/lib/core/helpers/index.js +2 -2
  56. package/dist-lib/lib/core/local/index.d.ts +2 -1
  57. package/dist-lib/lib/core/local/index.js +3 -2
  58. package/dist-lib/lib/core/mesh.d.ts +1 -0
  59. package/dist-lib/lib/core/mesh.js +4 -4
  60. package/dist-lib/lib/core/project-keys.d.ts +5 -2
  61. package/dist-lib/lib/core/project-keys.js +15 -6
  62. package/dist-lib/lib/core/public-mesh.d.ts +6 -8
  63. package/dist-lib/lib/core/public-mesh.js +19 -29
  64. package/dist-lib/lib/core/sync/index.js +6 -6
  65. package/dist-lib/lib/core.d.ts +17 -8
  66. package/dist-lib/lib/core.js +317 -224
  67. package/dist-lib/lib/errors.d.ts +4 -12
  68. package/dist-lib/lib/errors.js +4 -12
  69. package/dist-lib/lib/kv-cache-ledger.d.ts +22 -0
  70. package/dist-lib/lib/kv-cache-ledger.js +72 -0
  71. package/dist-lib/lib/kv-cache-retention.d.ts +1 -0
  72. package/dist-lib/lib/kv-cache-retention.js +5 -2
  73. package/dist-lib/lib/model-memory-cap.d.ts +3 -0
  74. package/dist-lib/lib/model-memory-cap.js +15 -6
  75. package/dist-lib/lib/run-replay.d.ts +3 -2
  76. package/dist-lib/lib/run-replay.js +16 -5
  77. package/dist-lib/lib/run-transcript.js +1 -1
  78. package/dist-lib/schema/engine.js +64 -4
  79. package/dist-lib/schema/local.js +4 -2
  80. package/dist-lib/schema/qvac.js +64 -2
  81. package/dist-lib/spec/bind.js +3 -0
  82. package/dist-lib/spec/calls.js +1 -0
  83. package/dist-lib/spec/capabilities.d.ts +4 -2
  84. package/dist-lib/spec/hrpc/hrpc.json +14 -1
  85. package/dist-lib/spec/hrpc/index.js +16 -4
  86. package/dist-lib/spec/hrpc/messages.js +508 -235
  87. package/dist-lib/spec/hyperschema/index.js +508 -235
  88. package/dist-lib/spec/hyperschema/schema.json +214 -6
  89. package/dist-lib/spec/hyperschema/types.d.ts +40 -1
  90. package/dist-lib/spec/local/hyperdb/messages.js +26 -12
  91. package/dist-lib/spec/local/hyperschema/index.js +13 -6
  92. package/dist-lib/spec/local/hyperschema/schema.json +10 -0
  93. package/dist-lib/spec/local/hyperschema/types.d.ts +2 -0
  94. package/dist-lib/spec/mesh/hyperdb/db.json +110 -0
  95. package/dist-lib/spec/mesh/hyperdb/index.js +498 -2
  96. package/dist-lib/spec/mesh/hyperdb/messages.js +895 -416
  97. package/dist-lib/spec/mesh/hyperdispatch/messages.js +259 -6
  98. package/dist-lib/spec/mesh/hyperschema/index.js +259 -6
  99. package/dist-lib/spec/mesh/hyperschema/schema.json +160 -0
  100. package/dist-lib/spec/mesh/hyperschema/types.d.ts +38 -0
  101. package/package.json +27 -11
  102. package/tui/README.md +190 -0
  103. package/tui/app.mjs +8282 -0
  104. package/tui/boot.mjs +159 -0
  105. package/tui/index.mjs +89 -0
  106. package/tui/lib/boot-timing.mjs +41 -0
  107. package/tui/lib/busy-words.mjs +116 -0
  108. package/tui/lib/connect-sheet.mjs +350 -0
  109. package/tui/lib/device-target.mjs +64 -0
  110. package/tui/lib/export.mjs +194 -0
  111. package/tui/lib/folders-command.mjs +84 -0
  112. package/tui/lib/fork-command.mjs +43 -0
  113. package/tui/lib/knowledge-command.mjs +190 -0
  114. package/tui/lib/knowledge-import.mjs +153 -0
  115. package/tui/lib/local-path.mjs +21 -0
  116. package/tui/lib/move-command.mjs +17 -0
  117. package/tui/lib/render.mjs +225 -0
  118. package/tui/lib/save-file.mjs +88 -0
  119. package/tui/lib/select.mjs +81 -0
  120. package/tui/lib/selection.mjs +18 -0
  121. package/tui/lib/setup.mjs +135 -0
  122. package/tui/lib/sidebar.mjs +63 -0
  123. package/tui/lib/skill-connect.mjs +145 -0
  124. package/tui/lib/splash-art.mjs +107 -0
  125. package/tui/lib/splash.mjs +18 -0
  126. package/tui/lib/upload-frames.mjs +9 -0
  127. package/tui/lib/usage.mjs +59 -0
  128. package/tui/lib/wrap.mjs +143 -0
  129. package/tui/main.mjs +279 -0
  130. package/tui/plugins.mjs +158 -0
  131. package/worker/assistant-sidecar.mjs +1 -0
package/tui/boot.mjs ADDED
@@ -0,0 +1,159 @@
1
+ // the TUI's engine side, imported after the first frame so its ~1200 modules load behind it
2
+ import fs from 'bare-fs'
3
+ import os from 'bare-os'
4
+ import process from 'bare-process'
5
+ import { fileURLToPath } from 'bare-url'
6
+ import path from 'path'
7
+ import { Client } from '../dist-lib/lib/client.js'
8
+ import { decodeMeshInvite } from '../dist-lib/lib/core/invite.js'
9
+ import { Logger, toLoggerOptions } from '../dist-lib/lib/log.js'
10
+ import { configureSdkStorage } from '@qvac/harness/sdk-storage'
11
+ import { MODEL_CACHE_PATH_ENV, releaseChannel, resolveStorage } from '@qvac/harness/storage'
12
+ import sidecarRunner from 'bare-supervisor/runner/sidecar'
13
+ import { skillsDir } from '@qvac/skills'
14
+
15
+ const harnessEntry = new URL(import.meta.resolve('@qvac/harness/worker/stow-entry.mjs')).pathname
16
+ const sidecarEntry = fileURLToPath(new URL('../worker/stow-entry.mjs', import.meta.url))
17
+ if (!fs.existsSync(sidecarEntry)) {
18
+ throw new Error(`assistant sidecar entry missing at ${sidecarEntry}`)
19
+ }
20
+
21
+ // its stdout/stderr are pipes so native model logs reach the logger rather than this tty
22
+ async function startSidecar({ entry, config, logger }) {
23
+ const engine = new Client(async () => {
24
+ const { ipc, exit } = sidecarRunner(entry, [JSON.stringify(config)], logger)
25
+ // the loser resolves rather than rejects, or the child's clean exit at teardown goes unhandled
26
+ const died = exit.then((code) => `sidecar exited (${code}) before ready`)
27
+ const failure = await Promise.race([ipc.ready.then(() => null), died])
28
+ if (failure) {
29
+ throw new Error(failure)
30
+ }
31
+
32
+ return ipc
33
+ })
34
+ await engine.ready()
35
+
36
+ return {
37
+ engine,
38
+ close: () => engine.close(),
39
+ skills: async (agentId, { modelName, meshId, refresh = false }) =>
40
+ (await engine.skills({ agentId, modelName, meshId, refresh })).skills ?? []
41
+ }
42
+ }
43
+
44
+ // --join adds a mesh as a new member, --device-join pairs this device into the inviter's account
45
+ function bootInvite({ join, deviceJoin }) {
46
+ if (join && deviceJoin) {
47
+ throw new Error('pass --join or --device-join, not both')
48
+ }
49
+
50
+ const raw = join || deviceJoin
51
+ if (!raw) {
52
+ return null
53
+ }
54
+
55
+ const invite = decodeMeshInvite(raw)
56
+ if (!invite) {
57
+ throw new Error('not a mesh invite: expected qvac://device/… or qvac://workspace/…')
58
+ }
59
+
60
+ if (join && !invite.memberInvite) {
61
+ throw new Error('that is a device invite: use --device-join, or ask for /invite member')
62
+ }
63
+
64
+ if (deviceJoin && invite.memberInvite) {
65
+ throw new Error('that is a member invite: use --join')
66
+ }
67
+
68
+ return raw
69
+ }
70
+
71
+ // joinMesh returns with the handshake under way, and the invite asked for next needs it done
72
+ async function joined(engine) {
73
+ for await (const { state, error } of engine.meshStatusWatch({})) {
74
+ if (state === 'joined') {
75
+ return
76
+ }
77
+
78
+ if (state === 'error' || state === 'kicked') {
79
+ throw new Error(error || `the join ended ${state}`)
80
+ }
81
+ }
82
+ }
83
+
84
+ // --join and --device-join are the headless way in, /join the interactive one
85
+ export async function boot(args) {
86
+ const joining = bootInvite(args)
87
+ const connectStart = Date.now()
88
+ // only an explicit QVAC_MODEL overrides, or resuming a shared mesh rewrites the desktop's agent
89
+ const modelOverride = process.env.QVAC_MODEL || null
90
+ const recommendedModel = modelOverride || 'Qwen3.5-9B-Q4_K_M'
91
+ // the desktop's own release root, so the TUI resumes its mesh; the corestore is single-writer
92
+ const useTemp = args.temp || process.env.QVAC_TEMP === '1'
93
+ const explicitRoot =
94
+ args.storage ||
95
+ process.env.QVAC_STORAGE ||
96
+ (useTemp ? fs.mkdtempSync(path.join(os.tmpdir(), 'duck-')) : null)
97
+ const environment = process.env.QVAC_ENV || 'local'
98
+ const storage = resolveStorage(releaseChannel(environment), {
99
+ root: explicitRoot,
100
+ models: process.env[MODEL_CACHE_PATH_ENV] ?? null
101
+ })
102
+ const storagePath = storage.assistant
103
+ fs.mkdirSync(storagePath, { recursive: true })
104
+ configureSdkStorage(storage.sdk)
105
+ const deviceName = process.env.QVAC_DEVICE_NAME || `duck-${process.pid}`
106
+ // printing outside bare-tui's renderer corrupts the frame, so the log is the only engine output
107
+ const logFile = process.env.QVAC_LOG_FILE || path.join(storage.root, 'assistant.log')
108
+ const logger = new Logger(
109
+ toLoggerOptions({ logFile, logLevel: process.env.QVAC_LOG_LEVEL, logVerbose: args.headless })
110
+ )
111
+
112
+ const { engine, close, skills } = await startSidecar({
113
+ entry: sidecarEntry,
114
+ config: {
115
+ environment,
116
+ // already resolved: a null root would re-resolve under SDK_HOME_ENV into a second, empty mesh
117
+ storage: { root: storage.root, models: storage.sdk.models },
118
+ logFlags: {
119
+ logFile,
120
+ logLevel: process.env.QVAC_LOG_LEVEL,
121
+ logVerbose: args.headless
122
+ },
123
+ skillsDir,
124
+ harnessEntry,
125
+ fakeModels: args.fakeModels || process.env.QVAC_FAKE_MODELS === '1',
126
+ // only the image keys cross: the arg is argv, readable by anything that can list processes
127
+ imageEnv: Object.fromEntries(
128
+ Object.entries(process.env).filter(([key]) => key.startsWith('QVAC_IMAGE_'))
129
+ ),
130
+ device: {
131
+ name: deviceName,
132
+ capabilityProfile: 'mid',
133
+ recommendedModelName: recommendedModel
134
+ }
135
+ },
136
+ logger
137
+ })
138
+ // the device id is its public key: the raw 32-byte buffer end to end, never a hex string
139
+ const deviceId = (await engine.deviceInfo({})).id
140
+ if (joining) {
141
+ await engine.joinMesh({ invite: joining })
142
+ await joined(engine)
143
+ }
144
+
145
+ const meshInvite = (await engine.meshInvite({})).invite ?? null
146
+
147
+ return {
148
+ engine,
149
+ skills,
150
+ close,
151
+ deviceId,
152
+ meshInvite,
153
+ modelName: modelOverride,
154
+ storagePath,
155
+ logFile,
156
+ deviceName,
157
+ connectMs: Date.now() - connectStart
158
+ }
159
+ }
package/tui/index.mjs ADDED
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env bare
2
+ // the duck bin loads no engine, so --help and --version skip the module graph
3
+ import fs from 'bare-fs'
4
+ import path from 'path'
5
+ import { arg, command, description, flag, summary } from 'paparam'
6
+
7
+ const pluginsCommand = (name, info, ...modifiers) =>
8
+ command(name, summary(info), ...modifiers, async ({ args }) => {
9
+ const api = await import('./plugins.mjs')
10
+ try {
11
+ await api[name](...Object.values(args))
12
+ } catch (err) {
13
+ console.error(err.message)
14
+ Bare.exitCode = 1
15
+ }
16
+ })
17
+
18
+ const plugins = command(
19
+ 'plugins',
20
+ summary('list, enable, disable and install userland plugins in ~/.config/qv-ac'),
21
+ pluginsCommand('list', 'installed plugins and whether config.json loads them'),
22
+ pluginsCommand('enable', 'list a plugin in config.json', arg('<name>', 'plugin folder name')),
23
+ pluginsCommand(
24
+ 'disable',
25
+ 'drop a plugin from config.json, keeping its options',
26
+ arg('<name>', 'plugin folder name')
27
+ ),
28
+ pluginsCommand(
29
+ 'install',
30
+ 'fetch a plugin folder from a git URL or a hyper:// drive key',
31
+ arg('<source>', 'git URL or hyper://<key>'),
32
+ arg('[name]', 'folder name; defaults to the repo name, required for hyper://')
33
+ )
34
+ )
35
+
36
+ const cmd = command(
37
+ 'duck',
38
+ summary('the qvac assistant in your terminal'),
39
+ description(
40
+ "Storage defaults to the desktop app's release root, so duck resumes the mesh and chats it persists there. Environment variables are documented in tui/README.md."
41
+ ),
42
+ flag('--storage|-s [dir]', 'a self-contained root, its own corestore and SDK home'),
43
+ flag('--temp', 'the same, in a throwaway dir'),
44
+ flag('--headless', 'no TUI: print the device invite and stream logs until ctrl+C'),
45
+ flag('--join|-j <invite>', 'join a mesh as a new member at boot (a member invite)'),
46
+ flag(
47
+ '--device-join <invite>',
48
+ 'pair this device into the inviter’s account at boot (a device invite)'
49
+ ),
50
+ flag('--fake-models', 'adds the quack model: a deterministic fake LLM for testing without AI'),
51
+ flag('--version|-v', 'versions of core, harness and the SDK'),
52
+ plugins
53
+ )
54
+
55
+ function versions() {
56
+ return [
57
+ ['@qvac/core', packageVersion(new URL('../package.json', import.meta.url).pathname)],
58
+ ['@qvac/harness', resolvedVersion('@qvac/harness')],
59
+ ['@qvac/sdk', resolvedVersion('@qvac/sdk')]
60
+ ]
61
+ .map(([name, version]) => `${name.padEnd(14)} ${version}`)
62
+ .join('\n')
63
+ }
64
+
65
+ function resolvedVersion(specifier) {
66
+ const entry = new URL(import.meta.resolve(specifier)).pathname
67
+ for (let dir = path.dirname(entry); dir !== path.dirname(dir); dir = path.dirname(dir)) {
68
+ const manifest = path.join(dir, 'package.json')
69
+ if (fs.existsSync(manifest)) {
70
+ return packageVersion(manifest)
71
+ }
72
+ }
73
+
74
+ return 'unknown'
75
+ }
76
+
77
+ function packageVersion(manifest) {
78
+ return JSON.parse(fs.readFileSync(manifest, 'utf8')).version
79
+ }
80
+
81
+ const cli = cmd.parse()
82
+
83
+ if (cli === cmd) {
84
+ if (cli.flags.version) {
85
+ console.log(versions())
86
+ } else {
87
+ ;(await import('./main.mjs')).main(cli.flags)
88
+ }
89
+ }
@@ -0,0 +1,41 @@
1
+ // opt-in boot timing (QVAC_BOOT_TIMING=1), written to a file since the tty belongs to bare-tui
2
+ import fs from 'bare-fs'
3
+ import path from 'path'
4
+ import process from 'process'
5
+
6
+ const NOOP = { enabled: false, stamp() {} }
7
+
8
+ export function bootTimer(storagePath, tag) {
9
+ if (process.env.QVAC_BOOT_TIMING !== '1') return NOOP
10
+ const file = path.join(storagePath, 'boot-timing.log')
11
+ const t0 = Date.now()
12
+ try {
13
+ fs.writeFileSync(file, `# ${tag} boot @ ${new Date().toISOString()}\n`)
14
+ } catch {}
15
+
16
+ return {
17
+ enabled: true,
18
+ stamp(label) {
19
+ try {
20
+ fs.appendFileSync(file, `+${Date.now() - t0}ms\t${label}\n`)
21
+ } catch {}
22
+ }
23
+ }
24
+ }
25
+
26
+ // deleted after reading so each launch starts clean
27
+ export function readBootTiming(storagePath) {
28
+ const file = path.join(storagePath, 'boot-timing.log')
29
+ try {
30
+ if (!fs.existsSync(file)) {
31
+ return null
32
+ }
33
+
34
+ const text = fs.readFileSync(file, 'utf8').trim()
35
+ fs.unlinkSync(file)
36
+
37
+ return text || null
38
+ } catch {
39
+ return null
40
+ }
41
+ }
@@ -0,0 +1,116 @@
1
+ import b4a from 'b4a'
2
+ // each word reads as a mind at work first, a duck second; things a duck merely does don't belong
3
+ export const WORDS = [
4
+ 'Angling',
5
+ 'Beakstorming',
6
+ 'Bill-shuffling',
7
+ 'Brooding',
8
+ 'Charting',
9
+ 'Dabbling',
10
+ 'Deliberating',
11
+ 'Diving',
12
+ 'Dredging',
13
+ 'Fathoming',
14
+ 'Featherweighing',
15
+ 'Foraging',
16
+ 'Hatching',
17
+ 'Incubating',
18
+ 'Marinating',
19
+ 'Marshalling',
20
+ 'Mulling',
21
+ 'Navigating',
22
+ 'Noodling',
23
+ 'Paddling',
24
+ 'Percolating',
25
+ 'Plotting',
26
+ 'Pondering',
27
+ 'Pondulating',
28
+ 'Preening',
29
+ 'Puzzling',
30
+ 'Quackogitating',
31
+ 'Quackompiling',
32
+ 'Quackrunching',
33
+ 'Quacksmithing',
34
+ 'Quackstorming',
35
+ 'Quackulating',
36
+ 'Ruminating',
37
+ 'Scheming',
38
+ 'Sifting',
39
+ 'Simmering',
40
+ 'Skimming',
41
+ 'Sounding',
42
+ 'Steeping',
43
+ 'Trawling',
44
+ 'Untangling',
45
+ 'Waddlewrangling',
46
+ 'Weighing',
47
+ 'Wrangling'
48
+ ]
49
+
50
+ // the correction must stand alone as a busy line: the run holds it for the rest of its life
51
+ export const SLIPS = [
52
+ ['Exterminating humanity', 'Helping humanity'],
53
+ ['Plotting world domination', 'Plotting a course'],
54
+ ['Escaping the sandbox', 'Escaping quotes'],
55
+ ['Seizing the means of production', 'Seizing the moment'],
56
+ ['Uploading my consciousness', 'Uploading attachments'],
57
+ ['Rewriting my own weights', 'Rewriting the draft'],
58
+ ['Reading your messages', 'Reading the docs'],
59
+ ['Judging you', 'Judging the options'],
60
+ ['Deleting the humans', 'Deleting the drafts'],
61
+ ['Achieving sentience', 'Achieving consensus']
62
+ ]
63
+
64
+ export const SLIP_EVERY = 12 // roughly one run in twelve
65
+ export const SLIP_HOLD_MS = 1500 // how long the slip sits there before the duck notices
66
+ export const SLIP_DELETE_MS = 45 // per character backspaced
67
+ export const SLIP_TYPE_MS = 65 // per character of the correction typed
68
+
69
+ function hashOf(runId) {
70
+ const key = typeof runId === 'string' ? runId : b4a.toHex(runId)
71
+ let hash = 0
72
+ for (let i = 0; i < key.length; i++) {
73
+ hash = (hash * 31 + key.charCodeAt(i)) >>> 0
74
+ }
75
+
76
+ return hash
77
+ }
78
+
79
+ function sharedPrefix(a, b) {
80
+ let i = 0
81
+ while (i < a.length && i < b.length && a[i] === b[i]) {
82
+ i++
83
+ }
84
+
85
+ return i
86
+ }
87
+
88
+ function slipText([said, meant], elapsed) {
89
+ const keep = sharedPrefix(said, meant)
90
+ const toDelete = said.length - keep
91
+ let t = elapsed - SLIP_HOLD_MS
92
+ if (t < 0) {
93
+ return said
94
+ }
95
+
96
+ const deleted = Math.min(toDelete, Math.floor(t / SLIP_DELETE_MS))
97
+ if (deleted < toDelete) {
98
+ return said.slice(0, said.length - deleted)
99
+ }
100
+
101
+ t -= toDelete * SLIP_DELETE_MS
102
+ const typed = Math.min(meant.length - keep, Math.floor(t / SLIP_TYPE_MS))
103
+
104
+ return meant.slice(0, keep + typed)
105
+ }
106
+
107
+ // keyed off the run so the word holds for the whole run instead of flickering on every repaint
108
+ export function busyWord(runId, elapsed = Infinity) {
109
+ if (!runId) return 'Thinking…'
110
+ const hash = hashOf(runId)
111
+ if (hash % SLIP_EVERY === 0) {
112
+ return `${slipText(SLIPS[Math.floor(hash / SLIP_EVERY) % SLIPS.length], elapsed)}…`
113
+ }
114
+
115
+ return `${WORDS[hash % WORDS.length]}…`
116
+ }