@zergai/ztc 0.4.0-beta.1 → 0.4.1-dev.36919234045
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/README.md +8 -1
- package/THIRD_PARTY_NOTICES.md +4 -0
- package/dist/App.js +2 -2
- package/dist/agent/agent.js +41 -5
- package/dist/agent/backends/anthropic.js +5 -10
- package/dist/agent/backends/gemini.js +2 -0
- package/dist/agent/backends/index.d.ts +1 -0
- package/dist/agent/backends/index.js +10 -1
- package/dist/agent/backends/openai.d.ts +0 -6
- package/dist/agent/backends/openai.js +5 -2
- package/dist/agent/backends/openai_compatible.d.ts +2 -0
- package/dist/agent/backends/openai_compatible.js +18 -8
- package/dist/agent/backends/provider_ids.d.ts +1 -0
- package/dist/agent/backends/provider_ids.js +4 -0
- package/dist/agent/backends/types.d.ts +1 -0
- package/dist/agent/backends/zrouter_stream.d.ts +5 -1
- package/dist/agent/backends/zrouter_stream.js +141 -37
- package/dist/agent/commands/compact.js +6 -5
- package/dist/agent/commands/config.js +4 -1
- package/dist/agent/commands/context.js +6 -1
- package/dist/agent/commands/effort.js +14 -6
- package/dist/agent/commands/model.js +12 -2
- package/dist/agent/commands/profile.js +21 -2
- package/dist/agent/commands/provider_selection.js +14 -1
- package/dist/agent/commands/settings.js +45 -7
- package/dist/agent/commands/types.d.ts +19 -0
- package/dist/agent/factory.js +14 -68
- package/dist/agent/subagent.d.ts +0 -10
- package/dist/agent/subagent.js +22 -0
- package/dist/agent/tool_response_store.d.ts +1 -1
- package/dist/agent/tool_response_store.js +4 -2
- package/dist/agent/tools/pane.d.ts +0 -7
- package/dist/agent/tools/pane.js +5 -4
- package/dist/app/command_context.js +33 -10
- package/dist/app/model_catalog_cache.d.ts +5 -0
- package/dist/app/model_catalog_cache.js +138 -0
- package/dist/app/restart.d.ts +1 -1
- package/dist/app/restart.js +16 -5
- package/dist/app/selection_completion.d.ts +17 -2
- package/dist/app/selection_completion.js +74 -6
- package/dist/app/session_manager.js +13 -8
- package/dist/cli_args.js +2 -16
- package/dist/cli_main.js +25 -6
- package/dist/cli_ratatui.js +70 -33
- package/dist/config/defaults.d.ts +2 -1
- package/dist/config/defaults.js +9 -2
- package/dist/config/resolved.d.ts +2 -2
- package/dist/config.d.ts +35 -3
- package/dist/config.js +227 -29
- package/dist/headless.js +2 -0
- package/dist/onboarding/first_run.js +5 -1
- package/dist/panes/model_catalog.d.ts +3 -3
- package/dist/panes/model_catalog.js +28 -4
- package/dist/panes/pane_registry.js +6 -2
- package/dist/panes/types.d.ts +2 -0
- package/dist/panes/ztc_launch.js +12 -0
- package/dist/session.d.ts +6 -2
- package/dist/session.js +65 -10
- package/dist/ui/views/completion_menu.js +10 -5
- package/dist/ui/views/status_bar.js +9 -5
- package/dist/ui/widgets/resume_panel.d.ts +2 -0
- package/dist/ui/widgets/resume_panel.js +17 -15
- package/dist/utils/compaction.d.ts +1 -1
- package/dist/utils/compaction.js +2 -2
- package/dist/utils/context.d.ts +4 -4
- package/dist/utils/context.js +14 -12
- package/dist/utils/deepseek.d.ts +2 -2
- package/dist/utils/deepseek.js +13 -5
- package/dist/utils/model_cache.d.ts +15 -0
- package/dist/utils/model_cache.js +143 -0
- package/dist/utils/models.d.ts +4 -2
- package/dist/utils/models.js +12 -16
- package/dist/utils/reasoning.d.ts +8 -1
- package/dist/utils/reasoning.js +31 -11
- package/dist/utils/router_catalog.d.ts +47 -0
- package/dist/utils/router_catalog.js +222 -0
- package/dist/zlm-embed.mjs +1180 -514
- package/node_modules/@zerg/model-contracts/LICENSE.md +375 -0
- package/node_modules/@zerg/model-contracts/README.md +78 -0
- package/node_modules/@zerg/model-contracts/index.d.ts +18 -0
- package/node_modules/@zerg/model-contracts/index.js +220 -0
- package/node_modules/@zerg/model-contracts/package.json +8 -0
- package/node_modules/glob/node_modules/brace-expansion/index.js +78 -22
- package/node_modules/glob/node_modules/brace-expansion/package.json +1 -1
- package/node_modules/readdir-glob/node_modules/brace-expansion/index.js +78 -22
- package/node_modules/readdir-glob/node_modules/brace-expansion/package.json +1 -1
- package/package.json +9 -6
- package/packages/model-contracts/LICENSE.md +375 -0
- package/packages/model-contracts/README.md +78 -0
- package/packages/model-contracts/index.d.ts +18 -0
- package/packages/model-contracts/index.js +220 -0
- package/packages/model-contracts/package.json +8 -0
package/dist/panes/ztc_launch.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isLocalSubscriptionProvider } from '../agent/backends/provider_ids.js';
|
|
2
|
+
import { configStore } from '../config.js';
|
|
1
3
|
import { existsSync } from 'fs';
|
|
2
4
|
import { dirname, join } from 'path';
|
|
3
5
|
import { generateSessionId } from '../session.js';
|
|
@@ -27,6 +29,8 @@ function filterChildZtcArgs(args) {
|
|
|
27
29
|
'--continue',
|
|
28
30
|
'-c',
|
|
29
31
|
'--session-id',
|
|
32
|
+
'--auth-mode',
|
|
33
|
+
'--router-url',
|
|
30
34
|
'--provider',
|
|
31
35
|
'--model',
|
|
32
36
|
'--profile',
|
|
@@ -77,6 +81,12 @@ export function buildZtcPaneLaunchCommand(spec, argv = process.argv) {
|
|
|
77
81
|
childArgs.push('--session-id', spec.session.id || generateSessionId());
|
|
78
82
|
}
|
|
79
83
|
childArgs.push('--pane');
|
|
84
|
+
const local = isLocalSubscriptionProvider(spec.providerOverride ?? configStore.getProvider());
|
|
85
|
+
const authMode = local ? 'direct' : spec.authMode ?? configStore.getChildAuthMode();
|
|
86
|
+
childArgs.push('--auth-mode', authMode);
|
|
87
|
+
const origin = spec.routerOrigin ?? configStore.get().zergProxyUrl;
|
|
88
|
+
if (authMode !== 'direct' && origin)
|
|
89
|
+
childArgs.push('--router-url', origin);
|
|
80
90
|
if (spec.providerOverride)
|
|
81
91
|
childArgs.push('--provider', spec.providerOverride);
|
|
82
92
|
if (spec.modelOverride)
|
|
@@ -113,6 +123,8 @@ export function createZtcLaunchSpec(options) {
|
|
|
113
123
|
session: { mode: sessionMode, id: sessionId },
|
|
114
124
|
cwd: options?.cwd,
|
|
115
125
|
title: options?.title || 'ZTC',
|
|
126
|
+
authMode: isLocalSubscriptionProvider(options?.providerOverride ?? configStore.getProvider()) ? 'direct' : configStore.getChildAuthMode(),
|
|
127
|
+
routerOrigin: configStore.get().zergProxyUrl,
|
|
116
128
|
providerOverride: options?.providerOverride,
|
|
117
129
|
modelOverride: options?.modelOverride,
|
|
118
130
|
extraArgs: options?.extraArgs,
|
package/dist/session.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ import type { GoalRecord } from './agent/commands/goal.js';
|
|
|
19
19
|
import type { HostedSessionSettings } from './hosted/session_settings.js';
|
|
20
20
|
import type { ToolResponseStore } from './agent/tool_response_store.js';
|
|
21
21
|
export interface SessionMetadata {
|
|
22
|
+
authMode?: 'auto' | 'direct' | 'zrouter';
|
|
23
|
+
routerOrigin?: string;
|
|
22
24
|
id: string;
|
|
23
25
|
projectHash: string;
|
|
24
26
|
cwd: string;
|
|
@@ -30,8 +32,8 @@ export interface SessionMetadata {
|
|
|
30
32
|
updatedAt: string;
|
|
31
33
|
messageCount: number;
|
|
32
34
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
+
* Derived from the first real user message and retained across compaction.
|
|
36
|
+
* User-facing surfaces should prefer `name` when set.
|
|
35
37
|
*/
|
|
36
38
|
title?: string;
|
|
37
39
|
/**
|
|
@@ -49,6 +51,8 @@ export interface SessionMetadata {
|
|
|
49
51
|
goal?: GoalRecord | null;
|
|
50
52
|
}
|
|
51
53
|
export interface SessionRuntimeState {
|
|
54
|
+
authMode?: 'auto' | 'direct' | 'zrouter';
|
|
55
|
+
routerOrigin?: string;
|
|
52
56
|
mode?: string;
|
|
53
57
|
planFile?: string | null;
|
|
54
58
|
artifactPath?: string | null;
|
package/dist/session.js
CHANGED
|
@@ -34,6 +34,12 @@ export const MAX_SESSION_FILE_BYTES = 4 * 1024 * 1024;
|
|
|
34
34
|
function buildRuntimeMetadata(runtimeState, existingSession) {
|
|
35
35
|
const metadata = {};
|
|
36
36
|
const existingMetadata = existingSession?.metadata;
|
|
37
|
+
const authMode = runtimeState?.authMode ?? existingMetadata?.authMode;
|
|
38
|
+
if (authMode)
|
|
39
|
+
metadata.authMode = authMode;
|
|
40
|
+
const routerOrigin = runtimeState?.routerOrigin ?? existingMetadata?.routerOrigin;
|
|
41
|
+
if (authMode !== 'direct' && routerOrigin)
|
|
42
|
+
metadata.routerOrigin = routerOrigin;
|
|
37
43
|
const mode = runtimeState?.mode ?? existingMetadata?.mode;
|
|
38
44
|
if (mode) {
|
|
39
45
|
metadata.mode = mode;
|
|
@@ -90,8 +96,55 @@ function isSessionShape(value) {
|
|
|
90
96
|
function normalizeLoadedSession(session) {
|
|
91
97
|
session.messages = stripEphemeralMessages(session.messages);
|
|
92
98
|
session.metadata.messageCount = session.messages.length;
|
|
99
|
+
if (isCompactionTitle(session.metadata.title)) {
|
|
100
|
+
session.metadata.title = deriveSessionTitle(session.messages);
|
|
101
|
+
}
|
|
93
102
|
return session;
|
|
94
103
|
}
|
|
104
|
+
function isCompactionTitle(title) {
|
|
105
|
+
// Includes the truncated 50-character title written by older versions.
|
|
106
|
+
return typeof title === 'string' && title.startsWith('[Conversation summary');
|
|
107
|
+
}
|
|
108
|
+
/** Recover only the explicit original-user record in the local summary format. */
|
|
109
|
+
function titleFromCompactedStart(content, depth = 0) {
|
|
110
|
+
if (depth >= 8)
|
|
111
|
+
return undefined;
|
|
112
|
+
const record = /\*\*Conversation start\*\*\r?\n([^\r\n]+)/.exec(content)?.[1];
|
|
113
|
+
if (!record)
|
|
114
|
+
return undefined;
|
|
115
|
+
try {
|
|
116
|
+
const parsed = JSON.parse(record);
|
|
117
|
+
if (!isPlainJsonObject(parsed) || parsed.role !== 'user' || typeof parsed.content !== 'string')
|
|
118
|
+
return undefined;
|
|
119
|
+
return isCompactionTitle(parsed.content)
|
|
120
|
+
? titleFromCompactedStart(parsed.content, depth + 1)
|
|
121
|
+
: parsed.content.slice(0, 50) || undefined;
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
// A bounded summary may have elided this record. Use surviving dialogue.
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/** Session identity belongs to the original request, not a summary carrier. */
|
|
129
|
+
function deriveSessionTitle(messages, previousTitle) {
|
|
130
|
+
if (typeof previousTitle === 'string' && previousTitle && previousTitle !== 'Untitled session' && previousTitle !== 'Untitled'
|
|
131
|
+
&& !isCompactionTitle(previousTitle))
|
|
132
|
+
return previousTitle;
|
|
133
|
+
for (const message of messages) {
|
|
134
|
+
if (message.role !== 'user' || typeof message.content !== 'string'
|
|
135
|
+
|| message.metadata?.ephemeral || message.metadata?.toolResult)
|
|
136
|
+
continue;
|
|
137
|
+
if (message.metadata?.compactionSummary === true || isCompactionTitle(message.content)) {
|
|
138
|
+
const recovered = titleFromCompactedStart(message.content);
|
|
139
|
+
if (recovered)
|
|
140
|
+
return recovered;
|
|
141
|
+
}
|
|
142
|
+
else if (message.content) {
|
|
143
|
+
return message.content.slice(0, 50);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return 'Untitled session';
|
|
147
|
+
}
|
|
95
148
|
export const COLONY_WORKTREE_MARKER = '.colony-worktree.json';
|
|
96
149
|
/**
|
|
97
150
|
* Bounded prefix read for session heads.
|
|
@@ -533,8 +586,14 @@ async function listSessionEntries(storage) {
|
|
|
533
586
|
}
|
|
534
587
|
async function readSessionSummaryEntry(entry, maxFileBytes) {
|
|
535
588
|
const head = await readSessionHeadSummary(entry);
|
|
536
|
-
if (head.kind === 'summary')
|
|
537
|
-
|
|
589
|
+
if (head.kind === 'summary') {
|
|
590
|
+
if (!isCompactionTitle(head.summary.title))
|
|
591
|
+
return head.summary;
|
|
592
|
+
// Repair old titles for display without rewriting another session's file.
|
|
593
|
+
// Keep oversized entries visible even when their transcript cannot be read.
|
|
594
|
+
return await readSessionSummaryFromFullParse(entry, maxFileBytes)
|
|
595
|
+
?? { ...head.summary, title: 'Untitled session' };
|
|
596
|
+
}
|
|
538
597
|
if (head.kind === 'excluded')
|
|
539
598
|
return null;
|
|
540
599
|
return readSessionSummaryFromFullParse(entry, maxFileBytes);
|
|
@@ -669,11 +728,8 @@ export async function saveSession(sessionId, cwd, messages, model, provider, mux
|
|
|
669
728
|
await ensureSessionStorage(storage, sessionId);
|
|
670
729
|
const sessionPath = getSessionJsonPath(storage, sessionId);
|
|
671
730
|
const existingSession = await loadSessionById(sessionId, cwd);
|
|
672
|
-
const
|
|
673
|
-
|
|
674
|
-
// Preserve user-set name across re-saves. saveSession is called every turn
|
|
675
|
-
// and re-derives `title` from the latest first-user-message; `name` is the
|
|
676
|
-
// opposite — set explicitly via /rename and must NOT be clobbered here.
|
|
731
|
+
const title = deriveSessionTitle(messages, existingSession?.metadata.title);
|
|
732
|
+
// User-set names remain independently controlled by /rename.
|
|
677
733
|
const session = {
|
|
678
734
|
schemaVersion: SESSION_SCHEMA_VERSION,
|
|
679
735
|
metadata: {
|
|
@@ -750,8 +806,6 @@ export async function loadSessionFromFile(path) {
|
|
|
750
806
|
*/
|
|
751
807
|
export async function saveSessionToFile(path, sessionId, cwd, messages, model, provider, muxState, paneSpecs, runtimeState, hostedSettings) {
|
|
752
808
|
const projectHash = getProjectHash(cwd);
|
|
753
|
-
const firstUserMsg = messages.find(m => m.role === 'user');
|
|
754
|
-
const title = firstUserMsg?.content?.slice(0, 50) || 'Untitled session';
|
|
755
809
|
let createdAt = new Date().toISOString();
|
|
756
810
|
let preservedName;
|
|
757
811
|
let existingSession = null;
|
|
@@ -769,6 +823,7 @@ export async function saveSessionToFile(path, sessionId, cwd, messages, model, p
|
|
|
769
823
|
// Existing file is broken; proceed with fresh createdAt.
|
|
770
824
|
}
|
|
771
825
|
}
|
|
826
|
+
const title = deriveSessionTitle(messages, existingSession?.metadata.title);
|
|
772
827
|
const session = {
|
|
773
828
|
schemaVersion: SESSION_SCHEMA_VERSION,
|
|
774
829
|
metadata: {
|
|
@@ -990,7 +1045,7 @@ export async function listSessions(cwd) {
|
|
|
990
1045
|
*/
|
|
991
1046
|
async function readSessionSummaryForListing(entry) {
|
|
992
1047
|
const head = await readSessionHead(entry);
|
|
993
|
-
if (head.kind === 'summary')
|
|
1048
|
+
if (head.kind === 'summary' && !isCompactionTitle(head.summary.title))
|
|
994
1049
|
return head.summary;
|
|
995
1050
|
if (head.kind === 'excluded')
|
|
996
1051
|
return null;
|
|
@@ -45,9 +45,10 @@ export function buildCompletionMenu(view, cols) {
|
|
|
45
45
|
const rowCount = Math.max(1, view.visibleRows ?? SELECTION_VISIBLE_ROWS);
|
|
46
46
|
const first = Math.min(Math.max(0, view.candidates.length - rowCount), Math.max(0, view.selected - rowCount + 1, Math.min(view.firstVisible ?? 0, view.selected)));
|
|
47
47
|
const kind = view.kind ?? (view.provider ? 'model' : 'provider');
|
|
48
|
-
const title = kind === '
|
|
48
|
+
const title = kind === 'reasoning' ? [view.command === 'thinking' ? 'Thinking' : 'Effort', view.model].filter(Boolean).join(' · ')
|
|
49
|
+
: kind === 'model' ? `Models · ${view.provider ?? ''}` : kind === 'command' ? 'Commands' : view.mixed ? 'Providers & models' : 'Providers';
|
|
49
50
|
const count = view.candidates.length ? `${view.selected + 1}/${view.candidates.length}` : '0 results';
|
|
50
|
-
const state = view.loading ? ' · loading' : view.unavailable ? ' · cached' : '';
|
|
51
|
+
const state = view.loading ? ' · loading' : view.unavailable ? kind === 'reasoning' ? ' · unavailable' : ' · cached' : '';
|
|
51
52
|
const heading = clip(title + state, Math.max(1, width - displayWidth(count) - 2));
|
|
52
53
|
const rows = [box([
|
|
53
54
|
text(padEndDisplay(heading, Math.max(0, width - displayWidth(count))), muted), text(count, muted),
|
|
@@ -80,16 +81,20 @@ export function buildCompletionMenu(view, cols) {
|
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
else {
|
|
83
|
-
const empty =
|
|
84
|
+
const empty = kind === 'reasoning'
|
|
85
|
+
? view.loading ? 'Loading reasoning definition…' : view.unavailable ? 'Reasoning definition unavailable.'
|
|
86
|
+
: view.query ? `No supported matches for “${view.query}”` : 'This model has no thinking controls.'
|
|
87
|
+
: view.loading ? 'Loading models…' : view.unavailable ? 'Model list unavailable. Enter an exact ID.' : `No matches${view.query ? ` for “${view.query}”` : ''}`;
|
|
84
88
|
rows.push(text(clip(empty, width), muted));
|
|
85
89
|
}
|
|
86
90
|
const selected = view.candidates[view.selected];
|
|
87
|
-
const enterAction = selected && view.query === selected.value
|
|
91
|
+
const enterAction = selected && !selected.needsArgument && (kind === 'model' || kind === 'reasoning' || view.mixed || view.query === selected.value) ? 'run' : 'fill';
|
|
88
92
|
const hints = view.candidates.length ? [
|
|
89
93
|
enterAction === 'run' ? '↑↓ move · Tab fill · Enter run · Esc close' : '↑↓ move · Tab/Enter fill · Esc close',
|
|
90
94
|
enterAction === 'run' ? '↑↓ · Tab fill · ↵ run · Esc' : '↑↓ · Tab/↵ fill · Esc',
|
|
91
95
|
'↑↓ Tab ↵ Esc',
|
|
92
|
-
] :
|
|
96
|
+
] : kind === 'reasoning' ? ['Enter shows settings · Esc close', '↵ settings · Esc', '↵ Esc']
|
|
97
|
+
: [kind === 'command' ? 'Keep typing · Esc close' : 'Enter exact ID · Esc close', '↵ exact ID · Esc', '↵ Esc'];
|
|
93
98
|
const hint = hints.find(value => displayWidth(value) <= width) ?? hints.at(-1);
|
|
94
99
|
return {
|
|
95
100
|
menu: box(rows, { flexDirection: 'column', paddingX: 2, flexShrink: 0 }),
|
|
@@ -91,6 +91,10 @@ function statusItemForms(item, props) {
|
|
|
91
91
|
: props.mode;
|
|
92
92
|
const providerName = props.provider ? getProviderDisplayName(props.provider) : '';
|
|
93
93
|
const displayModel = props.model ? ellipsize(props.model, 20) : '';
|
|
94
|
+
// Router IDs may already carry the provider. Strip it only in the combined label.
|
|
95
|
+
const pairedModel = props.provider && props.model?.startsWith(`${props.provider}/`)
|
|
96
|
+
? ellipsize(props.model.slice(props.provider.length + 1), 20)
|
|
97
|
+
: displayModel;
|
|
94
98
|
const workspace = props.authWorkspace || props.authEmail?.split('@')[0];
|
|
95
99
|
const shownWorkspace = workspace ? ellipsize(workspace, 20) : undefined;
|
|
96
100
|
const sessionName = props.sessionName ? ellipsize(props.sessionName, 24) : undefined;
|
|
@@ -106,15 +110,15 @@ function statusItemForms(item, props) {
|
|
|
106
110
|
// measured miss.
|
|
107
111
|
const cacheShare = cacheHitRate(props.state.cachedInputTokens, props.state.cacheInputTokens ?? usedTokens);
|
|
108
112
|
const cacheLabel = cacheShare === undefined ? undefined : `${Math.round(cacheShare)}%`;
|
|
109
|
-
const percentage = props.contextStatus ? `${Math.round(props.contextStatus.percentage)}%` : undefined;
|
|
110
|
-
const remaining = props.contextStatus ? `${Math.max(0, Math.round(props.contextStatus.remaining))}%` : undefined;
|
|
113
|
+
const percentage = props.contextStatus && props.contextStatus.total > 0 ? `${Math.round(props.contextStatus.percentage)}%` : undefined;
|
|
114
|
+
const remaining = props.contextStatus && props.contextStatus.total > 0 ? `${Math.max(0, Math.round(props.contextStatus.remaining))}%` : undefined;
|
|
111
115
|
const reasoning = reasoningEnabled(props.effort);
|
|
112
116
|
const inputMode = props.inputMode && props.inputMode !== 'queue'
|
|
113
117
|
? props.inputMode[0].toUpperCase() + props.inputMode.slice(1)
|
|
114
118
|
: undefined;
|
|
115
|
-
const model = providerName &&
|
|
116
|
-
? `${providerName}/${
|
|
117
|
-
: providerName ||
|
|
119
|
+
const model = providerName && pairedModel
|
|
120
|
+
? `${providerName}/${pairedModel}`
|
|
121
|
+
: providerName || pairedModel || undefined;
|
|
118
122
|
switch (item) {
|
|
119
123
|
case 'mode':
|
|
120
124
|
return { raw: modeConfig.icon, short: modeLabel, long: `${modeConfig.icon} ${modeLabel}` };
|
|
@@ -84,6 +84,7 @@ export declare class ResumePanelWidget {
|
|
|
84
84
|
private previewEntryId;
|
|
85
85
|
private preview;
|
|
86
86
|
private previewScroll;
|
|
87
|
+
private previewFollowTail;
|
|
87
88
|
private previewRequestSeq;
|
|
88
89
|
private previewViewportRows;
|
|
89
90
|
private lastBodyRows;
|
|
@@ -153,6 +154,7 @@ export declare class ResumePanelWidget {
|
|
|
153
154
|
*/
|
|
154
155
|
handleMouse(event: WidgetMouseEvent): boolean;
|
|
155
156
|
private scrollPreviewToBoundary;
|
|
157
|
+
private updatePreviewViewport;
|
|
156
158
|
private previewMaxScroll;
|
|
157
159
|
handleInput(input: string, key: KeyEvent): void;
|
|
158
160
|
private isPrintable;
|
|
@@ -56,6 +56,7 @@ export class ResumePanelWidget {
|
|
|
56
56
|
previewEntryId = null;
|
|
57
57
|
preview = null;
|
|
58
58
|
previewScroll = 0;
|
|
59
|
+
previewFollowTail = true;
|
|
59
60
|
previewRequestSeq = 0;
|
|
60
61
|
previewViewportRows = 1;
|
|
61
62
|
lastBodyRows = 1;
|
|
@@ -195,6 +196,7 @@ export class ResumePanelWidget {
|
|
|
195
196
|
this.previewEntryId = null;
|
|
196
197
|
this.preview = null;
|
|
197
198
|
this.previewScroll = 0;
|
|
199
|
+
this.previewFollowTail = true;
|
|
198
200
|
this.wrappedPreviewCache = null;
|
|
199
201
|
}
|
|
200
202
|
moveSelection(delta) {
|
|
@@ -205,7 +207,6 @@ export class ResumePanelWidget {
|
|
|
205
207
|
if (next === this.selectedIndex)
|
|
206
208
|
return;
|
|
207
209
|
this.selectedIndex = next;
|
|
208
|
-
this.previewScroll = 0;
|
|
209
210
|
this.requestPreviewForSelection();
|
|
210
211
|
}
|
|
211
212
|
moveToBoundary(end) {
|
|
@@ -216,7 +217,6 @@ export class ResumePanelWidget {
|
|
|
216
217
|
if (next === this.selectedIndex)
|
|
217
218
|
return;
|
|
218
219
|
this.selectedIndex = next;
|
|
219
|
-
this.previewScroll = 0;
|
|
220
220
|
this.requestPreviewForSelection();
|
|
221
221
|
}
|
|
222
222
|
pageStep() {
|
|
@@ -228,7 +228,6 @@ export class ResumePanelWidget {
|
|
|
228
228
|
applyFilter() {
|
|
229
229
|
this.selectedIndex = 0;
|
|
230
230
|
this.listScrollOffset = 0;
|
|
231
|
-
this.previewScroll = 0;
|
|
232
231
|
this.invalidateEntries();
|
|
233
232
|
this.requestPreviewForSelection();
|
|
234
233
|
}
|
|
@@ -240,6 +239,9 @@ export class ResumePanelWidget {
|
|
|
240
239
|
if (!this.active)
|
|
241
240
|
return;
|
|
242
241
|
const entry = this.selectedEntry();
|
|
242
|
+
// A refresh of the same row must not invalidate its pending disk read.
|
|
243
|
+
if (entry && this.previewEntryId === entry.id && (this.previewStatus === 'ready' || this.previewStatus === 'loading'))
|
|
244
|
+
return;
|
|
243
245
|
this.previewRequestSeq += 1;
|
|
244
246
|
const seq = this.previewRequestSeq;
|
|
245
247
|
if (!entry || !entry.path) {
|
|
@@ -249,11 +251,11 @@ export class ResumePanelWidget {
|
|
|
249
251
|
this.wrappedPreviewCache = null;
|
|
250
252
|
return;
|
|
251
253
|
}
|
|
252
|
-
if (this.previewEntryId === entry.id && (this.previewStatus === 'ready' || this.previewStatus === 'loading'))
|
|
253
|
-
return;
|
|
254
254
|
this.previewEntryId = entry.id;
|
|
255
255
|
this.previewStatus = 'loading';
|
|
256
256
|
this.preview = null;
|
|
257
|
+
this.previewScroll = 0;
|
|
258
|
+
this.previewFollowTail = true;
|
|
257
259
|
this.wrappedPreviewCache = null;
|
|
258
260
|
void this.active.loadPreview(entry)
|
|
259
261
|
.then((preview) => {
|
|
@@ -263,7 +265,6 @@ export class ResumePanelWidget {
|
|
|
263
265
|
return;
|
|
264
266
|
this.preview = preview;
|
|
265
267
|
this.previewStatus = preview ? 'ready' : 'error';
|
|
266
|
-
this.previewScroll = Math.max(0, Math.min(this.previewScroll, this.previewMaxScroll()));
|
|
267
268
|
this.host.render();
|
|
268
269
|
})
|
|
269
270
|
.catch(() => {
|
|
@@ -281,6 +282,7 @@ export class ResumePanelWidget {
|
|
|
281
282
|
if (next === this.previewScroll)
|
|
282
283
|
return;
|
|
283
284
|
this.previewScroll = next;
|
|
285
|
+
this.previewFollowTail = next === this.previewMaxScroll();
|
|
284
286
|
}
|
|
285
287
|
/**
|
|
286
288
|
* Scroll whichever pane the wheel is over.
|
|
@@ -308,8 +310,14 @@ export class ResumePanelWidget {
|
|
|
308
310
|
return false;
|
|
309
311
|
}
|
|
310
312
|
scrollPreviewToBoundary(end) {
|
|
313
|
+
this.previewFollowTail = end;
|
|
311
314
|
this.previewScroll = end ? this.previewMaxScroll() : 0;
|
|
312
315
|
}
|
|
316
|
+
updatePreviewViewport(rows) {
|
|
317
|
+
this.previewViewportRows = rows;
|
|
318
|
+
const max = this.previewMaxScroll();
|
|
319
|
+
this.previewScroll = this.previewFollowTail ? max : Math.max(0, Math.min(this.previewScroll, max));
|
|
320
|
+
}
|
|
313
321
|
previewMaxScroll() {
|
|
314
322
|
const lines = this.previewRenderLines();
|
|
315
323
|
return Math.max(0, lines.length - Math.max(1, this.previewViewportRows));
|
|
@@ -831,17 +839,14 @@ export class ResumePanelWidget {
|
|
|
831
839
|
lines.push(framedLine(row ? row.segments : [], width));
|
|
832
840
|
}
|
|
833
841
|
const stackedListBottom = lines.length - 1;
|
|
842
|
+
const paneRows = Math.max(1, split.previewRows);
|
|
843
|
+
this.updatePreviewViewport(paneRows);
|
|
834
844
|
lines.push(framedLine([{
|
|
835
845
|
text: clipText(this.previewHeaderText(), innerWidth),
|
|
836
846
|
style: { color: this.focus === 'preview' ? TERMINAL_THEME.info : TERMINAL_THEME.subtle, bold: true },
|
|
837
847
|
}], width, TERMINAL_THEME.bgPanel));
|
|
838
848
|
const stackedPreviewTop = lines.length - 1;
|
|
839
|
-
const paneRows = Math.max(1, split.previewRows);
|
|
840
|
-
this.previewViewportRows = paneRows;
|
|
841
|
-
this.previewScroll = Math.max(0, Math.min(this.previewScroll, this.previewMaxScroll()));
|
|
842
849
|
const previewLines = this.previewRenderLines();
|
|
843
|
-
const maxPreviewStart = Math.max(0, previewLines.length - paneRows);
|
|
844
|
-
this.previewScroll = Math.max(0, Math.min(this.previewScroll, maxPreviewStart));
|
|
845
850
|
for (let index = 0; index < paneRows; index += 1) {
|
|
846
851
|
const previewRow = previewLines[this.previewScroll + index];
|
|
847
852
|
lines.push(framedLine(previewRow ? previewRow.segments : [], width));
|
|
@@ -854,8 +859,7 @@ export class ResumePanelWidget {
|
|
|
854
859
|
else {
|
|
855
860
|
const listWidth = this.listPaneWidth();
|
|
856
861
|
const paneRows = Math.max(1, split.listRows);
|
|
857
|
-
this.
|
|
858
|
-
this.previewScroll = Math.max(0, Math.min(this.previewScroll, this.previewMaxScroll()));
|
|
862
|
+
this.updatePreviewViewport(paneRows);
|
|
859
863
|
lines.push(framedLine([
|
|
860
864
|
{
|
|
861
865
|
text: padEndDisplay(this.view === 'workspace' ? 'THIS WORKSPACE' : 'ALL SESSIONS', listWidth),
|
|
@@ -870,8 +874,6 @@ export class ResumePanelWidget {
|
|
|
870
874
|
const listRows = this.listRows(listWidth, nowMs);
|
|
871
875
|
const windowed = this.windowRows(listRows, paneRows);
|
|
872
876
|
const previewLines = this.previewRenderLines();
|
|
873
|
-
const maxPreviewStart = Math.max(0, previewLines.length - paneRows);
|
|
874
|
-
this.previewScroll = Math.max(0, Math.min(this.previewScroll, maxPreviewStart));
|
|
875
877
|
const sideBandTop = lines.length - 1;
|
|
876
878
|
for (let index = 0; index < paneRows; index += 1) {
|
|
877
879
|
const listRow = windowed.rows[index];
|
|
@@ -77,7 +77,7 @@ export declare function needsCompaction(messages: Message[], model: string, thre
|
|
|
77
77
|
* @param keepRecentMin Floor for recent messages to keep verbatim — actual
|
|
78
78
|
* count grows to fill the targetPercentage budget when messages are small.
|
|
79
79
|
*/
|
|
80
|
-
export declare function compactMessages(messages: Message[], model: string, summarizer: (messages: Message[]) => Promise<string>, targetPercentage?: number, keepRecentMin?: number, targetTokensOverride?: number): Promise<CompactionResult>;
|
|
80
|
+
export declare function compactMessages(messages: Message[], model: string, summarizer: (messages: Message[]) => Promise<string>, targetPercentage?: number, keepRecentMin?: number, targetTokensOverride?: number, windowOverride?: number | null): Promise<CompactionResult>;
|
|
81
81
|
/**
|
|
82
82
|
* Configuration for one compaction run. The strategy is chosen by the caller
|
|
83
83
|
* from the stored settings so this module stays config-free and testable.
|
package/dist/utils/compaction.js
CHANGED
|
@@ -582,9 +582,9 @@ function deflateMessages(messages) {
|
|
|
582
582
|
* @param keepRecentMin Floor for recent messages to keep verbatim — actual
|
|
583
583
|
* count grows to fill the targetPercentage budget when messages are small.
|
|
584
584
|
*/
|
|
585
|
-
export async function compactMessages(messages, model, summarizer, targetPercentage = 50, keepRecentMin = 10, targetTokensOverride) {
|
|
585
|
+
export async function compactMessages(messages, model, summarizer, targetPercentage = 50, keepRecentMin = 10, targetTokensOverride, windowOverride) {
|
|
586
586
|
const tokensBefore = estimateConversationTokens(messages);
|
|
587
|
-
const total = getContextWindowSize(model);
|
|
587
|
+
const total = getContextWindowSize(model, windowOverride) || tokensBefore;
|
|
588
588
|
// An absolute target wins over the window percentage: when the caller is
|
|
589
589
|
// compacting to an explicit token budget, aiming at a fraction of an
|
|
590
590
|
// advertised (possibly much larger) window would land over budget and make
|
package/dist/utils/context.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export declare function estimateConversationTokens(messages: Message[]): number;
|
|
|
30
30
|
/**
|
|
31
31
|
* Get context window size for a model
|
|
32
32
|
*/
|
|
33
|
-
export declare function getContextWindowSize(model: string): number;
|
|
33
|
+
export declare function getContextWindowSize(model: string, windowOverride?: number | null): number;
|
|
34
34
|
export interface ContextStatus {
|
|
35
35
|
used: number;
|
|
36
36
|
total: number;
|
|
@@ -54,19 +54,19 @@ export interface ContextStatus {
|
|
|
54
54
|
* MODEL_CONTEXT_WINDOWS guess, so the bar matches the provider's own meter. A
|
|
55
55
|
* non-positive / absent override falls back to the static table.
|
|
56
56
|
*/
|
|
57
|
-
export declare function contextStatusFromUsed(used: number, model: string, windowOverride?: number): ContextStatus;
|
|
57
|
+
export declare function contextStatusFromUsed(used: number, model: string, windowOverride?: number | null): ContextStatus;
|
|
58
58
|
/**
|
|
59
59
|
* Estimate-based status (char/4). This is the FALLBACK path only — used when no
|
|
60
60
|
* real provider token count is available. It delegates to contextStatusFromUsed
|
|
61
61
|
* so the percentage/level math is identical to the authoritative path.
|
|
62
62
|
*/
|
|
63
|
-
export declare function getContextStatus(messages: Message[], model: string): ContextStatus;
|
|
63
|
+
export declare function getContextStatus(messages: Message[], model: string, windowOverride?: number | null): ContextStatus;
|
|
64
64
|
export interface AutoCompactPolicy {
|
|
65
65
|
/** Authoritative provider input_tokens for the context in play. */
|
|
66
66
|
used: number;
|
|
67
67
|
model: string;
|
|
68
68
|
/** Provider-reported window, when the backend exposes a real one. */
|
|
69
|
-
windowOverride?: number;
|
|
69
|
+
windowOverride?: number | null;
|
|
70
70
|
/** Percentage of the effective window at which compaction triggers. */
|
|
71
71
|
thresholdPercent: number;
|
|
72
72
|
/**
|
package/dist/utils/context.js
CHANGED
|
@@ -142,7 +142,13 @@ export function estimateConversationTokens(messages) {
|
|
|
142
142
|
/**
|
|
143
143
|
* Get context window size for a model
|
|
144
144
|
*/
|
|
145
|
-
export function getContextWindowSize(model) {
|
|
145
|
+
export function getContextWindowSize(model, windowOverride) {
|
|
146
|
+
// null means Router explicitly has no context-size metadata. Zero is the
|
|
147
|
+
// display/policy sentinel for unknown; never infer a window from this id.
|
|
148
|
+
if (windowOverride === null)
|
|
149
|
+
return 0;
|
|
150
|
+
if (typeof windowOverride === 'number' && windowOverride > 0)
|
|
151
|
+
return windowOverride;
|
|
146
152
|
if (MODEL_CONTEXT_WINDOWS[model]) {
|
|
147
153
|
return MODEL_CONTEXT_WINDOWS[model];
|
|
148
154
|
}
|
|
@@ -173,10 +179,8 @@ export function getContextWindowSize(model) {
|
|
|
173
179
|
* non-positive / absent override falls back to the static table.
|
|
174
180
|
*/
|
|
175
181
|
export function contextStatusFromUsed(used, model, windowOverride) {
|
|
176
|
-
const total =
|
|
177
|
-
|
|
178
|
-
: getContextWindowSize(model);
|
|
179
|
-
const percentage = (used / total) * 100;
|
|
182
|
+
const total = getContextWindowSize(model, windowOverride);
|
|
183
|
+
const percentage = total > 0 ? (used / total) * 100 : 0;
|
|
180
184
|
const remaining = 100 - percentage;
|
|
181
185
|
let level;
|
|
182
186
|
if (remaining <= 5) {
|
|
@@ -198,8 +202,8 @@ export function contextStatusFromUsed(used, model, windowOverride) {
|
|
|
198
202
|
* real provider token count is available. It delegates to contextStatusFromUsed
|
|
199
203
|
* so the percentage/level math is identical to the authoritative path.
|
|
200
204
|
*/
|
|
201
|
-
export function getContextStatus(messages, model) {
|
|
202
|
-
return contextStatusFromUsed(estimateConversationTokens(messages), model);
|
|
205
|
+
export function getContextStatus(messages, model, windowOverride) {
|
|
206
|
+
return contextStatusFromUsed(estimateConversationTokens(messages), model, windowOverride);
|
|
203
207
|
}
|
|
204
208
|
/**
|
|
205
209
|
* Smallest gap, in ceiling percent, the target must keep below the trigger.
|
|
@@ -251,15 +255,13 @@ export function clampCompactionTargetPercent(targetPercent, triggerPercentOfCeil
|
|
|
251
255
|
* compactor target can never disagree.
|
|
252
256
|
*/
|
|
253
257
|
export function resolveAutoCompact(policy) {
|
|
254
|
-
const total =
|
|
255
|
-
|
|
256
|
-
: getContextWindowSize(policy.model);
|
|
257
|
-
const percentage = (policy.used / total) * 100;
|
|
258
|
+
const total = getContextWindowSize(policy.model, policy.windowOverride);
|
|
259
|
+
const percentage = total > 0 ? (policy.used / total) * 100 : 0;
|
|
258
260
|
const budgetActive = isTokenTriggerActive(policy.triggerMode, policy.tokenBudget);
|
|
259
261
|
const budgetHit = budgetActive && policy.used >= policy.tokenBudget;
|
|
260
262
|
// The window rule steps aside only for an active budget, which is exactly the
|
|
261
263
|
// case where the ceiling (and so the percentage) is measured differently.
|
|
262
|
-
const thresholdHit = !budgetActive && percentage >= policy.thresholdPercent;
|
|
264
|
+
const thresholdHit = total > 0 && !budgetActive && percentage >= policy.thresholdPercent;
|
|
263
265
|
const ceiling = budgetActive ? policy.tokenBudget : total;
|
|
264
266
|
// Both the target and the trigger are read in ceiling percent: the trigger is
|
|
265
267
|
// the whole budget when that is the trigger (so the ceiling is 100), otherwise
|
package/dist/utils/deepseek.d.ts
CHANGED
|
@@ -2,10 +2,10 @@ export declare const DEEPSEEK_FLASH_MODEL = "deepseek-flash";
|
|
|
2
2
|
export declare const MODAL_DEEPSEEK_FLASH_MODEL = "deepseek-v4.1-flash";
|
|
3
3
|
export declare const MODAL_DEEPSEEK_FLASH_CONTEXT = 1048576;
|
|
4
4
|
export declare const MODAL_DEEPSEEK_FLASH_MAX_OUTPUT = 1048576;
|
|
5
|
-
export declare const MODAL_DEEPSEEK_FLASH_EFFORTS: readonly
|
|
5
|
+
export declare const MODAL_DEEPSEEK_FLASH_EFFORTS: readonly import("@zerg/model-contracts").ReasoningEffort[];
|
|
6
6
|
export declare const DEEPSEEK_FLASH_CONTEXT = 1000000;
|
|
7
7
|
export declare const DEEPSEEK_FLASH_MAX_OUTPUT = 384000;
|
|
8
|
-
export declare const DEEPSEEK_FLASH_EFFORTS: readonly
|
|
8
|
+
export declare const DEEPSEEK_FLASH_EFFORTS: readonly import("@zerg/model-contracts").ReasoningEffort[];
|
|
9
9
|
export declare function isModalDeepSeekFlashModel(model: string | undefined): boolean;
|
|
10
10
|
export declare function isDeepSeekFlashModel(model: string | undefined): boolean;
|
|
11
11
|
export declare function deepseekRequestParams(request: {
|
package/dist/utils/deepseek.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { modelContract, normalizeContractModel, reasoningRequestParams } from '@zerg/model-contracts';
|
|
1
2
|
// DeepSeek's September 2026 API contract. The legacy Flash IDs currently alias
|
|
2
3
|
// V4.1 on the provider; keep their wire IDs intact when explicitly selected.
|
|
3
4
|
// https://api-docs.deepseek.com/quick_start/pricing/
|
|
@@ -7,10 +8,10 @@ export const MODAL_DEEPSEEK_FLASH_MODEL = 'deepseek-v4.1-flash';
|
|
|
7
8
|
// Production Modal /v1/models metadata, verified September 14, 2026.
|
|
8
9
|
export const MODAL_DEEPSEEK_FLASH_CONTEXT = 1_048_576;
|
|
9
10
|
export const MODAL_DEEPSEEK_FLASH_MAX_OUTPUT = 1_048_576;
|
|
10
|
-
export const MODAL_DEEPSEEK_FLASH_EFFORTS =
|
|
11
|
+
export const MODAL_DEEPSEEK_FLASH_EFFORTS = modelContract('modal', MODAL_DEEPSEEK_FLASH_MODEL).reasoningEfforts;
|
|
11
12
|
export const DEEPSEEK_FLASH_CONTEXT = 1_000_000;
|
|
12
13
|
export const DEEPSEEK_FLASH_MAX_OUTPUT = 384_000;
|
|
13
|
-
export const DEEPSEEK_FLASH_EFFORTS =
|
|
14
|
+
export const DEEPSEEK_FLASH_EFFORTS = modelContract('deepseek', DEEPSEEK_FLASH_MODEL).reasoningEfforts;
|
|
14
15
|
export function isModalDeepSeekFlashModel(model) {
|
|
15
16
|
return model?.toLowerCase().replace(/^modal\//, '') === MODAL_DEEPSEEK_FLASH_MODEL;
|
|
16
17
|
}
|
|
@@ -19,11 +20,18 @@ export function isDeepSeekFlashModel(model) {
|
|
|
19
20
|
return true;
|
|
20
21
|
return model !== undefined && [
|
|
21
22
|
DEEPSEEK_FLASH_MODEL, 'deepseek-v4-flash', 'deepseek-v4-flash-vision-exp',
|
|
22
|
-
].includes(model.toLowerCase().replace(/^deepseek\//, ''))
|
|
23
|
+
].includes(model.toLowerCase().replace(/^deepseek\//, ''))
|
|
24
|
+
|| (model !== undefined && ['deepseek-v4p1-flash', 'deepseek-v4-flash-0731']
|
|
25
|
+
.includes(normalizeContractModel('fireworks', model)));
|
|
23
26
|
}
|
|
24
27
|
export function deepseekRequestParams(request) {
|
|
25
|
-
if (!isDeepSeekFlashModel(request.model))
|
|
26
|
-
return
|
|
28
|
+
if (!isDeepSeekFlashModel(request.model)) {
|
|
29
|
+
return reasoningRequestParams('deepseek', request.model, request.codexEffort);
|
|
30
|
+
}
|
|
31
|
+
if (normalizeContractModel('fireworks', request.model) === 'deepseek-v4p1-flash'
|
|
32
|
+
|| request.model.toLowerCase().startsWith('fireworks/')) {
|
|
33
|
+
return reasoningRequestParams('fireworks', request.model, request.codexEffort);
|
|
34
|
+
}
|
|
27
35
|
if (isModalDeepSeekFlashModel(request.model)) {
|
|
28
36
|
// Modal's managed endpoint accepts reasoning_effort, not DeepSeek API's
|
|
29
37
|
// separate thinking toggle. Leave the endpoint default intact if omitted.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The cached model list for a provider, or an empty array when absent.
|
|
3
|
+
* Empty means "nothing usable cached", never an error to surface.
|
|
4
|
+
*/
|
|
5
|
+
export declare function readCachedModels(provider: string): Promise<string[]>;
|
|
6
|
+
/** Epoch ms of the cached listing, or undefined when there is none. */
|
|
7
|
+
export declare function readCachedModelsFetchedAt(provider: string): Promise<number | undefined>;
|
|
8
|
+
/**
|
|
9
|
+
* Record a successful listing for a provider. A no-op for an empty list: a
|
|
10
|
+
* provider that legitimately returns zero models should not erase a good
|
|
11
|
+
* earlier cache, which is the case an offline restart needs most.
|
|
12
|
+
*/
|
|
13
|
+
export declare function writeCachedModels(provider: string, models: readonly string[]): Promise<void>;
|
|
14
|
+
/** Drop one provider's cache without discarding concurrent catalog updates. */
|
|
15
|
+
export declare function clearCachedModels(provider: string): Promise<void>;
|