@aragon-agent/cli 0.6.34 → 0.6.35
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 +3071 -3007
- package/dist/agent/controller.d.ts +29 -0
- package/dist/agent/controller.js +42 -1
- package/dist/agent/kit-apply.d.ts +56 -0
- package/dist/agent/kit-apply.js +209 -0
- package/dist/agent/model-profile-settings.d.ts +28 -0
- package/dist/agent/model-profile-settings.js +142 -29
- package/dist/agent/reducer.d.ts +1 -1
- package/dist/commands/builtins.js +4 -0
- package/dist/commands/kit-command.d.ts +20 -0
- package/dist/commands/kit-command.js +131 -0
- package/dist/config/kit-resolution.d.ts +93 -0
- package/dist/config/kit-resolution.js +226 -0
- package/dist/config/model-kits.d.ts +224 -0
- package/dist/config/model-kits.js +302 -0
- package/dist/config/model-profile-store.d.ts +25 -0
- package/dist/config/model-profiles.d.ts +41 -3
- package/dist/config/model-profiles.js +46 -5
- package/dist/config/schema.d.ts +16 -0
- package/dist/input/keymap.js +18 -4
- package/dist/ui/App.js +108 -12
- package/dist/ui/Header.d.ts +9 -1
- package/dist/ui/Header.js +8 -2
- package/dist/ui/PromptInput.js +1 -1
- package/dist/ui/ScrollbackShell.d.ts +18 -3
- package/dist/ui/ScrollbackShell.js +1 -1
- package/dist/ui/StatusBar.d.ts +13 -0
- package/dist/ui/StatusBar.js +10 -3
- package/dist/ui/TeamPanel.d.ts +12 -0
- package/dist/ui/TeamPanel.js +10 -31
- package/dist/ui/Transcript.js +22 -2
- package/dist/ui/entries/TeamCard.d.ts +18 -2
- package/dist/ui/entries/TeamCard.js +47 -13
- package/dist/ui/layout/header-hints.d.ts +11 -1
- package/dist/ui/layout/header-hints.js +35 -3
- package/dist/ui/layout/kit-chip.d.ts +50 -0
- package/dist/ui/layout/kit-chip.js +81 -0
- package/dist/ui/layout/virtual-window.js +9 -0
- package/dist/ui/overlays/HelpOverlay.js +7 -0
- package/dist/ui/overlays/KitEditor.d.ts +23 -0
- package/dist/ui/overlays/KitEditor.js +101 -0
- package/dist/ui/overlays/KitManager.d.ts +23 -0
- package/dist/ui/overlays/KitManager.js +104 -0
- package/dist/ui/overlays/KitPicker.d.ts +49 -0
- package/dist/ui/overlays/KitPicker.js +58 -0
- package/dist/ui/overlays/ModelProfilePicker.js +16 -6
- package/dist/ui/overlays/SettingsScreen.js +139 -16
- package/dist/ui/overlays/kit-picker-state.d.ts +87 -0
- package/dist/ui/overlays/kit-picker-state.js +136 -0
- package/dist/ui/overlays/kit-settings-state.d.ts +129 -0
- package/dist/ui/overlays/kit-settings-state.js +267 -0
- package/dist/ui/overlays/model-profile-state.d.ts +26 -3
- package/dist/ui/overlays/model-profile-state.js +59 -6
- package/dist/ui/scrollback/LiveTail.d.ts +2 -2
- package/dist/ui/scrollback/LiveTail.js +7 -2
- package/dist/ui/scrollback/live-preview.js +10 -3
- package/dist/ui/scrollback/tail-window.d.ts +12 -0
- package/dist/ui/scrollback/tail-window.js +17 -2
- package/dist/ui/scrollback/use-scrollback-view.js +7 -0
- package/dist/ui/team-status.d.ts +141 -0
- package/dist/ui/team-status.js +224 -0
- package/dist/ui/transcript-text.js +13 -4
- package/dist/ui/use-wheel-routing.js +2 -2
- package/package.json +2 -2
|
@@ -23,6 +23,7 @@ import { getLogger } from '../logging/logger.js';
|
|
|
23
23
|
import { resolveFastTier } from '../fast/resolve.js';
|
|
24
24
|
import { subagentModelSummary } from '../ui/overlays/model-profile-state.js';
|
|
25
25
|
import { registerQueueCommand } from './queue-command.js';
|
|
26
|
+
import { registerKitCommand } from './kit-command.js';
|
|
26
27
|
import { perfCommand } from './perf.js';
|
|
27
28
|
import { runCompactCommand } from '../compaction/command.js';
|
|
28
29
|
import { runClearCommand } from './clear-command.js';
|
|
@@ -1371,6 +1372,9 @@ export function registerBuiltinCommands(registry) {
|
|
|
1371
1372
|
for (const command of COMMANDS)
|
|
1372
1373
|
registry.register(command);
|
|
1373
1374
|
registerQueueCommand(registry);
|
|
1375
|
+
// The command BODY lives in its own module (builtins.ts is already 1.5k lines);
|
|
1376
|
+
// this line is the whole registration (agent-model-kits §4.9).
|
|
1377
|
+
registerKitCommand(registry);
|
|
1374
1378
|
}
|
|
1375
1379
|
/**
|
|
1376
1380
|
* Every built-in command name INCLUDING aliases (`quit`), for documentation and
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `/kit` - the slash surface for agent model kits (agent-model-kits §4.9).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - `src/commands/**` is inside `glyphs.test.ts::inScope`.
|
|
5
|
+
*
|
|
6
|
+
* WHY A COMMAND AT ALL, WHEN `ctrl+K` EXISTS: a key that a terminal, tmux, an
|
|
7
|
+
* input method or a IME can swallow needs an equivalent that cannot be swallowed
|
|
8
|
+
* (`R-4`), and the same reading is what a user pastes into an issue. The two
|
|
9
|
+
* surfaces call the SAME controller methods, so they can never diverge in
|
|
10
|
+
* behaviour - only in how the answer is rendered.
|
|
11
|
+
*
|
|
12
|
+
* THERE IS NO `/kit default` (D-7): the session path is forbidden from writing
|
|
13
|
+
* the file, so a "make this the default" verb here would be the one hole in that
|
|
14
|
+
* promise. Setting a default is a settings action, with a Save the user sees.
|
|
15
|
+
*/
|
|
16
|
+
import type { CommandRegistry, CommandContext } from './registry.js';
|
|
17
|
+
/** The command body; `registerKitCommand` is the only registration site. */
|
|
18
|
+
export declare function runKitCommand(ctx: CommandContext): void;
|
|
19
|
+
/** Registered from `builtins.ts` with one line, next to every other subsystem. */
|
|
20
|
+
export declare function registerKitCommand(registry: CommandRegistry): void;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `/kit` - the slash surface for agent model kits (agent-model-kits §4.9).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - `src/commands/**` is inside `glyphs.test.ts::inScope`.
|
|
5
|
+
*
|
|
6
|
+
* WHY A COMMAND AT ALL, WHEN `ctrl+K` EXISTS: a key that a terminal, tmux, an
|
|
7
|
+
* input method or a IME can swallow needs an equivalent that cannot be swallowed
|
|
8
|
+
* (`R-4`), and the same reading is what a user pastes into an issue. The two
|
|
9
|
+
* surfaces call the SAME controller methods, so they can never diverge in
|
|
10
|
+
* behaviour - only in how the answer is rendered.
|
|
11
|
+
*
|
|
12
|
+
* THERE IS NO `/kit default` (D-7): the session path is forbidden from writing
|
|
13
|
+
* the file, so a "make this the default" verb here would be the one hole in that
|
|
14
|
+
* promise. Setting a default is a settings action, with a Save the user sees.
|
|
15
|
+
*/
|
|
16
|
+
import { kitMatches, findKit, kitSlotConnections } from '../config/model-kits.js';
|
|
17
|
+
import { kitApplyMessage, kitNoteMessages } from '../agent/kit-apply.js';
|
|
18
|
+
/** `main a:b / sub same as main / fast off`, shared by every branch below. */
|
|
19
|
+
function describeKit(config, kit) {
|
|
20
|
+
const connections = kitSlotConnections(config.modelProfiles, kit);
|
|
21
|
+
const main = connections.main
|
|
22
|
+
? `${connections.main.provider}:${connections.main.model}` : 'Profile missing';
|
|
23
|
+
const fast = kit.fastProfileId === null ? 'off'
|
|
24
|
+
: connections.fast ? `${connections.fast.provider}:${connections.fast.model}`
|
|
25
|
+
: 'Profile missing';
|
|
26
|
+
const subagent = kit.subagent.model === 'main' ? 'same as main'
|
|
27
|
+
: kit.subagent.model === 'fast' ? 'fast tier'
|
|
28
|
+
: connections.subagent.name ? `profile ${connections.subagent.name}` : 'Profile missing';
|
|
29
|
+
return `main ${main} / sub ${subagent} / fast ${fast}`;
|
|
30
|
+
}
|
|
31
|
+
function kitNames(config) {
|
|
32
|
+
return (config.modelProfiles?.kits ?? []).map((kit) => kit.name);
|
|
33
|
+
}
|
|
34
|
+
/** `/kit` with no argument: what is in effect, and what it resolves to. */
|
|
35
|
+
function reportActive(ctx) {
|
|
36
|
+
const config = ctx.controller.getConfig();
|
|
37
|
+
const active = ctx.controller.getActiveKit();
|
|
38
|
+
const kits = config.modelProfiles?.kits ?? [];
|
|
39
|
+
if (!kits.length) {
|
|
40
|
+
ctx.notify('info', 'No kits yet. Create one in /settings (Settings > Kit pack).');
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const session = active.source === 'session'
|
|
44
|
+
? `session: ${active.name}${active.held.length < 3
|
|
45
|
+
? `, holds ${active.held.join('+')}` : ''}`
|
|
46
|
+
: active.source === 'default' ? 'default' : 'current setup';
|
|
47
|
+
const kit = findKit(config.modelProfiles, active.id);
|
|
48
|
+
const detail = kit ? ` ${describeKit(config, kit)}.` : '';
|
|
49
|
+
const drift = active.modified && active.driftReasons.length
|
|
50
|
+
? ` Drifted: ${active.driftReasons.join('; ')}.` : '';
|
|
51
|
+
ctx.notify('info', `Kit pack: ${active.name} (${session}).${detail}${drift}`);
|
|
52
|
+
}
|
|
53
|
+
/** `/kit list`: every kit, its markers and its three connections. */
|
|
54
|
+
function listKits(ctx) {
|
|
55
|
+
const config = ctx.controller.getConfig();
|
|
56
|
+
const kits = config.modelProfiles?.kits ?? [];
|
|
57
|
+
const active = ctx.controller.getActiveKit();
|
|
58
|
+
const fallback = config.modelProfiles?.defaultKitId ?? null;
|
|
59
|
+
if (!kits.length) {
|
|
60
|
+
ctx.notify('info', 'No kits yet. Create one in /settings.');
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const lines = kits.map((kit) => {
|
|
64
|
+
const markers = [kit.id === fallback ? '[Default]' : '',
|
|
65
|
+
active.source !== 'none' && active.id === kit.id ? '[In use]' : '',
|
|
66
|
+
active.source !== 'none' && active.id === kit.id && active.modified ? '~' : '']
|
|
67
|
+
.filter(Boolean).join(' ');
|
|
68
|
+
return `${markers ? `${markers} ` : ''}${kit.name}: ${describeKit(config, kit)}`;
|
|
69
|
+
});
|
|
70
|
+
ctx.notify('info', `Kits (${kits.length}):\n${lines.join('\n')}`);
|
|
71
|
+
}
|
|
72
|
+
/** `/kit use current` and `/kit use <name|#prefix>`. */
|
|
73
|
+
function useKit(ctx, ref) {
|
|
74
|
+
const config = ctx.controller.getConfig();
|
|
75
|
+
if (ref.toLowerCase() === 'current') {
|
|
76
|
+
const released = ctx.controller.clearSessionKit();
|
|
77
|
+
ctx.toast(released.ok ? 'success' : 'warn', kitApplyMessage(released));
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const matches = kitMatches(config.modelProfiles, ref);
|
|
81
|
+
if (!matches.length) {
|
|
82
|
+
const names = kitNames(config);
|
|
83
|
+
ctx.notify('warn', `No kit named "${ref}".`
|
|
84
|
+
+ (names.length ? ` Available: ${names.join(', ')}.` : ' Create one in /settings first.'));
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (matches.length > 1) {
|
|
88
|
+
const ids = matches.map((kit) => `#${kit.id.slice(0, 8)}`).join(', ');
|
|
89
|
+
ctx.notify('warn', `Two or more kits are named "${ref}": ${ids}. Use one of those ids.`);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const kit = matches[0];
|
|
93
|
+
const result = ctx.controller.applySessionKit(kit.id);
|
|
94
|
+
if (!result.ok) {
|
|
95
|
+
// `kit_references_missing_profile` names the SLOT in its issues; without them
|
|
96
|
+
// the user would have to open three screens to find out which one is dead.
|
|
97
|
+
const detail = (result.issues ?? []).map((issue) => issue.message).join(' ');
|
|
98
|
+
ctx.notify('warn', [kitApplyMessage(result), detail].filter(Boolean).join(' '));
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const notes = kitNoteMessages(result.notes);
|
|
102
|
+
ctx.toast(notes.length ? 'warn' : 'success', [`Kit ${kit.name} applied for this session.`, ...notes].join(' '));
|
|
103
|
+
}
|
|
104
|
+
/** The command body; `registerKitCommand` is the only registration site. */
|
|
105
|
+
export function runKitCommand(ctx) {
|
|
106
|
+
const args = ctx.args.trim();
|
|
107
|
+
if (!args) {
|
|
108
|
+
reportActive(ctx);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const [verb = '', ...rest] = args.split(/\s+/);
|
|
112
|
+
if (verb.toLowerCase() === 'list') {
|
|
113
|
+
listKits(ctx);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (verb.toLowerCase() === 'use') {
|
|
117
|
+
const ref = rest.join(' ').trim();
|
|
118
|
+
if (!ref) {
|
|
119
|
+
ctx.notify('warn', 'Which kit? Use /kit use <name|#id prefix>, or /kit use current.');
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
useKit(ctx, ref);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
ctx.notify('warn', 'Unknown /kit subcommand. Try /kit, /kit list, /kit use <name>.');
|
|
126
|
+
}
|
|
127
|
+
/** Registered from `builtins.ts` with one line, next to every other subsystem. */
|
|
128
|
+
export function registerKitCommand(registry) {
|
|
129
|
+
registry.register({ name: 'kit', description: 'Agent kits: status, list, use for this session',
|
|
130
|
+
run: (ctx) => { runKitCommand(ctx); } });
|
|
131
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the ACTIVE kit comes from, and the two places a session kit has to be
|
|
3
|
+
* re-applied (agent-model-kits §4.3 / D-5 / D-6).
|
|
4
|
+
*
|
|
5
|
+
* ASCII ONLY - `src/config/**` is inside `glyphs.test.ts::inScope`.
|
|
6
|
+
*
|
|
7
|
+
* ONE TRUTH, PURELY DERIVED. `CliConfig` carries only `sessionKit: {id, held}`;
|
|
8
|
+
* everything a surface prints about "which kit is running" comes out of
|
|
9
|
+
* `resolveActiveKit(config)`. There is no `config.activeKit` field, because a
|
|
10
|
+
* second copy of that answer is a copy that can disagree with the first.
|
|
11
|
+
*/
|
|
12
|
+
import type { CliConfig, FastConfig, TeamConfig } from './schema.js';
|
|
13
|
+
import type { ModelProfilesConfig } from './model-profiles.js';
|
|
14
|
+
import { type KitSlot, type SessionKitState } from './model-kits.js';
|
|
15
|
+
/** The three slots, in the order every surface prints them. */
|
|
16
|
+
export declare const ALL_SLOTS: readonly KitSlot[];
|
|
17
|
+
/** The name the UI gives "no kit is in effect" (D-13). */
|
|
18
|
+
export declare const CURRENT_SETUP_NAME = "Current setup";
|
|
19
|
+
/**
|
|
20
|
+
* The answer when there is no kit, or when the host has no kit support at all.
|
|
21
|
+
*
|
|
22
|
+
* A CONSTANT SO CALLERS CANNOT INVENT A SECOND SHAPE: `App` needs one value that
|
|
23
|
+
* renders "no chip, `Current setup` row" for a controller that predates this
|
|
24
|
+
* port (a test double, an embedded host), and re-deriving it there would be a
|
|
25
|
+
* second definition of "nothing".
|
|
26
|
+
*/
|
|
27
|
+
export declare const INACTIVE_KIT: ActiveKit;
|
|
28
|
+
export interface ActiveKit {
|
|
29
|
+
source: 'session' | 'default' | 'none';
|
|
30
|
+
id: string | null;
|
|
31
|
+
/** `Current setup` when `source === 'none'`. */
|
|
32
|
+
name: string;
|
|
33
|
+
/** `[]` when `source === 'none'`; all three for a default kit. */
|
|
34
|
+
held: KitSlot[];
|
|
35
|
+
/** The kit's definition and the live connections no longer agree (§4.8). */
|
|
36
|
+
modified: boolean;
|
|
37
|
+
/** Human-readable ASCII reasons, for `/kit` and the root row. */
|
|
38
|
+
driftReasons: string[];
|
|
39
|
+
/** Slots whose referenced profile is gone (RV-P1-1 / I-8). */
|
|
40
|
+
missingProfiles: KitSlot[];
|
|
41
|
+
}
|
|
42
|
+
/** The session-kit runtime shape, owned by `model-kits.ts` and re-exported here. */
|
|
43
|
+
export type { SessionKitState } from './model-kits.js';
|
|
44
|
+
/**
|
|
45
|
+
* Which kit is in effect, and whether it has drifted (§4.8).
|
|
46
|
+
*
|
|
47
|
+
* Precedence is D-6's: session kit, then the persisted default, then the disk
|
|
48
|
+
* bindings (which the UI calls `Current setup`).
|
|
49
|
+
*/
|
|
50
|
+
export declare function resolveActiveKit(config: CliConfig): ActiveKit;
|
|
51
|
+
/**
|
|
52
|
+
* The minimum a candidate has to offer for the held slots to be re-applied.
|
|
53
|
+
*
|
|
54
|
+
* STRUCTURAL, NOT `PersistedConfig`: the same routine serves a disk candidate on
|
|
55
|
+
* its way to `liveCandidate` and a freshly reloaded `CliConfig`, and forcing
|
|
56
|
+
* either through a cast at the call site would hide the fact that only these
|
|
57
|
+
* three sections are ever written.
|
|
58
|
+
*/
|
|
59
|
+
export interface HeldTarget {
|
|
60
|
+
modelProfiles?: ModelProfilesConfig;
|
|
61
|
+
fast?: Partial<FastConfig>;
|
|
62
|
+
team?: Partial<TeamConfig>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Re-apply the still-`held` slots of a session kit onto a candidate.
|
|
66
|
+
*
|
|
67
|
+
* THE RETURN VALUE MAY ONLY EVER FEED `liveCandidate`. It must NEVER be handed
|
|
68
|
+
* to `commitModelSettings` (I-14 / RV-P0-1): "this session only" is a claim
|
|
69
|
+
* about the FILE, and a held slot that reaches the commit turns one unrelated
|
|
70
|
+
* save into a permanent, invisible change of the user's defaults. The one
|
|
71
|
+
* caller is `prepareModelSettings` in `agent/model-profile-settings.ts`, which
|
|
72
|
+
* keeps the two candidates in separate variables for exactly this reason.
|
|
73
|
+
*
|
|
74
|
+
* Slots whose kit, or whose referenced profile, disappeared are DROPPED and
|
|
75
|
+
* reported, so the caller can log the release instead of silently forgetting it.
|
|
76
|
+
*/
|
|
77
|
+
export declare function applyHeldToLive<T extends HeldTarget>(candidate: T, sessionKit: SessionKitState | null | undefined): {
|
|
78
|
+
candidate: T;
|
|
79
|
+
dropped: KitSlot[];
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Keep a session kit alive across `Reload settings` (D-6).
|
|
83
|
+
*
|
|
84
|
+
* THE PROJECTION HAS TO BE RECOMPUTED, not just the bindings: `I-3` says a
|
|
85
|
+
* library's projections never depend on whether a kit exists, so a live config
|
|
86
|
+
* whose `mainId` says "kit" while `provider`/`model` still name the reloaded
|
|
87
|
+
* file would break the equivalence every other surface relies on. Hence the
|
|
88
|
+
* round trip through `projectModelProfiles` + `resolveModelProfileState`.
|
|
89
|
+
*/
|
|
90
|
+
export declare function carrySessionKit(input: {
|
|
91
|
+
resolved: CliConfig;
|
|
92
|
+
previous: CliConfig;
|
|
93
|
+
}): CliConfig;
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the ACTIVE kit comes from, and the two places a session kit has to be
|
|
3
|
+
* re-applied (agent-model-kits §4.3 / D-5 / D-6).
|
|
4
|
+
*
|
|
5
|
+
* ASCII ONLY - `src/config/**` is inside `glyphs.test.ts::inScope`.
|
|
6
|
+
*
|
|
7
|
+
* ONE TRUTH, PURELY DERIVED. `CliConfig` carries only `sessionKit: {id, held}`;
|
|
8
|
+
* everything a surface prints about "which kit is running" comes out of
|
|
9
|
+
* `resolveActiveKit(config)`. There is no `config.activeKit` field, because a
|
|
10
|
+
* second copy of that answer is a copy that can disagree with the first.
|
|
11
|
+
*/
|
|
12
|
+
import { getLogger } from '../logging/logger.js';
|
|
13
|
+
import { normalizeProfileBaseUrl, projectModelProfiles, resolveModelProfileState } from './model-profile-resolution.js';
|
|
14
|
+
import { findKit, kitCandidate, kitSlotConnections } from './model-kits.js';
|
|
15
|
+
/** The three slots, in the order every surface prints them. */
|
|
16
|
+
export const ALL_SLOTS = ['main', 'fast', 'subagent'];
|
|
17
|
+
/** The name the UI gives "no kit is in effect" (D-13). */
|
|
18
|
+
export const CURRENT_SETUP_NAME = 'Current setup';
|
|
19
|
+
/**
|
|
20
|
+
* The answer when there is no kit, or when the host has no kit support at all.
|
|
21
|
+
*
|
|
22
|
+
* A CONSTANT SO CALLERS CANNOT INVENT A SECOND SHAPE: `App` needs one value that
|
|
23
|
+
* renders "no chip, `Current setup` row" for a controller that predates this
|
|
24
|
+
* port (a test double, an embedded host), and re-deriving it there would be a
|
|
25
|
+
* second definition of "nothing".
|
|
26
|
+
*/
|
|
27
|
+
export const INACTIVE_KIT = { source: 'none', id: null,
|
|
28
|
+
name: CURRENT_SETUP_NAME, held: [], modified: false, driftReasons: [],
|
|
29
|
+
missingProfiles: [] };
|
|
30
|
+
function driftOfMain(config, connection) {
|
|
31
|
+
if (!connection)
|
|
32
|
+
return [];
|
|
33
|
+
const changed = [];
|
|
34
|
+
if (config.provider !== connection.provider)
|
|
35
|
+
changed.push('provider');
|
|
36
|
+
if (config.model !== connection.model)
|
|
37
|
+
changed.push('model');
|
|
38
|
+
if (normalizeProfileBaseUrl(config.baseUrl) !== normalizeProfileBaseUrl(connection.baseUrl)) {
|
|
39
|
+
changed.push('endpoint');
|
|
40
|
+
}
|
|
41
|
+
return changed.length ? [`main: ${changed.join(', ')} changed`] : [];
|
|
42
|
+
}
|
|
43
|
+
function driftOfFast(config, kit, connection) {
|
|
44
|
+
if (kit.fastProfileId === null) {
|
|
45
|
+
// D-8: this kit TURNS THE TIER OFF, so the endpoints are irrelevant - only
|
|
46
|
+
// "is it on" can disagree. Comparing endpoints here would report drift for
|
|
47
|
+
// every user who ever ran a fast tier before applying a fast-off kit.
|
|
48
|
+
return config.fast.enabled ? ['fast: turned back on'] : [];
|
|
49
|
+
}
|
|
50
|
+
if (!connection)
|
|
51
|
+
return [];
|
|
52
|
+
const changed = [];
|
|
53
|
+
if (!config.fast.enabled)
|
|
54
|
+
changed.push('off');
|
|
55
|
+
if (config.fast.provider !== connection.provider)
|
|
56
|
+
changed.push('provider');
|
|
57
|
+
if (config.fast.model !== connection.model)
|
|
58
|
+
changed.push('model');
|
|
59
|
+
if (normalizeProfileBaseUrl(config.fast.baseUrl)
|
|
60
|
+
!== normalizeProfileBaseUrl(connection.baseUrl))
|
|
61
|
+
changed.push('endpoint');
|
|
62
|
+
return changed.length ? [`fast: ${changed.join(', ')} changed`] : [];
|
|
63
|
+
}
|
|
64
|
+
function driftOfSubagent(config, kit, connection) {
|
|
65
|
+
if (!connection)
|
|
66
|
+
return [];
|
|
67
|
+
const sameMode = config.team?.model === kit.subagent.model;
|
|
68
|
+
const sameId = kit.subagent.model === 'profile'
|
|
69
|
+
? (config.team?.modelProfileId ?? null) === kit.subagent.modelProfileId : true;
|
|
70
|
+
return sameMode && sameId ? [] : ['subagent: changed'];
|
|
71
|
+
}
|
|
72
|
+
function subagentConnection(config, kit) {
|
|
73
|
+
if (kit.subagent.model === 'profile')
|
|
74
|
+
return kit.subagent.modelProfileId;
|
|
75
|
+
return kit.subagent.model === 'main' ? 'main' : 'fast';
|
|
76
|
+
}
|
|
77
|
+
/** Build the verdict for a kit that exists, whatever installed it. */
|
|
78
|
+
function describe(config, library, kit, source, held) {
|
|
79
|
+
const connections = kitSlotConnections(library, kit);
|
|
80
|
+
const drift = { reasons: [], missing: [] };
|
|
81
|
+
if (held.includes('main')) {
|
|
82
|
+
if (!connections.main)
|
|
83
|
+
drift.missing.push('main');
|
|
84
|
+
else
|
|
85
|
+
drift.reasons.push(...driftOfMain(config, connections.main));
|
|
86
|
+
}
|
|
87
|
+
if (held.includes('fast')) {
|
|
88
|
+
if (kit.fastProfileId !== null && !connections.fast)
|
|
89
|
+
drift.missing.push('fast');
|
|
90
|
+
else
|
|
91
|
+
drift.reasons.push(...driftOfFast(config, kit, connections.fast));
|
|
92
|
+
}
|
|
93
|
+
if (held.includes('subagent')) {
|
|
94
|
+
const missingProfile = kit.subagent.model === 'profile' && !connections.subagent.name;
|
|
95
|
+
if (missingProfile)
|
|
96
|
+
drift.missing.push('subagent');
|
|
97
|
+
else
|
|
98
|
+
drift.reasons.push(...driftOfSubagent(config, kit, subagentConnection(config, kit)));
|
|
99
|
+
}
|
|
100
|
+
if (held.length < ALL_SLOTS.length)
|
|
101
|
+
drift.reasons.push(`holds ${held.join('+') || 'nothing'}`);
|
|
102
|
+
return { source, id: kit.id, name: kit.name, held: [...held],
|
|
103
|
+
modified: held.length < ALL_SLOTS.length || drift.reasons.length > 0
|
|
104
|
+
|| drift.missing.length > 0,
|
|
105
|
+
driftReasons: drift.reasons, missingProfiles: drift.missing };
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Which kit is in effect, and whether it has drifted (§4.8).
|
|
109
|
+
*
|
|
110
|
+
* Precedence is D-6's: session kit, then the persisted default, then the disk
|
|
111
|
+
* bindings (which the UI calls `Current setup`).
|
|
112
|
+
*/
|
|
113
|
+
export function resolveActiveKit(config) {
|
|
114
|
+
const library = config.modelProfiles;
|
|
115
|
+
const state = config.sessionKit;
|
|
116
|
+
const session = state ? findKit(library, state.id) : undefined;
|
|
117
|
+
if (state && session) {
|
|
118
|
+
const held = state.held.filter((slot) => ALL_SLOTS.includes(slot));
|
|
119
|
+
return describe(config, library, session, 'session', held.length ? held : []);
|
|
120
|
+
}
|
|
121
|
+
const fallback = findKit(library, library?.defaultKitId ?? null);
|
|
122
|
+
if (library && fallback)
|
|
123
|
+
return describe(config, library, fallback, 'default', [...ALL_SLOTS]);
|
|
124
|
+
return { source: 'none', id: null, name: CURRENT_SETUP_NAME, held: [], modified: false,
|
|
125
|
+
driftReasons: [], missingProfiles: [] };
|
|
126
|
+
}
|
|
127
|
+
function slotSurvives(library, kit, slot) {
|
|
128
|
+
const ids = new Set(library.entries.map((entry) => entry.id));
|
|
129
|
+
if (slot === 'main')
|
|
130
|
+
return ids.has(kit.mainProfileId);
|
|
131
|
+
if (slot === 'fast')
|
|
132
|
+
return kit.fastProfileId === null || ids.has(kit.fastProfileId);
|
|
133
|
+
return kit.subagent.model !== 'profile'
|
|
134
|
+
|| (!!kit.subagent.modelProfileId && ids.has(kit.subagent.modelProfileId));
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Re-apply the still-`held` slots of a session kit onto a candidate.
|
|
138
|
+
*
|
|
139
|
+
* THE RETURN VALUE MAY ONLY EVER FEED `liveCandidate`. It must NEVER be handed
|
|
140
|
+
* to `commitModelSettings` (I-14 / RV-P0-1): "this session only" is a claim
|
|
141
|
+
* about the FILE, and a held slot that reaches the commit turns one unrelated
|
|
142
|
+
* save into a permanent, invisible change of the user's defaults. The one
|
|
143
|
+
* caller is `prepareModelSettings` in `agent/model-profile-settings.ts`, which
|
|
144
|
+
* keeps the two candidates in separate variables for exactly this reason.
|
|
145
|
+
*
|
|
146
|
+
* Slots whose kit, or whose referenced profile, disappeared are DROPPED and
|
|
147
|
+
* reported, so the caller can log the release instead of silently forgetting it.
|
|
148
|
+
*/
|
|
149
|
+
export function applyHeldToLive(candidate, sessionKit) {
|
|
150
|
+
const heldIn = sessionKit?.held ?? [];
|
|
151
|
+
if (!sessionKit || heldIn.length === 0)
|
|
152
|
+
return { candidate, dropped: [] };
|
|
153
|
+
const library = candidate.modelProfiles;
|
|
154
|
+
const kit = findKit(library, sessionKit.id);
|
|
155
|
+
if (!library || !kit)
|
|
156
|
+
return { candidate, dropped: [...heldIn] };
|
|
157
|
+
const held = heldIn.filter((slot) => slotSurvives(library, kit, slot));
|
|
158
|
+
const dropped = heldIn.filter((slot) => !held.includes(slot));
|
|
159
|
+
if (!held.length)
|
|
160
|
+
return { candidate, dropped };
|
|
161
|
+
const patch = kitCandidate({ library, kit });
|
|
162
|
+
const next = {
|
|
163
|
+
...candidate,
|
|
164
|
+
modelProfiles: { ...library,
|
|
165
|
+
...(held.includes('main') ? { mainId: kit.mainProfileId } : {}),
|
|
166
|
+
...(held.includes('fast') ? { fastId: kit.fastProfileId } : {}) },
|
|
167
|
+
};
|
|
168
|
+
if (held.includes('subagent')) {
|
|
169
|
+
next.team = { ...candidate.team, ...patch.team };
|
|
170
|
+
}
|
|
171
|
+
if (held.includes('fast')) {
|
|
172
|
+
next.fast = { ...candidate.fast, enabled: kit.fastProfileId !== null };
|
|
173
|
+
}
|
|
174
|
+
return { candidate: next, dropped };
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Keep a session kit alive across `Reload settings` (D-6).
|
|
178
|
+
*
|
|
179
|
+
* THE PROJECTION HAS TO BE RECOMPUTED, not just the bindings: `I-3` says a
|
|
180
|
+
* library's projections never depend on whether a kit exists, so a live config
|
|
181
|
+
* whose `mainId` says "kit" while `provider`/`model` still name the reloaded
|
|
182
|
+
* file would break the equivalence every other surface relies on. Hence the
|
|
183
|
+
* round trip through `projectModelProfiles` + `resolveModelProfileState`.
|
|
184
|
+
*/
|
|
185
|
+
export function carrySessionKit(input) {
|
|
186
|
+
const state = input.previous.sessionKit;
|
|
187
|
+
const { resolved } = input;
|
|
188
|
+
if (!state)
|
|
189
|
+
return resolved;
|
|
190
|
+
const library = resolved.modelProfiles;
|
|
191
|
+
const kit = findKit(library, state.id);
|
|
192
|
+
if (!library || !kit) {
|
|
193
|
+
getLogger().warn('config', 'session_kit_released', { reason: 'kit_missing' });
|
|
194
|
+
return { ...resolved, sessionKit: undefined };
|
|
195
|
+
}
|
|
196
|
+
const applied = applyHeldToLive(resolved, state);
|
|
197
|
+
const held = state.held.filter((slot) => !applied.dropped.includes(slot));
|
|
198
|
+
if (!held.length) {
|
|
199
|
+
getLogger().warn('config', 'session_kit_released', { reason: 'slots_dropped' });
|
|
200
|
+
return { ...resolved, sessionKit: undefined };
|
|
201
|
+
}
|
|
202
|
+
const file = applied.candidate;
|
|
203
|
+
const projected = projectModelProfiles(file).file;
|
|
204
|
+
const next = { ...resolved, modelProfiles: projected.modelProfiles };
|
|
205
|
+
if (held.includes('main')) {
|
|
206
|
+
next.provider = projected.provider;
|
|
207
|
+
next.model = projected.model;
|
|
208
|
+
next.baseUrl = projected.baseUrl ?? undefined;
|
|
209
|
+
if (next.contextWindowOrigin !== 'env') {
|
|
210
|
+
next.contextWindow = projected.contextWindow ?? null;
|
|
211
|
+
next.contextWindowOrigin = next.contextWindow === null ? undefined : 'profile';
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (held.includes('fast') && projected.fast) {
|
|
215
|
+
next.fast = { ...next.fast, provider: projected.fast.provider ?? '',
|
|
216
|
+
model: projected.fast.model ?? '', baseUrl: projected.fast.baseUrl ?? '' };
|
|
217
|
+
}
|
|
218
|
+
if (held.includes('subagent') && file.team)
|
|
219
|
+
next.team = { ...next.team, ...file.team };
|
|
220
|
+
next.modelProfileState = resolveModelProfileState(next);
|
|
221
|
+
next.sessionKit = { id: kit.id, held };
|
|
222
|
+
if (applied.dropped.length) {
|
|
223
|
+
getLogger().warn('config', 'session_kit_slots_dropped', { slots: applied.dropped });
|
|
224
|
+
}
|
|
225
|
+
return next;
|
|
226
|
+
}
|