@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/app.mjs
CHANGED
|
@@ -16,6 +16,13 @@ import {
|
|
|
16
16
|
scopedKey,
|
|
17
17
|
SPOTIFY_CREDENTIAL_KEY
|
|
18
18
|
} from '../dist-lib/lib/oauth/keys.js'
|
|
19
|
+
import {
|
|
20
|
+
COMPACTION_MIN_CTX_SIZE,
|
|
21
|
+
contextOptionsForModel,
|
|
22
|
+
defaultContextForModel,
|
|
23
|
+
formatTokenCount,
|
|
24
|
+
maxContextForModel
|
|
25
|
+
} from '../dist-lib/lib/model-context.js'
|
|
19
26
|
import {
|
|
20
27
|
busyStatus,
|
|
21
28
|
findPendingApproval,
|
|
@@ -30,6 +37,9 @@ import { center, splash } from './lib/splash.mjs'
|
|
|
30
37
|
import { wrapBlock, wrapLine } from './lib/wrap.mjs'
|
|
31
38
|
import { knowledgeCommand } from './lib/knowledge-command.mjs'
|
|
32
39
|
import { saveUniqueFile } from './lib/save-file.mjs'
|
|
40
|
+
import { usageReport } from './lib/usage.mjs'
|
|
41
|
+
import { compactionTriggerRatio } from '../dist-lib/lib/compaction.js'
|
|
42
|
+
import { rememberSelection } from './lib/selection.mjs'
|
|
33
43
|
import {
|
|
34
44
|
configureActions,
|
|
35
45
|
isReady,
|
|
@@ -70,7 +80,9 @@ function fileStatusText(file) {
|
|
|
70
80
|
// Every entry is dispatched by _command and documented in /help; `palette: true`
|
|
71
81
|
// is the subset the `/` autocomplete advertises. The rest still run when typed in
|
|
72
82
|
// full — they're reachable through the menu (ctrl+p), so they no longer clutter
|
|
73
|
-
// the dropdown.
|
|
83
|
+
// the dropdown. `sub` lists the verbs a command dispatches on its second token,
|
|
84
|
+
// offered once the command is typed. See command-palette.ts, which pins these
|
|
85
|
+
// lists to the dispatcher.
|
|
74
86
|
const COMMANDS = [
|
|
75
87
|
{ name: 'help', desc: 'list every /command with a one-liner', palette: true },
|
|
76
88
|
{
|
|
@@ -80,19 +92,79 @@ const COMMANDS = [
|
|
|
80
92
|
},
|
|
81
93
|
{ name: 'new-chat', desc: 'create and switch to a new chat', palette: true },
|
|
82
94
|
{ name: 'agents', desc: 'switch between your agents (interactive picker)', palette: true },
|
|
83
|
-
{
|
|
95
|
+
{
|
|
96
|
+
name: 'agent',
|
|
97
|
+
desc: 'show, list, create, rename, or switch the active agent',
|
|
98
|
+
sub: [
|
|
99
|
+
{ name: 'list', desc: 'list your agents (* marks the active one)' },
|
|
100
|
+
{ name: 'new', desc: '<name> — create an agent hosted on this device and select it' },
|
|
101
|
+
{ name: 'rename', desc: '<name> — rename the active agent' },
|
|
102
|
+
{
|
|
103
|
+
name: 'use',
|
|
104
|
+
desc: '<name|id> — switch the active agent (same chat; re-targets the next run)'
|
|
105
|
+
},
|
|
106
|
+
{ name: 'borrow', desc: '[none] — borrow the model from the compute mesh, or stop borrowing' }
|
|
107
|
+
]
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: 'ctx',
|
|
111
|
+
desc: "show or set the agent's context size; ↑/↓ move, enter sets",
|
|
112
|
+
sub: [{ name: 'auto', desc: 'clear the agent’s own size so the device default applies' }]
|
|
113
|
+
},
|
|
84
114
|
{
|
|
85
115
|
name: 'activity',
|
|
86
116
|
desc: "list the active agent's tool-call activity (allowed/denied/auto/skip-all/blocked)"
|
|
87
117
|
},
|
|
88
118
|
{ name: 'chats', desc: 'switch between your chats (interactive picker)', palette: true },
|
|
89
|
-
{
|
|
119
|
+
{
|
|
120
|
+
name: 'chat',
|
|
121
|
+
desc: 'show, create, switch, rename, delete a chat, or toggle web search / rag',
|
|
122
|
+
sub: [
|
|
123
|
+
{ name: 'new', desc: '[title] — create and switch to a new chat' },
|
|
124
|
+
{ name: 'use', desc: '<title|id> — switch to another chat' },
|
|
125
|
+
{ name: 'rename', desc: '<title> — rename this chat' },
|
|
126
|
+
{ name: 'del', desc: '<title|id> — delete a chat' },
|
|
127
|
+
{ name: 'websearch', desc: 'on|off — let this chat search the web' },
|
|
128
|
+
{ name: 'rag', desc: 'on|off — retrieve from this chat’s knowledge' }
|
|
129
|
+
]
|
|
130
|
+
},
|
|
90
131
|
{
|
|
91
132
|
name: 'group',
|
|
92
133
|
desc: 'list, create, rename, delete chat groups; move a chat in or out of one',
|
|
93
|
-
palette: true
|
|
134
|
+
palette: true,
|
|
135
|
+
sub: [
|
|
136
|
+
{ name: 'new', desc: '<name> — create a chat group' },
|
|
137
|
+
{
|
|
138
|
+
name: 'move',
|
|
139
|
+
desc: '<group>|- [chat] [after <chat>|first] — move a chat into a group, or out'
|
|
140
|
+
},
|
|
141
|
+
{ name: 'order', desc: '<group> after <group>|first — reorder the groups themselves' },
|
|
142
|
+
{ name: 'rename', desc: '<group> <name> — rename a group' },
|
|
143
|
+
{ name: 'del', desc: '<group> — delete a group; its chats return to the ungrouped list' }
|
|
144
|
+
]
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
name: 'knowledge',
|
|
148
|
+
desc: 'list, download, or remove knowledge in the active chat',
|
|
149
|
+
sub: [
|
|
150
|
+
{ name: 'list', desc: 'knowledge and its indexing status for this chat' },
|
|
151
|
+
{ name: 'add', desc: '<file> — index one local document into this chat' },
|
|
152
|
+
{
|
|
153
|
+
name: 'add-dir',
|
|
154
|
+
desc: '<directory> — index the supported files directly inside a directory'
|
|
155
|
+
},
|
|
156
|
+
{ name: 'download', desc: '<n|id> — download a knowledge file' },
|
|
157
|
+
{ name: 'remove', desc: '<n|id> — remove a knowledge file' }
|
|
158
|
+
]
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
name: 'compact',
|
|
162
|
+
desc: 'fold the older turns of this chat into a summary now, as a full window would'
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
name: 'usage',
|
|
166
|
+
desc: 'this chat’s context usage: the window, how full it is, and what the prompt spends it on'
|
|
94
167
|
},
|
|
95
|
-
{ name: 'knowledge', desc: 'list, download, or remove knowledge in the active chat' },
|
|
96
168
|
{ name: 'files', desc: 'show file readiness, progress, and failures in this chat' },
|
|
97
169
|
{
|
|
98
170
|
name: 'skills',
|
|
@@ -100,9 +172,30 @@ const COMMANDS = [
|
|
|
100
172
|
palette: true
|
|
101
173
|
},
|
|
102
174
|
{ name: 'tools', desc: 'browse installed tools; ↑/↓ move, space toggles each on/off' },
|
|
103
|
-
{
|
|
104
|
-
|
|
105
|
-
|
|
175
|
+
{
|
|
176
|
+
name: 'skill',
|
|
177
|
+
desc: 'toggle a single skill on/off',
|
|
178
|
+
sub: [
|
|
179
|
+
{ name: 'on', desc: '<name> — enable a skill for this agent (sets scope=selected)' },
|
|
180
|
+
{ name: 'off', desc: '<name> — disable a skill for this agent (sets scope=selected)' }
|
|
181
|
+
]
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
name: 'tool',
|
|
185
|
+
desc: 'toggle a single tool on/off',
|
|
186
|
+
sub: [
|
|
187
|
+
{ name: 'on', desc: '<name> — enable a tool for this agent (sets scope=selected)' },
|
|
188
|
+
{ name: 'off', desc: '<name> — disable a tool for this agent (sets scope=selected)' }
|
|
189
|
+
]
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
name: 'scope',
|
|
193
|
+
desc: 'switch skills/tools scope between all and selected',
|
|
194
|
+
sub: [
|
|
195
|
+
{ name: 'skills', desc: 'all|selected — every installed skill, or only the enabled list' },
|
|
196
|
+
{ name: 'tools', desc: 'all|selected — every installed tool, or only the enabled list' }
|
|
197
|
+
]
|
|
198
|
+
},
|
|
106
199
|
{
|
|
107
200
|
name: 'permissions',
|
|
108
201
|
desc: "the agent's approval mode and its toolset switches; space toggles"
|
|
@@ -118,28 +211,69 @@ const COMMANDS = [
|
|
|
118
211
|
desc: 'write the last run (or last n) to a markdown file — thinking, answer, tools',
|
|
119
212
|
palette: true
|
|
120
213
|
},
|
|
121
|
-
{
|
|
214
|
+
{
|
|
215
|
+
name: 'join',
|
|
216
|
+
desc: "join another device's mesh with its invite (replaces this one)",
|
|
217
|
+
sub: [{ name: 'cancel', desc: 'abort a join still waiting to be admitted' }]
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
name: 'leave',
|
|
221
|
+
desc: 'leave the active mesh; a fresh account is minted when nothing else is writable'
|
|
222
|
+
},
|
|
122
223
|
{
|
|
123
224
|
name: 'invite',
|
|
124
225
|
desc: 'show this mesh device invite - /invite member opens your shared room and invites someone into it (your account is never shared)',
|
|
125
|
-
palette: true
|
|
226
|
+
palette: true,
|
|
227
|
+
sub: [
|
|
228
|
+
{
|
|
229
|
+
name: 'member',
|
|
230
|
+
desc: '[n|id] — invite a person into your shared room (or a named room), never your account'
|
|
231
|
+
}
|
|
232
|
+
]
|
|
126
233
|
},
|
|
127
234
|
{ name: 'members', desc: 'list mesh members with their devices grouped', palette: true },
|
|
128
235
|
// before `meshes`, so a bare /mesh offers the verb first and the list second
|
|
129
236
|
{
|
|
130
237
|
name: 'mesh',
|
|
131
238
|
desc: 'switch which mesh is the active one, open another, or name one',
|
|
132
|
-
palette: true
|
|
239
|
+
palette: true,
|
|
240
|
+
sub: [
|
|
241
|
+
{ name: 'use', desc: '<n|id> — make one of your meshes the active one' },
|
|
242
|
+
{ name: 'new', desc: '[compute] — open another shared room, or lend this device’s model' },
|
|
243
|
+
{ name: 'label', desc: '<n|id> <name> — name a room, privately to you' }
|
|
244
|
+
]
|
|
133
245
|
},
|
|
134
246
|
{ name: 'meshes', desc: 'list the meshes this device belongs to', palette: true },
|
|
135
247
|
{ name: 'cred', desc: 'set a credential value for this agent' },
|
|
136
|
-
{
|
|
248
|
+
{
|
|
249
|
+
name: 'connect',
|
|
250
|
+
desc: 'OAuth-connect a skill for this agent',
|
|
251
|
+
sub: [
|
|
252
|
+
{ name: 'gmail', desc: 'Google OAuth (needs GOOGLE_OAUTH_CLIENT_ID + _SECRET)' },
|
|
253
|
+
{ name: 'google-calendar', desc: 'Google OAuth (needs GOOGLE_OAUTH_CLIENT_ID + _SECRET)' },
|
|
254
|
+
{ name: 'google-docs', desc: 'Google OAuth (needs GOOGLE_OAUTH_CLIENT_ID + _SECRET)' },
|
|
255
|
+
{ name: 'google-drive', desc: 'Google OAuth (needs GOOGLE_OAUTH_CLIENT_ID + _SECRET)' },
|
|
256
|
+
{ name: 'google-sheets', desc: 'Google OAuth (needs GOOGLE_OAUTH_CLIENT_ID + _SECRET)' },
|
|
257
|
+
{ name: 'spotify', desc: 'Spotify OAuth, PKCE only (needs SPOTIFY_OAUTH_CLIENT_ID)' },
|
|
258
|
+
{ name: 'notion', desc: 'Notion MCP OAuth, PKCE + dynamic registration (no env)' },
|
|
259
|
+
{ name: 'asana', desc: 'Asana MCP OAuth, PKCE (needs ASANA_OAUTH_CLIENT_ID + _SECRET)' }
|
|
260
|
+
]
|
|
261
|
+
},
|
|
137
262
|
{
|
|
138
263
|
name: 'my-device',
|
|
139
264
|
desc: 'CPU/GPU inventory for this device (manufacturer, cores, drivers, …)'
|
|
140
265
|
},
|
|
141
266
|
{ name: 'models', desc: 'browse every model in the SDK registry (optional type filter)' },
|
|
142
|
-
{
|
|
267
|
+
{
|
|
268
|
+
name: 'image',
|
|
269
|
+
desc: 'show or set the agent’s image defaults (model, steps, size)',
|
|
270
|
+
sub: [
|
|
271
|
+
{ name: 'model', desc: '<sd2|sdxl|flux2-klein> — the diffusion model image tools use' },
|
|
272
|
+
{ name: 'steps', desc: '<1..100> — diffusion steps per image' },
|
|
273
|
+
{ name: 'size', desc: '<WxH> — image size in pixels' },
|
|
274
|
+
{ name: 'reset', desc: 'back to the device defaults' }
|
|
275
|
+
]
|
|
276
|
+
},
|
|
143
277
|
{ name: 'speak', desc: 'synthesize speech from text to a WAV file (TTS)' },
|
|
144
278
|
{ name: 'speak-stream', desc: 'synthesize speech per sentence over a duplex stream (TTS)' },
|
|
145
279
|
{ name: 'transcribe', desc: 'transcribe a 16kHz mono s16 WAV file to text (STT)' },
|
|
@@ -392,6 +526,58 @@ export function formatPermissions(sel) {
|
|
|
392
526
|
return [header, '', ...lines]
|
|
393
527
|
}
|
|
394
528
|
|
|
529
|
+
// /ctx overlay: the model's context options, with the size in use, the default and the ceiling
|
|
530
|
+
// marked. An agent without a size of its own is at the default, and the header says so.
|
|
531
|
+
export function formatContextSizes(sel) {
|
|
532
|
+
const { rows, cursor, model, current, inUse, max, defaultSize } = sel
|
|
533
|
+
const state = current ? '' : ' (default)'
|
|
534
|
+
const header = fg.dim.render(
|
|
535
|
+
`Context size · ${model} — ${formatTokenCount(inUse)} in use${state} · max ${formatTokenCount(max)} — ↑/↓ move · enter set · esc return`
|
|
536
|
+
)
|
|
537
|
+
const lines = rows.map((size, i) => {
|
|
538
|
+
const point = i === cursor ? fg.magenta.render('❯ ') : ' '
|
|
539
|
+
const badge = size === inUse ? fg.cyan.render('● ') : fg.dim.render('○ ')
|
|
540
|
+
const notes = []
|
|
541
|
+
if (size === defaultSize) notes.push('default')
|
|
542
|
+
if (size === max) notes.push('max')
|
|
543
|
+
if (size < COMPACTION_MIN_CTX_SIZE) notes.push('no compaction')
|
|
544
|
+
const label = formatTokenCount(size).padEnd(10)
|
|
545
|
+
return `${point}${badge}${fg.white.render(label)} ${fg.dim.render(notes.join(' · '))}`
|
|
546
|
+
})
|
|
547
|
+
return [header, '', ...lines]
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// `8k` is how the picker prints a size, so it reads back the same way (k = 1,024)
|
|
551
|
+
export function parseTokenCount(raw) {
|
|
552
|
+
const match = /^(\d+(?:\.\d+)?)([km])?$/i.exec(raw)
|
|
553
|
+
if (!match) return null
|
|
554
|
+
const scale = match[2] ? (match[2].toLowerCase() === 'k' ? 1_024 : 1_048_576) : 1
|
|
555
|
+
const size = Math.round(Number(match[1]) * scale)
|
|
556
|
+
return size > 0 ? size : null
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
function contextSizeNotice(agent, size) {
|
|
560
|
+
const max = formatTokenCount(maxContextForModel(agent.modelName ?? ''))
|
|
561
|
+
if (!size) {
|
|
562
|
+
const fallback = formatTokenCount(defaultContextForModel(agent.modelName ?? ''))
|
|
563
|
+
return `${agent.name} context size cleared — runs at the default ${fallback} (max ${max}) — lands on the next message`
|
|
564
|
+
}
|
|
565
|
+
const floor =
|
|
566
|
+
size < COMPACTION_MIN_CTX_SIZE
|
|
567
|
+
? ' · under the 4K compaction floor: a full window is not folded, the overflow ladder handles it'
|
|
568
|
+
: ''
|
|
569
|
+
return `${agent.name} context size set to ${formatTokenCount(size)} (max ${max})${floor} — lands on the next message`
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
// the menu row already answers the two numbers the picker is about
|
|
573
|
+
function contextSizeHint(agent) {
|
|
574
|
+
const model = agent?.modelName ?? ''
|
|
575
|
+
const now = agent?.ctxSize
|
|
576
|
+
? formatTokenCount(agent.ctxSize)
|
|
577
|
+
: `${formatTokenCount(defaultContextForModel(model))} default`
|
|
578
|
+
return `${now} · max ${formatTokenCount(maxContextForModel(model))}`
|
|
579
|
+
}
|
|
580
|
+
|
|
395
581
|
const SKILL_STATUS_PAINT = {
|
|
396
582
|
ready: 'dim',
|
|
397
583
|
'needs-setup': 'amber',
|
|
@@ -410,6 +596,7 @@ const SKILL_STATUS_PAINT = {
|
|
|
410
596
|
export function formatSelector(sel) {
|
|
411
597
|
const { kind, rows, enabled, scope, cursor, detail } = sel
|
|
412
598
|
if (kind === 'permissions') return formatPermissions(sel)
|
|
599
|
+
if (kind === 'ctx') return formatContextSizes(sel)
|
|
413
600
|
const title = kind === 'skills' ? 'Skills' : 'Tools'
|
|
414
601
|
if (!rows.length) {
|
|
415
602
|
return [fg.dim.render(`(no ${kind} advertised — provider offline or pre-upgrade)`)]
|
|
@@ -526,6 +713,8 @@ export function renderTurn(turn, agentName, deviceLabels, opts = {}) {
|
|
|
526
713
|
// A requested-but-not-yet-started run has a turn (so busy derives from it)
|
|
527
714
|
// but nothing to say — the busy line is its visible side.
|
|
528
715
|
if (turn.from === 'agent' && !turn.segments.length && !turn.status) return ''
|
|
716
|
+
// the turns above it stay on screen; only the prompt the model reads shrank
|
|
717
|
+
if (turn.from === 'compaction') return fg.dim.render('── compacted session ──')
|
|
529
718
|
const userLabel =
|
|
530
719
|
(turn.deviceId && deviceLabels?.get(turn.deviceId)) || turn.deviceId?.slice(0, 8) || 'you'
|
|
531
720
|
const label = turn.from === 'user' ? fg.cyan.render(userLabel) : fg.magenta.render(agentName)
|
|
@@ -534,7 +723,7 @@ export function renderTurn(turn, agentName, deviceLabels, opts = {}) {
|
|
|
534
723
|
if (segment.type === 'thinking') {
|
|
535
724
|
// a model that skips its reasoning still streams the think tags' newlines
|
|
536
725
|
const thought = segment.text.trim()
|
|
537
|
-
if (thought) lines.push(fg.dim.render(` (thinking: ${thought})`))
|
|
726
|
+
if (thought) lines.push(fg.dim.render(` (thinking: ${thought})`), '')
|
|
538
727
|
} else if (segment.type === 'tool-call') {
|
|
539
728
|
const call = ` → ${segment.detail.name}(${JSON.stringify(segment.detail.arguments)})`
|
|
540
729
|
lines.push(fg.amber.render(clampTool(call, opts)))
|
|
@@ -582,7 +771,14 @@ export function renderTurn(turn, agentName, deviceLabels, opts = {}) {
|
|
|
582
771
|
if (turn.status === 'failed') {
|
|
583
772
|
lines.push(fg.err.render(` [failed${turn.statusReason ? `: ${turn.statusReason}` : ''}]`))
|
|
584
773
|
}
|
|
774
|
+
// the gap after a thought separates it from the answer, not from the busy line
|
|
775
|
+
if (lines.at(-1) === '') lines.pop()
|
|
585
776
|
const metrics = turn.status === 'completed' ? turn.statusDetail?.metrics : null
|
|
777
|
+
// the SDK stops a turn at the ceiling with what it has and the run completes, so this line
|
|
778
|
+
// is the only thing that says the answer is not whole
|
|
779
|
+
if (metrics?.stopReason === 'length') {
|
|
780
|
+
lines.push(fg.amber.render(' [answer cut by the context window]'))
|
|
781
|
+
}
|
|
586
782
|
if (metrics) {
|
|
587
783
|
const parts = [`${metrics.totalTokens} tok`]
|
|
588
784
|
if (metrics.tokensPerSecond) parts.push(`${metrics.tokensPerSecond.toFixed(1)} tok/s`)
|
|
@@ -627,16 +823,22 @@ function enabledDrivers(drivers) {
|
|
|
627
823
|
export function matchCommands(inputValue) {
|
|
628
824
|
const raw = inputValue ?? ''
|
|
629
825
|
if (!raw.startsWith('/')) return []
|
|
630
|
-
const query = raw.slice(1).split(/\s
|
|
631
|
-
//
|
|
632
|
-
//
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
826
|
+
const [query, second, ...more] = raw.slice(1).toLowerCase().split(/\s+/)
|
|
827
|
+
// a space after the token means the command is chosen — exact match only, so `/skill on x`
|
|
828
|
+
// stops surfacing /skills — and the palette moves on to that command's own verbs
|
|
829
|
+
if (second === undefined) {
|
|
830
|
+
const hits = COMMANDS.filter((c) => c.name.startsWith(query))
|
|
831
|
+
// the curated few first, then every other command — a bare `/` still opens on
|
|
832
|
+
// what most people want, and typing reaches everything the TUI dispatches
|
|
833
|
+
return [...hits.filter((c) => c.palette), ...hits.filter((c) => !c.palette)]
|
|
834
|
+
}
|
|
835
|
+
const command = COMMANDS.find((c) => c.name === query)
|
|
836
|
+
if (!command) return []
|
|
837
|
+
const subs = (command.sub ?? [])
|
|
838
|
+
.filter((s) => (more.length ? s.name === second : s.name.startsWith(second)))
|
|
839
|
+
.map((s) => ({ name: `${command.name} ${s.name}`, desc: s.desc }))
|
|
840
|
+
// a verb under way narrows to its completions; a bare `/chat ` offers the command itself first
|
|
841
|
+
return second && subs.length ? subs : [command, ...subs]
|
|
640
842
|
}
|
|
641
843
|
|
|
642
844
|
// The dropdown never grows past PALETTE_ROWS — with every command matchable, a
|
|
@@ -750,6 +952,75 @@ function formatGpuLines(gpu) {
|
|
|
750
952
|
return lines
|
|
751
953
|
}
|
|
752
954
|
|
|
955
|
+
// /usage overlay: the window and how much of it the last run left in use, then what the prompt
|
|
956
|
+
// spends it on — every number as the run reported it, none counted here (lib/usage.mjs).
|
|
957
|
+
export function formatUsage(report, { title, deviceLabel }) {
|
|
958
|
+
const header = fg.dim.render(`Usage · ${title} — esc to return`)
|
|
959
|
+
if (!report) {
|
|
960
|
+
return [
|
|
961
|
+
header,
|
|
962
|
+
'',
|
|
963
|
+
fg.dim.render('no completed run in this chat yet — usage is read off the last one')
|
|
964
|
+
]
|
|
965
|
+
}
|
|
966
|
+
return [
|
|
967
|
+
header,
|
|
968
|
+
'',
|
|
969
|
+
...usageWindow(report, deviceLabel),
|
|
970
|
+
...usageRows(report),
|
|
971
|
+
'',
|
|
972
|
+
...usageRuns(report)
|
|
973
|
+
]
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
const pct = (share) => `${Math.round(share * 100)}%`
|
|
977
|
+
|
|
978
|
+
function usageWindow({ window, occupied }, deviceLabel) {
|
|
979
|
+
const where = deviceLabel ? ` · as loaded on ${deviceLabel}` : ''
|
|
980
|
+
const lines = [` window ${window ? formatTokenCount(window) : 'not reported'}${where}`]
|
|
981
|
+
if (!occupied) {
|
|
982
|
+
lines.push(fg.dim.render(' in use not reported by the last run'))
|
|
983
|
+
return lines
|
|
984
|
+
}
|
|
985
|
+
const tokens = `${occupied.toLocaleString()} tokens`
|
|
986
|
+
if (!window) return [...lines, ` in use ${tokens}`]
|
|
987
|
+
const share = occupied / window
|
|
988
|
+
const fold = compactionTriggerRatio(window)
|
|
989
|
+
const filled = Math.round(share * 24)
|
|
990
|
+
const bar = '█'.repeat(filled) + '░'.repeat(24 - filled)
|
|
991
|
+
const paint = share >= fold ? fg.amber : fg.cyan
|
|
992
|
+
lines.push(` in use ${tokens} · ${pct(share)} ${paint.render(bar)} · folds at ${pct(fold)}`)
|
|
993
|
+
return lines
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
function usageRows({ rows, occupied }) {
|
|
997
|
+
if (!rows) return ['', fg.dim.render(' no prompt breakdown reported by the last run')]
|
|
998
|
+
const width = Math.max(...rows.map((row) => row.label.length))
|
|
999
|
+
return [
|
|
1000
|
+
'',
|
|
1001
|
+
...rows.map(
|
|
1002
|
+
({ label, tokens }) =>
|
|
1003
|
+
` ${label.padEnd(width)} ${tokens.toLocaleString().padStart(7)} · ${pct(tokens / occupied).padStart(4)}`
|
|
1004
|
+
)
|
|
1005
|
+
]
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
function usageRuns({ runs, generated, folds, last }) {
|
|
1009
|
+
const chat = [
|
|
1010
|
+
`${runs} ${runs === 1 ? 'run' : 'runs'}`,
|
|
1011
|
+
`${generated.toLocaleString()} tokens generated`
|
|
1012
|
+
]
|
|
1013
|
+
if (folds) chat.push(`compacted ${folds}×`)
|
|
1014
|
+
const parts = []
|
|
1015
|
+
if (last.totalTokens) parts.push(`${last.totalTokens.toLocaleString()} tok`)
|
|
1016
|
+
if (last.tokensPerSecond) parts.push(`${last.tokensPerSecond.toFixed(1)} tok/s`)
|
|
1017
|
+
if (last.timeToFirstToken) parts.push(`ttft ${Math.round(last.timeToFirstToken)}ms`)
|
|
1018
|
+
if (last.stopReason === 'length') parts.push('answer cut by the context window')
|
|
1019
|
+
const lines = [fg.dim.render(` ${chat.join(' · ')}`)]
|
|
1020
|
+
if (parts.length) lines.push(fg.dim.render(` last run: ${parts.join(' · ')}`))
|
|
1021
|
+
return lines
|
|
1022
|
+
}
|
|
1023
|
+
|
|
753
1024
|
export function formatDiagnostics(stats) {
|
|
754
1025
|
if (!stats) {
|
|
755
1026
|
return [fg.dim.render('(no diagnostics snapshot yet — try again in a moment)')]
|
|
@@ -800,6 +1071,14 @@ const MEMBER_INVITE_DISCLOSURES = [
|
|
|
800
1071
|
'and today a co-member approval rule governs your tool calls in this room (tracked separately)'
|
|
801
1072
|
]
|
|
802
1073
|
|
|
1074
|
+
// A compute mesh carries no conversation and no approval rules, so two of the disclosures above
|
|
1075
|
+
// would be false of one. What is true of it is the key material and the device inventory.
|
|
1076
|
+
const COMPUTE_INVITE_DISCLOSURES = [
|
|
1077
|
+
'everyone ever admitted to this mesh holds its key material for good - a kick revokes a writer, never the key',
|
|
1078
|
+
'co-members see each of your devices: name, platform, app version, installed tools, skills, models and tool catalog',
|
|
1079
|
+
'nothing else travels: no chats, no documents, no knowledge, no agents, no tool settings'
|
|
1080
|
+
]
|
|
1081
|
+
|
|
803
1082
|
// A mesh has no name, only its 64-char key, so the list is read by its number:
|
|
804
1083
|
// `/mesh use <n>` takes the same index.
|
|
805
1084
|
// `shared` is occupancy, not the registry marker: what the user wants to know is which of these
|
|
@@ -809,7 +1088,8 @@ function formatMeshes(meshes) {
|
|
|
809
1088
|
const rows = meshes.map((mesh, index) => {
|
|
810
1089
|
const tags = [
|
|
811
1090
|
mesh.home ? 'account' : null,
|
|
812
|
-
|
|
1091
|
+
mesh.compute ? 'compute' : null,
|
|
1092
|
+
!mesh.home && !mesh.compute && mesh.members > 1 ? 'shared' : null,
|
|
813
1093
|
mesh.open ? 'open' : 'closed'
|
|
814
1094
|
]
|
|
815
1095
|
if (mesh.open) tags.push(mesh.writable ? 'writable' : 'read-only')
|
|
@@ -837,11 +1117,16 @@ function resolveMesh(meshes, selector) {
|
|
|
837
1117
|
// How long a bootstrap waits for the mesh's own seed to replicate before minting its own.
|
|
838
1118
|
const SEED_REPLICATION_MS = 10_000
|
|
839
1119
|
|
|
1120
|
+
// a room holds one default per member, each pinned to its owner's device; ours runs here
|
|
1121
|
+
const isOwnDefault = (agent, deviceId) =>
|
|
1122
|
+
Boolean(deviceId) && agent.isDefault === true && agent.providerDeviceId?.equals(deviceId) === true
|
|
1123
|
+
const ownDefault = (agents, deviceId) => agents.find((agent) => isOwnDefault(agent, deviceId))
|
|
1124
|
+
|
|
840
1125
|
// The mesh seeds its default agent at birth and a joiner waits for it to replicate - watch-driven
|
|
841
1126
|
// (agentsWatch fires on every change), no polling. This device mints one as a fallback if none
|
|
842
1127
|
// shows within the timeout: an unbounded wait here blocks the composer for good, and a mesh can
|
|
843
1128
|
// legitimately hold no agent - one nobody has reached yet, or one whose every agent was deleted.
|
|
844
|
-
async function firstAgent(engine, deviceId, modelName) {
|
|
1129
|
+
async function firstAgent(engine, deviceId, modelName, remembered) {
|
|
845
1130
|
const watch = engine.agentsWatch({})[Symbol.asyncIterator]()
|
|
846
1131
|
let timer
|
|
847
1132
|
const timeout = new Promise((resolve) => {
|
|
@@ -851,7 +1136,10 @@ async function firstAgent(engine, deviceId, modelName) {
|
|
|
851
1136
|
while (true) {
|
|
852
1137
|
const { value, done } = await Promise.race([watch.next(), timeout])
|
|
853
1138
|
if (done) break
|
|
854
|
-
const
|
|
1139
|
+
const agents = value.agents ?? []
|
|
1140
|
+
// the agent the last session left active outranks the seed, as it does on the desktop
|
|
1141
|
+
const live =
|
|
1142
|
+
agents.find((agent) => agent.id === remembered) ?? ownDefault(agents, deviceId) ?? agents[0]
|
|
855
1143
|
if (live) return live
|
|
856
1144
|
}
|
|
857
1145
|
} finally {
|
|
@@ -875,7 +1163,7 @@ async function firstAgent(engine, deviceId, modelName) {
|
|
|
875
1163
|
// The birth op seeds a default chat too; a joiner waits for it to replicate -
|
|
876
1164
|
// watch-driven like firstAgent (chatsWatch), no polling. The provider mints one
|
|
877
1165
|
// as a fallback if none shows within the timeout.
|
|
878
|
-
async function firstChat(engine, agent, isProvider) {
|
|
1166
|
+
async function firstChat(engine, agent, isProvider, remembered) {
|
|
879
1167
|
const watch = engine.chatsWatch({})[Symbol.asyncIterator]()
|
|
880
1168
|
let timer
|
|
881
1169
|
const timeout = new Promise((resolve) => {
|
|
@@ -885,7 +1173,8 @@ async function firstChat(engine, agent, isProvider) {
|
|
|
885
1173
|
while (true) {
|
|
886
1174
|
const { value, done } = await Promise.race([watch.next(), timeout])
|
|
887
1175
|
if (done) break
|
|
888
|
-
const
|
|
1176
|
+
const chats = (value.chats ?? []).filter((chat) => !chat.deletedAt)
|
|
1177
|
+
const live = chats.find((chat) => chat.id === remembered) ?? chats[0]
|
|
889
1178
|
if (live) return live
|
|
890
1179
|
}
|
|
891
1180
|
} finally {
|
|
@@ -976,6 +1265,7 @@ export class ChatApp {
|
|
|
976
1265
|
this.vp = viewport.create({ width: 0, height: Math.max(1, this.height - CHROME_ROWS) })
|
|
977
1266
|
this.spin = spinner.create({ fps: 10 })
|
|
978
1267
|
this.busy = false
|
|
1268
|
+
this._busySince = 0 // when busy last flipped on — the busy word's clock (see busyWord's slips)
|
|
979
1269
|
this.modelState = null // last 'model' event from the harness (loading/downloading/ready/unloading)
|
|
980
1270
|
this.status = ''
|
|
981
1271
|
this.notice = null // last /command output, rendered as a trailing transcript block
|
|
@@ -1018,6 +1308,7 @@ export class ChatApp {
|
|
|
1018
1308
|
this._chats = []
|
|
1019
1309
|
this._groups = []
|
|
1020
1310
|
this._chatsIterator = null
|
|
1311
|
+
this._ownDefaultIterator = null
|
|
1021
1312
|
this._turns = [] // last rendered turns — re-combined with the busy line on every render
|
|
1022
1313
|
// Derived from _turns on every _setTranscript, not bridged in from the
|
|
1023
1314
|
// harness — approval state lives entirely in the chunk stream (see
|
|
@@ -1084,14 +1375,29 @@ export class ChatApp {
|
|
|
1084
1375
|
return async () => {
|
|
1085
1376
|
try {
|
|
1086
1377
|
await firstWritable(this.engine)
|
|
1087
|
-
|
|
1378
|
+
// the pick the last session persisted; null on a fake engine that has no config
|
|
1379
|
+
const config = this.engine.getConfig ? await this.engine.getConfig({}) : null
|
|
1380
|
+
let agent = await firstAgent(
|
|
1381
|
+
this.engine,
|
|
1382
|
+
this.originDeviceId,
|
|
1383
|
+
this._modelName,
|
|
1384
|
+
config?.activeAgentId
|
|
1385
|
+
)
|
|
1088
1386
|
const isProvider = agent.providerDeviceId?.equals(this.originDeviceId) ?? false
|
|
1089
1387
|
if (isProvider && this._modelName) {
|
|
1090
1388
|
// Only set the model — scopes stay as the shared seed left them
|
|
1091
1389
|
agent = await this.engine.updateAgent({ id: agent.id, modelName: this._modelName })
|
|
1092
1390
|
}
|
|
1093
|
-
const chat = await firstChat(this.engine, agent, isProvider)
|
|
1094
|
-
|
|
1391
|
+
const chat = await firstChat(this.engine, agent, isProvider, config?.activeChatId)
|
|
1392
|
+
const agentRemembered = agent.id === config?.activeAgentId
|
|
1393
|
+
const chatRemembered = chat.id === config?.activeChatId
|
|
1394
|
+
// a remembered agent drives whichever chat it was left on (/agent use keeps the chat);
|
|
1395
|
+
// without one, the resumed chat runs under its own agent, as any switch does (_agentFor)
|
|
1396
|
+
if (chatRemembered && !agentRemembered && chat.agentId !== agent.id) {
|
|
1397
|
+
// getAgent throws for a deleted agent; the seed drives the chat then, as _agentFor does
|
|
1398
|
+
agent = await this.engine.getAgent({ id: chat.agentId }).catch(() => agent)
|
|
1399
|
+
}
|
|
1400
|
+
return { type: 'booted', agent, chat, remembered: agentRemembered || chatRemembered }
|
|
1095
1401
|
} catch (error) {
|
|
1096
1402
|
return { type: 'boot-error', error }
|
|
1097
1403
|
}
|
|
@@ -1168,6 +1474,26 @@ export class ChatApp {
|
|
|
1168
1474
|
}
|
|
1169
1475
|
}
|
|
1170
1476
|
|
|
1477
|
+
// a joiner boots onto whatever agent the room holds; its own default is seeded after the join
|
|
1478
|
+
_watchOwnDefault() {
|
|
1479
|
+
if (!this.engine.agentsWatch || isOwnDefault(this.agent, this.originDeviceId)) return null
|
|
1480
|
+
const gen = this.gen
|
|
1481
|
+
const booted = this.agent?.id
|
|
1482
|
+
const it = this.engine.agentsWatch({})[Symbol.asyncIterator]()
|
|
1483
|
+
this._ownDefaultIterator = it
|
|
1484
|
+
return async () => {
|
|
1485
|
+
while (true) {
|
|
1486
|
+
const { value, done } = await it.next()
|
|
1487
|
+
if (done) return { type: 'own-default', gen, booted, agent: null }
|
|
1488
|
+
const agent = ownDefault(value.agents ?? [], this.originDeviceId)
|
|
1489
|
+
if (agent) {
|
|
1490
|
+
await it.return?.()
|
|
1491
|
+
return { type: 'own-default', gen, booted, agent }
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1171
1497
|
// Device names for the per-device user labels — same re-arm/stale-guard
|
|
1172
1498
|
// shape as the other watch loops. Null when the engine lacks the
|
|
1173
1499
|
// capability (e.g. a headless test fake).
|
|
@@ -1237,6 +1563,7 @@ export class ChatApp {
|
|
|
1237
1563
|
if (lastTurn?.from === 'agent') this._awaitingRun = false
|
|
1238
1564
|
const wasBusy = this.busy
|
|
1239
1565
|
this.busy = running || this._awaitingRun
|
|
1566
|
+
if (this.busy && !wasBusy) this._busySince = Date.now()
|
|
1240
1567
|
// The most recent run's id, for _requestStop() below to stopRun() —
|
|
1241
1568
|
// undefined once nothing is running.
|
|
1242
1569
|
this._runningRunId = this.busy ? (lastChunk?.runId ?? this._runningRunId) : null
|
|
@@ -1263,7 +1590,7 @@ export class ChatApp {
|
|
|
1263
1590
|
if (this.pendingApproval) return null
|
|
1264
1591
|
if (!this.busy) return null
|
|
1265
1592
|
const runTurn = runningAgentTurn(this._turns)
|
|
1266
|
-
const { text, on } = busyStatus(this.modelState, runTurn)
|
|
1593
|
+
const { text, on } = busyStatus(this.modelState, runTurn, Date.now() - this._busySince)
|
|
1267
1594
|
const where =
|
|
1268
1595
|
on === 'local'
|
|
1269
1596
|
? this._deviceName(this.originDeviceId?.toString('hex'))
|
|
@@ -1394,13 +1721,16 @@ export class ChatApp {
|
|
|
1394
1721
|
' /group order <group> after <group>|first — reorder the groups themselves',
|
|
1395
1722
|
' /knowledge [list] · /knowledge add <file> · /knowledge add-dir <directory> · /knowledge download <n|id> · /knowledge remove <n|id>',
|
|
1396
1723
|
' /files — show upload progress, local readiness, and failures for this chat',
|
|
1724
|
+
' /compact — fold the older turns of this chat into a summary now (what a full context window triggers on its own); the notice shows the summary or why the fold was refused',
|
|
1725
|
+
' /usage — this chat’s context usage as the last run reported it: the window, how much of it is in use, and what the prompt spends it on (conversation, system prompt, agent instructions, skills, tools)',
|
|
1397
1726
|
' /attach <path> [<path> …] — attach local files to this chat (quote paths that contain spaces)',
|
|
1398
1727
|
' /save [n] — download the latest (or n-th) attachment to ~/Downloads',
|
|
1399
1728
|
' /export [n] — write the last run (or last n) to a markdown file: prompt, thinking, answer, tools',
|
|
1400
1729
|
'',
|
|
1401
1730
|
'Agent',
|
|
1402
|
-
' /agents — pick from your agents to switch (interactive) · /agent — show current · /agent list · /agent new <name> · /agent rename <name> · /agent use <name|id>',
|
|
1731
|
+
' /agents — pick from your agents to switch (interactive) · /agent — show current · /agent list · /agent new <name> · /agent rename <name> · /agent use <name|id> · /agent borrow [none] - borrow the model from the compute mesh, or stop',
|
|
1403
1732
|
" /activity — list the active agent's recent tool calls, each with its decision (allowed/denied/auto/skip-all/blocked)",
|
|
1733
|
+
' /ctx — pick the agent’s context size (the current one and the model’s maximum shown) · /ctx <tokens> (8192, 8k; k = 1,024) · /ctx auto — clear it so the device default applies',
|
|
1404
1734
|
' /skills · /tools — browse installed; ↑/↓ move, space toggles each on/off (sets scope=selected), enter sets up or reconfigures the skill, esc returns',
|
|
1405
1735
|
' /skill on|off <name> · /tool on|off <name> — toggle (sets scope=selected)',
|
|
1406
1736
|
' /permissions — approval mode + the toolset switches; ↑/↓ move, space toggles',
|
|
@@ -1424,8 +1754,9 @@ export class ChatApp {
|
|
|
1424
1754
|
' /cred <key> <value> — set a credential by hand for this agent (e.g. /cred github_access_token ghp_…); /skills, enter on the skill, fills this in for you',
|
|
1425
1755
|
' /scope skills|tools all|selected — switch scope',
|
|
1426
1756
|
' /join <qvac://mesh/…> — retire this device’s mesh and join that one (ctrl+y copies this mesh’s invite) · /join cancel — abort a join in progress',
|
|
1757
|
+
' /leave — leave the active mesh; the device lands on another mesh it can write to, or mints a fresh account',
|
|
1427
1758
|
' /invite - show this mesh device invite · /invite member - open your shared room and invite someone into it (your account is never shared)',
|
|
1428
|
-
' /mesh new - open another shared room · /mesh label <n|id> <name> - name a room, privately to you',
|
|
1759
|
+
' /mesh new - open another shared room · /mesh new compute - lend this device · /mesh label <n|id> <name> - name a room, privately to you',
|
|
1429
1760
|
' /members — list mesh members with their devices grouped',
|
|
1430
1761
|
' /meshes - list the meshes this device belongs to, numbered, marking account / shared / active / open / writable',
|
|
1431
1762
|
' /mesh use <n|id> - make one of them active; its agent, chat and roster replace the ones on screen',
|
|
@@ -1459,8 +1790,38 @@ export class ChatApp {
|
|
|
1459
1790
|
|
|
1460
1791
|
if (cmd === 'new-chat') return this._newChat('New Chat')
|
|
1461
1792
|
|
|
1793
|
+
if (cmd === 'compact') {
|
|
1794
|
+
if (rawArgs.trim()) return notice('usage: /compact')
|
|
1795
|
+
if (this.busy) return notice('a run is in flight — /compact once it has finished')
|
|
1796
|
+
return run(async () => {
|
|
1797
|
+
const result = await engine.compactChat({ id: this.chatId })
|
|
1798
|
+
if (!result.compacted) return `not compacted: ${result.reason ?? 'unknown reason'}`
|
|
1799
|
+
const { chunks } = await engine.listChunks({ chatId: this.chatId, type: 'compaction' })
|
|
1800
|
+
const summary = chunks?.at(-1)?.compaction?.summary ?? ''
|
|
1801
|
+
return `compacted ${result.foldedTurns} turn(s) into:\n${summary}`
|
|
1802
|
+
})
|
|
1803
|
+
}
|
|
1804
|
+
|
|
1462
1805
|
if (cmd === 'my-device') return this._showDiagnostics()
|
|
1463
1806
|
|
|
1807
|
+
if (cmd === 'usage') {
|
|
1808
|
+
if (rawArgs.trim()) return notice('usage: /usage')
|
|
1809
|
+
return this._showUsage()
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
if (cmd === 'ctx') {
|
|
1813
|
+
const raw = rest[0]?.toLowerCase()
|
|
1814
|
+
if (!raw) return this._showContextSizes()
|
|
1815
|
+
const max = maxContextForModel(agent.modelName ?? '')
|
|
1816
|
+
const size = raw === 'auto' ? 0 : parseTokenCount(raw)
|
|
1817
|
+
if (rest.length > 1 || size === null || size > max) {
|
|
1818
|
+
return notice(
|
|
1819
|
+
`usage: /ctx · /ctx <tokens>|auto — up to ${formatTokenCount(max)} for ${agent.modelName ?? 'this model'}`
|
|
1820
|
+
)
|
|
1821
|
+
}
|
|
1822
|
+
return this._setContextSize(size)
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1464
1825
|
if (cmd === 'models') {
|
|
1465
1826
|
const raw = rest[0]?.toLowerCase()
|
|
1466
1827
|
if (!raw) return this._showModels(null)
|
|
@@ -1535,7 +1896,10 @@ export class ChatApp {
|
|
|
1535
1896
|
if (!action) {
|
|
1536
1897
|
return run(async () => {
|
|
1537
1898
|
const a = await engine.getAgent({ id: agent.id })
|
|
1538
|
-
|
|
1899
|
+
const lender = a.lenderDeviceId
|
|
1900
|
+
? ` · model borrowed from ${a.lenderDeviceId.toString('hex').slice(0, 8)}`
|
|
1901
|
+
: ''
|
|
1902
|
+
return `agent ${a.name} (${a.id.slice(0, 8)}) · skills=${a.skillsScope ?? 'all'} tools=${a.toolsScope ?? 'all'}${lender}`
|
|
1539
1903
|
})
|
|
1540
1904
|
}
|
|
1541
1905
|
if (action === 'list') {
|
|
@@ -1556,6 +1920,7 @@ export class ChatApp {
|
|
|
1556
1920
|
modelName: agent.modelName
|
|
1557
1921
|
})
|
|
1558
1922
|
this.agent = created
|
|
1923
|
+
await this._persistSelection()
|
|
1559
1924
|
return `created + selected ${created.name} (${created.id.slice(0, 8)}) · no skills/tools enabled`
|
|
1560
1925
|
})
|
|
1561
1926
|
}
|
|
@@ -1566,6 +1931,21 @@ export class ChatApp {
|
|
|
1566
1931
|
return `renamed to ${this.agent.name} (${this.agent.id.slice(0, 8)})`
|
|
1567
1932
|
})
|
|
1568
1933
|
}
|
|
1934
|
+
if (action === 'borrow') {
|
|
1935
|
+
return run(async () => {
|
|
1936
|
+
if (arg === 'none') {
|
|
1937
|
+
this.agent = await engine.updateAgent({ id: agent.id, clearLenderDeviceId: true })
|
|
1938
|
+
return `${this.agent.name} answers on this device again`
|
|
1939
|
+
}
|
|
1940
|
+
if (arg) return 'usage: /agent borrow · /agent borrow none'
|
|
1941
|
+
const { computeLenderId } = await engine.deviceInfo({})
|
|
1942
|
+
if (!computeLenderId) {
|
|
1943
|
+
return 'no single device to borrow from - /mesh new compute lends one, and two lenders is no choice'
|
|
1944
|
+
}
|
|
1945
|
+
this.agent = await engine.updateAgent({ id: agent.id, lenderDeviceId: computeLenderId })
|
|
1946
|
+
return `${this.agent.name} borrows its model from ${computeLenderId.toString('hex').slice(0, 8)}`
|
|
1947
|
+
})
|
|
1948
|
+
}
|
|
1569
1949
|
if (action === 'use') {
|
|
1570
1950
|
if (!arg) return notice('usage: /agent use <name|id>')
|
|
1571
1951
|
return run(async () => {
|
|
@@ -1573,10 +1953,11 @@ export class ChatApp {
|
|
|
1573
1953
|
const found = agents.find((a) => a.id === arg || a.id.startsWith(arg) || a.name === arg)
|
|
1574
1954
|
if (!found) return `no agent matching: ${arg}`
|
|
1575
1955
|
this.agent = found
|
|
1956
|
+
await this._persistSelection()
|
|
1576
1957
|
return `selected ${found.name} (${found.id.slice(0, 8)})`
|
|
1577
1958
|
})
|
|
1578
1959
|
}
|
|
1579
|
-
return notice('usage: /agent [list|new <name>|rename <name>|use <name|id
|
|
1960
|
+
return notice('usage: /agent [list|new <name>|rename <name>|use <name|id>|borrow [none]]')
|
|
1580
1961
|
}
|
|
1581
1962
|
|
|
1582
1963
|
if (cmd === 'activity') {
|
|
@@ -1981,7 +2362,7 @@ export class ChatApp {
|
|
|
1981
2362
|
if (cmd === 'join') {
|
|
1982
2363
|
const arg = rawArgs.trim()
|
|
1983
2364
|
if (!arg) return notice('usage: /join <qvac://mesh/…> · /join cancel')
|
|
1984
|
-
if (
|
|
2365
|
+
if (rest[0] === 'cancel') {
|
|
1985
2366
|
return run(async () => {
|
|
1986
2367
|
await engine.cancelMeshJoin({})
|
|
1987
2368
|
return 'join canceled'
|
|
@@ -1997,7 +2378,7 @@ export class ChatApp {
|
|
|
1997
2378
|
async () => {
|
|
1998
2379
|
try {
|
|
1999
2380
|
await engine.joinMesh({ invite })
|
|
2000
|
-
const next = await engine.meshInvite({}).catch(
|
|
2381
|
+
const next = await engine.meshInvite({}).catch(noop)
|
|
2001
2382
|
return { type: 'mesh.joined', invite: next?.invite ?? null }
|
|
2002
2383
|
} catch (error) {
|
|
2003
2384
|
return { type: 'mesh.joined', error }
|
|
@@ -2006,6 +2387,27 @@ export class ChatApp {
|
|
|
2006
2387
|
]
|
|
2007
2388
|
}
|
|
2008
2389
|
|
|
2390
|
+
if (cmd === 'leave') {
|
|
2391
|
+
if (rawArgs.trim()) return notice('usage: /leave')
|
|
2392
|
+
// the menu bypasses _submit's block, and the refusal below would drop a parked join's
|
|
2393
|
+
if (this._booting) return notice('a mesh transition is already in flight')
|
|
2394
|
+
this._booting = true
|
|
2395
|
+
this.status = 'leaving mesh…'
|
|
2396
|
+
this.notice = null
|
|
2397
|
+
return [
|
|
2398
|
+
this,
|
|
2399
|
+
async () => {
|
|
2400
|
+
try {
|
|
2401
|
+
await engine.leaveMesh({})
|
|
2402
|
+
const next = await engine.meshInvite({}).catch(noop)
|
|
2403
|
+
return { type: 'mesh.left', invite: next?.invite ?? null }
|
|
2404
|
+
} catch (error) {
|
|
2405
|
+
return { type: 'mesh.left', error }
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2408
|
+
]
|
|
2409
|
+
}
|
|
2410
|
+
|
|
2009
2411
|
if (cmd === 'invite') {
|
|
2010
2412
|
const member = rest[0] === 'member'
|
|
2011
2413
|
const target = member ? rest[1] : null
|
|
@@ -2029,7 +2431,9 @@ export class ChatApp {
|
|
|
2029
2431
|
}
|
|
2030
2432
|
const lines = [await this._roomHeading(res.meshId)]
|
|
2031
2433
|
if (res.notice) lines.push(res.notice)
|
|
2032
|
-
|
|
2434
|
+
const { meshes: listed } = await engine.listMeshes({}).catch(() => ({ meshes: [] }))
|
|
2435
|
+
const isCompute = (listed ?? []).find((m) => m.meshId === res.meshId)?.compute
|
|
2436
|
+
lines.push(...(isCompute ? COMPUTE_INVITE_DISCLOSURES : MEMBER_INVITE_DISCLOSURES))
|
|
2033
2437
|
lines.push(`${copied ? 'invite (copied)' : 'invite'}:\n${res.invite}`)
|
|
2034
2438
|
return lines.join('\n')
|
|
2035
2439
|
})
|
|
@@ -2047,7 +2451,7 @@ export class ChatApp {
|
|
|
2047
2451
|
const lines = []
|
|
2048
2452
|
for (const m of members) {
|
|
2049
2453
|
const hex = m.id.toString('hex')
|
|
2050
|
-
lines.push(`${m.name} (${hex.slice(0, 8)})`)
|
|
2454
|
+
lines.push(`${m.name} (${hex.slice(0, 8)})${m.removed ? ' (removed)' : ''}`)
|
|
2051
2455
|
for (const d of devices) {
|
|
2052
2456
|
if (d.memberId?.toString('hex') !== hex) continue
|
|
2053
2457
|
lines.push(` · ${d.name}${d.revoked ? ' (revoked)' : ''}`)
|
|
@@ -2076,9 +2480,11 @@ export class ChatApp {
|
|
|
2076
2480
|
const [action, target, ...labelParts] = rest
|
|
2077
2481
|
if (action === 'use' && target) return this._selectMesh(target)
|
|
2078
2482
|
if (action === 'new') {
|
|
2483
|
+
const compute = target === 'compute'
|
|
2079
2484
|
return run(async () => {
|
|
2080
|
-
const { meshId } = await engine.createRoom({})
|
|
2081
|
-
|
|
2485
|
+
const { meshId } = await engine.createRoom({ compute })
|
|
2486
|
+
const invite = '/invite member <n|id> invites someone into it'
|
|
2487
|
+
return `${await this._roomHeading(meshId)}\n${invite}`
|
|
2082
2488
|
})
|
|
2083
2489
|
}
|
|
2084
2490
|
if (action === 'label' && target) {
|
|
@@ -2091,7 +2497,7 @@ export class ChatApp {
|
|
|
2091
2497
|
return `${named.meshId.slice(0, 8)} is "${label}" to you - the room co-members never see it`
|
|
2092
2498
|
})
|
|
2093
2499
|
}
|
|
2094
|
-
return notice('usage: /mesh use <n|id> · /mesh new · /mesh label <n|id> <name>')
|
|
2500
|
+
return notice('usage: /mesh use <n|id> · /mesh new [compute] · /mesh label <n|id> <name>')
|
|
2095
2501
|
}
|
|
2096
2502
|
|
|
2097
2503
|
// /chats + /agents open the same interactive pickers as the menu's Switch
|
|
@@ -2340,7 +2746,8 @@ export class ChatApp {
|
|
|
2340
2746
|
// not whichever one happens to be active (else _submit() runs the wrong provider).
|
|
2341
2747
|
async _agentFor(chat) {
|
|
2342
2748
|
if (chat.agentId === this.agent.id) return this.agent
|
|
2343
|
-
|
|
2749
|
+
// getAgent throws for a deleted agent; the active one drives the chat then
|
|
2750
|
+
return this.engine.getAgent({ id: chat.agentId }).catch(() => this.agent)
|
|
2344
2751
|
}
|
|
2345
2752
|
|
|
2346
2753
|
_newChat(title) {
|
|
@@ -2423,6 +2830,8 @@ export class ChatApp {
|
|
|
2423
2830
|
_resetMeshWatches() {
|
|
2424
2831
|
this._devicesIterator?.return?.().catch(() => {})
|
|
2425
2832
|
this._devicesIterator = null
|
|
2833
|
+
this._ownDefaultIterator?.return?.().catch(() => {})
|
|
2834
|
+
this._ownDefaultIterator = null
|
|
2426
2835
|
this.deviceLabels = new Map()
|
|
2427
2836
|
this.deviceMembers = new Map()
|
|
2428
2837
|
this.memberNames = new Map()
|
|
@@ -2445,7 +2854,7 @@ export class ChatApp {
|
|
|
2445
2854
|
return { type: 'mesh.selected', text: `already on mesh ${mesh.meshId.slice(0, 8)}` }
|
|
2446
2855
|
}
|
|
2447
2856
|
await this.engine.selectMesh({ meshId: mesh.meshId })
|
|
2448
|
-
const next = await this.engine.meshInvite({}).catch(
|
|
2857
|
+
const next = await this.engine.meshInvite({}).catch(noop)
|
|
2449
2858
|
return { type: 'mesh.selected', meshId: mesh.meshId, invite: next?.invite ?? null }
|
|
2450
2859
|
} catch (error) {
|
|
2451
2860
|
return { type: 'mesh.selected', error }
|
|
@@ -2474,6 +2883,25 @@ export class ChatApp {
|
|
|
2474
2883
|
return batch(...[this._watchNextDevices(), this._bootstrap()].filter(Boolean))
|
|
2475
2884
|
}
|
|
2476
2885
|
|
|
2886
|
+
// The pick outlives the session in Core's device-local config — the same record the desktop
|
|
2887
|
+
// app resumes from. A fake engine without config, or a pick not yet resolved, has nothing to keep.
|
|
2888
|
+
async _persistSelection() {
|
|
2889
|
+
if (!this.engine.getConfig || !this.agent || !this.chatId) return
|
|
2890
|
+
await rememberSelection(this.engine, { agentId: this.agent.id, chatId: this.chatId })
|
|
2891
|
+
}
|
|
2892
|
+
|
|
2893
|
+
_rememberSelection() {
|
|
2894
|
+
if (!this.engine.getConfig) return null
|
|
2895
|
+
return async () => {
|
|
2896
|
+
try {
|
|
2897
|
+
await this._persistSelection()
|
|
2898
|
+
return { type: 'selection.remembered' }
|
|
2899
|
+
} catch (error) {
|
|
2900
|
+
return { type: 'run.error', error }
|
|
2901
|
+
}
|
|
2902
|
+
}
|
|
2903
|
+
}
|
|
2904
|
+
|
|
2477
2905
|
// Swap the active chat: drop the old chat's watches, adopt the chat's owning
|
|
2478
2906
|
// agent, clear the transcript + run state, and re-arm on the new chatId.
|
|
2479
2907
|
_switchTo(chat, agent) {
|
|
@@ -2601,6 +3029,27 @@ export class ChatApp {
|
|
|
2601
3029
|
]
|
|
2602
3030
|
}
|
|
2603
3031
|
|
|
3032
|
+
// /usage: the chat's run statuses carry the last run's own numbers; the folds say why they dropped
|
|
3033
|
+
_showUsage() {
|
|
3034
|
+
const { engine, chatId } = this
|
|
3035
|
+
return [
|
|
3036
|
+
this,
|
|
3037
|
+
async () => {
|
|
3038
|
+
try {
|
|
3039
|
+
const [statuses, folds, chat] = await Promise.all([
|
|
3040
|
+
engine.listChunks({ chatId, type: 'run-status' }),
|
|
3041
|
+
engine.listChunks({ chatId, type: 'compaction' }),
|
|
3042
|
+
engine.getChat({ id: chatId })
|
|
3043
|
+
])
|
|
3044
|
+
const report = usageReport(statuses.chunks ?? [], folds.chunks ?? [])
|
|
3045
|
+
return { type: 'usage.result', report, title: chat.title }
|
|
3046
|
+
} catch (error) {
|
|
3047
|
+
return { type: 'usage.result', error }
|
|
3048
|
+
}
|
|
3049
|
+
}
|
|
3050
|
+
]
|
|
3051
|
+
}
|
|
3052
|
+
|
|
2604
3053
|
// /models [type]: fetch the full SDK registry via the Engine RPC (both
|
|
2605
3054
|
// topologies wire harness.list into Core.listModels) and overlay it. Always
|
|
2606
3055
|
// fullRegistry — the curated subset was a second command (/all-sdk-models);
|
|
@@ -2658,10 +3107,59 @@ export class ChatApp {
|
|
|
2658
3107
|
// (pre-upgrade provider) — the selector then renders as it always did.
|
|
2659
3108
|
async _skillDetail() {
|
|
2660
3109
|
if (!this._skills) return null
|
|
2661
|
-
const skills = await this._skills(this.agent?.id, this.agent?.modelName).catch(
|
|
3110
|
+
const skills = await this._skills(this.agent?.id, this.agent?.modelName).catch(noop)
|
|
2662
3111
|
return skills ? new Map(skills.map((skill) => [skill.name, skill])) : null
|
|
2663
3112
|
}
|
|
2664
3113
|
|
|
3114
|
+
// The rows are the model's own catalog options, so a size it cannot load never shows.
|
|
3115
|
+
_showContextSizes() {
|
|
3116
|
+
const { engine, agent } = this
|
|
3117
|
+
return [
|
|
3118
|
+
this,
|
|
3119
|
+
async () => {
|
|
3120
|
+
try {
|
|
3121
|
+
const fresh = await engine.getAgent({ id: agent.id })
|
|
3122
|
+
const model = fresh.modelName ?? ''
|
|
3123
|
+
return {
|
|
3124
|
+
type: 'ctx.result',
|
|
3125
|
+
model,
|
|
3126
|
+
options: contextOptionsForModel(model),
|
|
3127
|
+
current: fresh.ctxSize || 0,
|
|
3128
|
+
max: maxContextForModel(model),
|
|
3129
|
+
defaultSize: defaultContextForModel(model)
|
|
3130
|
+
}
|
|
3131
|
+
} catch (error) {
|
|
3132
|
+
return { type: 'ctx.result', error }
|
|
3133
|
+
}
|
|
3134
|
+
}
|
|
3135
|
+
]
|
|
3136
|
+
}
|
|
3137
|
+
|
|
3138
|
+
// 0 clears the agent's own size, so the device default (and past it the harness) applies again
|
|
3139
|
+
_setContextSize(size) {
|
|
3140
|
+
const { engine, agent } = this
|
|
3141
|
+
const patch = size ? { ctxSize: size } : { clearCtxSize: true }
|
|
3142
|
+
return [
|
|
3143
|
+
this,
|
|
3144
|
+
async () => {
|
|
3145
|
+
try {
|
|
3146
|
+
this.agent = await engine.updateAgent({ id: agent.id, ...patch })
|
|
3147
|
+
return { type: 'notice', text: contextSizeNotice(this.agent, size) }
|
|
3148
|
+
} catch (error) {
|
|
3149
|
+
return { type: 'run.error', error }
|
|
3150
|
+
}
|
|
3151
|
+
}
|
|
3152
|
+
]
|
|
3153
|
+
}
|
|
3154
|
+
|
|
3155
|
+
// one value, not a set: the pick closes the overlay and the notice says what landed
|
|
3156
|
+
_pickContextSize(s) {
|
|
3157
|
+
const size = s.rows[s.cursor]
|
|
3158
|
+
this._selector = null
|
|
3159
|
+
this._render()
|
|
3160
|
+
return this._setContextSize(size)
|
|
3161
|
+
}
|
|
3162
|
+
|
|
2665
3163
|
// The PRD's Tools screen: the approval mode on top, then the toolset switches. Rows come
|
|
2666
3164
|
// from TOOLSETS, not the provider catalog — a toolset with nothing installed here still shows,
|
|
2667
3165
|
// so it can be switched off before the agent ever runs somewhere that has it.
|
|
@@ -2723,6 +3221,7 @@ export class ChatApp {
|
|
|
2723
3221
|
{ label: 'Tools', hint: 'toggle tools on/off', overlay: 'tools' },
|
|
2724
3222
|
{ label: 'Permissions', hint: 'approval mode & toolsets', overlay: 'permissions' },
|
|
2725
3223
|
{ label: 'Model', hint: "pick the agent's model", overlay: 'models' },
|
|
3224
|
+
{ label: 'Context size', hint: contextSizeHint(this.agent), overlay: 'ctx' },
|
|
2726
3225
|
{ label: 'Image defaults', hint: 'model, steps, size', command: '/image' },
|
|
2727
3226
|
{ label: 'Activity', hint: 'recent tool calls', command: '/activity' },
|
|
2728
3227
|
{
|
|
@@ -2814,6 +3313,8 @@ export class ChatApp {
|
|
|
2814
3313
|
{ label: 'Move to group…', hint: '/group move <group>|-', prefill: '/group move ' },
|
|
2815
3314
|
{ label: 'New group…', hint: '/group new <name>', prefill: '/group new ' },
|
|
2816
3315
|
{ label: 'Knowledge', hint: 'list chat knowledge', command: '/knowledge' },
|
|
3316
|
+
{ label: 'Usage', hint: 'the context window: how full, and on what', command: '/usage' },
|
|
3317
|
+
{ label: 'Compact', hint: 'fold older turns into a summary now', command: '/compact' },
|
|
2817
3318
|
{ label: 'Files', hint: 'readiness, progress, and failures', command: '/files' },
|
|
2818
3319
|
{ label: 'Attach file…', hint: '/attach <path>', prefill: '/attach ' },
|
|
2819
3320
|
{ label: 'Save attachment', hint: 'latest → save dir', command: '/save' },
|
|
@@ -2830,6 +3331,7 @@ export class ChatApp {
|
|
|
2830
3331
|
{ label: 'Meshes', hint: 'the meshes this device belongs to', command: '/meshes' },
|
|
2831
3332
|
{ label: 'Switch mesh…', hint: '/mesh use <n|id>', prefill: '/mesh use ' },
|
|
2832
3333
|
{ label: 'Join mesh…', hint: '/join <qvac://mesh/…>', prefill: '/join ' },
|
|
3334
|
+
{ label: 'Leave mesh', hint: 'leave the active mesh', command: '/leave' },
|
|
2833
3335
|
{ label: 'Cancel join', hint: 'abort a join in progress', command: '/join cancel' }
|
|
2834
3336
|
]
|
|
2835
3337
|
}
|
|
@@ -2974,6 +3476,7 @@ export class ChatApp {
|
|
|
2974
3476
|
if (entry.overlay === 'models') return this._showModels(null)
|
|
2975
3477
|
if (entry.overlay === 'diagnostics') return this._showDiagnostics()
|
|
2976
3478
|
if (entry.overlay === 'permissions') return this._showPermissions()
|
|
3479
|
+
if (entry.overlay === 'ctx') return this._showContextSizes()
|
|
2977
3480
|
return this._showSelector(entry.overlay)
|
|
2978
3481
|
}
|
|
2979
3482
|
if (entry.prefill) {
|
|
@@ -3123,6 +3626,7 @@ export class ChatApp {
|
|
|
3123
3626
|
// Optimistic: the row updates now, the engine call syncs this.agent after.
|
|
3124
3627
|
_toggleSelector() {
|
|
3125
3628
|
const s = this._selector
|
|
3629
|
+
if (s.kind === 'ctx') return this._pickContextSize(s)
|
|
3126
3630
|
const name = s.rows[s.cursor]
|
|
3127
3631
|
if (!name) return [this, null]
|
|
3128
3632
|
if (s.kind === 'permissions') return this._togglePermission(s, name)
|
|
@@ -3156,6 +3660,7 @@ export class ChatApp {
|
|
|
3156
3660
|
// prints its steps. The overlay closes either way — the setup is the next step.
|
|
3157
3661
|
_setupSelected() {
|
|
3158
3662
|
const s = this._selector
|
|
3663
|
+
if (s.kind === 'ctx') return this._pickContextSize(s)
|
|
3159
3664
|
if (s.kind !== 'skills' || !s.detail) return [this, null]
|
|
3160
3665
|
const skill = s.detail.get(s.rows[s.cursor])
|
|
3161
3666
|
if (!skill) return [this, null]
|
|
@@ -3714,7 +4219,7 @@ export class ChatApp {
|
|
|
3714
4219
|
|
|
3715
4220
|
if (msg.type === 'chat.switch') {
|
|
3716
4221
|
this._switchTo(msg.chat, msg.agent)
|
|
3717
|
-
return [this, batch(this._watchNext(), this._watchNextFiles())]
|
|
4222
|
+
return [this, batch(this._watchNext(), this._watchNextFiles(), this._rememberSelection())]
|
|
3718
4223
|
}
|
|
3719
4224
|
|
|
3720
4225
|
// /join settled. The joined mesh brings its own agents and chats, so this
|
|
@@ -3731,6 +4236,19 @@ export class ChatApp {
|
|
|
3731
4236
|
return [this, this._adoptMesh(msg.invite, 'joined — resolving the mesh’s agent and chat…')]
|
|
3732
4237
|
}
|
|
3733
4238
|
|
|
4239
|
+
if (msg.type === 'mesh.left') {
|
|
4240
|
+
if (msg.error) {
|
|
4241
|
+
this._booting = false
|
|
4242
|
+
this.status = fg.err.render(`leave failed: ${msg.error.message}`)
|
|
4243
|
+
this._render()
|
|
4244
|
+
return [this, null]
|
|
4245
|
+
}
|
|
4246
|
+
return [
|
|
4247
|
+
this,
|
|
4248
|
+
this._adoptMesh(msg.invite, 'left — resolving the landing mesh’s agent and chat…')
|
|
4249
|
+
]
|
|
4250
|
+
}
|
|
4251
|
+
|
|
3734
4252
|
// /mesh use settled. Same landing as a join, minus the admission: the target
|
|
3735
4253
|
// mesh was already ours, so only the agent, chat and roster have to catch up.
|
|
3736
4254
|
if (msg.type === 'mesh.selected') {
|
|
@@ -3766,13 +4284,30 @@ export class ChatApp {
|
|
|
3766
4284
|
this.chatId = msg.chat.id
|
|
3767
4285
|
this._booting = false
|
|
3768
4286
|
this._render()
|
|
3769
|
-
|
|
4287
|
+
// a remembered pick is the user's, so the seeded default must not move them off it
|
|
4288
|
+
const seed = msg.remembered ? null : this._watchOwnDefault()
|
|
4289
|
+
return [
|
|
4290
|
+
this,
|
|
4291
|
+
batch(this._watchNext(), this._watchNextFiles(), seed, this._rememberSelection())
|
|
4292
|
+
]
|
|
3770
4293
|
}
|
|
3771
4294
|
if (msg.type === 'boot-error') {
|
|
3772
4295
|
this.status = fg.err.render(`startup failed: ${msg.error.message}`)
|
|
3773
4296
|
this._render()
|
|
3774
4297
|
return [this, null]
|
|
3775
4298
|
}
|
|
4299
|
+
if (msg.type === 'own-default') {
|
|
4300
|
+
// a stale one-shot must not clear the field a newer watch owns
|
|
4301
|
+
if (msg.gen !== this.gen) return [this, null]
|
|
4302
|
+
this._ownDefaultIterator = null
|
|
4303
|
+
if (!msg.agent) return [this, null]
|
|
4304
|
+
// the seed lands whenever it replicates, and a /agent pick since the watch armed outranks it
|
|
4305
|
+
if (msg.booted !== this.agent?.id) return [this, null]
|
|
4306
|
+
this.agent = msg.agent
|
|
4307
|
+
this.notice = `selected ${msg.agent.name} (${msg.agent.id.slice(0, 8)}) · this device's default`
|
|
4308
|
+
this._render()
|
|
4309
|
+
return [this, this._rememberSelection()]
|
|
4310
|
+
}
|
|
3776
4311
|
|
|
3777
4312
|
if (msg.type === 'mesh-status') {
|
|
3778
4313
|
if (msg.gen !== this.gen) return [this, null]
|
|
@@ -3830,6 +4365,19 @@ export class ChatApp {
|
|
|
3830
4365
|
return [this, null]
|
|
3831
4366
|
}
|
|
3832
4367
|
|
|
4368
|
+
if (msg.type === 'usage.result') {
|
|
4369
|
+
this._models = null
|
|
4370
|
+
this._selector = null
|
|
4371
|
+
this.overlay = msg.error
|
|
4372
|
+
? [fg.err.render(`/usage failed: ${msg.error.message}`)]
|
|
4373
|
+
: formatUsage(msg.report, {
|
|
4374
|
+
title: msg.title,
|
|
4375
|
+
deviceLabel: this._deviceName(msg.report?.last.deviceId)
|
|
4376
|
+
})
|
|
4377
|
+
this._render()
|
|
4378
|
+
return [this, null]
|
|
4379
|
+
}
|
|
4380
|
+
|
|
3833
4381
|
// /models resolved: an interactive overlay (↑/↓ + enter to adopt a model)
|
|
3834
4382
|
// until esc; a rejection is a static err line instead of a silent dismiss.
|
|
3835
4383
|
if (msg.type === 'models.result') {
|
|
@@ -3889,6 +4437,29 @@ export class ChatApp {
|
|
|
3889
4437
|
this._render()
|
|
3890
4438
|
return [this, null]
|
|
3891
4439
|
}
|
|
4440
|
+
if (msg.type === 'ctx.result') {
|
|
4441
|
+
if (msg.error) {
|
|
4442
|
+
this._selector = null
|
|
4443
|
+
this.overlay = [fg.err.render(`/ctx failed: ${msg.error.message}`)]
|
|
4444
|
+
} else {
|
|
4445
|
+
this._models = null
|
|
4446
|
+
this.overlay = null
|
|
4447
|
+
// an agent with no size of its own runs at the default, so that is the row in use
|
|
4448
|
+
const inUse = msg.current || msg.defaultSize
|
|
4449
|
+
this._selector = {
|
|
4450
|
+
kind: 'ctx',
|
|
4451
|
+
rows: msg.options,
|
|
4452
|
+
model: msg.model,
|
|
4453
|
+
current: msg.current,
|
|
4454
|
+
inUse,
|
|
4455
|
+
max: msg.max,
|
|
4456
|
+
defaultSize: msg.defaultSize,
|
|
4457
|
+
cursor: Math.max(0, msg.options.indexOf(inUse))
|
|
4458
|
+
}
|
|
4459
|
+
}
|
|
4460
|
+
this._render()
|
|
4461
|
+
return [this, null]
|
|
4462
|
+
}
|
|
3892
4463
|
if (msg.type === 'selector.saved') return [this, null] // the toggle already re-rendered; sync only
|
|
3893
4464
|
|
|
3894
4465
|
// A fetched menu page resolved. From a menu row (menu open) it drills in as a
|
|
@@ -4055,13 +4626,13 @@ export class ChatApp {
|
|
|
4055
4626
|
return [this, null]
|
|
4056
4627
|
}
|
|
4057
4628
|
|
|
4058
|
-
// Enter runs the highlighted palette row
|
|
4059
|
-
//
|
|
4060
|
-
// came from history — the typed line is authoritative and submits verbatim.
|
|
4629
|
+
// Enter runs the highlighted palette row while the user is still choosing — the typed
|
|
4630
|
+
// line is a prefix of that row, `/chat n` for `/chat new`; once an argument follows — or
|
|
4631
|
+
// the line came from history — the typed line is authoritative and submits verbatim.
|
|
4061
4632
|
if (key.matches(msg, 'enter')) {
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
}
|
|
4633
|
+
const pick = matches[Math.min(this._paletteAt, matches.length - 1)]
|
|
4634
|
+
const typed = this.input.value.trim().slice(1).toLowerCase()
|
|
4635
|
+
if (inPalette && pick.name.startsWith(typed)) this._setInput(`/${pick.name}`)
|
|
4065
4636
|
return this._submit()
|
|
4066
4637
|
}
|
|
4067
4638
|
|
|
@@ -4247,6 +4818,11 @@ export class ChatApp {
|
|
|
4247
4818
|
const { meshes } = await this.engine.listMeshes({}).catch(() => ({ meshes: [] }))
|
|
4248
4819
|
const index = (meshes ?? []).findIndex((mesh) => mesh.meshId === meshId)
|
|
4249
4820
|
const where = index < 0 ? '/meshes lists it' : `/mesh use ${index + 1} to open it`
|
|
4821
|
+
// a compute mesh is not a room to talk in: there is nothing to select into, so saying
|
|
4822
|
+
// "shared room" of one would promise a place to work that it deliberately is not
|
|
4823
|
+
if ((meshes ?? [])[index]?.compute) {
|
|
4824
|
+
return `compute mesh ${meshId.slice(0, 8)} - lends this device, carries nothing`
|
|
4825
|
+
}
|
|
4250
4826
|
return `shared room ${meshId.slice(0, 8)} - not selected, ${where}`
|
|
4251
4827
|
}
|
|
4252
4828
|
|
|
@@ -4552,3 +5128,5 @@ export class ChatApp {
|
|
|
4552
5128
|
return [header, body, this._skillsLine(), inputBox, footer].join('\n')
|
|
4553
5129
|
}
|
|
4554
5130
|
}
|
|
5131
|
+
|
|
5132
|
+
function noop() {}
|