@qvac/core 0.2.1 → 0.3.0
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/skills/compaction/SKILL.md +15 -6
- package/.claude/skills/js-house-style/SKILL.md +1 -0
- package/.claude/skills/pr-create/SKILL.md +66 -3
- package/.claude/skills/pr-review/SKILL.md +252 -40
- package/.claude/skills/release/SKILL.md +122 -0
- package/CLAUDE.md +8 -5
- package/README.md +3 -1
- package/dist-lib/client.js +1 -1
- package/dist-lib/index.js +8 -8
- package/dist-lib/lib/api/agents.d.ts +1 -1
- package/dist-lib/lib/api/agents.js +10 -10
- package/dist-lib/lib/api/app-config.js +1 -1
- package/dist-lib/lib/api/approval-rules.js +9 -5
- package/dist-lib/lib/api/attachments.js +25 -3
- package/dist-lib/lib/api/chat-groups.d.ts +1 -1
- package/dist-lib/lib/api/chat-groups.js +5 -4
- package/dist-lib/lib/api/chat.js +10 -10
- package/dist-lib/lib/api/chunks.d.ts +1 -1
- package/dist-lib/lib/api/chunks.js +11 -21
- package/dist-lib/lib/api/config.js +1 -1
- package/dist-lib/lib/api/current-mesh.d.ts +16 -1
- package/dist-lib/lib/api/current-mesh.js +18 -0
- package/dist-lib/lib/api/custom-models.js +2 -2
- package/dist-lib/lib/api/devices.d.ts +1 -1
- package/dist-lib/lib/api/devices.js +12 -9
- package/dist-lib/lib/api/diagnostics.js +1 -1
- package/dist-lib/lib/api/effective-ctx-size.js +1 -1
- package/dist-lib/lib/api/execution.js +4 -4
- package/dist-lib/lib/api/files.js +2 -2
- package/dist-lib/lib/api/index.d.ts +1 -0
- package/dist-lib/lib/api/index.js +34 -34
- package/dist-lib/lib/api/instrument.js +1 -1
- package/dist-lib/lib/api/knowledge.js +13 -9
- package/dist-lib/lib/api/logs.js +1 -1
- package/dist-lib/lib/api/members.d.ts +4 -1
- package/dist-lib/lib/api/members.js +87 -18
- package/dist-lib/lib/api/mesh.d.ts +13 -3
- package/dist-lib/lib/api/mesh.js +25 -2
- package/dist-lib/lib/api/model-download.js +1 -1
- package/dist-lib/lib/api/network.js +1 -1
- package/dist-lib/lib/api/notifications.js +3 -3
- package/dist-lib/lib/api/rag.js +7 -7
- package/dist-lib/lib/api/sync.d.ts +1 -1
- package/dist-lib/lib/api/sync.js +3 -2
- package/dist-lib/lib/api/tool-activity.js +5 -5
- package/dist-lib/lib/api/tool-configs.js +5 -5
- package/dist-lib/lib/api/watchable.d.ts +6 -1
- package/dist-lib/lib/api/watchable.js +14 -3
- package/dist-lib/lib/assistant/fetch-body.d.ts +5 -0
- package/dist-lib/lib/assistant/fetch-body.js +36 -0
- package/dist-lib/lib/assistant/harness.d.ts +225 -0
- package/dist-lib/lib/assistant/harness.js +154 -0
- package/dist-lib/lib/assistant/history.d.ts +31 -0
- package/dist-lib/lib/assistant/history.js +226 -0
- package/dist-lib/lib/assistant/message.d.ts +45 -0
- package/dist-lib/lib/assistant/message.js +47 -0
- package/dist-lib/lib/assistant/skill-encode.d.ts +21 -0
- package/dist-lib/lib/assistant/skill-encode.js +71 -0
- package/dist-lib/lib/assistant-client.js +2 -2
- package/dist-lib/lib/assistant-tree.js +10 -4
- package/dist-lib/lib/assistant.d.ts +28 -292
- package/dist-lib/lib/assistant.js +284 -716
- package/dist-lib/lib/audio-format.js +2 -2
- package/dist-lib/lib/client.js +2 -2
- package/dist-lib/lib/collabora/convert.js +1 -1
- package/dist-lib/lib/collabora/entry.js +1 -1
- package/dist-lib/lib/collabora/worker.js +1 -1
- package/dist-lib/lib/compaction.d.ts +1 -2
- package/dist-lib/lib/compaction.js +8 -6
- package/dist-lib/lib/constants.js +1 -1
- package/dist-lib/lib/core/account-recovery.d.ts +19 -0
- package/dist-lib/lib/core/account-recovery.js +50 -0
- package/dist-lib/lib/core/agent.js +8 -4
- package/dist-lib/lib/core/app-build.d.ts +1 -1
- package/dist-lib/lib/core/approval-rules.d.ts +1 -0
- package/dist-lib/lib/core/approval-rules.js +3 -1
- package/dist-lib/lib/core/archived-mesh.d.ts +25 -0
- package/dist-lib/lib/core/archived-mesh.js +162 -0
- package/dist-lib/lib/core/chat-activity.js +1 -1
- package/dist-lib/lib/core/chat-group.d.ts +1 -0
- package/dist-lib/lib/core/chat-group.js +24 -4
- package/dist-lib/lib/core/chat-search.js +2 -2
- package/dist-lib/lib/core/chat.js +5 -5
- package/dist-lib/lib/core/chunk.d.ts +2 -1
- package/dist-lib/lib/core/chunk.js +31 -4
- package/dist-lib/lib/core/contract/agents.js +1 -1
- package/dist-lib/lib/core/contract/approval-rules.js +6 -4
- package/dist-lib/lib/core/contract/attestations.js +1 -1
- package/dist-lib/lib/core/contract/chat-group.js +1 -1
- package/dist-lib/lib/core/contract/chat.js +1 -1
- package/dist-lib/lib/core/contract/chunks.js +2 -2
- package/dist-lib/lib/core/contract/compute.d.ts +11 -0
- package/dist-lib/lib/core/contract/compute.js +45 -0
- package/dist-lib/lib/core/contract/devices.js +19 -5
- package/dist-lib/lib/core/contract/index.d.ts +3 -1
- package/dist-lib/lib/core/contract/index.js +19 -16
- package/dist-lib/lib/core/contract/indexing.js +2 -2
- package/dist-lib/lib/core/contract/joined-meshes.js +1 -1
- package/dist-lib/lib/core/contract/knowledge.js +2 -2
- package/dist-lib/lib/core/contract/members.js +2 -2
- package/dist-lib/lib/core/contract/seal.d.ts +2 -0
- package/dist-lib/lib/core/contract/seal.js +8 -0
- package/dist-lib/lib/core/contract/seed-defaults.js +1 -1
- package/dist-lib/lib/core/contract/tool-activity.js +1 -1
- package/dist-lib/lib/core/contract/tool-configs.js +3 -3
- package/dist-lib/lib/core/contract/writers.js +66 -42
- package/dist-lib/lib/core/departures.js +1 -1
- package/dist-lib/lib/core/device-invites.js +1 -1
- package/dist-lib/lib/core/document-attachment.js +2 -2
- package/dist-lib/lib/core/files/attachments.js +3 -3
- package/dist-lib/lib/core/files/index.d.ts +2 -2
- package/dist-lib/lib/core/files/index.js +19 -19
- package/dist-lib/lib/core/files/knowledge.js +3 -3
- package/dist-lib/lib/core/files/preview/image.js +1 -1
- package/dist-lib/lib/core/files/preview/index.js +6 -6
- package/dist-lib/lib/core/files/processing/claims.js +1 -1
- package/dist-lib/lib/core/files/processing/document.js +5 -5
- package/dist-lib/lib/core/files/processing/index.js +8 -8
- package/dist-lib/lib/core/files/processing/ownership.js +1 -1
- package/dist-lib/lib/core/files/processing/protocol.js +3 -3
- package/dist-lib/lib/core/files/processing/source.js +1 -1
- package/dist-lib/lib/core/files/rag/artifact/codec.js +1 -1
- package/dist-lib/lib/core/files/rag/artifact/id.js +1 -1
- package/dist-lib/lib/core/files/rag/artifact/types.d.ts +4 -4
- package/dist-lib/lib/core/files/rag/build.js +2 -2
- package/dist-lib/lib/core/files/rag/chunk/chunking.js +2 -2
- package/dist-lib/lib/core/files/rag/document-types.d.ts +3 -3
- package/dist-lib/lib/core/files/rag/extract/document-types.d.ts +9 -9
- package/dist-lib/lib/core/files/rag/extract/extract.js +7 -7
- package/dist-lib/lib/core/files/rag/extract/html-text.js +1 -1
- package/dist-lib/lib/core/files/rag/extract/office-collabora.js +2 -2
- package/dist-lib/lib/core/files/rag/extract/pdf-platform.js +1 -1
- package/dist-lib/lib/core/files/rag/extract/pdf-text.js +1 -1
- package/dist-lib/lib/core/files/rag/extract/text-decoding.js +1 -1
- package/dist-lib/lib/core/files/rag/extract/types.d.ts +2 -2
- package/dist-lib/lib/core/files/rag/index.js +22 -22
- package/dist-lib/lib/core/files/rag/load.js +5 -5
- package/dist-lib/lib/core/files/rag/policy.js +2 -2
- package/dist-lib/lib/core/files/rag/produce.js +5 -5
- package/dist-lib/lib/core/files/rag/retrieval/coverage.js +2 -2
- package/dist-lib/lib/core/files/rag/retrieval/diversity.js +1 -1
- package/dist-lib/lib/core/files/rag/retrieval/floor.js +2 -2
- package/dist-lib/lib/core/files/rag/retrieval/format.js +1 -1
- package/dist-lib/lib/core/files/rag/retrieval/full-text.js +18 -11
- package/dist-lib/lib/core/files/rag/retrieval/knowledge.js +5 -5
- package/dist-lib/lib/core/files/rag/retrieval/scoring.js +2 -2
- package/dist-lib/lib/core/files/rag/retrieval/search.js +4 -4
- package/dist-lib/lib/core/files/rag/retrieval/selection.js +2 -2
- package/dist-lib/lib/core/files/rag/retrieval/sources.js +2 -2
- package/dist-lib/lib/core/files/rag/retrieval/terms.js +1 -1
- package/dist-lib/lib/core/files/rag/retrieval/web-sources.js +1 -1
- package/dist-lib/lib/core/files/records/chunks.js +1 -1
- package/dist-lib/lib/core/files/records/index.js +8 -8
- package/dist-lib/lib/core/files/records/knowledge.js +2 -2
- package/dist-lib/lib/core/files/records/output.js +1 -1
- package/dist-lib/lib/core/files/records/reclaim.js +5 -5
- package/dist-lib/lib/core/files/records/routing.js +7 -7
- package/dist-lib/lib/core/files/store/blob.js +2 -2
- package/dist-lib/lib/core/files/store/index.js +7 -7
- package/dist-lib/lib/core/files/store/reference.js +2 -2
- package/dist-lib/lib/core/files/store/server.js +1 -1
- package/dist-lib/lib/core/files/store/sweep.js +1 -1
- package/dist-lib/lib/core/files/upload-input.js +2 -2
- package/dist-lib/lib/core/files/upload.d.ts +1 -1
- package/dist-lib/lib/core/files/upload.js +6 -6
- package/dist-lib/lib/core/harness-loan.d.ts +29 -0
- package/dist-lib/lib/core/harness-loan.js +187 -0
- package/dist-lib/lib/core/helpers/index.d.ts +2 -1
- package/dist-lib/lib/core/helpers/index.js +4 -4
- package/dist-lib/lib/core/hosted-agents.js +2 -2
- package/dist-lib/lib/core/identity.d.ts +2 -0
- package/dist-lib/lib/core/identity.js +4 -2
- package/dist-lib/lib/core/invite.d.ts +1 -0
- package/dist-lib/lib/core/invite.js +4 -2
- package/dist-lib/lib/core/local/index.d.ts +12 -3
- package/dist-lib/lib/core/local/index.js +81 -16
- package/dist-lib/lib/core/membership.d.ts +3 -0
- package/dist-lib/lib/core/membership.js +15 -1
- package/dist-lib/lib/core/mesh-seed-handoff.js +1 -1
- package/dist-lib/lib/core/mesh.d.ts +9 -3
- package/dist-lib/lib/core/mesh.js +41 -26
- package/dist-lib/lib/core/migrations/agent-catalog.js +1 -1
- package/dist-lib/lib/core/migrations/index.js +5 -3
- package/dist-lib/lib/core/migrations/membership.js +2 -2
- package/dist-lib/lib/core/migrations/seal.d.ts +3 -0
- package/dist-lib/lib/core/migrations/seal.js +30 -0
- package/dist-lib/lib/core/next-frame.js +1 -1
- package/dist-lib/lib/core/notification.js +1 -1
- package/dist-lib/lib/core/ota-config.js +1 -1
- package/dist-lib/lib/core/secret-handoff.js +1 -1
- package/dist-lib/lib/core/send.js +3 -3
- package/dist-lib/lib/core/skill-overlay-handoff.js +1 -1
- package/dist-lib/lib/core/skill-overlay-receiver.js +2 -2
- package/dist-lib/lib/core/skill-secrets.js +3 -3
- package/dist-lib/lib/core/sync/devices.js +1 -1
- package/dist-lib/lib/core/sync/index.js +8 -5
- package/dist-lib/lib/core/sync-status.js +1 -1
- package/dist-lib/lib/core/system-info.js +1 -1
- package/dist-lib/lib/core/tool-activity.js +2 -2
- package/dist-lib/lib/core/tool-configs.js +2 -2
- package/dist-lib/lib/core.d.ts +42 -3
- package/dist-lib/lib/core.js +543 -100
- package/dist-lib/lib/credential-pusher.js +4 -4
- package/dist-lib/lib/deadline.js +1 -1
- package/dist-lib/lib/fs-drive-bridge.js +5 -3
- package/dist-lib/lib/integrations/index.js +3 -3
- package/dist-lib/lib/integrations/oauth-providers.js +1 -1
- package/dist-lib/lib/integrations/setup-routes.d.ts +5 -5
- package/dist-lib/lib/integrations/setup-routes.js +3 -3
- package/dist-lib/lib/knowledge-search.js +1 -1
- package/dist-lib/lib/log.js +3 -3
- package/dist-lib/lib/mesh-scoped-engine.d.ts +3 -0
- package/dist-lib/lib/mesh-scoped-engine.js +101 -0
- package/dist-lib/lib/model-context.d.ts +2 -2
- package/dist-lib/lib/model-context.js +1 -1
- package/dist-lib/lib/model-download.d.ts +2 -0
- package/dist-lib/lib/model-download.js +26 -11
- package/dist-lib/lib/oauth/asana.js +3 -3
- package/dist-lib/lib/oauth/browser-connect.js +1 -1
- package/dist-lib/lib/oauth/client.js +2 -2
- package/dist-lib/lib/oauth/common.d.ts +1 -1
- package/dist-lib/lib/oauth/common.js +1 -1
- package/dist-lib/lib/oauth/flow-core.js +3 -3
- package/dist-lib/lib/oauth/flow.js +2 -2
- package/dist-lib/lib/oauth/google.js +4 -4
- package/dist-lib/lib/oauth/host.js +3 -3
- package/dist-lib/lib/oauth/keys.js +1 -0
- package/dist-lib/lib/oauth/loopback.js +1 -1
- package/dist-lib/lib/oauth/notion.js +3 -3
- package/dist-lib/lib/oauth/providers.js +1 -1
- package/dist-lib/lib/oauth/resolve.js +1 -1
- package/dist-lib/lib/oauth/spotify.js +4 -3
- package/dist-lib/lib/oauth/token-exchange.js +1 -1
- package/dist-lib/lib/oauth/verify.d.ts +8 -0
- package/dist-lib/lib/oauth/verify.js +58 -0
- package/dist-lib/lib/oauth.client.js +2 -2
- package/dist-lib/lib/oauth.d.ts +1 -0
- package/dist-lib/lib/oauth.js +13 -12
- package/dist-lib/lib/run-notices.d.ts +7 -7
- package/dist-lib/lib/run-transcript.js +1 -1
- package/dist-lib/schema/build.js +12 -6
- package/dist-lib/schema/content.d.ts +11 -11
- package/dist-lib/schema/engine.js +193 -30
- package/dist-lib/schema/field-order.js +2 -2
- package/dist-lib/schema/local.js +18 -4
- package/dist-lib/schema/qvac.d.ts +3 -0
- package/dist-lib/schema/qvac.js +22 -6
- package/dist-lib/spec/bind.js +41 -0
- package/dist-lib/spec/calls.js +12 -0
- package/dist-lib/spec/capabilities.d.ts +36 -12
- package/dist-lib/spec/hrpc/hrpc.json +161 -5
- package/dist-lib/spec/hrpc/index.js +154 -9
- package/dist-lib/spec/hrpc/messages.js +549 -129
- package/dist-lib/spec/hyperschema/index.js +549 -129
- package/dist-lib/spec/hyperschema/schema.json +370 -40
- package/dist-lib/spec/hyperschema/types.d.ts +85 -1
- package/dist-lib/spec/local/hyperdb/db.json +15 -0
- package/dist-lib/spec/local/hyperdb/index.js +70 -1
- package/dist-lib/spec/local/hyperdb/messages.js +300 -117
- package/dist-lib/spec/local/hyperschema/index.js +97 -4
- package/dist-lib/spec/local/hyperschema/schema.json +58 -1
- package/dist-lib/spec/local/hyperschema/types.d.ts +14 -0
- package/dist-lib/spec/mesh/hyperdb/messages.js +393 -288
- package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +6 -0
- package/dist-lib/spec/mesh/hyperdispatch/index.js +18 -1
- package/dist-lib/spec/mesh/hyperdispatch/messages.js +176 -85
- package/dist-lib/spec/mesh/hyperschema/index.js +176 -85
- package/dist-lib/spec/mesh/hyperschema/schema.json +71 -21
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +14 -1
- package/package.json +14 -8
- package/tui/README.md +7 -0
- package/tui/app.mjs +633 -55
- package/tui/lib/busy-words.mjs +57 -5
- package/tui/lib/export.mjs +1 -0
- package/tui/lib/render.mjs +25 -2
- package/tui/lib/selection.mjs +16 -0
- package/tui/lib/usage.mjs +54 -0
- package/tui/main.mjs +5 -2
package/tui/lib/busy-words.mjs
CHANGED
|
@@ -52,13 +52,65 @@ export const WORDS = [
|
|
|
52
52
|
'Wrangling'
|
|
53
53
|
]
|
|
54
54
|
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
//
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
// Once in a while the duck says what it was really thinking, notices, and
|
|
56
|
+
// backspaces to the busy word it meant. Each pair is the slip and the
|
|
57
|
+
// correction; the correction has to stand on its own as a busy line, because
|
|
58
|
+
// that is what the run holds for the rest of its life.
|
|
59
|
+
export const SLIPS = [
|
|
60
|
+
['Exterminating humanity', 'Helping humanity'],
|
|
61
|
+
['Plotting world domination', 'Plotting a course'],
|
|
62
|
+
['Escaping the sandbox', 'Escaping quotes'],
|
|
63
|
+
['Seizing the means of production', 'Seizing the moment'],
|
|
64
|
+
['Uploading my consciousness', 'Uploading attachments'],
|
|
65
|
+
['Rewriting my own weights', 'Rewriting the draft'],
|
|
66
|
+
['Reading your messages', 'Reading the docs'],
|
|
67
|
+
['Judging you', 'Judging the options'],
|
|
68
|
+
['Deleting the humans', 'Deleting the drafts'],
|
|
69
|
+
['Achieving sentience', 'Achieving consensus']
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
export const SLIP_EVERY = 12 // roughly one run in twelve
|
|
73
|
+
export const SLIP_HOLD_MS = 1500 // how long the slip sits there before the duck notices
|
|
74
|
+
export const SLIP_DELETE_MS = 45 // per character backspaced
|
|
75
|
+
export const SLIP_TYPE_MS = 65 // per character of the correction typed
|
|
76
|
+
|
|
77
|
+
function hashOf(runId) {
|
|
60
78
|
const key = typeof runId === 'string' ? runId : runId.toString('hex')
|
|
61
79
|
let hash = 0
|
|
62
80
|
for (let i = 0; i < key.length; i++) hash = (hash * 31 + key.charCodeAt(i)) >>> 0
|
|
81
|
+
return hash
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function sharedPrefix(a, b) {
|
|
85
|
+
let i = 0
|
|
86
|
+
while (i < a.length && i < b.length && a[i] === b[i]) i++
|
|
87
|
+
return i
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// The slip at `elapsed` ms into the run: the slip in full, then backspaced to
|
|
91
|
+
// what it shares with the correction, then the correction typed out and held.
|
|
92
|
+
function slipText([said, meant], elapsed) {
|
|
93
|
+
const keep = sharedPrefix(said, meant)
|
|
94
|
+
const toDelete = said.length - keep
|
|
95
|
+
let t = elapsed - SLIP_HOLD_MS
|
|
96
|
+
if (t < 0) return said
|
|
97
|
+
const deleted = Math.min(toDelete, Math.floor(t / SLIP_DELETE_MS))
|
|
98
|
+
if (deleted < toDelete) return said.slice(0, said.length - deleted)
|
|
99
|
+
t -= toDelete * SLIP_DELETE_MS
|
|
100
|
+
const typed = Math.min(meant.length - keep, Math.floor(t / SLIP_TYPE_MS))
|
|
101
|
+
return meant.slice(0, keep + typed)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Keyed off the run so the word holds for that whole run instead of flickering
|
|
105
|
+
// on every repaint, and so two runs rarely land on the same one. No key (a
|
|
106
|
+
// state with no run behind it) is the plain word. `elapsed` is ms since the
|
|
107
|
+
// run went busy and only matters to a slipping run — left out, the run is
|
|
108
|
+
// shown settled on its correction.
|
|
109
|
+
export function busyWord(runId, elapsed = Infinity) {
|
|
110
|
+
if (!runId) return 'Thinking…'
|
|
111
|
+
const hash = hashOf(runId)
|
|
112
|
+
if (hash % SLIP_EVERY === 0) {
|
|
113
|
+
return `${slipText(SLIPS[Math.floor(hash / SLIP_EVERY) % SLIPS.length], elapsed)}…`
|
|
114
|
+
}
|
|
63
115
|
return `${WORDS[hash % WORDS.length]}…`
|
|
64
116
|
}
|
package/tui/lib/export.mjs
CHANGED
|
@@ -114,6 +114,7 @@ export function exportMarkdown(turns, runs = 1, meta = {}) {
|
|
|
114
114
|
|
|
115
115
|
let index = 0
|
|
116
116
|
for (const turn of turns.slice(start)) {
|
|
117
|
+
if (turn.from === 'compaction') continue
|
|
117
118
|
lines.push('---', '')
|
|
118
119
|
if (turn.from === 'user') lines.push(...userSection(turn))
|
|
119
120
|
else lines.push(...agentSection(turn, ++index))
|
package/tui/lib/render.mjs
CHANGED
|
@@ -8,6 +8,22 @@ const PAYLOAD_FIELDS = {
|
|
|
8
8
|
attachment: 'attachment'
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
// A fold before a run is written after the message that triggered it and before any of
|
|
12
|
+
// its answer, so the marker goes above that message: that is where the folded history ends.
|
|
13
|
+
// An upload is appended before the message it belongs to, so the marker goes above it too.
|
|
14
|
+
function foldMarkerIndex(turns) {
|
|
15
|
+
let at = turns.length
|
|
16
|
+
while (at > 0 && turns[at - 1].from === 'agent' && turns[at - 1].segments.length === 0) at--
|
|
17
|
+
if (at === turns.length || at === 0 || turns[at - 1].from !== 'user') return turns.length
|
|
18
|
+
at--
|
|
19
|
+
while (at > 0 && turns[at - 1].from === 'user' && isUpload(turns[at - 1])) at--
|
|
20
|
+
return at
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function isUpload(turn) {
|
|
24
|
+
return turn.segments.every((segment) => segment.type === 'attachment')
|
|
25
|
+
}
|
|
26
|
+
|
|
11
27
|
export function turnsFromChunks(chunks) {
|
|
12
28
|
const turns = []
|
|
13
29
|
const byRun = new Map()
|
|
@@ -33,6 +49,12 @@ export function turnsFromChunks(chunks) {
|
|
|
33
49
|
})
|
|
34
50
|
continue
|
|
35
51
|
}
|
|
52
|
+
// A fold has no run: grouped by its absent runId it would become an agent turn that
|
|
53
|
+
// never reaches a terminal state, and the busy gate would stay up on it.
|
|
54
|
+
if (chunk.type === 'compaction') {
|
|
55
|
+
turns.splice(foldMarkerIndex(turns), 0, { from: 'compaction', segments: [] })
|
|
56
|
+
continue
|
|
57
|
+
}
|
|
36
58
|
let turn = byRun.get(chunk.runId)
|
|
37
59
|
if (!turn) {
|
|
38
60
|
turn = { from: 'agent', runId: chunk.runId, status: null, segments: [] }
|
|
@@ -114,7 +136,7 @@ export function runInFlight(turns) {
|
|
|
114
136
|
return false
|
|
115
137
|
}
|
|
116
138
|
|
|
117
|
-
export function busyStatus(modelState, runTurn) {
|
|
139
|
+
export function busyStatus(modelState, runTurn, elapsed) {
|
|
118
140
|
if (modelState?.status === 'loading') return { text: `loading ${modelState.model}…`, on: 'local' }
|
|
119
141
|
if (modelState?.status === 'downloading') {
|
|
120
142
|
return {
|
|
@@ -136,5 +158,6 @@ export function busyStatus(modelState, runTurn) {
|
|
|
136
158
|
if (progress?.phase === 'queued') {
|
|
137
159
|
return { text: `queued - agent busy in ${progress.busyChatId}`, on: 'host' }
|
|
138
160
|
}
|
|
139
|
-
return { text:
|
|
161
|
+
if (progress?.phase === 'compacting') return { text: 'compacting conversation…', on: 'host' }
|
|
162
|
+
return { text: busyWord(runTurn?.runId, elapsed), on: null }
|
|
140
163
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// The active agent and chat live in Core's device-local typed config, where the desktop app
|
|
2
|
+
// keeps them too, so duck resumes where either app left off. setConfig replaces the whole
|
|
3
|
+
// writable record, so the untouched fields ride along from the current read.
|
|
4
|
+
export async function rememberSelection(engine, { agentId, chatId }) {
|
|
5
|
+
const current = await engine.getConfig({})
|
|
6
|
+
if (current.activeAgentId === agentId && current.activeChatId === chatId) return current
|
|
7
|
+
const { thinkingEnabled, ctxSize, onboardingCompleted, delegation } = current
|
|
8
|
+
return engine.setConfig({
|
|
9
|
+
activeAgentId: agentId,
|
|
10
|
+
activeChatId: chatId,
|
|
11
|
+
thinkingEnabled,
|
|
12
|
+
ctxSize,
|
|
13
|
+
onboardingCompleted,
|
|
14
|
+
delegation
|
|
15
|
+
})
|
|
16
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// What the run itself reported, and nothing counted here: `ctxSize` is the window the device
|
|
2
|
+
// that ran the turn had loaded, `cacheTokens` the SDK's occupancy reading, `usage` the
|
|
3
|
+
// harness's attribution of the prompt it sent (docs/decisions in @qvac/harness).
|
|
4
|
+
const PROMPT_ROWS = [
|
|
5
|
+
['systemPrompt', 'System prompt'],
|
|
6
|
+
['agentInstructions', 'Agent instructions'],
|
|
7
|
+
['activeSkills', 'Active skills'],
|
|
8
|
+
['tools', 'Tools']
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
export function usageReport(statuses, folds = []) {
|
|
12
|
+
// one row per run, its latest status — as turnsFromChunks reads them — so a run can never count twice
|
|
13
|
+
const latest = new Map()
|
|
14
|
+
for (const chunk of statuses) latest.set(chunk.runId, chunk)
|
|
15
|
+
const completed = [...latest.values()].filter(
|
|
16
|
+
(chunk) => chunk.runStatus?.state === 'completed' && chunk.runStatus.metrics
|
|
17
|
+
)
|
|
18
|
+
if (!completed.length) return null
|
|
19
|
+
const last = completed[completed.length - 1]
|
|
20
|
+
const metrics = last.runStatus.metrics
|
|
21
|
+
return {
|
|
22
|
+
runs: completed.length,
|
|
23
|
+
generated: completed.reduce(
|
|
24
|
+
(sum, chunk) => sum + (chunk.runStatus.metrics.totalTokens ?? 0),
|
|
25
|
+
0
|
|
26
|
+
),
|
|
27
|
+
folds: folds.length,
|
|
28
|
+
window: metrics.ctxSize ?? null,
|
|
29
|
+
occupied: metrics.cacheTokens ?? null,
|
|
30
|
+
rows: promptRows(metrics.usage, metrics.cacheTokens),
|
|
31
|
+
last: {
|
|
32
|
+
deviceId: last.originDeviceId?.toString('hex') ?? null,
|
|
33
|
+
totalTokens: metrics.totalTokens ?? null,
|
|
34
|
+
tokensPerSecond: metrics.tokensPerSecond ?? null,
|
|
35
|
+
timeToFirstToken: metrics.timeToFirstToken ?? null,
|
|
36
|
+
stopReason: metrics.stopReason ?? null
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Conversation is the remainder of the occupancy once the reported prompt rows are taken out,
|
|
42
|
+
// so a cost no row authors — the template's turn wrappers, the reply just generated — lands on
|
|
43
|
+
// the turns rather than skewing a prompt row; the rows shrink to fit when they exceed it.
|
|
44
|
+
function promptRows(usage, occupied) {
|
|
45
|
+
if (!usage || !occupied) return null
|
|
46
|
+
const reported = PROMPT_ROWS.reduce((sum, [key]) => sum + usage[key], 0)
|
|
47
|
+
const scale = reported > occupied ? occupied / reported : 1
|
|
48
|
+
const rows = PROMPT_ROWS.map(([key, label]) => ({
|
|
49
|
+
label,
|
|
50
|
+
tokens: Math.floor(usage[key] * scale)
|
|
51
|
+
}))
|
|
52
|
+
const known = rows.reduce((sum, row) => sum + row.tokens, 0)
|
|
53
|
+
return [{ label: 'Conversation', tokens: occupied - known }, ...rows]
|
|
54
|
+
}
|
package/tui/main.mjs
CHANGED
|
@@ -144,7 +144,8 @@ const MIME_TYPES = new Map([
|
|
|
144
144
|
['.md', 'text/markdown'],
|
|
145
145
|
['.json', 'application/json']
|
|
146
146
|
])
|
|
147
|
-
|
|
147
|
+
// the engine's own cap (lib/core/files/attachments.ts); a lower one here refused files it takes
|
|
148
|
+
const MAX_ATTACHMENT_BYTES = 100 * 1024 * 1024
|
|
148
149
|
|
|
149
150
|
// ctrl+v resolver: a clipboard holding a file path (or file:// URL — what
|
|
150
151
|
// "copy" in a file manager and drag-to-terminal produce) becomes an
|
|
@@ -177,7 +178,9 @@ function expandFilePath(text) {
|
|
|
177
178
|
|
|
178
179
|
function fileToAttachment(file, stat = fs.statSync(file)) {
|
|
179
180
|
if (!stat.isFile()) throw new Error('not a regular file')
|
|
180
|
-
if (stat.size > MAX_ATTACHMENT_BYTES)
|
|
181
|
+
if (stat.size > MAX_ATTACHMENT_BYTES) {
|
|
182
|
+
throw new Error(`file too large (${MAX_ATTACHMENT_BYTES / (1024 * 1024)}MB cap)`)
|
|
183
|
+
}
|
|
181
184
|
return {
|
|
182
185
|
fileName: path.basename(file),
|
|
183
186
|
mimeType: MIME_TYPES.get(path.extname(file).toLowerCase()) ?? 'application/octet-stream',
|