chainlesschain 0.166.163 → 0.166.165
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 +28 -2
- package/package.json +1 -1
- package/src/assets/linux-subreaper/linux-arm64/manifest.json +1 -1
- package/src/assets/linux-subreaper/linux-x64/manifest.json +1 -1
- package/src/data/changelog.json +26 -0
- package/src/lib/settings-loader.cjs +9 -2
- package/src/repl/agent-repl.js +387 -243
- package/src/repl/permission-prompt.js +62 -5
- package/src/repl/terminal-window.js +363 -0
- package/src/runtime/headless-stream.js +18 -2
package/src/repl/agent-repl.js
CHANGED
|
@@ -138,6 +138,9 @@ import {
|
|
|
138
138
|
selectModelForTask,
|
|
139
139
|
} from "../lib/task-model-selector.js";
|
|
140
140
|
import { runnableTaskModel, hasUsableKey } from "../lib/runnable-provider.js";
|
|
141
|
+
import { resolveProviderDefinition } from "../lib/llm-providers.js";
|
|
142
|
+
import { isLkEndpoint, LK_MODELS } from "../lib/llm-channel-presets.js";
|
|
143
|
+
import { maybeWarnDeprecatedModel } from "../lib/model-deprecation.js";
|
|
141
144
|
import { CLIPermanentMemory } from "../lib/permanent-memory.js";
|
|
142
145
|
import { resolveClaudeProjectAutoMemory } from "../lib/claude-project-auto-memory.js";
|
|
143
146
|
import { CLIAutonomousAgent, GoalStatus } from "../lib/autonomous-agent.js";
|
|
@@ -225,11 +228,11 @@ import {
|
|
|
225
228
|
buildPermissionPrompt,
|
|
226
229
|
resolveAskIdleTimeoutMs,
|
|
227
230
|
questionWithIdleTimeout,
|
|
231
|
+
createReplQuestionQueue,
|
|
228
232
|
} from "./permission-prompt.js";
|
|
229
233
|
import { describeAskContext, raceLocalAndRemote } from "./remote-approval.js";
|
|
230
234
|
import { runWithHostHooksV2Workspace } from "../lib/hooks-v2-workspace-context.js";
|
|
231
235
|
import {
|
|
232
|
-
parsePermissionTier,
|
|
233
236
|
parsePermissionModeArg,
|
|
234
237
|
permissionModeForTier,
|
|
235
238
|
describeTier,
|
|
@@ -3182,6 +3185,7 @@ export async function startAgentRepl(options = {}) {
|
|
|
3182
3185
|
async function startAgentReplInWorkspace(options = {}, startupAdmission) {
|
|
3183
3186
|
let failureHandler = null;
|
|
3184
3187
|
let disposePipeSafety = null;
|
|
3188
|
+
let disposeTerminalWindow = null;
|
|
3185
3189
|
const flow = installOutputBackpressure({
|
|
3186
3190
|
stdout: process.stdout,
|
|
3187
3191
|
stderr: process.stderr,
|
|
@@ -3197,9 +3201,13 @@ async function startAgentReplInWorkspace(options = {}, startupAdmission) {
|
|
|
3197
3201
|
setPipeDisposer(disposer) {
|
|
3198
3202
|
disposePipeSafety = disposer;
|
|
3199
3203
|
},
|
|
3204
|
+
setTerminalDisposer(disposer) {
|
|
3205
|
+
disposeTerminalWindow = disposer;
|
|
3206
|
+
},
|
|
3200
3207
|
restore() {
|
|
3201
3208
|
if (restored) return;
|
|
3202
3209
|
restored = true;
|
|
3210
|
+
disposeTerminalWindow?.();
|
|
3203
3211
|
disposePipeSafety?.();
|
|
3204
3212
|
flow.restore();
|
|
3205
3213
|
},
|
|
@@ -3358,7 +3366,7 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
3358
3366
|
// clear steering immediately so queued work cannot start another paid call.
|
|
3359
3367
|
let _processingLine = false;
|
|
3360
3368
|
let _lineSettled = null;
|
|
3361
|
-
const
|
|
3369
|
+
const _activeConcurrentCalls = new Set();
|
|
3362
3370
|
const _mcpTaskTrackers = new Map();
|
|
3363
3371
|
const _mcpTaskAutoWakeQueue = [];
|
|
3364
3372
|
let _mcpTaskAutoWakeRunning = false;
|
|
@@ -3459,6 +3467,7 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
3459
3467
|
}
|
|
3460
3468
|
};
|
|
3461
3469
|
let model = options.model || "qwen2.5:7b";
|
|
3470
|
+
let pendingModel = null;
|
|
3462
3471
|
let provider = options.provider || "ollama";
|
|
3463
3472
|
// Extended thinking (Anthropic; opt-in via --think/--ultrathink). Carried from
|
|
3464
3473
|
// the runtime policy into the agent-loop options below. Mutable so the
|
|
@@ -3823,6 +3832,8 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
3823
3832
|
// (strict / trusted / autopilot).
|
|
3824
3833
|
let _renderStatus = null;
|
|
3825
3834
|
let _managedSettings = null;
|
|
3835
|
+
let _replQuestions;
|
|
3836
|
+
let baseApprovalGate;
|
|
3826
3837
|
try {
|
|
3827
3838
|
const { getApprovalGate } =
|
|
3828
3839
|
await import("../lib/session-core-singletons.js");
|
|
@@ -3831,6 +3842,7 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
3831
3842
|
_approvalGate?.createSessionScope?.(
|
|
3832
3843
|
sessionId || `repl-scope:${randomUUID()}`,
|
|
3833
3844
|
) || _approvalGate;
|
|
3845
|
+
baseApprovalGate = _approvalGate;
|
|
3834
3846
|
_approvalGate?.setAuthorizationConsumer?.(null);
|
|
3835
3847
|
// autoMode.decisions: wrap the gate with the configurable classifier
|
|
3836
3848
|
// BEFORE setConfirmer so the wrapper captures the interactive confirmer.
|
|
@@ -3861,12 +3873,7 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
3861
3873
|
// the device answers first, and `canceled` mutes the stranded
|
|
3862
3874
|
// idle-timeout leg so it can't print "auto-denied" after the fact.
|
|
3863
3875
|
const askGateApprovalLocally = ({ tool, args, riskLevel }) => {
|
|
3864
|
-
const
|
|
3865
|
-
input: process.stdin,
|
|
3866
|
-
output: process.stdout,
|
|
3867
|
-
});
|
|
3868
|
-
let canceled = false;
|
|
3869
|
-
const q = (p) => new Promise((res) => rlConfirm.question(p, res));
|
|
3876
|
+
const question = _replQuestions.create();
|
|
3870
3877
|
const cmd = args?.command ? ` ${args.command}` : "";
|
|
3871
3878
|
const promise = (async () => {
|
|
3872
3879
|
const status = _renderStatus?.({
|
|
@@ -3875,16 +3882,16 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
3875
3882
|
});
|
|
3876
3883
|
if (status) process.stdout.write(status + "\n");
|
|
3877
3884
|
const res = await questionWithIdleTimeout(
|
|
3878
|
-
|
|
3885
|
+
question.ask,
|
|
3879
3886
|
chalk.yellow(
|
|
3880
3887
|
`\n[ApprovalGate] ${riskLevel || "medium"} risk command:${cmd}\n` +
|
|
3881
3888
|
` Proceed? [y]es once / [a]lways allow / [N]o: `,
|
|
3882
3889
|
),
|
|
3883
3890
|
_askIdleTimeoutMs,
|
|
3884
3891
|
);
|
|
3885
|
-
|
|
3886
|
-
if (canceled) return false; // raced out — the device already decided
|
|
3892
|
+
if (question.canceled) return false;
|
|
3887
3893
|
if (res.timedOut) {
|
|
3894
|
+
question.cancel();
|
|
3888
3895
|
process.stdout.write(
|
|
3889
3896
|
chalk.yellow(
|
|
3890
3897
|
`\n ⏱ no response in ${_askIdleTimeoutMs}ms — auto-denied\n`,
|
|
@@ -3892,7 +3899,7 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
3892
3899
|
);
|
|
3893
3900
|
return false;
|
|
3894
3901
|
}
|
|
3895
|
-
const ans = res.answer.trim().toLowerCase();
|
|
3902
|
+
const ans = (res.answer || "").trim().toLowerCase();
|
|
3896
3903
|
if (ans === "a" || ans === "always") {
|
|
3897
3904
|
const saved = await _persistAlwaysAllow(tool || "run_shell", args);
|
|
3898
3905
|
if (saved) {
|
|
@@ -3908,10 +3915,7 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
3908
3915
|
})();
|
|
3909
3916
|
return {
|
|
3910
3917
|
promise,
|
|
3911
|
-
cancel:
|
|
3912
|
-
canceled = true;
|
|
3913
|
-
rlConfirm.close();
|
|
3914
|
-
},
|
|
3918
|
+
cancel: question.cancel,
|
|
3915
3919
|
};
|
|
3916
3920
|
};
|
|
3917
3921
|
_approvalGate.setConfirmer(
|
|
@@ -3972,7 +3976,11 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
3972
3976
|
const { readBooleanSetting } = await import("../lib/settings-loader.cjs");
|
|
3973
3977
|
const { createPermissionRulesProvider, loadPermissionAuthority } =
|
|
3974
3978
|
await import("../lib/permission-authority.js");
|
|
3975
|
-
const permissionAuthorityOptions = {
|
|
3979
|
+
const permissionAuthorityOptions = {
|
|
3980
|
+
cwd: process.cwd(),
|
|
3981
|
+
settingsFile: options.settingsFile,
|
|
3982
|
+
managedSettingsFile: options.managedSettingsFile,
|
|
3983
|
+
};
|
|
3976
3984
|
const loaded = loadPermissionAuthority(permissionAuthorityOptions);
|
|
3977
3985
|
_managedSettings = loaded.managed;
|
|
3978
3986
|
_permissionRulesProvider = createPermissionRulesProvider(
|
|
@@ -3998,25 +4006,20 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
3998
4006
|
// Local prompt as a cancelable handle (same shape as the gate confirmer
|
|
3999
4007
|
// above) so /remote-control can race it against a paired device.
|
|
4000
4008
|
const askPermissionLocally = ({ tool, args, rule, reason }) => {
|
|
4001
|
-
const
|
|
4002
|
-
input: process.stdin,
|
|
4003
|
-
output: process.stdout,
|
|
4004
|
-
});
|
|
4005
|
-
let canceled = false;
|
|
4006
|
-
const q = (p) => new Promise((res) => rl.question(p, res));
|
|
4009
|
+
const question = _replQuestions.create();
|
|
4007
4010
|
// Picks the right phrasing whether the caller passed a `rule`
|
|
4008
4011
|
// (settings/hook ask) or a `reason` (destructive-git / sensitive-file
|
|
4009
4012
|
// guards) — avoids the literal "null" the old template printed.
|
|
4010
4013
|
const header = buildPermissionPrompt({ tool, args, rule, reason });
|
|
4011
4014
|
const promise = (async () => {
|
|
4012
4015
|
const res = await questionWithIdleTimeout(
|
|
4013
|
-
|
|
4016
|
+
question.ask,
|
|
4014
4017
|
chalk.yellow(`\n${header}\n Proceed? (y/N) `),
|
|
4015
4018
|
_askIdleTimeoutMs,
|
|
4016
4019
|
);
|
|
4017
|
-
|
|
4018
|
-
if (canceled) return false; // raced out — the device already decided
|
|
4020
|
+
if (question.canceled) return false;
|
|
4019
4021
|
if (res.timedOut) {
|
|
4022
|
+
question.cancel();
|
|
4020
4023
|
process.stdout.write(
|
|
4021
4024
|
chalk.yellow(
|
|
4022
4025
|
`\n ⏱ no response in ${_askIdleTimeoutMs}ms — auto-denied\n`,
|
|
@@ -4024,15 +4027,12 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
4024
4027
|
);
|
|
4025
4028
|
return false;
|
|
4026
4029
|
}
|
|
4027
|
-
const ans = res.answer.trim().toLowerCase();
|
|
4030
|
+
const ans = (res.answer || "").trim().toLowerCase();
|
|
4028
4031
|
return ans === "y" || ans === "yes";
|
|
4029
4032
|
})();
|
|
4030
4033
|
return {
|
|
4031
4034
|
promise,
|
|
4032
|
-
cancel:
|
|
4033
|
-
canceled = true;
|
|
4034
|
-
rl.close();
|
|
4035
|
-
},
|
|
4035
|
+
cancel: question.cancel,
|
|
4036
4036
|
};
|
|
4037
4037
|
};
|
|
4038
4038
|
// Confirmer is shared by permission `ask` rules AND hook `ask` decisions,
|
|
@@ -4951,43 +4951,30 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
4951
4951
|
}
|
|
4952
4952
|
}
|
|
4953
4953
|
|
|
4954
|
-
|
|
4955
|
-
const { assertManagedPermissionMode } =
|
|
4954
|
+
const { assertManagedPermissionMode, defaultInteractivePermissionMode } =
|
|
4956
4955
|
await import("../lib/settings-loader.cjs");
|
|
4957
|
-
|
|
4958
|
-
assertManagedPermissionMode(
|
|
4959
|
-
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
|
|
4964
|
-
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
_bundleResolved.approvalPolicy.default,
|
|
4974
|
-
);
|
|
4975
|
-
if (applied) setSessionTier(applied);
|
|
4976
|
-
} catch (error) {
|
|
4977
|
-
logger.warn(`Bundle approval policy was not persisted: ${error.message}`);
|
|
4978
|
-
}
|
|
4979
|
-
}
|
|
4980
|
-
|
|
4981
|
-
// --permission-mode for the interactive session (headless parity): manual →
|
|
4982
|
-
// strict, acceptEdits → trusted, bypassPermissions → autopilot, and auto →
|
|
4983
|
-
// trusted tier + the autoMode.decisions classifier. An explicit flag wins
|
|
4984
|
-
// over the bundle's approvalPolicy default. Unknown values are ignored here
|
|
4985
|
-
// (headless validates them; interactively we just keep the default tier).
|
|
4986
|
-
if ((planPermissionMode || options.permissionMode) && sessionId) {
|
|
4956
|
+
const assertSessionTier = (tier) =>
|
|
4957
|
+
assertManagedPermissionMode(permissionModeForTier(tier), _managedSettings);
|
|
4958
|
+
const fallbackPermissionMode =
|
|
4959
|
+
defaultInteractivePermissionMode(_managedSettings);
|
|
4960
|
+
const savedPermissionMode = (sid) => {
|
|
4961
|
+
const saved = baseApprovalGate?.getAuthorizationPolicySnapshot?.(sid);
|
|
4962
|
+
if (!saved?.revision) return fallbackPermissionMode;
|
|
4963
|
+
return saved.policy === "autopilot" && fallbackPermissionMode === "default"
|
|
4964
|
+
? "default"
|
|
4965
|
+
: saved.policy;
|
|
4966
|
+
};
|
|
4967
|
+
if (sessionId) {
|
|
4968
|
+
const requested =
|
|
4969
|
+
planPermissionMode ||
|
|
4970
|
+
options.permissionMode ||
|
|
4971
|
+
_bundleResolved?.approvalPolicy?.default;
|
|
4987
4972
|
const parsed = parsePermissionModeArg(
|
|
4988
|
-
|
|
4973
|
+
requested || savedPermissionMode(sessionId),
|
|
4989
4974
|
);
|
|
4990
|
-
if (parsed
|
|
4975
|
+
if (!parsed) throw new Error(`Invalid permission mode "${requested}"`);
|
|
4976
|
+
assertSessionTier(parsed.tier);
|
|
4977
|
+
if (typeof _approvalGate?.setSessionPolicy === "function") {
|
|
4991
4978
|
try {
|
|
4992
4979
|
await _approvalGate.setSessionPolicy(sessionId, parsed.tier);
|
|
4993
4980
|
await _approvalGate.awaitPersistence?.();
|
|
@@ -5001,11 +4988,6 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
5001
4988
|
} else if (planManager.executionLock) {
|
|
5002
4989
|
throw new Error("Cannot apply the approved plan's permission mode");
|
|
5003
4990
|
}
|
|
5004
|
-
} else if (_approvalGate && sessionId) {
|
|
5005
|
-
const tier = parsePermissionTier(
|
|
5006
|
-
_approvalGate.getSessionPolicy?.(sessionId),
|
|
5007
|
-
);
|
|
5008
|
-
if (tier) setSessionTier(tier);
|
|
5009
4991
|
}
|
|
5010
4992
|
|
|
5011
4993
|
// Phase G #5 — inject top-K memory recall into system prompt for new sessions
|
|
@@ -5250,46 +5232,33 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
5250
5232
|
if (_screenReaderMode) _theme = "mono";
|
|
5251
5233
|
applyThemeChalk(_theme, chalk, _chalkBaselineLevel);
|
|
5252
5234
|
|
|
5253
|
-
//
|
|
5254
|
-
//
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
} = await import("./fullscreen-tui.js");
|
|
5235
|
+
// A real terminal gets the interactive window by default. Keep scrollback
|
|
5236
|
+
// for screen-reader mode, redirection and an explicit /tui default.
|
|
5237
|
+
const { resolveTuiMode: _resolveTuiMode, renderTuiStatus: _renderTuiStatus } =
|
|
5238
|
+
await import("./fullscreen-tui.js");
|
|
5239
|
+
const canUseTerminalWindow = Boolean(
|
|
5240
|
+
process.stdin.isTTY &&
|
|
5241
|
+
process.stdout.isTTY &&
|
|
5242
|
+
process.env.TERM !== "dumb" &&
|
|
5243
|
+
!_screenReaderMode,
|
|
5244
|
+
);
|
|
5264
5245
|
let _tuiMode = "default";
|
|
5265
|
-
|
|
5266
|
-
|
|
5267
|
-
|
|
5268
|
-
|
|
5269
|
-
setting
|
|
5270
|
-
}
|
|
5271
|
-
|
|
5272
|
-
_tuiMode = _resolveTuiMode({ env: process.env.CC_NO_FLICKER });
|
|
5273
|
-
}
|
|
5274
|
-
if (_screenReaderMode) _tuiMode = "default";
|
|
5275
|
-
const _setTuiMode = (next) => {
|
|
5276
|
-
if (next === _tuiMode) return;
|
|
5277
|
-
// Enter/leave the alternate screen buffer so the user's scrollback is
|
|
5278
|
-
// preserved either way. Only touch a real TTY.
|
|
5279
|
-
if (process.stdout.isTTY) {
|
|
5280
|
-
process.stdout.write(next === "fullscreen" ? _ALT_ENTER : _ALT_LEAVE);
|
|
5246
|
+
if (canUseTerminalWindow) {
|
|
5247
|
+
let setting = "fullscreen";
|
|
5248
|
+
try {
|
|
5249
|
+
const { getConfigValue } = await import("../lib/config-manager.js");
|
|
5250
|
+
setting = getConfigValue("cli.tuiMode") || setting;
|
|
5251
|
+
} catch {
|
|
5252
|
+
// Optional configuration.
|
|
5281
5253
|
}
|
|
5282
|
-
_tuiMode =
|
|
5283
|
-
};
|
|
5284
|
-
if (_tuiMode === "fullscreen" && process.stdout.isTTY) {
|
|
5285
|
-
process.stdout.write(_ALT_ENTER);
|
|
5254
|
+
_tuiMode = _resolveTuiMode({ env: process.env.CC_NO_FLICKER, setting });
|
|
5286
5255
|
}
|
|
5287
5256
|
|
|
5288
5257
|
// Fast mode (Claude-Code `/fast` parity, generalized to a latency profile).
|
|
5289
5258
|
// When on, the next turn minimizes reasoning and — unless the user pinned a
|
|
5290
5259
|
// model this session — swaps to the provider's low-latency model. Resolved
|
|
5291
5260
|
// from config `cli.fastMode`; toggled at runtime via `/fast`. `_modelPinned`
|
|
5292
|
-
// tracks an explicit `/model x` so
|
|
5261
|
+
// tracks an explicit `/model x` so automatic routing keeps that choice.
|
|
5293
5262
|
const {
|
|
5294
5263
|
parseFastCommand: _parseFastCommand,
|
|
5295
5264
|
resolveFastPlan: _resolveFastPlan,
|
|
@@ -5387,6 +5356,7 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
5387
5356
|
"/hooks",
|
|
5388
5357
|
"/ide",
|
|
5389
5358
|
"/init",
|
|
5359
|
+
"/interrupt",
|
|
5390
5360
|
"/mcp",
|
|
5391
5361
|
"/mcp-watch",
|
|
5392
5362
|
"/memory",
|
|
@@ -5461,9 +5431,56 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
5461
5431
|
},
|
|
5462
5432
|
});
|
|
5463
5433
|
|
|
5434
|
+
const { createTerminalWindow, isStandaloneEscape } =
|
|
5435
|
+
await import("./terminal-window.js");
|
|
5436
|
+
const liveSlashCommands = new Set([
|
|
5437
|
+
"/cost",
|
|
5438
|
+
"/help",
|
|
5439
|
+
"/model",
|
|
5440
|
+
"/permissions",
|
|
5441
|
+
"/status",
|
|
5442
|
+
"/tasks",
|
|
5443
|
+
"/todos",
|
|
5444
|
+
"/tui",
|
|
5445
|
+
]);
|
|
5446
|
+
const isModelCommand = (line) => /^\/model(?:\s|$)/u.test(line);
|
|
5447
|
+
const terminalWindow = canUseTerminalWindow
|
|
5448
|
+
? createTerminalWindow({
|
|
5449
|
+
input: process.stdin,
|
|
5450
|
+
stdout: process.stdout,
|
|
5451
|
+
stderr: process.stderr,
|
|
5452
|
+
waitForOutput: _waitForReplOutput,
|
|
5453
|
+
getStatus: () =>
|
|
5454
|
+
[
|
|
5455
|
+
_replQuestions.isActive()
|
|
5456
|
+
? "Waiting for input"
|
|
5457
|
+
: _processingLine
|
|
5458
|
+
? "Working · Esc to interrupt"
|
|
5459
|
+
: "Ready",
|
|
5460
|
+
`Permissions ${_sessionTier}`,
|
|
5461
|
+
pendingModel ? `Next model ${pendingModel}` : `Model ${model}`,
|
|
5462
|
+
_pendingLines.length && `${_pendingLines.length} queued`,
|
|
5463
|
+
!_slashCommandsDisabled && "/help",
|
|
5464
|
+
]
|
|
5465
|
+
.filter(Boolean)
|
|
5466
|
+
.join(" · "),
|
|
5467
|
+
getSlashSuggestions: (line) => {
|
|
5468
|
+
if (_replQuestions.isActive() || !/^\/[\w:.-]*$/.test(line))
|
|
5469
|
+
return [];
|
|
5470
|
+
const commands = atCompleter(line)[0];
|
|
5471
|
+
if (line !== "/" || !_processingLine) return commands;
|
|
5472
|
+
return commands.sort(
|
|
5473
|
+
(a, b) =>
|
|
5474
|
+
Number(liveSlashCommands.has(b)) -
|
|
5475
|
+
Number(liveSlashCommands.has(a)),
|
|
5476
|
+
);
|
|
5477
|
+
},
|
|
5478
|
+
isQuestionActive: () => _replQuestions.isActive(),
|
|
5479
|
+
})
|
|
5480
|
+
: null;
|
|
5464
5481
|
const rl = readline.createInterface({
|
|
5465
5482
|
input: process.stdin,
|
|
5466
|
-
output: process.stdout,
|
|
5483
|
+
output: terminalWindow?.readlineOutput || process.stdout,
|
|
5467
5484
|
prompt: getPrompt(),
|
|
5468
5485
|
terminal: true,
|
|
5469
5486
|
completer: atCompleter,
|
|
@@ -5471,6 +5488,25 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
5471
5488
|
// Let the EPIPE guard route a broken pipe through this interface's graceful
|
|
5472
5489
|
// "close" cleanup instead of a bare exit.
|
|
5473
5490
|
_replRl = rl;
|
|
5491
|
+
_replQuestions = createReplQuestionQueue(rl, (text) =>
|
|
5492
|
+
process.stdout.write(text),
|
|
5493
|
+
);
|
|
5494
|
+
terminalWindow?.bind(rl);
|
|
5495
|
+
const disposeTerminal = () => {
|
|
5496
|
+
terminalWindow?.dispose();
|
|
5497
|
+
process.removeListener("exit", disposeTerminal);
|
|
5498
|
+
};
|
|
5499
|
+
if (terminalWindow) {
|
|
5500
|
+
outputScope.setTerminalDisposer(disposeTerminal);
|
|
5501
|
+
process.once("exit", disposeTerminal);
|
|
5502
|
+
if (_tuiMode === "fullscreen") terminalWindow.enable();
|
|
5503
|
+
}
|
|
5504
|
+
const _setTuiMode = (next) => {
|
|
5505
|
+
if (next === _tuiMode) return;
|
|
5506
|
+
if (next === "fullscreen") terminalWindow?.enable();
|
|
5507
|
+
else terminalWindow?.disable();
|
|
5508
|
+
_tuiMode = next;
|
|
5509
|
+
};
|
|
5474
5510
|
|
|
5475
5511
|
// Prompt-side interaction modules share the production readline surface.
|
|
5476
5512
|
// A per-REPL registry avoids singleton handlers retaining an old session.
|
|
@@ -5510,58 +5546,43 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
5510
5546
|
);
|
|
5511
5547
|
for (const client of mcpElicitationClients) {
|
|
5512
5548
|
client.setElicitationHandler(
|
|
5513
|
-
(request) =>
|
|
5514
|
-
|
|
5515
|
-
|
|
5516
|
-
|
|
5517
|
-
|
|
5518
|
-
|
|
5519
|
-
|
|
5520
|
-
|
|
5521
|
-
|
|
5522
|
-
|
|
5523
|
-
|
|
5524
|
-
),
|
|
5525
|
-
async (answer) => {
|
|
5526
|
-
const approved = /^(y|yes)$/i.test(String(answer || "").trim());
|
|
5527
|
-
if (!approved) {
|
|
5528
|
-
resolve({ action: "decline" });
|
|
5529
|
-
rl.prompt();
|
|
5530
|
-
return;
|
|
5531
|
-
}
|
|
5532
|
-
try {
|
|
5533
|
-
const { defaultOpenBrowser } =
|
|
5534
|
-
await import("../lib/mcp-oauth.js");
|
|
5535
|
-
const opened = defaultOpenBrowser(request.url);
|
|
5536
|
-
resolve(opened ? { action: "accept" } : { action: "cancel" });
|
|
5537
|
-
} catch {
|
|
5538
|
-
resolve({ action: "cancel" });
|
|
5539
|
-
}
|
|
5540
|
-
rl.prompt();
|
|
5541
|
-
},
|
|
5542
|
-
);
|
|
5543
|
-
return;
|
|
5544
|
-
}
|
|
5545
|
-
rl.question(
|
|
5546
|
-
chalk.yellow(`\n MCP [${request.server}] ${label}\n > `),
|
|
5547
|
-
(answer) => {
|
|
5548
|
-
const trimmed = String(answer || "").trim();
|
|
5549
|
-
if (!trimmed) {
|
|
5550
|
-
resolve({ action: "cancel" });
|
|
5551
|
-
} else {
|
|
5552
|
-
let content = { value: trimmed };
|
|
5553
|
-
try {
|
|
5554
|
-
const parsed = JSON.parse(trimmed);
|
|
5555
|
-
if (parsed && typeof parsed === "object") content = parsed;
|
|
5556
|
-
} catch {
|
|
5557
|
-
// Plain text remains a valid single-field elicitation answer.
|
|
5558
|
-
}
|
|
5559
|
-
resolve({ action: "accept", content });
|
|
5560
|
-
}
|
|
5561
|
-
rl.prompt();
|
|
5562
|
-
},
|
|
5549
|
+
async (request) => {
|
|
5550
|
+
const label = request.message || "MCP server requests additional input";
|
|
5551
|
+
const question = _replQuestions.create();
|
|
5552
|
+
if (request.mode === "url") {
|
|
5553
|
+
const answer = await question.ask(
|
|
5554
|
+
chalk.yellow(
|
|
5555
|
+
`\n MCP [${request.server}] ${label}\n` +
|
|
5556
|
+
` Host: ${request.urlHost}\n` +
|
|
5557
|
+
` URL: ${request.url}\n` +
|
|
5558
|
+
" Open this secure page? [y/N] ",
|
|
5559
|
+
),
|
|
5563
5560
|
);
|
|
5564
|
-
|
|
5561
|
+
if (answer === null) return { action: "cancel" };
|
|
5562
|
+
if (!/^(y|yes)$/i.test(answer.trim())) return { action: "decline" };
|
|
5563
|
+
try {
|
|
5564
|
+
const { defaultOpenBrowser } = await import("../lib/mcp-oauth.js");
|
|
5565
|
+
return {
|
|
5566
|
+
action: defaultOpenBrowser(request.url) ? "accept" : "cancel",
|
|
5567
|
+
};
|
|
5568
|
+
} catch {
|
|
5569
|
+
return { action: "cancel" };
|
|
5570
|
+
}
|
|
5571
|
+
}
|
|
5572
|
+
const answer = await question.ask(
|
|
5573
|
+
chalk.yellow(`\n MCP [${request.server}] ${label}\n > `),
|
|
5574
|
+
);
|
|
5575
|
+
const trimmed = answer?.trim();
|
|
5576
|
+
if (!trimmed) return { action: "cancel" };
|
|
5577
|
+
let content = { value: trimmed };
|
|
5578
|
+
try {
|
|
5579
|
+
const parsed = JSON.parse(trimmed);
|
|
5580
|
+
if (parsed && typeof parsed === "object") content = parsed;
|
|
5581
|
+
} catch {
|
|
5582
|
+
// Plain text is a valid single-field answer.
|
|
5583
|
+
}
|
|
5584
|
+
return { action: "accept", content };
|
|
5585
|
+
},
|
|
5565
5586
|
{ timeoutMs: options.mcpElicitationTimeoutMs },
|
|
5566
5587
|
);
|
|
5567
5588
|
}
|
|
@@ -5676,42 +5697,54 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
5676
5697
|
// Idle Esc presses (no active turn) are ignored, and escape-prefixed key
|
|
5677
5698
|
// sequences (arrows etc.) never reach here as bare "escape".
|
|
5678
5699
|
_turnAbort = null;
|
|
5700
|
+
const interruptTurn = () => {
|
|
5701
|
+
if (!_turnAbort || _turnAbort.signal.aborted) return false;
|
|
5702
|
+
process.stdout.write(chalk.yellow("\n⎋ interrupting…\n"));
|
|
5703
|
+
_turnAbort.abort();
|
|
5704
|
+
_replQuestions.cancelActive();
|
|
5705
|
+
if (_settingsHooks) {
|
|
5706
|
+
import("../lib/settings-hook-events.js")
|
|
5707
|
+
.then(({ runObserveHooks }) =>
|
|
5708
|
+
runObserveHooks(
|
|
5709
|
+
_settingsHooks,
|
|
5710
|
+
"SessionPause",
|
|
5711
|
+
{
|
|
5712
|
+
session_id: sessionId,
|
|
5713
|
+
reason: "user-interrupt",
|
|
5714
|
+
cwd: process.cwd(),
|
|
5715
|
+
},
|
|
5716
|
+
{ cwd: process.cwd() },
|
|
5717
|
+
),
|
|
5718
|
+
)
|
|
5719
|
+
.catch(() => {});
|
|
5720
|
+
}
|
|
5721
|
+
return true;
|
|
5722
|
+
};
|
|
5679
5723
|
let _lastIdleEscAt = 0;
|
|
5680
5724
|
let _replKeypressHandler = null;
|
|
5681
5725
|
if (process.stdin.isTTY) {
|
|
5682
5726
|
_replKeypressHandler = async (_str, key) => {
|
|
5683
5727
|
const k = key || {};
|
|
5728
|
+
const escape = isStandaloneEscape(k);
|
|
5729
|
+
if (terminalWindow?.handlePickerKey(_str, k)) {
|
|
5730
|
+
_consumeReadlineKeypress(key);
|
|
5731
|
+
return;
|
|
5732
|
+
}
|
|
5684
5733
|
// 1) Turn abort always wins, regardless of vim mode.
|
|
5685
|
-
if (
|
|
5734
|
+
if (escape && (_turnAbort || _replQuestions.isActive())) {
|
|
5686
5735
|
_consumeReadlineKeypress(key);
|
|
5687
|
-
|
|
5688
|
-
|
|
5689
|
-
|
|
5690
|
-
|
|
5691
|
-
|
|
5692
|
-
|
|
5693
|
-
|
|
5694
|
-
|
|
5695
|
-
|
|
5696
|
-
// keypress handler can't await, so fire observe-only fire-and-forget.
|
|
5697
|
-
if (_settingsHooks) {
|
|
5698
|
-
import("../lib/settings-hook-events.js")
|
|
5699
|
-
.then(({ runObserveHooks }) =>
|
|
5700
|
-
runObserveHooks(
|
|
5701
|
-
_settingsHooks,
|
|
5702
|
-
"SessionPause",
|
|
5703
|
-
{
|
|
5704
|
-
session_id: sessionId,
|
|
5705
|
-
reason: "user-interrupt",
|
|
5706
|
-
cwd: process.cwd(),
|
|
5707
|
-
},
|
|
5708
|
-
{ cwd: process.cwd() },
|
|
5709
|
-
),
|
|
5710
|
-
)
|
|
5711
|
-
.catch(() => {});
|
|
5712
|
-
}
|
|
5736
|
+
if (!interruptTurn()) _replQuestions.cancelActive();
|
|
5737
|
+
return;
|
|
5738
|
+
}
|
|
5739
|
+
if (
|
|
5740
|
+
_tuiMode === "fullscreen" &&
|
|
5741
|
+
(k.name === "pageup" || k.name === "pagedown")
|
|
5742
|
+
) {
|
|
5743
|
+
_consumeReadlineKeypress(key);
|
|
5744
|
+
terminalWindow.scroll(k.name === "pageup" ? 1 : -1);
|
|
5713
5745
|
return;
|
|
5714
5746
|
}
|
|
5747
|
+
if (_replQuestions.isActive()) return;
|
|
5715
5748
|
|
|
5716
5749
|
// 1.5) Shift+Tab cycles the session approval tier (Claude-Code mode
|
|
5717
5750
|
// cycling): strict → trusted → autopilot → strict. Drives the existing
|
|
@@ -5728,7 +5761,9 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
5728
5761
|
) {
|
|
5729
5762
|
// "auto" rides the trusted tier, so it cycles as trusted → autopilot
|
|
5730
5763
|
// (cycling is also how you exit auto mode without /permissions).
|
|
5731
|
-
|
|
5764
|
+
let next = nextTier(gateTierFor(_sessionTier));
|
|
5765
|
+
if (next === "autopilot" && fallbackPermissionMode === "default")
|
|
5766
|
+
next = nextTier(next);
|
|
5732
5767
|
try {
|
|
5733
5768
|
await _approvalGate.setSessionPolicy(sessionId, next);
|
|
5734
5769
|
await _approvalGate.awaitPersistence?.();
|
|
@@ -5750,6 +5785,39 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
5750
5785
|
return;
|
|
5751
5786
|
}
|
|
5752
5787
|
|
|
5788
|
+
if (_tuiMode === "fullscreen" && !_vim) {
|
|
5789
|
+
if (
|
|
5790
|
+
(k.meta || k.shift) &&
|
|
5791
|
+
(k.name === "return" || k.name === "enter")
|
|
5792
|
+
) {
|
|
5793
|
+
_consumeReadlineKeypress(key);
|
|
5794
|
+
rl.line =
|
|
5795
|
+
rl.line.slice(0, rl.cursor) + "\n" + rl.line.slice(rl.cursor);
|
|
5796
|
+
rl.cursor++;
|
|
5797
|
+
terminalWindow.schedule();
|
|
5798
|
+
return;
|
|
5799
|
+
}
|
|
5800
|
+
if (terminalWindow.handleSlashKey(k)) {
|
|
5801
|
+
_consumeReadlineKeypress(key);
|
|
5802
|
+
return;
|
|
5803
|
+
}
|
|
5804
|
+
if (
|
|
5805
|
+
k.name === "up" &&
|
|
5806
|
+
!k.ctrl &&
|
|
5807
|
+
!k.meta &&
|
|
5808
|
+
!k.shift &&
|
|
5809
|
+
_processingLine &&
|
|
5810
|
+
!rl.line &&
|
|
5811
|
+
_pendingLines.length
|
|
5812
|
+
) {
|
|
5813
|
+
_consumeReadlineKeypress(key);
|
|
5814
|
+
rl.line = _pendingLines.pop();
|
|
5815
|
+
rl.cursor = rl.line.length;
|
|
5816
|
+
terminalWindow.schedule();
|
|
5817
|
+
return;
|
|
5818
|
+
}
|
|
5819
|
+
}
|
|
5820
|
+
|
|
5753
5821
|
// 1.75) Prompt interaction keybindings share the controller used by
|
|
5754
5822
|
// slash commands. They are idle-only and stay out of Vim NORMAL mode,
|
|
5755
5823
|
// where the modal editor owns every key.
|
|
@@ -5785,7 +5853,7 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
5785
5853
|
if (_vimEnabled && !_turnAbort) {
|
|
5786
5854
|
if (!_vim) {
|
|
5787
5855
|
// INSERT mode — readline owns the keys; Esc switches to NORMAL.
|
|
5788
|
-
if (
|
|
5856
|
+
if (escape) {
|
|
5789
5857
|
_consumeReadlineKeypress(key);
|
|
5790
5858
|
_vimEnterNormal();
|
|
5791
5859
|
}
|
|
@@ -5813,7 +5881,7 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
5813
5881
|
}
|
|
5814
5882
|
|
|
5815
5883
|
// 3) Non-vim: double-Esc while idle → rewind picker shortcut.
|
|
5816
|
-
if (
|
|
5884
|
+
if (!escape) return;
|
|
5817
5885
|
_consumeReadlineKeypress(key);
|
|
5818
5886
|
const nowTs = Date.now();
|
|
5819
5887
|
if (nowTs - _lastIdleEscAt < 600) {
|
|
@@ -5896,6 +5964,48 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
5896
5964
|
let _ctxRequestWindow = null;
|
|
5897
5965
|
let _turnCount = 0;
|
|
5898
5966
|
const _costStore = newCostStore(); // running token spend for `/cost`
|
|
5967
|
+
|
|
5968
|
+
const recentModels = new Map();
|
|
5969
|
+
const applyPendingModel = () => {
|
|
5970
|
+
if (!pendingModel) return;
|
|
5971
|
+
model = pendingModel;
|
|
5972
|
+
pendingModel = null;
|
|
5973
|
+
_curModel = model;
|
|
5974
|
+
_ctxRequestWindow = null;
|
|
5975
|
+
_modelPinned = true;
|
|
5976
|
+
terminalWindow?.schedule();
|
|
5977
|
+
};
|
|
5978
|
+
const selectModel = (next, defer) => {
|
|
5979
|
+
pendingModel = next;
|
|
5980
|
+
if (!defer) applyPendingModel();
|
|
5981
|
+
if (!recentModels.has(provider)) recentModels.set(provider, new Set());
|
|
5982
|
+
recentModels.get(provider).add(next);
|
|
5983
|
+
logger.info(
|
|
5984
|
+
defer
|
|
5985
|
+
? `Next turn will use ${chalk.cyan(next)}`
|
|
5986
|
+
: `Model: ${chalk.cyan(next)}`,
|
|
5987
|
+
);
|
|
5988
|
+
maybeWarnDeprecatedModel({ model: next });
|
|
5989
|
+
};
|
|
5990
|
+
const modelChoices = (selected) => {
|
|
5991
|
+
// The gateway catalog distinguishes chat models by compatible wire API.
|
|
5992
|
+
const protocol = provider === "custom" ? "openai" : provider;
|
|
5993
|
+
const known = isLkEndpoint(baseUrl)
|
|
5994
|
+
? LK_MODELS.filter(
|
|
5995
|
+
(entry) =>
|
|
5996
|
+
entry.type === "chat" &&
|
|
5997
|
+
entry.compatibleProtocols.includes(protocol),
|
|
5998
|
+
).map((entry) => entry.id)
|
|
5999
|
+
: resolveProviderDefinition(provider)?.models || [];
|
|
6000
|
+
return [
|
|
6001
|
+
...new Set([
|
|
6002
|
+
selected,
|
|
6003
|
+
model,
|
|
6004
|
+
...(recentModels.get(provider) || []),
|
|
6005
|
+
...known,
|
|
6006
|
+
]),
|
|
6007
|
+
];
|
|
6008
|
+
};
|
|
5899
6009
|
try {
|
|
5900
6010
|
const slm = await import("../lib/status-line.js");
|
|
5901
6011
|
const _sl = slm.default || slm;
|
|
@@ -5938,6 +6048,7 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
5938
6048
|
}
|
|
5939
6049
|
|
|
5940
6050
|
const prompt = () => {
|
|
6051
|
+
if (_replQuestions.isActive()) return;
|
|
5941
6052
|
if (_statusLineEnabled && _renderStatus) {
|
|
5942
6053
|
const line = _renderStatus();
|
|
5943
6054
|
// Built-in line is dimmed; a custom command may carry its own ANSI.
|
|
@@ -5945,7 +6056,7 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
5945
6056
|
process.stdout.write((_customStatus ? line : chalk.dim(line)) + "\n");
|
|
5946
6057
|
}
|
|
5947
6058
|
rl.setPrompt(getPrompt());
|
|
5948
|
-
rl.prompt();
|
|
6059
|
+
rl.prompt(true);
|
|
5949
6060
|
};
|
|
5950
6061
|
|
|
5951
6062
|
// Fire SessionStart hook (fire-and-forget; hook failures never break REPL)
|
|
@@ -6060,6 +6171,7 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
6060
6171
|
}
|
|
6061
6172
|
} finally {
|
|
6062
6173
|
_processingLine = false;
|
|
6174
|
+
if (!_replClosing) applyPendingModel();
|
|
6063
6175
|
settleLine();
|
|
6064
6176
|
_lineSettled = null;
|
|
6065
6177
|
_mcpTaskAutoWakeRunning = false;
|
|
@@ -6081,7 +6193,8 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
6081
6193
|
kickMcpTaskAutoWake();
|
|
6082
6194
|
return true;
|
|
6083
6195
|
};
|
|
6084
|
-
const handleLine = async (input) => {
|
|
6196
|
+
const handleLine = async (input, concurrent = false) => {
|
|
6197
|
+
if (!concurrent) applyPendingModel();
|
|
6085
6198
|
let mcpAutoWakeDelivery =
|
|
6086
6199
|
input === _mcpTaskAutoWakeSentinel
|
|
6087
6200
|
? _mcpTaskAutoWakeQueue.shift() || null
|
|
@@ -6106,16 +6219,18 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
6106
6219
|
}
|
|
6107
6220
|
}
|
|
6108
6221
|
// Backslash continuation — accumulate and re-prompt without firing a turn.
|
|
6109
|
-
|
|
6110
|
-
|
|
6111
|
-
|
|
6112
|
-
|
|
6113
|
-
|
|
6114
|
-
|
|
6115
|
-
|
|
6116
|
-
|
|
6117
|
-
|
|
6118
|
-
|
|
6222
|
+
if (!concurrent) {
|
|
6223
|
+
const continuation = analyzeContinuation(input);
|
|
6224
|
+
if (continuation.continued) {
|
|
6225
|
+
_mlBuffer.push(continuation.text);
|
|
6226
|
+
rl.setPrompt(chalk.dim("... "));
|
|
6227
|
+
rl.prompt(true);
|
|
6228
|
+
return;
|
|
6229
|
+
}
|
|
6230
|
+
if (_mlBuffer.length) {
|
|
6231
|
+
input = joinContinuation(_mlBuffer, input);
|
|
6232
|
+
_mlBuffer.length = 0;
|
|
6233
|
+
}
|
|
6119
6234
|
}
|
|
6120
6235
|
|
|
6121
6236
|
const rawLine = input.trim();
|
|
@@ -6218,6 +6333,11 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
6218
6333
|
rl.close();
|
|
6219
6334
|
return;
|
|
6220
6335
|
}
|
|
6336
|
+
if (trimmed === "/interrupt") {
|
|
6337
|
+
if (!interruptTurn()) logger.info("No active model turn to interrupt.");
|
|
6338
|
+
prompt();
|
|
6339
|
+
return;
|
|
6340
|
+
}
|
|
6221
6341
|
|
|
6222
6342
|
// The interaction commands are registered through the shared registry,
|
|
6223
6343
|
// while the mature REPL handlers below remain on their existing direct
|
|
@@ -6234,6 +6354,9 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
6234
6354
|
|
|
6235
6355
|
if (trimmed === "/help") {
|
|
6236
6356
|
logger.log(chalk.bold("\nCommands:"));
|
|
6357
|
+
logger.log(
|
|
6358
|
+
` ${chalk.cyan("/interrupt")} Stop the current turn without closing the session`,
|
|
6359
|
+
);
|
|
6237
6360
|
logger.log(
|
|
6238
6361
|
` ${chalk.cyan("! <cmd>")} Run a shell command directly (output joins context)`,
|
|
6239
6362
|
);
|
|
@@ -6247,7 +6370,7 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
6247
6370
|
` ${chalk.cyan("/exit")} Exit the agent (alias: /quit)`,
|
|
6248
6371
|
);
|
|
6249
6372
|
logger.log(
|
|
6250
|
-
` ${chalk.cyan("/model")}
|
|
6373
|
+
` ${chalk.cyan("/model")} Select a model or enter /model <id>`,
|
|
6251
6374
|
);
|
|
6252
6375
|
logger.log(` ${chalk.cyan("/provider")} Show/change provider`);
|
|
6253
6376
|
logger.log(
|
|
@@ -6723,27 +6846,35 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
6723
6846
|
return;
|
|
6724
6847
|
}
|
|
6725
6848
|
|
|
6726
|
-
if (trimmed
|
|
6849
|
+
if (isModelCommand(trimmed)) {
|
|
6727
6850
|
const arg = trimmed.slice(6).trim();
|
|
6728
6851
|
if (arg) {
|
|
6729
|
-
|
|
6730
|
-
|
|
6731
|
-
|
|
6732
|
-
logger.info(`Model: ${chalk.cyan(model)}`);
|
|
6733
|
-
// Claude-Code 2.1.183 parity: warn when the newly-selected model is a
|
|
6734
|
-
// provider-retired/deprecated snapshot. Headless paths already warn via
|
|
6735
|
-
// maybeWarnDeprecatedModel; the interactive /model switch did not, so a
|
|
6736
|
-
// user could silently switch to a retired id and only learn of it when
|
|
6737
|
-
// the next turn fails with an opaque "model not found".
|
|
6738
|
-
try {
|
|
6739
|
-
const { maybeWarnDeprecatedModel } =
|
|
6740
|
-
await import("../lib/model-deprecation.js");
|
|
6741
|
-
maybeWarnDeprecatedModel({ model });
|
|
6742
|
-
} catch {
|
|
6743
|
-
// deprecation notice is best-effort
|
|
6744
|
-
}
|
|
6852
|
+
if (arg.length > 256 || /[\s\p{Cc}]/u.test(arg))
|
|
6853
|
+
logger.info("Usage: /model <model-id>");
|
|
6854
|
+
else selectModel(arg, concurrent && _processingLine);
|
|
6745
6855
|
} else {
|
|
6746
|
-
|
|
6856
|
+
const selected = pendingModel || model;
|
|
6857
|
+
const choices = modelChoices(selected);
|
|
6858
|
+
if (_tuiMode === "fullscreen") {
|
|
6859
|
+
const pickerProvider = provider;
|
|
6860
|
+
terminalWindow.showPicker({
|
|
6861
|
+
title: `Select model · ${pickerProvider}`,
|
|
6862
|
+
choices,
|
|
6863
|
+
selected,
|
|
6864
|
+
current: model,
|
|
6865
|
+
onSelect: (next) => {
|
|
6866
|
+
if (provider === pickerProvider)
|
|
6867
|
+
selectModel(next, _processingLine);
|
|
6868
|
+
else logger.info("Provider changed. Run /model again.");
|
|
6869
|
+
},
|
|
6870
|
+
});
|
|
6871
|
+
} else {
|
|
6872
|
+
logger.info(`Current model: ${chalk.cyan(model)}`);
|
|
6873
|
+
if (pendingModel)
|
|
6874
|
+
logger.info(`Next model: ${chalk.cyan(pendingModel)}`);
|
|
6875
|
+
logger.info(`Models for ${provider}: ${choices.join(", ")}`);
|
|
6876
|
+
logger.info("Use /model <model-id> to switch.");
|
|
6877
|
+
}
|
|
6747
6878
|
}
|
|
6748
6879
|
prompt();
|
|
6749
6880
|
return;
|
|
@@ -7023,10 +7154,10 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
7023
7154
|
prompt();
|
|
7024
7155
|
return;
|
|
7025
7156
|
}
|
|
7026
|
-
if (
|
|
7157
|
+
if (!canUseTerminalWindow && next === "fullscreen") {
|
|
7027
7158
|
logger.info(
|
|
7028
7159
|
chalk.gray(
|
|
7029
|
-
"
|
|
7160
|
+
"Fullscreen requires an interactive terminal with screen-reader mode off.",
|
|
7030
7161
|
),
|
|
7031
7162
|
);
|
|
7032
7163
|
prompt();
|
|
@@ -7520,12 +7651,13 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
7520
7651
|
if (rewindConversation)
|
|
7521
7652
|
pruneMarksAfter(_checkpointMarks, turnIndex);
|
|
7522
7653
|
if (cp) {
|
|
7523
|
-
const q = (p) => new Promise((r) => rl.question(p, r));
|
|
7524
7654
|
const promptText = rewindConversation
|
|
7525
7655
|
? ` Also restore files to before this turn? (checkpoint ${cp.id}) [Y/n] `
|
|
7526
7656
|
: ` Restore files to before this turn? (checkpoint ${cp.id}) [Y/n] `;
|
|
7527
|
-
const ans = (
|
|
7528
|
-
.
|
|
7657
|
+
const ans = (
|
|
7658
|
+
await _replQuestions.create().ask(chalk.yellow(promptText))
|
|
7659
|
+
)
|
|
7660
|
+
?.trim()
|
|
7529
7661
|
.toLowerCase();
|
|
7530
7662
|
if (ans === "" || ans === "y" || ans === "yes") {
|
|
7531
7663
|
try {
|
|
@@ -7991,7 +8123,7 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
7991
8123
|
targetPlan.permissionMode ||
|
|
7992
8124
|
(reuseCurrentLease
|
|
7993
8125
|
? _sessionTier
|
|
7994
|
-
:
|
|
8126
|
+
: savedPermissionMode(prepared.sessionId)) ||
|
|
7995
8127
|
"strict",
|
|
7996
8128
|
);
|
|
7997
8129
|
if (typeof _approvalGate?.setSessionPolicy === "function") {
|
|
@@ -9415,6 +9547,7 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
9415
9547
|
);
|
|
9416
9548
|
} else {
|
|
9417
9549
|
try {
|
|
9550
|
+
assertSessionTier(parsed.tier);
|
|
9418
9551
|
await _approvalGate.setSessionPolicy(sessionId, parsed.tier);
|
|
9419
9552
|
await _approvalGate.awaitPersistence?.();
|
|
9420
9553
|
setSessionTier(
|
|
@@ -10055,7 +10188,11 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
10055
10188
|
// get a 401). Runnable-first: keep the configured (working) model instead.
|
|
10056
10189
|
let activeModel = model;
|
|
10057
10190
|
const taskDetection = detectTaskType(promptText);
|
|
10058
|
-
if (
|
|
10191
|
+
if (
|
|
10192
|
+
!_modelPinned &&
|
|
10193
|
+
taskDetection.confidence > 0.3 &&
|
|
10194
|
+
!mcpContinuationStarted
|
|
10195
|
+
) {
|
|
10059
10196
|
const recommended = selectModelForTask(provider, taskDetection.taskType);
|
|
10060
10197
|
const switchTo = runnableTaskModel({
|
|
10061
10198
|
provider,
|
|
@@ -10796,6 +10933,11 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
10796
10933
|
rl.on("line", async (input) => {
|
|
10797
10934
|
if (!(await _waitForReplOutput())) return;
|
|
10798
10935
|
if (_replClosing) return;
|
|
10936
|
+
const submitted = input.trim();
|
|
10937
|
+
if (_tuiMode === "fullscreen" && submitted) {
|
|
10938
|
+
terminalWindow.follow();
|
|
10939
|
+
terminalWindow.append(`\n> ${input}\n`);
|
|
10940
|
+
}
|
|
10799
10941
|
if (_runtimeLedgerTerminalLatch.isTripped()) {
|
|
10800
10942
|
const terminalInput = input.trim();
|
|
10801
10943
|
if (terminalInput === "/exit" || terminalInput === "/quit") {
|
|
@@ -10809,21 +10951,29 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
10809
10951
|
if (_processingLine) {
|
|
10810
10952
|
const concurrentBtw = _slashCommandsDisabled
|
|
10811
10953
|
? null
|
|
10812
|
-
: parseBtwCommand(
|
|
10813
|
-
|
|
10814
|
-
|
|
10815
|
-
|
|
10816
|
-
|
|
10817
|
-
|
|
10818
|
-
|
|
10819
|
-
|
|
10954
|
+
: parseBtwCommand(submitted);
|
|
10955
|
+
const liveCommand =
|
|
10956
|
+
submitted === "/exit" ||
|
|
10957
|
+
submitted === "/quit" ||
|
|
10958
|
+
(!_slashCommandsDisabled &&
|
|
10959
|
+
(submitted === "/interrupt" ||
|
|
10960
|
+
isModelCommand(submitted) ||
|
|
10961
|
+
liveSlashCommands.has(submitted)));
|
|
10962
|
+
if (liveCommand || concurrentBtw) {
|
|
10963
|
+
const sideCall = liveCommand
|
|
10964
|
+
? handleLine(input, true)
|
|
10965
|
+
: runBtwSideQuestion(concurrentBtw, { concurrent: true });
|
|
10966
|
+
_activeConcurrentCalls.add(sideCall);
|
|
10820
10967
|
void sideCall.then(
|
|
10821
|
-
() =>
|
|
10822
|
-
() =>
|
|
10968
|
+
() => _activeConcurrentCalls.delete(sideCall),
|
|
10969
|
+
(error) => {
|
|
10970
|
+
_activeConcurrentCalls.delete(sideCall);
|
|
10971
|
+
if (!_replClosing) logger.error(error.message);
|
|
10972
|
+
},
|
|
10823
10973
|
);
|
|
10824
10974
|
return;
|
|
10825
10975
|
}
|
|
10826
|
-
if (
|
|
10976
|
+
if (submitted) {
|
|
10827
10977
|
_pendingLines.push(input);
|
|
10828
10978
|
logger.log(
|
|
10829
10979
|
chalk.gray(
|
|
@@ -10853,6 +11003,8 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
10853
11003
|
}
|
|
10854
11004
|
} finally {
|
|
10855
11005
|
_processingLine = false;
|
|
11006
|
+
if (!_replClosing) applyPendingModel();
|
|
11007
|
+
terminalWindow?.schedule();
|
|
10856
11008
|
settleLine();
|
|
10857
11009
|
_lineSettled = null;
|
|
10858
11010
|
kickMcpTaskAutoWake();
|
|
@@ -10871,6 +11023,7 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
10871
11023
|
if (_replCleanupStarted) return;
|
|
10872
11024
|
_replCleanupStarted = true;
|
|
10873
11025
|
_replClosing = true;
|
|
11026
|
+
disposeTerminal();
|
|
10874
11027
|
_pendingLines.length = 0;
|
|
10875
11028
|
_mcpTaskAutoWakeQueue.length = 0;
|
|
10876
11029
|
// Do not certify a Run while its model/tool or auxiliary usage settlement
|
|
@@ -10893,7 +11046,7 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
10893
11046
|
const autonomousShutdown = autonomousAgent.shutdown();
|
|
10894
11047
|
void autonomousShutdown.catch(() => {});
|
|
10895
11048
|
await _lineSettled;
|
|
10896
|
-
await Promise.allSettled([...
|
|
11049
|
+
await Promise.allSettled([..._activeConcurrentCalls]);
|
|
10897
11050
|
try {
|
|
10898
11051
|
const { interrupted } = await autonomousShutdown;
|
|
10899
11052
|
if (interrupted > 0 && _evolutionSession !== null) {
|
|
@@ -10913,15 +11066,6 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
10913
11066
|
process.stdin.removeListener("keypress", listener);
|
|
10914
11067
|
}
|
|
10915
11068
|
}
|
|
10916
|
-
// Leave the alternate screen buffer first so the terminal is restored to
|
|
10917
|
-
// the user's scrollback no matter how the REPL exits.
|
|
10918
|
-
if (_tuiMode === "fullscreen" && process.stdout.isTTY) {
|
|
10919
|
-
try {
|
|
10920
|
-
process.stdout.write(_ALT_LEAVE);
|
|
10921
|
-
} catch (_err) {
|
|
10922
|
-
// best-effort restore
|
|
10923
|
-
}
|
|
10924
|
-
}
|
|
10925
11069
|
// Stop inbound channel listeners before anything else — no new external
|
|
10926
11070
|
// events may enter a session that is shutting down.
|
|
10927
11071
|
if (_channels) {
|