@nathapp/nax 0.91.7-canary.3 → 0.91.7-canary.5
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/dist/nax.js +855 -196
- package/package.json +2 -2
package/dist/nax.js
CHANGED
|
@@ -16622,7 +16622,7 @@ function resolveUnsandboxedCall(p) {
|
|
|
16622
16622
|
return {
|
|
16623
16623
|
kind: "unsandboxed",
|
|
16624
16624
|
suffix: unsandboxedReasonSuffix(p.input),
|
|
16625
|
-
asksOnAllow: p.option.bashApproval !== "raw"
|
|
16625
|
+
asksOnAllow: p.option.alwaysAsk === true || p.option.bashApproval !== "raw"
|
|
16626
16626
|
};
|
|
16627
16627
|
}
|
|
16628
16628
|
function convertUnsandboxedAllow(p) {
|
|
@@ -20590,6 +20590,7 @@ function nativeProfileRules(profile, raw) {
|
|
|
20590
20590
|
var isStringArray = (value) => Array.isArray(value) && value.every((item) => typeof item === "string"), OptionsSchema2;
|
|
20591
20591
|
var init_native_backend_options = __esm(() => {
|
|
20592
20592
|
init_zod();
|
|
20593
|
+
init_schemas_sandbox();
|
|
20593
20594
|
init_models();
|
|
20594
20595
|
init_compaction_settings();
|
|
20595
20596
|
init_instruction_file_name();
|
|
@@ -20604,9 +20605,16 @@ var init_native_backend_options = __esm(() => {
|
|
|
20604
20605
|
loopHandlerRole: string2().min(1).optional(),
|
|
20605
20606
|
hostPorts: strictObject({
|
|
20606
20607
|
protectedPaths: custom((value) => isRecord2(value) && isStringArray(value.gitExcludePathspecs) && isStringArray(value.gitIgnorePatterns), "must be a protected-paths policy with gitExcludePathspecs and gitIgnorePatterns string arrays").optional(),
|
|
20608
|
+
commandShadow: custom(hasMethods2(["observe", "settle", "drain"]), "must implement observe, settle and drain").optional(),
|
|
20607
20609
|
commandInterceptor: custom(hasMethods2(["intercept"]), "must implement intercept").optional()
|
|
20608
20610
|
}).optional(),
|
|
20609
20611
|
bashApproval: _enum(["raw", "gated", "escalate"]).optional(),
|
|
20612
|
+
askOnUnsandboxed: boolean2().optional(),
|
|
20613
|
+
askWhenSandboxDown: boolean2().optional(),
|
|
20614
|
+
askDiscoveredTools: boolean2().optional(),
|
|
20615
|
+
askRules: array(string2().min(1)).optional(),
|
|
20616
|
+
denyRules: array(string2().min(1)).optional(),
|
|
20617
|
+
sandbox: SandboxConfigSchema.optional(),
|
|
20610
20618
|
allowUnsandboxed: boolean2().optional(),
|
|
20611
20619
|
allowedTools: array(string2().min(1)).optional(),
|
|
20612
20620
|
allowUnsandboxedCommands: boolean2().optional(),
|
|
@@ -20615,6 +20623,41 @@ var init_native_backend_options = __esm(() => {
|
|
|
20615
20623
|
});
|
|
20616
20624
|
});
|
|
20617
20625
|
|
|
20626
|
+
// ../nax-agent/src/session/native-posture-rules.ts
|
|
20627
|
+
function nativePostureRules(profile, raw) {
|
|
20628
|
+
const toolOnlyOptions = [
|
|
20629
|
+
"askRules",
|
|
20630
|
+
"denyRules",
|
|
20631
|
+
"askOnUnsandboxed",
|
|
20632
|
+
"askWhenSandboxDown",
|
|
20633
|
+
"askDiscoveredTools"
|
|
20634
|
+
];
|
|
20635
|
+
for (const name of toolOnlyOptions) {
|
|
20636
|
+
if ((profile === "none" || profile === "read") && raw[name] !== undefined) {
|
|
20637
|
+
const path = `backend.${name}`;
|
|
20638
|
+
throw new AgentSessionError(`Invalid agent session options: ${path} applies to profiles "ask", "full" and "review" only`, "AGENT_SESSION_INVALID_OPTIONS", { path });
|
|
20639
|
+
}
|
|
20640
|
+
}
|
|
20641
|
+
if (raw.askOnUnsandboxed === true && raw.allowUnsandboxedCommands !== true) {
|
|
20642
|
+
throw new AgentSessionError("Invalid agent session options: backend.askOnUnsandboxed requires backend.allowUnsandboxedCommands: true", "AGENT_SESSION_INVALID_OPTIONS", { path: "backend.askOnUnsandboxed" });
|
|
20643
|
+
}
|
|
20644
|
+
return {
|
|
20645
|
+
askOnUnsandboxed: raw.askOnUnsandboxed === true,
|
|
20646
|
+
askWhenSandboxDown: raw.askWhenSandboxDown === true,
|
|
20647
|
+
askDiscoveredTools: raw.askDiscoveredTools === true,
|
|
20648
|
+
askRules: parseRuleList(raw.askRules ?? []),
|
|
20649
|
+
denyRules: parseRuleList(raw.denyRules ?? []),
|
|
20650
|
+
sandbox: raw.sandbox === undefined ? DEFAULT_SANDBOX_CONFIG : SandboxConfigSchema.parse(raw.sandbox)
|
|
20651
|
+
};
|
|
20652
|
+
}
|
|
20653
|
+
function effectiveBashApproval(profileMode, askWhenSandboxDown, sandboxKind) {
|
|
20654
|
+
return askWhenSandboxDown && sandboxKind !== "available" ? "gated" : profileMode;
|
|
20655
|
+
}
|
|
20656
|
+
var init_native_posture_rules = __esm(() => {
|
|
20657
|
+
init_schemas_sandbox();
|
|
20658
|
+
init_agent_session_errors();
|
|
20659
|
+
});
|
|
20660
|
+
|
|
20618
20661
|
// ../nax-agent/src/session/session-interaction.ts
|
|
20619
20662
|
function embedderToolDescriptor(tool) {
|
|
20620
20663
|
return {
|
|
@@ -20736,8 +20779,13 @@ function createSessionInteractionHandler(deps) {
|
|
|
20736
20779
|
async onInteraction(request) {
|
|
20737
20780
|
if (request.kind === "question")
|
|
20738
20781
|
return answerQuestion(deps, request.text);
|
|
20739
|
-
if (request.kind === "context-tool")
|
|
20782
|
+
if (request.kind === "context-tool") {
|
|
20783
|
+
if (deps.unavailableTools?.has(request.name)) {
|
|
20784
|
+
const reason = `Tool "${request.name}" is not available under the session policy`;
|
|
20785
|
+
return { answer: `Denied: ${reason}`, denied: { reason, breach: false } };
|
|
20786
|
+
}
|
|
20740
20787
|
throw toolError(`Unknown tool "${request.name}"`, request.name);
|
|
20788
|
+
}
|
|
20741
20789
|
const tool = deps.embedderTools.get(request.name);
|
|
20742
20790
|
return tool !== undefined ? runEmbedderTool(deps, tool, request) : runCodingTool(deps, request);
|
|
20743
20791
|
}
|
|
@@ -20757,7 +20805,15 @@ function unsandboxedToolOptions(args) {
|
|
|
20757
20805
|
return args.unsandboxedCommands === true ? { unsandboxedCommands: true } : {};
|
|
20758
20806
|
}
|
|
20759
20807
|
function unsandboxedRuntimeOption(args) {
|
|
20760
|
-
|
|
20808
|
+
if (args.unsandboxedCommands !== true)
|
|
20809
|
+
return {};
|
|
20810
|
+
return {
|
|
20811
|
+
unsandboxed: {
|
|
20812
|
+
enabled: true,
|
|
20813
|
+
bashApproval: args.bashApproval,
|
|
20814
|
+
...args.askOnUnsandboxed === true ? { alwaysAsk: true } : {}
|
|
20815
|
+
}
|
|
20816
|
+
};
|
|
20761
20817
|
}
|
|
20762
20818
|
function buildDeclaredCommandTools(args) {
|
|
20763
20819
|
return [
|
|
@@ -21012,7 +21068,11 @@ function buildCodingToolSupport(args) {
|
|
|
21012
21068
|
})
|
|
21013
21069
|
],
|
|
21014
21070
|
...args.providerIdByTool !== undefined ? { providerIdByTool: args.providerIdByTool } : {},
|
|
21015
|
-
...unsandboxedRuntimeOption({
|
|
21071
|
+
...unsandboxedRuntimeOption({
|
|
21072
|
+
unsandboxedCommands: args.unsandboxedCommands,
|
|
21073
|
+
askOnUnsandboxed: args.askOnUnsandboxed,
|
|
21074
|
+
bashApproval
|
|
21075
|
+
})
|
|
21016
21076
|
});
|
|
21017
21077
|
const tools = runtime.advertised(advertised);
|
|
21018
21078
|
const providerTools = tools.filter((tool) => args.providerIdByTool?.has(tool.name) === true);
|
|
@@ -21109,7 +21169,7 @@ async function resolveSessionLauncher(args) {
|
|
|
21109
21169
|
return { launcher: undefined, sandbox: { kind: "disabled" } };
|
|
21110
21170
|
}
|
|
21111
21171
|
const launcher = await resolveSessionSandbox({
|
|
21112
|
-
config: DEFAULT_SANDBOX_CONFIG,
|
|
21172
|
+
config: args.config ?? DEFAULT_SANDBOX_CONFIG,
|
|
21113
21173
|
root: args.root,
|
|
21114
21174
|
needsLauncher: true,
|
|
21115
21175
|
protectedPaths: args.protectedPaths,
|
|
@@ -21132,6 +21192,13 @@ function narrowBuiltIns(profileTools, allowedTools) {
|
|
|
21132
21192
|
const allowed = new Set(allowedTools);
|
|
21133
21193
|
return profileTools.filter((tool) => UNIVERSAL_CODING_TOOLS.includes(tool) || allowed.has(tool));
|
|
21134
21194
|
}
|
|
21195
|
+
function postureToolOptions(args) {
|
|
21196
|
+
return {
|
|
21197
|
+
...args.denyRules !== undefined ? { denyRules: args.denyRules } : {},
|
|
21198
|
+
...args.askOnUnsandboxed !== undefined ? { askOnUnsandboxed: args.askOnUnsandboxed } : {},
|
|
21199
|
+
...args.commandShadow !== undefined ? { commandShadow: args.commandShadow } : {}
|
|
21200
|
+
};
|
|
21201
|
+
}
|
|
21135
21202
|
function buildSessionToolSupport(args) {
|
|
21136
21203
|
const profileTools = narrowBuiltIns(declaredToolsFor(args.profile, args.protectedPaths), args.allowedTools);
|
|
21137
21204
|
const declared = [
|
|
@@ -21140,10 +21207,11 @@ function buildSessionToolSupport(args) {
|
|
|
21140
21207
|
const grants = [...grantsFor(profileTools), ...args.providerTools?.grants ?? []];
|
|
21141
21208
|
const askRules = [
|
|
21142
21209
|
...askRulesFor(profileTools, args.bashApproval, args.profile),
|
|
21143
|
-
...(args.profile === "ask" ? args.providerTools?.askTools ?? [] : []).map((tool) => ({
|
|
21210
|
+
...(args.profile === "ask" || args.askDiscoveredTools ? args.providerTools?.askTools ?? [] : []).map((tool) => ({
|
|
21144
21211
|
tool,
|
|
21145
21212
|
patterns: ["*"]
|
|
21146
|
-
}))
|
|
21213
|
+
})),
|
|
21214
|
+
...args.askRules ?? []
|
|
21147
21215
|
];
|
|
21148
21216
|
const providerInstructions = renderProviderInstructions(args.providerTools?.instructions ?? []);
|
|
21149
21217
|
const support = buildCodingToolSupport({
|
|
@@ -21165,7 +21233,8 @@ function buildSessionToolSupport(args) {
|
|
|
21165
21233
|
...askRules.length > 0 ? { askRules } : {},
|
|
21166
21234
|
...args.interceptor !== undefined ? { interceptor: args.interceptor } : {},
|
|
21167
21235
|
...args.launcher !== undefined ? { launcher: args.launcher } : {},
|
|
21168
|
-
...unsandboxedToolOptions(args)
|
|
21236
|
+
...unsandboxedToolOptions(args),
|
|
21237
|
+
...postureToolOptions(args)
|
|
21169
21238
|
});
|
|
21170
21239
|
if (support === undefined) {
|
|
21171
21240
|
throw new AgentSessionError("No coding tools resolved for the session", "AGENT_SESSION_INVALID_OPTIONS", {
|
|
@@ -21209,7 +21278,12 @@ async function openNative(resolved, ctx) {
|
|
|
21209
21278
|
const raw = resolved.raw;
|
|
21210
21279
|
if (ctx.resume !== undefined && raw.carryHistoryAcrossModels !== true)
|
|
21211
21280
|
checkResumeModel(ctx.resume.doc, ctx.sessionId, raw.model);
|
|
21212
|
-
const {
|
|
21281
|
+
const {
|
|
21282
|
+
bashApproval: profileMode,
|
|
21283
|
+
allowUnsandboxed,
|
|
21284
|
+
allowUnsandboxedCommands
|
|
21285
|
+
} = nativeProfileRules(ctx.profile, raw);
|
|
21286
|
+
const posture = nativePostureRules(ctx.profile, raw);
|
|
21213
21287
|
const protectedPaths = {
|
|
21214
21288
|
...defaultProtectedPaths(raw.credentials !== undefined),
|
|
21215
21289
|
...raw.hostPorts?.protectedPaths
|
|
@@ -21218,9 +21292,11 @@ async function openNative(resolved, ctx) {
|
|
|
21218
21292
|
profile: ctx.profile,
|
|
21219
21293
|
root: ctx.workdir,
|
|
21220
21294
|
protectedPaths,
|
|
21221
|
-
bashApproval,
|
|
21222
|
-
allowUnsandboxed
|
|
21295
|
+
bashApproval: profileMode,
|
|
21296
|
+
allowUnsandboxed,
|
|
21297
|
+
config: posture.sandbox
|
|
21223
21298
|
});
|
|
21299
|
+
const bashApproval = effectiveBashApproval(profileMode, posture.askWhenSandboxDown, sandbox.kind);
|
|
21224
21300
|
const providerTools = ctx.profile === "none" || raw.toolProviders === undefined ? undefined : await resolveProviderTools(raw.toolProviders, SESSION_STAGE, ctx.workdir, raw.allowedTools !== undefined ? { admits: providerAdmits(raw.allowedTools) } : undefined);
|
|
21225
21301
|
for (const failure of providerTools?.failures ?? []) {
|
|
21226
21302
|
getLogger().warn("session", "Tool provider skipped", { sessionId: ctx.sessionId, ...failure });
|
|
@@ -21242,11 +21318,17 @@ async function openNative(resolved, ctx) {
|
|
|
21242
21318
|
launcher,
|
|
21243
21319
|
askResolver: createSessionAskResolver(createSessionAskLink({ port: ctx.asks, currentCallId: () => callId })),
|
|
21244
21320
|
interceptor: raw.hostPorts?.commandInterceptor,
|
|
21321
|
+
askRules: posture.askRules,
|
|
21322
|
+
denyRules: posture.denyRules,
|
|
21323
|
+
askOnUnsandboxed: posture.askOnUnsandboxed,
|
|
21324
|
+
askDiscoveredTools: posture.askDiscoveredTools,
|
|
21325
|
+
commandShadow: raw.hostPorts?.commandShadow,
|
|
21245
21326
|
...allowUnsandboxedCommands ? { unsandboxedCommands: true } : {}
|
|
21246
21327
|
});
|
|
21247
21328
|
const interactionHandler = createSessionInteractionHandler({
|
|
21248
21329
|
sessionId: ctx.sessionId,
|
|
21249
21330
|
runtime: support.runtime,
|
|
21331
|
+
unavailableTools: new Set((support.declaredTools ?? []).filter((name) => !support.tools.some((tool) => tool.name === name))),
|
|
21250
21332
|
embedderTools: new Map(ctx.tools.map((tool) => [tool.name, tool])),
|
|
21251
21333
|
asks: ctx.asks,
|
|
21252
21334
|
turnSignal: ctx.turnSignal,
|
|
@@ -21328,6 +21410,7 @@ var init_native_backend = __esm(() => {
|
|
|
21328
21410
|
init_provider_advertise();
|
|
21329
21411
|
init_agent_session_errors();
|
|
21330
21412
|
init_native_backend_options();
|
|
21413
|
+
init_native_posture_rules();
|
|
21331
21414
|
init_session_ask_link();
|
|
21332
21415
|
init_session_interaction();
|
|
21333
21416
|
init_session_tool_support();
|
|
@@ -25262,13 +25345,28 @@ function lookupStageBlock(blocks, stage) {
|
|
|
25262
25345
|
return;
|
|
25263
25346
|
const seen = new Set;
|
|
25264
25347
|
let key = stage;
|
|
25265
|
-
let block = blocks[stage];
|
|
25348
|
+
let block = Object.hasOwn(blocks, stage) ? blocks[stage] : undefined;
|
|
25266
25349
|
while (block?.inherit !== undefined && key !== undefined && !seen.has(key)) {
|
|
25267
25350
|
seen.add(key);
|
|
25268
25351
|
key = block.inherit;
|
|
25269
|
-
block = blocks[key];
|
|
25352
|
+
block = Object.hasOwn(blocks, key) ? blocks[key] : undefined;
|
|
25353
|
+
}
|
|
25354
|
+
return block ?? (Object.hasOwn(blocks, "default") ? blocks.default : undefined);
|
|
25355
|
+
}
|
|
25356
|
+
function resolveTuiPermissions(config) {
|
|
25357
|
+
const block = lookupStageBlock(config?.execution?.permissions, "tui");
|
|
25358
|
+
const bashApproval = resolveBashApproval(config?.execution?.bashApproval, block?.bashApproval);
|
|
25359
|
+
const askRules = block?.ask ?? [];
|
|
25360
|
+
const denyRules = block?.deny ?? [];
|
|
25361
|
+
if (bashApproval === "escalate") {
|
|
25362
|
+
getSafeLogger2()?.warn("permissions", '[tui] bashApproval "escalate" has no meaning in chat; using "gated"');
|
|
25363
|
+
} else if (bashApproval === "raw" && hasScopedBashRules([...askRules, ...denyRules])) {
|
|
25364
|
+
getSafeLogger2()?.warn("permissions", '[tui] Bash(...) ask/deny patterns are not consulted under bashApproval "raw"');
|
|
25270
25365
|
}
|
|
25271
|
-
return
|
|
25366
|
+
return { bashApproval: bashApproval === "escalate" ? "gated" : bashApproval, askRules, denyRules };
|
|
25367
|
+
}
|
|
25368
|
+
function hasScopedBashRules(rules) {
|
|
25369
|
+
return parseRuleList(rules).some((rule) => rule.tool === "Bash" && !rule.patterns.includes("*"));
|
|
25272
25370
|
}
|
|
25273
25371
|
function stageRules(config, stage) {
|
|
25274
25372
|
const blocks = config?.execution?.permissions;
|
|
@@ -26197,6 +26295,27 @@ function validateMcpExpression(stage, expression) {
|
|
|
26197
26295
|
}
|
|
26198
26296
|
}
|
|
26199
26297
|
}
|
|
26298
|
+
function validatePermissionInheritance(blocks, stage, inherit) {
|
|
26299
|
+
if (typeof inherit === "string" && (!Object.hasOwn(blocks, inherit) || blocks[inherit] === undefined)) {
|
|
26300
|
+
throw new NaxError(`Invalid configuration \u2014 execution.permissions.${stage}.inherit names "${inherit}", which is not a permission block.`, "CONFIG_PERMISSIONS_BAD_INHERIT", { stage: "config" });
|
|
26301
|
+
}
|
|
26302
|
+
const seen = new Set([stage]);
|
|
26303
|
+
const path = [stage];
|
|
26304
|
+
let cursor = inherit;
|
|
26305
|
+
while (typeof cursor === "string") {
|
|
26306
|
+
path.push(cursor);
|
|
26307
|
+
if (seen.has(cursor)) {
|
|
26308
|
+
throw new NaxError([
|
|
26309
|
+
`Invalid configuration \u2014 execution.permissions has an inherit cycle: ${path.join(" -> ")}.`,
|
|
26310
|
+
"A cycle resolves to the default block rather than the grants written here,",
|
|
26311
|
+
"so the stage would be denied something the config appears to permit."
|
|
26312
|
+
].join(`
|
|
26313
|
+
`), "CONFIG_PERMISSIONS_INHERIT_CYCLE", { stage: "config" });
|
|
26314
|
+
}
|
|
26315
|
+
seen.add(cursor);
|
|
26316
|
+
cursor = Object.hasOwn(blocks, cursor) ? blocks[cursor]?.inherit : undefined;
|
|
26317
|
+
}
|
|
26318
|
+
}
|
|
26200
26319
|
function validatePermissionsBlock(conf) {
|
|
26201
26320
|
const execution = conf.execution;
|
|
26202
26321
|
const blocks = execution?.permissions;
|
|
@@ -26204,25 +26323,7 @@ function validatePermissionsBlock(conf) {
|
|
|
26204
26323
|
return;
|
|
26205
26324
|
const known = new Set([...RESERVED_TOOL_NAMES, MCP_RULE_TOOL]);
|
|
26206
26325
|
for (const [stage, block] of Object.entries(blocks)) {
|
|
26207
|
-
|
|
26208
|
-
throw new NaxError(`Invalid configuration \u2014 execution.permissions.${stage}.inherit names "${block.inherit}", which is not a permission block.`, "CONFIG_PERMISSIONS_BAD_INHERIT", { stage: "config" });
|
|
26209
|
-
}
|
|
26210
|
-
const seen = new Set([stage]);
|
|
26211
|
-
const path = [stage];
|
|
26212
|
-
let cursor = block?.inherit;
|
|
26213
|
-
while (typeof cursor === "string") {
|
|
26214
|
-
path.push(cursor);
|
|
26215
|
-
if (seen.has(cursor)) {
|
|
26216
|
-
throw new NaxError([
|
|
26217
|
-
`Invalid configuration \u2014 execution.permissions has an inherit cycle: ${path.join(" -> ")}.`,
|
|
26218
|
-
"A cycle resolves to the default block rather than the grants written here,",
|
|
26219
|
-
"so the stage would be denied something the config appears to permit."
|
|
26220
|
-
].join(`
|
|
26221
|
-
`), "CONFIG_PERMISSIONS_INHERIT_CYCLE", { stage: "config" });
|
|
26222
|
-
}
|
|
26223
|
-
seen.add(cursor);
|
|
26224
|
-
cursor = blocks[cursor]?.inherit;
|
|
26225
|
-
}
|
|
26326
|
+
validatePermissionInheritance(blocks, stage, block?.inherit);
|
|
26226
26327
|
if (block?.allowedTools !== undefined && block?.allow !== undefined) {
|
|
26227
26328
|
throw new NaxError([
|
|
26228
26329
|
`Invalid configuration \u2014 execution.permissions.${stage} carries both "allowedTools" and "allow".`,
|
|
@@ -40141,7 +40242,7 @@ var init_rules_index_builder = __esm(() => {
|
|
|
40141
40242
|
|
|
40142
40243
|
// src/prompts/builders/chat-builder.ts
|
|
40143
40244
|
function chatPermissionParagraph(mode) {
|
|
40144
|
-
return mode === "full" ? "In full mode, tools run without asking." : "In guarded mode,
|
|
40245
|
+
return mode === "full" ? "In full mode, tools run without asking." : "In guarded mode, commands run inside the sandbox under the configured posture; a command that asks to run outside the sandbox, any command while the sandbox is unavailable, a call the configured permission rules mark for asking, and a call to an MCP tool that is not read-only are put to the person before they run.";
|
|
40145
40246
|
}
|
|
40146
40247
|
function buildChatInstructions(input) {
|
|
40147
40248
|
const sections = [
|
|
@@ -51955,7 +52056,7 @@ var package_default;
|
|
|
51955
52056
|
var init_package = __esm(() => {
|
|
51956
52057
|
package_default = {
|
|
51957
52058
|
name: "@nathapp/nax",
|
|
51958
|
-
version: "0.91.7-canary.
|
|
52059
|
+
version: "0.91.7-canary.5",
|
|
51959
52060
|
description: "AI Coding Agent Orchestrator \u2014 loops until done",
|
|
51960
52061
|
type: "module",
|
|
51961
52062
|
bin: {
|
|
@@ -52041,7 +52142,7 @@ var init_package = __esm(() => {
|
|
|
52041
52142
|
"@agentclientprotocol/sdk": "~1.7.0",
|
|
52042
52143
|
"@anthropic-ai/sandbox-runtime": "0.0.77",
|
|
52043
52144
|
"@modelcontextprotocol/sdk": "^1.32.1",
|
|
52044
|
-
"@nathapp/nax-ai": "0.91.7-canary.
|
|
52145
|
+
"@nathapp/nax-ai": "0.91.7-canary.5",
|
|
52045
52146
|
chalk: "^5.6.2",
|
|
52046
52147
|
commander: "^13.1.0",
|
|
52047
52148
|
"highlight.js": "^11.12.0",
|
|
@@ -52151,6 +52252,12 @@ async function lookupContextWindow(provider, model) {
|
|
|
52151
52252
|
return;
|
|
52152
52253
|
}
|
|
52153
52254
|
}
|
|
52255
|
+
async function listCatalogModels(providerIds) {
|
|
52256
|
+
const catalog = await loadCatalog(_catalogDeps.loadProviders);
|
|
52257
|
+
if (catalog === null)
|
|
52258
|
+
return [];
|
|
52259
|
+
return providerIds.flatMap((provider) => catalog.listModels(provider).filter((model) => model.supportsTools).map((model) => `${provider}/${model.id}`));
|
|
52260
|
+
}
|
|
52154
52261
|
function catalogLoadFailed() {
|
|
52155
52262
|
return catalogCache.get(_catalogDeps.loadProviders) === null;
|
|
52156
52263
|
}
|
|
@@ -77346,8 +77453,8 @@ var init_version = __esm(() => {
|
|
|
77346
77453
|
NAX_AI_VERSION = CATALOG_VERSION;
|
|
77347
77454
|
NAX_COMMIT = (() => {
|
|
77348
77455
|
try {
|
|
77349
|
-
if (/^[0-9a-f]{6,10}$/.test("
|
|
77350
|
-
return "
|
|
77456
|
+
if (/^[0-9a-f]{6,10}$/.test("2415c3a"))
|
|
77457
|
+
return "2415c3a";
|
|
77351
77458
|
} catch {}
|
|
77352
77459
|
try {
|
|
77353
77460
|
const result = Bun.spawnSync(["git", "rev-parse", "--short", "HEAD"], {
|
|
@@ -144875,8 +144982,29 @@ var init_chat_ledger = __esm(() => {
|
|
|
144875
144982
|
});
|
|
144876
144983
|
|
|
144877
144984
|
// src/chat/chat-mode.ts
|
|
144878
|
-
function chatSessionSettings(mode) {
|
|
144879
|
-
return mode === "full" ? { profile: "full", bashApproval: "raw", metaMode: "full" } : { profile: "
|
|
144985
|
+
function chatSessionSettings(mode, posture) {
|
|
144986
|
+
return mode === "full" ? { profile: "full", bashApproval: "raw", metaMode: "full" } : { profile: "full", bashApproval: requiredPosture(posture).bashApproval, metaMode: "ask" };
|
|
144987
|
+
}
|
|
144988
|
+
function requiredPosture(posture) {
|
|
144989
|
+
if (posture === undefined) {
|
|
144990
|
+
throw new NaxError("[chat] guarded session requires a resolved posture", "CHAT_POSTURE_REQUIRED", {
|
|
144991
|
+
stage: "chat"
|
|
144992
|
+
});
|
|
144993
|
+
}
|
|
144994
|
+
return posture;
|
|
144995
|
+
}
|
|
144996
|
+
function chatBackendPosture(mode, config, posture) {
|
|
144997
|
+
if (mode === "full")
|
|
144998
|
+
return { sandbox: config.execution.sandbox };
|
|
144999
|
+
const resolved = requiredPosture(posture);
|
|
145000
|
+
return {
|
|
145001
|
+
sandbox: config.execution.sandbox,
|
|
145002
|
+
askRules: resolved.askRules,
|
|
145003
|
+
denyRules: resolved.denyRules,
|
|
145004
|
+
askOnUnsandboxed: true,
|
|
145005
|
+
askWhenSandboxDown: true,
|
|
145006
|
+
askDiscoveredTools: true
|
|
145007
|
+
};
|
|
144880
145008
|
}
|
|
144881
145009
|
function nextChatMode(mode) {
|
|
144882
145010
|
return mode === "guarded" ? "full" : "guarded";
|
|
@@ -144888,6 +145016,29 @@ function chatModeOfMeta(mode) {
|
|
|
144888
145016
|
return "full";
|
|
144889
145017
|
return null;
|
|
144890
145018
|
}
|
|
145019
|
+
var init_chat_mode = __esm(() => {
|
|
145020
|
+
init_errors4();
|
|
145021
|
+
});
|
|
145022
|
+
|
|
145023
|
+
// src/chat/chat-models.ts
|
|
145024
|
+
function tierModels(config) {
|
|
145025
|
+
const tiers = config.models.native;
|
|
145026
|
+
const models = ["fast", "balanced", "powerful"].flatMap((tier) => {
|
|
145027
|
+
const entry = tiers?.[tier];
|
|
145028
|
+
return entry === undefined ? [] : [typeof entry === "string" ? entry : `${entry.provider}/${entry.model}`];
|
|
145029
|
+
});
|
|
145030
|
+
return Object.freeze([...new Set(models)]);
|
|
145031
|
+
}
|
|
145032
|
+
async function chatModelChoices(input) {
|
|
145033
|
+
const models = [
|
|
145034
|
+
...tierModels(input.config),
|
|
145035
|
+
...(input.config.agent?.native?.catalogOverrides ?? []).flatMap(({ provider, models }) => models.filter((model) => model.supportsTools).map(({ id }) => `${provider}/${id}`))
|
|
145036
|
+
];
|
|
145037
|
+
try {
|
|
145038
|
+
models.push(...await input.listCatalogModels(input.availableProviders));
|
|
145039
|
+
} catch {}
|
|
145040
|
+
return Object.freeze([...new Set(models)]);
|
|
145041
|
+
}
|
|
144891
145042
|
|
|
144892
145043
|
// src/chat/open-chat-session.ts
|
|
144893
145044
|
import { randomUUID as randomUUID20 } from "crypto";
|
|
@@ -144914,15 +145065,16 @@ async function readResumeMeta(storage, id) {
|
|
|
144914
145065
|
}
|
|
144915
145066
|
return stored;
|
|
144916
145067
|
}
|
|
144917
|
-
|
|
144918
|
-
|
|
144919
|
-
|
|
144920
|
-
|
|
144921
|
-
|
|
144922
|
-
|
|
144923
|
-
|
|
144924
|
-
|
|
144925
|
-
|
|
145068
|
+
function validatedMode(stored) {
|
|
145069
|
+
const mode = chatModeOfMeta(stored.mode);
|
|
145070
|
+
if (mode === null) {
|
|
145071
|
+
throw new NaxError(`session ${stored.sessionId} was created in mode ${stored.mode}; nax chat opens full or ask sessions only`, "CHAT_SESSION_MODE_UNSUPPORTED", { stage: "chat", sessionId: stored.sessionId });
|
|
145072
|
+
}
|
|
145073
|
+
return mode;
|
|
145074
|
+
}
|
|
145075
|
+
function sessionMeta(request, { mode, posture, stored }, deps) {
|
|
145076
|
+
const settings = chatSessionSettings(mode, posture);
|
|
145077
|
+
if (stored !== undefined) {
|
|
144926
145078
|
return {
|
|
144927
145079
|
...stored,
|
|
144928
145080
|
mode: settings.metaMode,
|
|
@@ -144935,7 +145087,6 @@ async function sessionMeta(request, deps) {
|
|
|
144935
145087
|
stage: "chat"
|
|
144936
145088
|
});
|
|
144937
145089
|
}
|
|
144938
|
-
const settings = chatSessionSettings(request.mode ?? "guarded");
|
|
144939
145090
|
return {
|
|
144940
145091
|
schemaVersion: 1,
|
|
144941
145092
|
sessionId: deps.randomUUID(),
|
|
@@ -144948,7 +145099,11 @@ async function sessionMeta(request, deps) {
|
|
|
144948
145099
|
updatedAt: null
|
|
144949
145100
|
};
|
|
144950
145101
|
}
|
|
144951
|
-
async function sessionOptions(request,
|
|
145102
|
+
async function sessionOptions(request, {
|
|
145103
|
+
meta,
|
|
145104
|
+
posture,
|
|
145105
|
+
commandShadow
|
|
145106
|
+
}, deps) {
|
|
144952
145107
|
const rules = request.config.context.rules;
|
|
144953
145108
|
const set = await deps.resolveRuleSet({
|
|
144954
145109
|
repoRoot: request.repoRoot,
|
|
@@ -144961,6 +145116,8 @@ async function sessionOptions(request, meta, deps) {
|
|
|
144961
145116
|
const compaction = request.config.execution.compaction;
|
|
144962
145117
|
return {
|
|
144963
145118
|
backend: deps.nativeBackend({
|
|
145119
|
+
...chatBackendPosture(mode, request.config, posture),
|
|
145120
|
+
...commandShadow !== undefined ? { hostPorts: { commandShadow } } : {},
|
|
144964
145121
|
model: meta.model,
|
|
144965
145122
|
bashApproval: meta.bashApproval,
|
|
144966
145123
|
allowUnsandboxed: true,
|
|
@@ -144973,23 +145130,54 @@ async function sessionOptions(request, meta, deps) {
|
|
|
144973
145130
|
...compaction !== undefined ? { compaction } : {}
|
|
144974
145131
|
}),
|
|
144975
145132
|
sessionId: meta.sessionId,
|
|
144976
|
-
profile: chatSessionSettings(mode).profile,
|
|
145133
|
+
profile: chatSessionSettings(mode, posture).profile,
|
|
144977
145134
|
workdir: request.cwd,
|
|
144978
145135
|
instructions: buildChatInstructions({ mode, rulesIndex: set.rules.map(toRulesIndexEntry) }),
|
|
144979
145136
|
approvalTimeoutMs: request.config.execution.approvalTimeout
|
|
144980
145137
|
};
|
|
144981
145138
|
}
|
|
145139
|
+
function sessionRelease(unlock, shadow) {
|
|
145140
|
+
let drained;
|
|
145141
|
+
let unlocked;
|
|
145142
|
+
return async (options) => {
|
|
145143
|
+
try {
|
|
145144
|
+
drained ??= Promise.resolve().then(() => shadow()?.drain());
|
|
145145
|
+
await drained;
|
|
145146
|
+
} finally {
|
|
145147
|
+
if (!options?.retainLock) {
|
|
145148
|
+
unlocked ??= unlock();
|
|
145149
|
+
await unlocked;
|
|
145150
|
+
}
|
|
145151
|
+
}
|
|
145152
|
+
};
|
|
145153
|
+
}
|
|
144982
145154
|
async function openChatSession(request, deps = _openChatSessionDeps) {
|
|
144983
145155
|
if (request.resumeId !== undefined && !SESSION_ID_PATTERN.test(request.resumeId)) {
|
|
144984
145156
|
throw new NaxError("[chat] invalid session id", "CHAT_SESSION_ID_INVALID", { stage: "chat" });
|
|
144985
145157
|
}
|
|
144986
145158
|
const transcripts = deps.createFileTranscriptStore(request.storage.dir);
|
|
144987
|
-
const
|
|
144988
|
-
const
|
|
144989
|
-
|
|
145159
|
+
const stored = request.resumeId === undefined ? undefined : await readResumeMeta(request.storage, request.resumeId);
|
|
145160
|
+
const storedMode = stored === undefined ? undefined : validatedMode(stored);
|
|
145161
|
+
const mode = request.mode ?? storedMode ?? "guarded";
|
|
145162
|
+
const posture = mode === "guarded" ? deps.resolveTuiPermissions(request.config) : undefined;
|
|
145163
|
+
const meta = sessionMeta(request, { mode, posture, stored }, deps);
|
|
145164
|
+
const unlock = await request.storage.acquireLock(meta.sessionId);
|
|
145165
|
+
let commandShadow;
|
|
145166
|
+
const release = sessionRelease(unlock, () => commandShadow);
|
|
145167
|
+
try {
|
|
145168
|
+
if (mode === "guarded")
|
|
145169
|
+
commandShadow = deps.buildCommandShadow({
|
|
145170
|
+
config: request.config.execution.commandSafety,
|
|
145171
|
+
outputDir: request.storage.dir,
|
|
145172
|
+
runId: meta.sessionId,
|
|
145173
|
+
env: deps.env
|
|
145174
|
+
});
|
|
144990
145175
|
if (request.resumeId === undefined)
|
|
144991
145176
|
await request.storage.writeMeta(meta);
|
|
144992
|
-
const options = {
|
|
145177
|
+
const options = {
|
|
145178
|
+
...await sessionOptions(request, { meta, posture, commandShadow }, deps),
|
|
145179
|
+
transcriptStore: transcripts
|
|
145180
|
+
};
|
|
144993
145181
|
const doc = await transcripts.load(meta.sessionId);
|
|
144994
145182
|
const session = doc === null ? await deps.createAgentSession(options) : await deps.resumeAgentSession(meta.sessionId, options);
|
|
144995
145183
|
return { session, meta, release };
|
|
@@ -145005,13 +145193,16 @@ var init_open_chat_session = __esm(() => {
|
|
|
145005
145193
|
init_rule_set();
|
|
145006
145194
|
init_errors4();
|
|
145007
145195
|
init_prompts();
|
|
145196
|
+
init_chat_mode();
|
|
145008
145197
|
_openChatSessionDeps = {
|
|
145198
|
+
buildCommandShadow,
|
|
145009
145199
|
createAgentSession,
|
|
145010
145200
|
resumeAgentSession,
|
|
145011
145201
|
nativeBackend,
|
|
145012
145202
|
createSessionStorage,
|
|
145013
145203
|
createFileTranscriptStore,
|
|
145014
145204
|
resolveRuleSet,
|
|
145205
|
+
resolveTuiPermissions,
|
|
145015
145206
|
randomUUID: () => randomUUID20(),
|
|
145016
145207
|
env: process.env,
|
|
145017
145208
|
now: () => new Date
|
|
@@ -145019,8 +145210,8 @@ var init_open_chat_session = __esm(() => {
|
|
|
145019
145210
|
});
|
|
145020
145211
|
|
|
145021
145212
|
// src/chat/subagent-session.ts
|
|
145022
|
-
async function subagentSessionOptions(input, deps) {
|
|
145023
|
-
const settings = chatSessionSettings(input.mode);
|
|
145213
|
+
async function subagentSessionOptions(input, posture, deps) {
|
|
145214
|
+
const settings = chatSessionSettings(input.mode, posture);
|
|
145024
145215
|
const rules = input.config.context.rules;
|
|
145025
145216
|
const set = await deps.resolveRuleSet({
|
|
145026
145217
|
repoRoot: input.repoRoot,
|
|
@@ -145032,6 +145223,7 @@ async function subagentSessionOptions(input, deps) {
|
|
|
145032
145223
|
const compaction = input.config.execution.compaction;
|
|
145033
145224
|
return {
|
|
145034
145225
|
backend: deps.nativeBackend({
|
|
145226
|
+
...chatBackendPosture(input.mode, input.config, posture),
|
|
145035
145227
|
model: input.model,
|
|
145036
145228
|
bashApproval: settings.bashApproval,
|
|
145037
145229
|
allowUnsandboxed: true,
|
|
@@ -145113,7 +145305,8 @@ async function runOnSession(session, input) {
|
|
|
145113
145305
|
async function runSubagent(input, deps = _subagentSessionDeps) {
|
|
145114
145306
|
if (input.signal?.aborted)
|
|
145115
145307
|
return cancelledResult2(input);
|
|
145116
|
-
const
|
|
145308
|
+
const posture = input.mode === "guarded" ? deps.resolveTuiPermissions(input.config) : undefined;
|
|
145309
|
+
const options = await subagentSessionOptions(input, posture, deps);
|
|
145117
145310
|
let session;
|
|
145118
145311
|
try {
|
|
145119
145312
|
session = await deps.createAgentSession(options);
|
|
@@ -145126,15 +145319,18 @@ var _subagentSessionDeps, NO_TEXT_CONTENT = "(the subagent returned no text)";
|
|
|
145126
145319
|
var init_subagent_session = __esm(() => {
|
|
145127
145320
|
init_src();
|
|
145128
145321
|
init_internal();
|
|
145322
|
+
init_config();
|
|
145129
145323
|
init_rule_set();
|
|
145130
145324
|
init_errors4();
|
|
145131
145325
|
init_logger2();
|
|
145132
145326
|
init_prompts();
|
|
145327
|
+
init_chat_mode();
|
|
145133
145328
|
_subagentSessionDeps = {
|
|
145134
145329
|
createAgentSession,
|
|
145135
145330
|
nativeBackend,
|
|
145136
145331
|
createMemoryTranscriptStore,
|
|
145137
|
-
resolveRuleSet
|
|
145332
|
+
resolveRuleSet,
|
|
145333
|
+
resolveTuiPermissions
|
|
145138
145334
|
};
|
|
145139
145335
|
});
|
|
145140
145336
|
|
|
@@ -145337,14 +145533,6 @@ var init_turn_runner = __esm(() => {
|
|
|
145337
145533
|
});
|
|
145338
145534
|
|
|
145339
145535
|
// src/chat/chat-host.ts
|
|
145340
|
-
function nativeModels(config) {
|
|
145341
|
-
const tiers = config.models.native;
|
|
145342
|
-
const models = ["fast", "balanced", "powerful"].flatMap((tier) => {
|
|
145343
|
-
const entry = tiers?.[tier];
|
|
145344
|
-
return entry === undefined ? [] : [typeof entry === "string" ? entry : `${entry.provider}/${entry.model}`];
|
|
145345
|
-
});
|
|
145346
|
-
return Object.freeze([...new Set(models)]);
|
|
145347
|
-
}
|
|
145348
145536
|
async function closeHandle(handle) {
|
|
145349
145537
|
try {
|
|
145350
145538
|
await handle.session.close();
|
|
@@ -145383,7 +145571,7 @@ class NativeChatHost {
|
|
|
145383
145571
|
this.catalog = deps.resources?.catalog;
|
|
145384
145572
|
this.naxPlugins = deps.resources?.naxPlugins;
|
|
145385
145573
|
this.mcp = deps.resources?.mcp;
|
|
145386
|
-
this.models =
|
|
145574
|
+
this.models = deps.models ?? tierModels(deps.config);
|
|
145387
145575
|
this.projectKey = getProjectKey(deps.config, deps.repoRoot);
|
|
145388
145576
|
this.outputDir = projectOutputDir(this.projectKey, deps.config.outputDir);
|
|
145389
145577
|
const rules = deps.config.context.rules;
|
|
@@ -145600,7 +145788,16 @@ class NativeChatHost {
|
|
|
145600
145788
|
loopHandlers: this.loopHandlers,
|
|
145601
145789
|
...this.toolProviders ? { toolProviders: this.toolProviders } : {}
|
|
145602
145790
|
});
|
|
145603
|
-
return {
|
|
145791
|
+
return {
|
|
145792
|
+
...next,
|
|
145793
|
+
release: async (options) => {
|
|
145794
|
+
try {
|
|
145795
|
+
await next.release(options);
|
|
145796
|
+
} finally {
|
|
145797
|
+
await previous.release(options);
|
|
145798
|
+
}
|
|
145799
|
+
}
|
|
145800
|
+
};
|
|
145604
145801
|
}
|
|
145605
145802
|
async switchTo(input) {
|
|
145606
145803
|
await this.withSessionOperation(() => this.switchSession(input));
|
|
@@ -145611,14 +145808,23 @@ class NativeChatHost {
|
|
|
145611
145808
|
const target = { mode: input.mode ?? from.mode, model: input.model ?? from.model };
|
|
145612
145809
|
if (target.mode === from.mode && target.model === from.model)
|
|
145613
145810
|
return;
|
|
145614
|
-
|
|
145811
|
+
try {
|
|
145812
|
+
await previous.session.close();
|
|
145813
|
+
} finally {
|
|
145814
|
+
await previous.release({ retainLock: true });
|
|
145815
|
+
}
|
|
145615
145816
|
let next;
|
|
145616
145817
|
try {
|
|
145617
145818
|
next = await this.reopen(target, previous);
|
|
145618
145819
|
await this.deps.storage.writeMeta(next.meta);
|
|
145619
145820
|
} catch (error) {
|
|
145620
|
-
if (next)
|
|
145621
|
-
|
|
145821
|
+
if (next) {
|
|
145822
|
+
try {
|
|
145823
|
+
await next.session.close();
|
|
145824
|
+
} finally {
|
|
145825
|
+
await next.release({ retainLock: true });
|
|
145826
|
+
}
|
|
145827
|
+
}
|
|
145622
145828
|
this.handle = await this.reopen(from, previous);
|
|
145623
145829
|
throw error;
|
|
145624
145830
|
}
|
|
@@ -145730,6 +145936,7 @@ var init_chat_host = __esm(() => {
|
|
|
145730
145936
|
init_ask_fallback();
|
|
145731
145937
|
init_chat_agents_listing();
|
|
145732
145938
|
init_chat_ledger();
|
|
145939
|
+
init_chat_mode();
|
|
145733
145940
|
init_open_chat_session();
|
|
145734
145941
|
init_subagent_runs();
|
|
145735
145942
|
init_turn_runner();
|
|
@@ -145854,6 +146061,7 @@ var init_chat = __esm(() => {
|
|
|
145854
146061
|
init_chat_host();
|
|
145855
146062
|
init_chat_ledger();
|
|
145856
146063
|
init_chat_mcp();
|
|
146064
|
+
init_chat_mode();
|
|
145857
146065
|
init_open_chat_session();
|
|
145858
146066
|
init_subagent_model();
|
|
145859
146067
|
init_subagent_tools();
|
|
@@ -164601,6 +164809,9 @@ var require_jsx_dev_runtime = __commonJS(function(exports, module) {
|
|
|
164601
164809
|
});
|
|
164602
164810
|
|
|
164603
164811
|
// src/tui/chat/styled-line.tsx
|
|
164812
|
+
function plainText(line) {
|
|
164813
|
+
return line.map((span) => span.text).join("");
|
|
164814
|
+
}
|
|
164604
164815
|
function displayWidth(text) {
|
|
164605
164816
|
return Bun.stringWidth(text);
|
|
164606
164817
|
}
|
|
@@ -164622,7 +164833,8 @@ function spanProps(span, theme) {
|
|
|
164622
164833
|
color: span.color === undefined ? undefined : theme.colors[span.color],
|
|
164623
164834
|
backgroundColor: span.background === undefined ? undefined : theme.colors[span.background],
|
|
164624
164835
|
bold: span.bold,
|
|
164625
|
-
italic: span.italic
|
|
164836
|
+
italic: span.italic,
|
|
164837
|
+
inverse: span.inverse
|
|
164626
164838
|
};
|
|
164627
164839
|
}
|
|
164628
164840
|
function StyledLineView({ line, theme }) {
|
|
@@ -164651,7 +164863,7 @@ function styled(text, style) {
|
|
|
164651
164863
|
return { text, ...style };
|
|
164652
164864
|
}
|
|
164653
164865
|
function sameStyle(left, right) {
|
|
164654
|
-
return left.color === right.color && left.background === right.background && Boolean(left.bold) === Boolean(right.bold) && Boolean(left.italic) === Boolean(right.italic);
|
|
164866
|
+
return left.color === right.color && left.background === right.background && Boolean(left.bold) === Boolean(right.bold) && Boolean(left.italic) === Boolean(right.italic) && Boolean(left.inverse) === Boolean(right.inverse);
|
|
164655
164867
|
}
|
|
164656
164868
|
function mergeSpans(spans) {
|
|
164657
164869
|
const merged = [];
|
|
@@ -164675,7 +164887,8 @@ function styleOf(span) {
|
|
|
164675
164887
|
color: span.color,
|
|
164676
164888
|
background: span.background,
|
|
164677
164889
|
bold: span.bold,
|
|
164678
|
-
italic: span.italic
|
|
164890
|
+
italic: span.italic,
|
|
164891
|
+
inverse: span.inverse
|
|
164679
164892
|
};
|
|
164680
164893
|
}
|
|
164681
164894
|
function fragmentsBetween(parts, offsets, start, end) {
|
|
@@ -166088,6 +166301,10 @@ function modelEntries(input) {
|
|
|
166088
166301
|
current: model === input.currentModel
|
|
166089
166302
|
}));
|
|
166090
166303
|
}
|
|
166304
|
+
function matchingEntries(entries, query) {
|
|
166305
|
+
const needle = query.toLowerCase();
|
|
166306
|
+
return entries.filter((entry) => entry.value.toLowerCase().includes(needle));
|
|
166307
|
+
}
|
|
166091
166308
|
function modeEntries(input) {
|
|
166092
166309
|
return MODE_CHOICES.map((choice) => ({
|
|
166093
166310
|
value: choice.mode,
|
|
@@ -166116,8 +166333,18 @@ function resumeNote(input) {
|
|
|
166116
166333
|
function pickerModel(input) {
|
|
166117
166334
|
if (input.kind === "mode")
|
|
166118
166335
|
return { kind: "mode", title: TITLES3.mode, entries: modeEntries(input) };
|
|
166119
|
-
if (input.kind === "model")
|
|
166120
|
-
|
|
166336
|
+
if (input.kind === "model") {
|
|
166337
|
+
const allEntries = modelEntries(input);
|
|
166338
|
+
const entries = matchingEntries(allEntries, input.query ?? "");
|
|
166339
|
+
return {
|
|
166340
|
+
kind: "model",
|
|
166341
|
+
title: TITLES3.model,
|
|
166342
|
+
entries,
|
|
166343
|
+
allEntries,
|
|
166344
|
+
query: input.query ?? "",
|
|
166345
|
+
...entries.length === 0 ? { note: { text: "no models match", tone: "muted" } } : {}
|
|
166346
|
+
};
|
|
166347
|
+
}
|
|
166121
166348
|
const nowMs = input.nowMs ?? _pickerDeps.now();
|
|
166122
166349
|
const sessions = input.sessions ?? [];
|
|
166123
166350
|
const note = resumeNote(input);
|
|
@@ -166132,7 +166359,7 @@ function pickerMode(value) {
|
|
|
166132
166359
|
return value === "full" ? "full" : "guarded";
|
|
166133
166360
|
}
|
|
166134
166361
|
function fixedRows(model) {
|
|
166135
|
-
return FRAME_ROWS + (model.note === undefined ? 0 : 1);
|
|
166362
|
+
return FRAME_ROWS + (model.kind === "model" ? 1 : 0) + (model.note === undefined ? 0 : 1);
|
|
166136
166363
|
}
|
|
166137
166364
|
function visibleEntries(model, budget) {
|
|
166138
166365
|
return Math.min(model.entries.length, PICKER_MAX_ROWS, Math.max(0, budget - fixedRows(model)));
|
|
@@ -166181,6 +166408,9 @@ function pickerLayout(model, options) {
|
|
|
166181
166408
|
const lines = [
|
|
166182
166409
|
ruleRow2(options.theme, columns),
|
|
166183
166410
|
cutSpans([styled2(displayText(model.title), { bold: true })], columns),
|
|
166411
|
+
...model.kind === "model" ? [
|
|
166412
|
+
cutSpans([styled2(model.query ? `Filter: ${displayText(model.query)}` : "type to filter", { color: "muted" })], columns)
|
|
166413
|
+
] : [],
|
|
166184
166414
|
...model.entries.slice(first, first + rows).map((entry, at) => entryRow(entry, first + at === selected, options.theme, columns)),
|
|
166185
166415
|
...model.note === undefined ? [] : [noteRow(model.note, options.theme, columns)],
|
|
166186
166416
|
ruleRow2(options.theme, columns)
|
|
@@ -166200,6 +166430,7 @@ function heldWarning(sessionId, pid) {
|
|
|
166200
166430
|
function modelOf(state, current, models) {
|
|
166201
166431
|
return pickerModel({
|
|
166202
166432
|
kind: state.kind,
|
|
166433
|
+
query: state.query,
|
|
166203
166434
|
models,
|
|
166204
166435
|
currentModel: current.model,
|
|
166205
166436
|
currentMode: current.mode,
|
|
@@ -166217,7 +166448,7 @@ function useChatPicker({ host, runControl, onError }) {
|
|
|
166217
166448
|
const open = import_react31.useCallback((kind) => {
|
|
166218
166449
|
openings.current += 1;
|
|
166219
166450
|
const opening = openings.current;
|
|
166220
|
-
setState({ kind });
|
|
166451
|
+
setState({ kind, query: "" });
|
|
166221
166452
|
if (kind !== "resume")
|
|
166222
166453
|
return;
|
|
166223
166454
|
host.listSessions().then((sessions) => {
|
|
@@ -166247,27 +166478,76 @@ function useChatPicker({ host, runControl, onError }) {
|
|
|
166247
166478
|
}, [state, host, runControl]);
|
|
166248
166479
|
const current = state === undefined ? undefined : host.current();
|
|
166249
166480
|
const model = state === undefined || current === undefined ? undefined : modelOf(state, current, host.models);
|
|
166250
|
-
|
|
166481
|
+
const setQuery = import_react31.useCallback((query) => {
|
|
166482
|
+
setState((current) => current?.kind === "model" ? { ...current, query } : current);
|
|
166483
|
+
}, []);
|
|
166484
|
+
return { model, open, cancel, choose, setQuery };
|
|
166251
166485
|
}
|
|
166252
166486
|
function ownsPickerKey(key) {
|
|
166253
166487
|
return Boolean(key.escape || key.return || key.upArrow || key.downArrow);
|
|
166254
166488
|
}
|
|
166255
|
-
function
|
|
166489
|
+
function editedQuery(input, key, query) {
|
|
166490
|
+
if (key.ctrl || key.meta)
|
|
166491
|
+
return;
|
|
166492
|
+
if (key.backspace || key.delete) {
|
|
166493
|
+
const graphemes = Array.from(QUERY_SEGMENTER.segment(query), (part) => part.segment);
|
|
166494
|
+
return graphemes.slice(0, -1).join("");
|
|
166495
|
+
}
|
|
166496
|
+
if (input !== "" && !key.return && !key.upArrow && !key.downArrow && Array.from(input).every((char) => {
|
|
166497
|
+
const code = char.codePointAt(0) ?? 0;
|
|
166498
|
+
return code >= 32 && code !== 127;
|
|
166499
|
+
}))
|
|
166500
|
+
return query + input;
|
|
166501
|
+
return;
|
|
166502
|
+
}
|
|
166503
|
+
function Picker({
|
|
166504
|
+
model,
|
|
166505
|
+
width,
|
|
166506
|
+
theme,
|
|
166507
|
+
budget,
|
|
166508
|
+
active = true,
|
|
166509
|
+
onChoose,
|
|
166510
|
+
onCancel,
|
|
166511
|
+
query = model.query ?? "",
|
|
166512
|
+
onQuery
|
|
166513
|
+
}) {
|
|
166256
166514
|
const [selection, setSelection] = import_react31.useState({ kind: model.kind, index: FIRST_ENTRY });
|
|
166257
166515
|
const latest = import_react31.useRef(selection);
|
|
166258
|
-
if (latest.current.kind !== model.kind)
|
|
166259
|
-
latest.current = { kind: model.kind, index: FIRST_ENTRY };
|
|
166260
|
-
|
|
166261
|
-
const
|
|
166516
|
+
if (latest.current.kind !== model.kind || latest.current.query !== query) {
|
|
166517
|
+
latest.current = { kind: model.kind, query, index: FIRST_ENTRY };
|
|
166518
|
+
}
|
|
166519
|
+
const queryRef = import_react31.useRef(query);
|
|
166520
|
+
queryRef.current = query;
|
|
166521
|
+
const entries = () => model.kind === "model" ? matchingEntries(model.allEntries ?? model.entries, queryRef.current) : model.entries;
|
|
166522
|
+
const last = () => Math.max(FIRST_ENTRY, entries().length - 1);
|
|
166523
|
+
const pointer = () => Math.min(Math.max(latest.current.index, FIRST_ENTRY), last());
|
|
166262
166524
|
const move = (delta) => {
|
|
166263
166525
|
const value = {
|
|
166264
166526
|
kind: model.kind,
|
|
166265
|
-
|
|
166527
|
+
query: queryRef.current,
|
|
166528
|
+
index: Math.min(Math.max(pointer() + delta, FIRST_ENTRY), last())
|
|
166266
166529
|
};
|
|
166267
166530
|
latest.current = value;
|
|
166268
166531
|
setSelection(value);
|
|
166269
166532
|
};
|
|
166270
|
-
|
|
166533
|
+
const editQuery = (input, key) => {
|
|
166534
|
+
if (model.kind !== "model" || key.escape)
|
|
166535
|
+
return false;
|
|
166536
|
+
const next = editedQuery(input, key, queryRef.current);
|
|
166537
|
+
if (next === undefined)
|
|
166538
|
+
return false;
|
|
166539
|
+
if (next === queryRef.current)
|
|
166540
|
+
return true;
|
|
166541
|
+
queryRef.current = next;
|
|
166542
|
+
onQuery?.(next);
|
|
166543
|
+
const reset = { kind: model.kind, query: next, index: FIRST_ENTRY };
|
|
166544
|
+
latest.current = reset;
|
|
166545
|
+
setSelection(reset);
|
|
166546
|
+
return true;
|
|
166547
|
+
};
|
|
166548
|
+
use_input_default((input, key) => {
|
|
166549
|
+
if (editQuery(input, key))
|
|
166550
|
+
return;
|
|
166271
166551
|
if (!ownsPickerKey(key))
|
|
166272
166552
|
return;
|
|
166273
166553
|
if (key.escape) {
|
|
@@ -166276,7 +166556,7 @@ function Picker({ model, width, theme, budget, active = true, onChoose, onCancel
|
|
|
166276
166556
|
}
|
|
166277
166557
|
if (key.shift || key.ctrl || key.meta)
|
|
166278
166558
|
return;
|
|
166279
|
-
const entry =
|
|
166559
|
+
const entry = entries()[pointer()];
|
|
166280
166560
|
if (entry === undefined)
|
|
166281
166561
|
return;
|
|
166282
166562
|
if (key.return)
|
|
@@ -166295,7 +166575,7 @@ function Picker({ model, width, theme, budget, active = true, onChoose, onCancel
|
|
|
166295
166575
|
}, index, false, undefined, this))
|
|
166296
166576
|
}, undefined, false, undefined, this);
|
|
166297
166577
|
}
|
|
166298
|
-
var import_react31, jsx_dev_runtime4, PICKER_MAX_ROWS = 8, FRAME_ROWS = 3, FIRST_ENTRY = 0, COLUMN_GAP = " ", CURRENT_MARK = "(current)", ID_CHARS = 8, UNTITLED = "untitled", LOADING = "loading\u2026", NO_SESSIONS = "no saved sessions", TITLES3, MODE_CHOICES, _pickerDeps;
|
|
166578
|
+
var import_react31, jsx_dev_runtime4, PICKER_MAX_ROWS = 8, FRAME_ROWS = 3, FIRST_ENTRY = 0, COLUMN_GAP = " ", CURRENT_MARK = "(current)", ID_CHARS = 8, UNTITLED = "untitled", LOADING = "loading\u2026", NO_SESSIONS = "no saved sessions", TITLES3, MODE_CHOICES, _pickerDeps, QUERY_SEGMENTER;
|
|
166299
166579
|
var init_Picker = __esm(async () => {
|
|
166300
166580
|
init_relative_time();
|
|
166301
166581
|
await __promiseAll([
|
|
@@ -166316,6 +166596,7 @@ var init_Picker = __esm(async () => {
|
|
|
166316
166596
|
{ mode: "full", detail: "never asks; runs outside the sandbox when it is unavailable" }
|
|
166317
166597
|
];
|
|
166318
166598
|
_pickerDeps = { now: () => Date.now() };
|
|
166599
|
+
QUERY_SEGMENTER = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
166319
166600
|
});
|
|
166320
166601
|
|
|
166321
166602
|
// src/tui/chat/bottom-region.ts
|
|
@@ -166586,8 +166867,11 @@ function modeSpan(state, glyphs) {
|
|
|
166586
166867
|
color: full ? "danger" : "muted"
|
|
166587
166868
|
};
|
|
166588
166869
|
}
|
|
166589
|
-
function hintSpan(hint) {
|
|
166590
|
-
return {
|
|
166870
|
+
function hintSpan(hint, copiedChars = 0) {
|
|
166871
|
+
return {
|
|
166872
|
+
text: hint === "copied" ? `copied ${copiedChars} chars` : HINT_TEXT[hint],
|
|
166873
|
+
color: hint === "quit" ? "warning" : "muted"
|
|
166874
|
+
};
|
|
166591
166875
|
}
|
|
166592
166876
|
function sandboxSpan(sandbox) {
|
|
166593
166877
|
if (sandbox?.kind === "available")
|
|
@@ -166597,11 +166881,12 @@ function sandboxSpan(sandbox) {
|
|
|
166597
166881
|
}
|
|
166598
166882
|
return { text: `${SEPARATOR}${SANDBOX_OFF}`, color: "muted" };
|
|
166599
166883
|
}
|
|
166600
|
-
function leftLine(
|
|
166884
|
+
function leftLine(input) {
|
|
166885
|
+
const { state, hint, glyphs, copiedChars } = input;
|
|
166601
166886
|
if (hint === "quit")
|
|
166602
166887
|
return [hintSpan(hint)];
|
|
166603
166888
|
const sandbox = sandboxSpan(state.sandbox);
|
|
166604
|
-
const spans = [modeSpan(state, glyphs), { text: SEPARATOR, color: "muted" }, hintSpan(hint)];
|
|
166889
|
+
const spans = [modeSpan(state, glyphs), { text: SEPARATOR, color: "muted" }, hintSpan(hint, copiedChars)];
|
|
166605
166890
|
return sandbox === undefined ? spans : [...spans, sandbox];
|
|
166606
166891
|
}
|
|
166607
166892
|
function contextPercent(state, status) {
|
|
@@ -166632,7 +166917,7 @@ function rightLine(state, status) {
|
|
|
166632
166917
|
}
|
|
166633
166918
|
function footerModel(input) {
|
|
166634
166919
|
return {
|
|
166635
|
-
left: leftLine(
|
|
166920
|
+
left: leftLine({ ...input, glyphs: input.glyphs ?? GLYPHS }),
|
|
166636
166921
|
right: rightLine(input.state, input.status)
|
|
166637
166922
|
};
|
|
166638
166923
|
}
|
|
@@ -166773,6 +167058,7 @@ var init_chat_status = __esm(async () => {
|
|
|
166773
167058
|
outputTokens: 0
|
|
166774
167059
|
};
|
|
166775
167060
|
HINT_TEXT = {
|
|
167061
|
+
copied: "copied",
|
|
166776
167062
|
quit: "press ctrl-c again to quit",
|
|
166777
167063
|
clear: "esc again to clear",
|
|
166778
167064
|
busy: "esc to interrupt",
|
|
@@ -174805,7 +175091,16 @@ function renderMarkdown(text, options) {
|
|
|
174805
175091
|
} catch {
|
|
174806
175092
|
return sourceLines(text);
|
|
174807
175093
|
}
|
|
174808
|
-
|
|
175094
|
+
const lines = [];
|
|
175095
|
+
for (const token of tokens) {
|
|
175096
|
+
const block = blockLines(token, context);
|
|
175097
|
+
if (block.length === 0)
|
|
175098
|
+
continue;
|
|
175099
|
+
if (lines.length > 0)
|
|
175100
|
+
lines.push([]);
|
|
175101
|
+
lines.push(...block);
|
|
175102
|
+
}
|
|
175103
|
+
return lines;
|
|
174809
175104
|
}
|
|
174810
175105
|
var _markdownDeps, LIST_INDENT = " ", UNORDERED_MARKER = "- ", NUMBER_SEPARATOR = ". ", NEWLINE_RUN, SOURCE_LINE_BREAK2, TRAILING_NEWLINE2 = `
|
|
174811
175106
|
`;
|
|
@@ -175345,6 +175640,10 @@ function reduceViewport(state, action, total, height) {
|
|
|
175345
175640
|
return afterMove(state, LINE_STEP, total, height);
|
|
175346
175641
|
case "lineDown":
|
|
175347
175642
|
return afterMove(state, -LINE_STEP, total, height);
|
|
175643
|
+
case "wheelUp":
|
|
175644
|
+
return afterMove(state, WHEEL_LINES, total, height);
|
|
175645
|
+
case "wheelDown":
|
|
175646
|
+
return afterMove(state, -WHEEL_LINES, total, height);
|
|
175348
175647
|
case "home":
|
|
175349
175648
|
return settle2(maxOffset(total, height), total, height, state.unseen);
|
|
175350
175649
|
case "end":
|
|
@@ -175355,11 +175654,141 @@ function visibleRange(total, height, offset) {
|
|
|
175355
175654
|
const end = Math.min(total, Math.max(total - offset, 0));
|
|
175356
175655
|
return { start: Math.max(end - height, 0), end };
|
|
175357
175656
|
}
|
|
175358
|
-
var INITIAL_VIEWPORT, LINE_STEP = 1, PAGE_OVERLAP = 1;
|
|
175657
|
+
var INITIAL_VIEWPORT, LINE_STEP = 1, WHEEL_LINES = 3, PAGE_OVERLAP = 1;
|
|
175359
175658
|
var init_viewport = __esm(() => {
|
|
175360
175659
|
INITIAL_VIEWPORT = { offset: 0, follow: true, unseen: 0 };
|
|
175361
175660
|
});
|
|
175362
175661
|
|
|
175662
|
+
// src/tui/chat/selection.ts
|
|
175663
|
+
function transcriptPointAt(geometry, x, y) {
|
|
175664
|
+
const { top, height, total, offset, unseen } = geometry;
|
|
175665
|
+
const row = y - 1 - top;
|
|
175666
|
+
if (x < 1 || row < 0 || row >= height)
|
|
175667
|
+
return;
|
|
175668
|
+
const { start, end } = visibleRange(total, height, offset);
|
|
175669
|
+
const marker = unseen > 0 ? 1 : 0;
|
|
175670
|
+
const count = Math.max(0, end - start - marker);
|
|
175671
|
+
const padding = Math.max(0, height - count - marker);
|
|
175672
|
+
const index = row - padding;
|
|
175673
|
+
if (index < 0 || index >= count)
|
|
175674
|
+
return;
|
|
175675
|
+
return { line: start + index, column: x - 1 };
|
|
175676
|
+
}
|
|
175677
|
+
function ordered(selection) {
|
|
175678
|
+
const { anchor, focus } = selection;
|
|
175679
|
+
return anchor.line < focus.line || anchor.line === focus.line && anchor.column <= focus.column ? [anchor, focus] : [focus, anchor];
|
|
175680
|
+
}
|
|
175681
|
+
function textRange(text, start, end) {
|
|
175682
|
+
let column = 0;
|
|
175683
|
+
let from = text.length;
|
|
175684
|
+
let to = text.length;
|
|
175685
|
+
let found = false;
|
|
175686
|
+
for (const { segment, index } of SEGMENTER.segment(text)) {
|
|
175687
|
+
const width = displayWidth(segment);
|
|
175688
|
+
if (column + width > start && column <= end) {
|
|
175689
|
+
if (!found)
|
|
175690
|
+
from = index;
|
|
175691
|
+
to = index + segment.length;
|
|
175692
|
+
found = true;
|
|
175693
|
+
}
|
|
175694
|
+
column += width;
|
|
175695
|
+
}
|
|
175696
|
+
return [from, to];
|
|
175697
|
+
}
|
|
175698
|
+
function lineRange(line, index, selection) {
|
|
175699
|
+
const [start, end] = ordered(selection);
|
|
175700
|
+
return textRange(plainText(line), index === start.line ? start.column : 0, index === end.line ? end.column : Number.POSITIVE_INFINITY);
|
|
175701
|
+
}
|
|
175702
|
+
function selectedText(lines, selection) {
|
|
175703
|
+
const [start, end] = ordered(selection);
|
|
175704
|
+
const result = [];
|
|
175705
|
+
for (let index = Math.max(0, start.line);index <= Math.min(end.line, lines.length - 1); index += 1) {
|
|
175706
|
+
const line = lines[index];
|
|
175707
|
+
const [from, to] = lineRange(line, index, selection);
|
|
175708
|
+
result.push(plainText(line).slice(from, to).replace(/ +$/u, ""));
|
|
175709
|
+
}
|
|
175710
|
+
return result.join(`
|
|
175711
|
+
`);
|
|
175712
|
+
}
|
|
175713
|
+
function highlightLine(line, index, selection) {
|
|
175714
|
+
const [start, end] = ordered(selection);
|
|
175715
|
+
if (index < start.line || index > end.line)
|
|
175716
|
+
return line;
|
|
175717
|
+
const [from, to] = lineRange(line, index, selection);
|
|
175718
|
+
if (from === to)
|
|
175719
|
+
return line;
|
|
175720
|
+
const result = [];
|
|
175721
|
+
let offset = 0;
|
|
175722
|
+
for (const span of line) {
|
|
175723
|
+
const left = Math.max(0, Math.min(span.text.length, from - offset));
|
|
175724
|
+
const right = Math.max(left, Math.min(span.text.length, to - offset));
|
|
175725
|
+
if (left > 0)
|
|
175726
|
+
result.push({ ...span, text: span.text.slice(0, left) });
|
|
175727
|
+
if (right > left)
|
|
175728
|
+
result.push({ ...span, text: span.text.slice(left, right), inverse: true });
|
|
175729
|
+
if (right < span.text.length)
|
|
175730
|
+
result.push({ ...span, text: span.text.slice(right) });
|
|
175731
|
+
offset += span.text.length;
|
|
175732
|
+
}
|
|
175733
|
+
return result;
|
|
175734
|
+
}
|
|
175735
|
+
var SEGMENTER;
|
|
175736
|
+
var init_selection = __esm(async () => {
|
|
175737
|
+
init_viewport();
|
|
175738
|
+
await init_styled_line();
|
|
175739
|
+
SEGMENTER = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
175740
|
+
});
|
|
175741
|
+
|
|
175742
|
+
// src/tui/chat/use-mouse-selection.ts
|
|
175743
|
+
function finishSelection(gesture, input) {
|
|
175744
|
+
gesture.dragging = false;
|
|
175745
|
+
const range = gesture.selection;
|
|
175746
|
+
if (!range || range.anchor.line === range.focus.line && range.anchor.column === range.focus.column)
|
|
175747
|
+
return;
|
|
175748
|
+
const text = selectedText(input.lines, range);
|
|
175749
|
+
if (text.length > 0)
|
|
175750
|
+
input.onCopy?.(text);
|
|
175751
|
+
}
|
|
175752
|
+
function useMouseSelection(input) {
|
|
175753
|
+
const latest = import_react33.useRef(input);
|
|
175754
|
+
latest.current = input;
|
|
175755
|
+
const gesture = import_react33.useRef({ dragging: false });
|
|
175756
|
+
const [selection, setSelection] = import_react33.useState();
|
|
175757
|
+
const [total, setTotal] = import_react33.useState(input.lines.length);
|
|
175758
|
+
if (total !== input.lines.length) {
|
|
175759
|
+
setTotal(input.lines.length);
|
|
175760
|
+
gesture.current = { dragging: false };
|
|
175761
|
+
setSelection(undefined);
|
|
175762
|
+
}
|
|
175763
|
+
import_react33.useEffect(() => {
|
|
175764
|
+
if (!input.active || !input.mouse)
|
|
175765
|
+
return;
|
|
175766
|
+
return input.mouse.subscribe((event) => {
|
|
175767
|
+
if (event.button !== "left")
|
|
175768
|
+
return;
|
|
175769
|
+
const { geometry } = latest.current;
|
|
175770
|
+
const point = transcriptPointAt(geometry, event.x, event.y);
|
|
175771
|
+
const current = gesture.current;
|
|
175772
|
+
if (event.kind === "press") {
|
|
175773
|
+
current.selection = point ? { anchor: point, focus: point } : undefined;
|
|
175774
|
+
current.dragging = point !== undefined;
|
|
175775
|
+
setSelection(undefined);
|
|
175776
|
+
} else if (event.kind === "drag" && current.dragging && current.selection && point) {
|
|
175777
|
+
current.selection = { ...current.selection, focus: point };
|
|
175778
|
+
setSelection(current.selection);
|
|
175779
|
+
} else if (event.kind === "release" && current.dragging) {
|
|
175780
|
+
finishSelection(current, latest.current);
|
|
175781
|
+
}
|
|
175782
|
+
});
|
|
175783
|
+
}, [input.active, input.mouse]);
|
|
175784
|
+
return selection;
|
|
175785
|
+
}
|
|
175786
|
+
var import_react33;
|
|
175787
|
+
var init_use_mouse_selection = __esm(async () => {
|
|
175788
|
+
await init_selection();
|
|
175789
|
+
import_react33 = __toESM(require_react(), 1);
|
|
175790
|
+
});
|
|
175791
|
+
|
|
175363
175792
|
// src/tui/chat/TranscriptViewport.tsx
|
|
175364
175793
|
function viewRows(height) {
|
|
175365
175794
|
return Number.isFinite(height) ? Math.max(MIN_VIEWPORT_ROWS, Math.trunc(height)) : MIN_VIEWPORT_ROWS;
|
|
@@ -175432,11 +175861,14 @@ function TranscriptViewport({
|
|
|
175432
175861
|
height,
|
|
175433
175862
|
theme,
|
|
175434
175863
|
active = true,
|
|
175864
|
+
mouse,
|
|
175865
|
+
top = 0,
|
|
175866
|
+
onCopy,
|
|
175435
175867
|
followToken = 0
|
|
175436
175868
|
}) {
|
|
175437
175869
|
const rows = viewRows(height);
|
|
175438
175870
|
const total = lines.length;
|
|
175439
|
-
const [memory, setMemory] =
|
|
175871
|
+
const [memory, setMemory] = import_react34.useState({
|
|
175440
175872
|
state: INITIAL_VIEWPORT,
|
|
175441
175873
|
total,
|
|
175442
175874
|
height: rows,
|
|
@@ -175445,6 +175877,19 @@ function TranscriptViewport({
|
|
|
175445
175877
|
if (memory.total !== total || memory.height !== rows || memory.token !== followToken) {
|
|
175446
175878
|
setMemory(nextMemory(memory, total, rows, followToken));
|
|
175447
175879
|
}
|
|
175880
|
+
import_react34.useEffect(() => {
|
|
175881
|
+
if (!active || !mouse)
|
|
175882
|
+
return;
|
|
175883
|
+
return mouse.subscribe((event) => {
|
|
175884
|
+
if (event.kind !== "wheelUp" && event.kind !== "wheelDown")
|
|
175885
|
+
return;
|
|
175886
|
+
const action = { type: event.kind };
|
|
175887
|
+
setMemory((previous) => ({
|
|
175888
|
+
...previous,
|
|
175889
|
+
state: reduceViewport(previous.state, action, previous.total, previous.height)
|
|
175890
|
+
}));
|
|
175891
|
+
});
|
|
175892
|
+
}, [active, mouse]);
|
|
175448
175893
|
use_input_default((_input, key) => {
|
|
175449
175894
|
const action = viewportAction(key);
|
|
175450
175895
|
if (action === undefined)
|
|
@@ -175454,22 +175899,32 @@ function TranscriptViewport({
|
|
|
175454
175899
|
state: reduceViewport(previous.state, action, previous.total, previous.height)
|
|
175455
175900
|
}));
|
|
175456
175901
|
}, { isActive: active });
|
|
175902
|
+
const selection = useMouseSelection({
|
|
175903
|
+
mouse,
|
|
175904
|
+
active,
|
|
175905
|
+
lines,
|
|
175906
|
+
onCopy,
|
|
175907
|
+
geometry: { top, height: rows, total, offset: memory.state.offset, unseen: memory.state.unseen }
|
|
175908
|
+
});
|
|
175457
175909
|
const { start, end } = visibleRange(total, rows, memory.state.offset);
|
|
175910
|
+
const visible = lines.slice(start, end).map((line, index) => selection ? highlightLine(line, start + index, selection) : line);
|
|
175458
175911
|
return /* @__PURE__ */ jsx_dev_runtime6.jsxDEV(ViewportRows, {
|
|
175459
|
-
visible
|
|
175912
|
+
visible,
|
|
175460
175913
|
rows,
|
|
175461
175914
|
unseen: memory.state.unseen,
|
|
175462
175915
|
theme
|
|
175463
175916
|
}, undefined, false, undefined, this);
|
|
175464
175917
|
}
|
|
175465
|
-
var
|
|
175918
|
+
var import_react34, jsx_dev_runtime6, MIN_VIEWPORT_ROWS = 1, ROW_HEIGHT = 1, BLANK_ROW = " ", UNSEEN_MARKER = "\u2193", UNSEEN_LABEL = "new lines (End)";
|
|
175466
175919
|
var init_TranscriptViewport = __esm(async () => {
|
|
175467
175920
|
init_viewport();
|
|
175468
175921
|
await __promiseAll([
|
|
175469
175922
|
init_build3(),
|
|
175470
|
-
|
|
175923
|
+
init_selection(),
|
|
175924
|
+
init_styled_line(),
|
|
175925
|
+
init_use_mouse_selection()
|
|
175471
175926
|
]);
|
|
175472
|
-
|
|
175927
|
+
import_react34 = __toESM(require_react(), 1);
|
|
175473
175928
|
jsx_dev_runtime6 = __toESM(require_jsx_dev_runtime(), 1);
|
|
175474
175929
|
});
|
|
175475
175930
|
|
|
@@ -175603,6 +176058,69 @@ function reduceTranscript(entries, event) {
|
|
|
175603
176058
|
}
|
|
175604
176059
|
var AGENT_RUN_TOOL2 = "nax-agents__run", COMPACTION_NOTICE = "conversation compacted";
|
|
175605
176060
|
|
|
176061
|
+
// src/tui/chat/clipboard.ts
|
|
176062
|
+
function osc52(text) {
|
|
176063
|
+
return `\x1B]52;c;${Buffer.from(text, "utf8").toString("base64")}\x07`;
|
|
176064
|
+
}
|
|
176065
|
+
async function copyToClipboard(text) {
|
|
176066
|
+
_clipboardDeps.write(osc52(text));
|
|
176067
|
+
if (_clipboardDeps.platform !== "darwin")
|
|
176068
|
+
return;
|
|
176069
|
+
try {
|
|
176070
|
+
await _clipboardDeps.spawnCopy(text);
|
|
176071
|
+
} catch {}
|
|
176072
|
+
}
|
|
176073
|
+
var _clipboardDeps;
|
|
176074
|
+
var init_clipboard = __esm(() => {
|
|
176075
|
+
_clipboardDeps = {
|
|
176076
|
+
write: (text) => {
|
|
176077
|
+
process.stdout.write(text);
|
|
176078
|
+
},
|
|
176079
|
+
platform: process.platform,
|
|
176080
|
+
spawn: Bun.spawn,
|
|
176081
|
+
spawnCopy: async (text) => {
|
|
176082
|
+
const child = _clipboardDeps.spawn(["pbcopy"], {
|
|
176083
|
+
stdin: new TextEncoder().encode(text),
|
|
176084
|
+
stdout: "ignore",
|
|
176085
|
+
stderr: "ignore"
|
|
176086
|
+
});
|
|
176087
|
+
return child.exited;
|
|
176088
|
+
}
|
|
176089
|
+
};
|
|
176090
|
+
});
|
|
176091
|
+
|
|
176092
|
+
// src/tui/chat/use-clipboard-feedback.ts
|
|
176093
|
+
function footerHint(input) {
|
|
176094
|
+
if (input.quitArmed)
|
|
176095
|
+
return "quit";
|
|
176096
|
+
if (input.clearArmed)
|
|
176097
|
+
return "clear";
|
|
176098
|
+
if (input.busy)
|
|
176099
|
+
return "busy";
|
|
176100
|
+
if (input.expanded)
|
|
176101
|
+
return "expanded";
|
|
176102
|
+
return "idle";
|
|
176103
|
+
}
|
|
176104
|
+
function useClipboardFeedback(mouse) {
|
|
176105
|
+
const [copiedChars, setCopiedChars] = import_react35.useState();
|
|
176106
|
+
use_input_default(() => setCopiedChars(undefined));
|
|
176107
|
+
import_react35.useEffect(() => mouse?.subscribe((event) => {
|
|
176108
|
+
if (event.kind === "press")
|
|
176109
|
+
setCopiedChars(undefined);
|
|
176110
|
+
}), [mouse]);
|
|
176111
|
+
const onCopy = import_react35.useCallback((text) => {
|
|
176112
|
+
copyToClipboard(text);
|
|
176113
|
+
setCopiedChars(text.length);
|
|
176114
|
+
}, []);
|
|
176115
|
+
return { copiedChars, onCopy };
|
|
176116
|
+
}
|
|
176117
|
+
var import_react35;
|
|
176118
|
+
var init_use_clipboard_feedback = __esm(async () => {
|
|
176119
|
+
init_clipboard();
|
|
176120
|
+
await init_build3();
|
|
176121
|
+
import_react35 = __toESM(require_react(), 1);
|
|
176122
|
+
});
|
|
176123
|
+
|
|
175606
176124
|
// src/tui/chat/use-slash-menu-keys.ts
|
|
175607
176125
|
function useSlashMenuKeys({
|
|
175608
176126
|
items,
|
|
@@ -175610,7 +176128,7 @@ function useSlashMenuKeys({
|
|
|
175610
176128
|
initialDismissal,
|
|
175611
176129
|
blocked
|
|
175612
176130
|
}) {
|
|
175613
|
-
const live =
|
|
176131
|
+
const live = import_react36.useRef({ query: initialQuery, dismissed: initialDismissal });
|
|
175614
176132
|
return {
|
|
175615
176133
|
ownsKeys: () => slashMenuQueryState({ items, query: live.current.query, dismissed: live.current.dismissed, blocked }).open,
|
|
175616
176134
|
sawPrompt: (text) => {
|
|
@@ -175621,10 +176139,10 @@ function useSlashMenuKeys({
|
|
|
175621
176139
|
}
|
|
175622
176140
|
};
|
|
175623
176141
|
}
|
|
175624
|
-
var
|
|
176142
|
+
var import_react36;
|
|
175625
176143
|
var init_use_slash_menu_keys = __esm(async () => {
|
|
175626
176144
|
await init_slash_menu();
|
|
175627
|
-
|
|
176145
|
+
import_react36 = __toESM(require_react(), 1);
|
|
175628
176146
|
});
|
|
175629
176147
|
|
|
175630
176148
|
// src/tui/chat/useChatKeys.ts
|
|
@@ -175636,12 +176154,12 @@ function clearTimer(handle) {
|
|
|
175636
176154
|
}
|
|
175637
176155
|
function useChatKeys({ host, running, refresh, onError }) {
|
|
175638
176156
|
const { exit } = use_app_default();
|
|
175639
|
-
const queued =
|
|
175640
|
-
const interruptedAt =
|
|
175641
|
-
const quitExpiry =
|
|
175642
|
-
const switching =
|
|
175643
|
-
const closing =
|
|
175644
|
-
const [locked, setLocked] =
|
|
176157
|
+
const queued = import_react37.useRef(undefined);
|
|
176158
|
+
const interruptedAt = import_react37.useRef(undefined);
|
|
176159
|
+
const quitExpiry = import_react37.useRef(undefined);
|
|
176160
|
+
const switching = import_react37.useRef(undefined);
|
|
176161
|
+
const closing = import_react37.useRef(false);
|
|
176162
|
+
const [locked, setLocked] = import_react37.useState(false);
|
|
175645
176163
|
function armQuit() {
|
|
175646
176164
|
clearTimer(quitExpiry);
|
|
175647
176165
|
quitExpiry.current = setTimeout(() => {
|
|
@@ -175649,7 +176167,7 @@ function useChatKeys({ host, running, refresh, onError }) {
|
|
|
175649
176167
|
refresh();
|
|
175650
176168
|
}, DOUBLE_INTERRUPT_MS);
|
|
175651
176169
|
}
|
|
175652
|
-
|
|
176170
|
+
import_react37.useEffect(() => () => clearTimer(quitExpiry), []);
|
|
175653
176171
|
function quitArmed() {
|
|
175654
176172
|
const armedAt = interruptedAt.current;
|
|
175655
176173
|
return armedAt !== undefined && _chatKeyDeps.now() - armedAt < DOUBLE_INTERRUPT_MS;
|
|
@@ -175729,11 +176247,11 @@ function useChatKeys({ host, running, refresh, onError }) {
|
|
|
175729
176247
|
}
|
|
175730
176248
|
};
|
|
175731
176249
|
}
|
|
175732
|
-
var
|
|
176250
|
+
var import_react37, DOUBLE_INTERRUPT_MS = 2000, _chatKeyDeps;
|
|
175733
176251
|
var init_useChatKeys = __esm(async () => {
|
|
175734
176252
|
init_chat();
|
|
175735
176253
|
await init_build3();
|
|
175736
|
-
|
|
176254
|
+
import_react37 = __toESM(require_react(), 1);
|
|
175737
176255
|
_chatKeyDeps = { now: () => Date.now() };
|
|
175738
176256
|
});
|
|
175739
176257
|
|
|
@@ -175765,17 +176283,6 @@ function welcomeEntry(host) {
|
|
|
175765
176283
|
mcpConnected: servers.filter((server) => lastServerEvent(events, server.id)?.kind === "connected").length
|
|
175766
176284
|
};
|
|
175767
176285
|
}
|
|
175768
|
-
function footerHint(input) {
|
|
175769
|
-
if (input.quitArmed)
|
|
175770
|
-
return "quit";
|
|
175771
|
-
if (input.clearArmed)
|
|
175772
|
-
return "clear";
|
|
175773
|
-
if (input.busy)
|
|
175774
|
-
return "busy";
|
|
175775
|
-
if (input.expanded)
|
|
175776
|
-
return "expanded";
|
|
175777
|
-
return "idle";
|
|
175778
|
-
}
|
|
175779
176286
|
function stopTurn(status) {
|
|
175780
176287
|
return status.running ? { ...status, running: false } : status;
|
|
175781
176288
|
}
|
|
@@ -175799,37 +176306,39 @@ function slashSink(title, append) {
|
|
|
175799
176306
|
}
|
|
175800
176307
|
function ChatApp({
|
|
175801
176308
|
host,
|
|
176309
|
+
mouse,
|
|
175802
176310
|
theme = DEFAULT_THEME,
|
|
175803
176311
|
version = NAX_VERSION,
|
|
175804
176312
|
cwd = host.repoRoot,
|
|
175805
176313
|
home = ""
|
|
175806
176314
|
}) {
|
|
175807
176315
|
const { stdout } = use_stdout_default();
|
|
175808
|
-
const
|
|
175809
|
-
const [
|
|
175810
|
-
const [
|
|
175811
|
-
const [
|
|
175812
|
-
const [
|
|
175813
|
-
const [
|
|
175814
|
-
const [
|
|
175815
|
-
const [
|
|
175816
|
-
const [
|
|
175817
|
-
const [
|
|
175818
|
-
const [
|
|
175819
|
-
const [
|
|
175820
|
-
const
|
|
175821
|
-
const
|
|
175822
|
-
const
|
|
175823
|
-
const
|
|
175824
|
-
const
|
|
176316
|
+
const { copiedChars, onCopy } = useClipboardFeedback(mouse);
|
|
176317
|
+
const [size, setSize] = import_react38.useState(() => terminalSize2(stdout));
|
|
176318
|
+
const [entries, setEntries] = import_react38.useState(() => [welcomeEntry(host)]);
|
|
176319
|
+
const [status, setStatus] = import_react38.useState(IDLE_STATUS);
|
|
176320
|
+
const [draft, setDraft] = import_react38.useState(EMPTY_DRAFT);
|
|
176321
|
+
const [busy, setBusy] = import_react38.useState(false);
|
|
176322
|
+
const [clearArmed, setClearArmed] = import_react38.useState(false);
|
|
176323
|
+
const [answerDraft, setAnswerDraft] = import_react38.useState(NO_ANSWER2);
|
|
176324
|
+
const [hint, setHint] = import_react38.useState(undefined);
|
|
176325
|
+
const [nowMs, setNowMs] = import_react38.useState(() => Date.now());
|
|
176326
|
+
const [expanded, setExpanded] = import_react38.useState(false);
|
|
176327
|
+
const [dismissedQuery, setDismissedQuery] = import_react38.useState(undefined);
|
|
176328
|
+
const [followToken, setFollowToken] = import_react38.useState(0);
|
|
176329
|
+
const inputHandle = import_react38.useRef(undefined);
|
|
176330
|
+
const sending = import_react38.useRef(false);
|
|
176331
|
+
const [, refresh] = import_react38.useState(0);
|
|
176332
|
+
const update = import_react38.useCallback(() => refresh((revision) => revision + 1), []);
|
|
176333
|
+
const append = import_react38.useCallback((entry) => {
|
|
175825
176334
|
setEntries((rows) => [...rows, entry]);
|
|
175826
176335
|
}, []);
|
|
175827
|
-
const showError =
|
|
176336
|
+
const showError = import_react38.useCallback((error) => append({ kind: "error", text: errorMessage(error) }), [append]);
|
|
175828
176337
|
const keys = useChatKeys({ host, running: sending, refresh: update, onError: showError });
|
|
175829
176338
|
const picker = useChatPicker({ host, runControl: keys.runControl, onError: showError });
|
|
175830
176339
|
const ask = host.asks.pending()[0];
|
|
175831
176340
|
const turnRunning = busy || status.running;
|
|
175832
|
-
const menuItems =
|
|
176341
|
+
const menuItems = import_react38.useMemo(() => slashMenuItems(host), [host]);
|
|
175833
176342
|
const slashKeys = useSlashMenuKeys({
|
|
175834
176343
|
items: menuItems,
|
|
175835
176344
|
initialQuery: draft.editor.text,
|
|
@@ -175843,7 +176352,8 @@ function ChatApp({
|
|
|
175843
176352
|
blocked: bottomBlocked(ask, picker.model)
|
|
175844
176353
|
});
|
|
175845
176354
|
const working = workingLine(status, nowMs, theme.glyphs);
|
|
175846
|
-
const
|
|
176355
|
+
const usableRows = size.rows - FRAME_SLACK_ROWS;
|
|
176356
|
+
const bottomBudget = Math.max(1, usableRows - HEADER_ROWS - (working ? WORKING_ROWS : 0) - FOOTER_ROWS - MIN_VIEWPORT_ROWS2);
|
|
175847
176357
|
const menuRows = menuRowsFor({ rows: menu.rows, budget: bottomBudget });
|
|
175848
176358
|
function menuShown() {
|
|
175849
176359
|
return menu.open && menuRows > 0;
|
|
@@ -175866,15 +176376,15 @@ function ChatApp({
|
|
|
175866
176376
|
return;
|
|
175867
176377
|
host.cancel();
|
|
175868
176378
|
});
|
|
175869
|
-
|
|
176379
|
+
import_react38.useEffect(() => {
|
|
175870
176380
|
const onResize = () => setSize(terminalSize2(stdout));
|
|
175871
176381
|
stdout.on("resize", onResize);
|
|
175872
176382
|
return () => {
|
|
175873
176383
|
stdout.off("resize", onResize);
|
|
175874
176384
|
};
|
|
175875
176385
|
}, [stdout]);
|
|
175876
|
-
|
|
175877
|
-
|
|
176386
|
+
import_react38.useEffect(() => host.asks.onChange(update), [host, update]);
|
|
176387
|
+
import_react38.useEffect(() => {
|
|
175878
176388
|
const resourceNotice = host.resourceNotice?.();
|
|
175879
176389
|
if (resourceNotice)
|
|
175880
176390
|
append({ kind: "notice", text: resourceNotice });
|
|
@@ -175882,15 +176392,15 @@ function ChatApp({
|
|
|
175882
176392
|
const state = host.current();
|
|
175883
176393
|
const notice = host.notice();
|
|
175884
176394
|
const warn = state.mode === "full" && state.sandbox?.kind === "unavailable";
|
|
175885
|
-
|
|
176395
|
+
import_react38.useEffect(() => {
|
|
175886
176396
|
if (notice)
|
|
175887
176397
|
append({ kind: "notice", text: notice });
|
|
175888
176398
|
}, [notice, append]);
|
|
175889
|
-
|
|
176399
|
+
import_react38.useEffect(() => {
|
|
175890
176400
|
if (warn)
|
|
175891
176401
|
append({ kind: "warning", text: SANDBOX_WARNING });
|
|
175892
176402
|
}, [warn, append]);
|
|
175893
|
-
|
|
176403
|
+
import_react38.useEffect(() => {
|
|
175894
176404
|
if (!status.running)
|
|
175895
176405
|
return;
|
|
175896
176406
|
let handle;
|
|
@@ -175907,7 +176417,7 @@ function ChatApp({
|
|
|
175907
176417
|
clearTimeout(handle);
|
|
175908
176418
|
};
|
|
175909
176419
|
}, [status.running]);
|
|
175910
|
-
const handleEvent =
|
|
176420
|
+
const handleEvent = import_react38.useCallback((event) => {
|
|
175911
176421
|
setEntries((rows) => reduceTranscript(rows, event));
|
|
175912
176422
|
setStatus((current) => reduceTurnStatus(current, event));
|
|
175913
176423
|
if (event.type === "turn_start")
|
|
@@ -176003,7 +176513,8 @@ function ChatApp({
|
|
|
176003
176513
|
const footer = footerModel({
|
|
176004
176514
|
state,
|
|
176005
176515
|
status,
|
|
176006
|
-
hint: footerHint({ quitArmed: keys.quitArmed(), clearArmed, busy: turnRunning, expanded }),
|
|
176516
|
+
hint: copiedChars === undefined ? footerHint({ quitArmed: keys.quitArmed(), clearArmed, busy: turnRunning, expanded }) : "copied",
|
|
176517
|
+
copiedChars,
|
|
176007
176518
|
glyphs: theme.glyphs
|
|
176008
176519
|
});
|
|
176009
176520
|
const inputBudget = Math.max(1, bottomBudget - INPUT_RULE_ROWS - menuRows);
|
|
@@ -176026,7 +176537,7 @@ function ChatApp({
|
|
|
176026
176537
|
input: inputBottomRows + menuRows,
|
|
176027
176538
|
budget: bottomBudget
|
|
176028
176539
|
});
|
|
176029
|
-
const viewportHeight = Math.max(MIN_VIEWPORT_ROWS2,
|
|
176540
|
+
const viewportHeight = Math.max(MIN_VIEWPORT_ROWS2, usableRows - HEADER_ROWS - (working ? WORKING_ROWS : 0) - bottomRows - FOOTER_ROWS);
|
|
176030
176541
|
return /* @__PURE__ */ jsx_dev_runtime7.jsxDEV(Box_default, {
|
|
176031
176542
|
flexDirection: "column",
|
|
176032
176543
|
width: columns,
|
|
@@ -176041,6 +176552,9 @@ function ChatApp({
|
|
|
176041
176552
|
}, index, false, undefined, this))
|
|
176042
176553
|
}, undefined, false, undefined, this),
|
|
176043
176554
|
/* @__PURE__ */ jsx_dev_runtime7.jsxDEV(TranscriptViewport, {
|
|
176555
|
+
mouse,
|
|
176556
|
+
top: HEADER_ROWS,
|
|
176557
|
+
onCopy,
|
|
176044
176558
|
lines,
|
|
176045
176559
|
height: viewportHeight,
|
|
176046
176560
|
theme,
|
|
@@ -176080,7 +176594,9 @@ function ChatApp({
|
|
|
176080
176594
|
budget: bottomBudget,
|
|
176081
176595
|
active: !keys.locked,
|
|
176082
176596
|
onChoose: picker.choose,
|
|
176083
|
-
onCancel: picker.cancel
|
|
176597
|
+
onCancel: picker.cancel,
|
|
176598
|
+
onQuery: picker.setQuery,
|
|
176599
|
+
query: picker.model.query
|
|
176084
176600
|
}, undefined, false, undefined, this)
|
|
176085
176601
|
}, undefined, false, undefined, this) : /* @__PURE__ */ jsx_dev_runtime7.jsxDEV(Box_default, {
|
|
176086
176602
|
height: bottomRows,
|
|
@@ -176140,7 +176656,7 @@ function ChatApp({
|
|
|
176140
176656
|
]
|
|
176141
176657
|
}, undefined, true, undefined, this);
|
|
176142
176658
|
}
|
|
176143
|
-
var
|
|
176659
|
+
var import_react38, jsx_dev_runtime7, FRAME_SLACK_ROWS = 1, HEADER_ROWS = 3, FOOTER_ROWS = 1, WORKING_ROWS = 1, MIN_VIEWPORT_ROWS2 = 1, DEFAULT_COLUMNS = 80, DEFAULT_ROWS = 24, SANDBOX_WARNING = "sandbox unavailable: commands run outside the sandbox", TURN_BUSY_NOTICE = "wait for the turn to finish (Ctrl-C to interrupt)", QUIT = "quit", CLEAR = "clear", TELL_NAX_HINT = "tell nax what to do instead", CTRL_O = "o", DEFAULT_THEME, LISTING_TITLES, NO_ANSWER2;
|
|
176144
176660
|
var init_ChatApp = __esm(async () => {
|
|
176145
176661
|
init_internal();
|
|
176146
176662
|
init_prompts();
|
|
@@ -176161,10 +176677,11 @@ var init_ChatApp = __esm(async () => {
|
|
|
176161
176677
|
init_slash_menu(),
|
|
176162
176678
|
init_styled_line(),
|
|
176163
176679
|
init_TranscriptViewport(),
|
|
176680
|
+
init_use_clipboard_feedback(),
|
|
176164
176681
|
init_use_slash_menu_keys(),
|
|
176165
176682
|
init_useChatKeys()
|
|
176166
176683
|
]);
|
|
176167
|
-
|
|
176684
|
+
import_react38 = __toESM(require_react(), 1);
|
|
176168
176685
|
jsx_dev_runtime7 = __toESM(require_jsx_dev_runtime(), 1);
|
|
176169
176686
|
DEFAULT_THEME = resolveChatTheme({ env: {}, colorLevel: 0 });
|
|
176170
176687
|
LISTING_TITLES = new Map([
|
|
@@ -176179,6 +176696,114 @@ var init_ChatApp = __esm(async () => {
|
|
|
176179
176696
|
NO_ANSWER2 = { requestId: "", draft: EMPTY_DRAFT };
|
|
176180
176697
|
});
|
|
176181
176698
|
|
|
176699
|
+
// src/tui/chat/mouse-input.ts
|
|
176700
|
+
import { PassThrough as PassThrough3 } from "stream";
|
|
176701
|
+
import { StringDecoder } from "string_decoder";
|
|
176702
|
+
function parseSgrMouse(sequence) {
|
|
176703
|
+
const match = REPORT.exec(sequence);
|
|
176704
|
+
if (!match || match[0] !== sequence)
|
|
176705
|
+
return;
|
|
176706
|
+
const bits = Number(match[1]);
|
|
176707
|
+
const buttonIndex = bits & BUTTON_MASK;
|
|
176708
|
+
const x = Number(match[2]);
|
|
176709
|
+
const y = Number(match[3]);
|
|
176710
|
+
if (bits & WHEEL_BIT) {
|
|
176711
|
+
if (buttonIndex > 1)
|
|
176712
|
+
return;
|
|
176713
|
+
return { kind: buttonIndex === 0 ? "wheelUp" : "wheelDown", button: "none", x, y };
|
|
176714
|
+
}
|
|
176715
|
+
const button = BUTTONS[buttonIndex] ?? "none";
|
|
176716
|
+
const kind = match[4] === "m" ? "release" : bits & MOTION_BIT ? button === "none" ? "move" : "drag" : "press";
|
|
176717
|
+
return { kind, button, x, y };
|
|
176718
|
+
}
|
|
176719
|
+
function filterReports(text, emit) {
|
|
176720
|
+
let keys = "";
|
|
176721
|
+
let cursor = 0;
|
|
176722
|
+
let start = text.indexOf(REPORT_PREFIX);
|
|
176723
|
+
while (start !== -1) {
|
|
176724
|
+
keys += text.slice(cursor, start);
|
|
176725
|
+
const tail = text.slice(start);
|
|
176726
|
+
const match = REPORT.exec(tail);
|
|
176727
|
+
if (match) {
|
|
176728
|
+
const event = parseSgrMouse(match[0]);
|
|
176729
|
+
if (event)
|
|
176730
|
+
emit(event);
|
|
176731
|
+
cursor = start + match[0].length;
|
|
176732
|
+
} else {
|
|
176733
|
+
if (tail.length <= MAX_PENDING_REPORT_LENGTH && PARTIAL_REPORT.exec(tail)?.[0] === tail) {
|
|
176734
|
+
return { keys, pending: tail };
|
|
176735
|
+
}
|
|
176736
|
+
keys += REPORT_PREFIX;
|
|
176737
|
+
cursor = start + REPORT_PREFIX.length;
|
|
176738
|
+
}
|
|
176739
|
+
start = text.indexOf(REPORT_PREFIX, cursor);
|
|
176740
|
+
}
|
|
176741
|
+
return { keys: keys + text.slice(cursor), pending: "" };
|
|
176742
|
+
}
|
|
176743
|
+
function inkStream(source) {
|
|
176744
|
+
const stream = Object.assign(new PassThrough3, {
|
|
176745
|
+
get isTTY() {
|
|
176746
|
+
return source.isTTY;
|
|
176747
|
+
},
|
|
176748
|
+
setRawMode(mode) {
|
|
176749
|
+
source.setRawMode(mode);
|
|
176750
|
+
return stream;
|
|
176751
|
+
},
|
|
176752
|
+
ref() {
|
|
176753
|
+
source.ref();
|
|
176754
|
+
return stream;
|
|
176755
|
+
},
|
|
176756
|
+
unref() {
|
|
176757
|
+
source.unref();
|
|
176758
|
+
return stream;
|
|
176759
|
+
},
|
|
176760
|
+
get isRaw() {
|
|
176761
|
+
return source.isRaw;
|
|
176762
|
+
}
|
|
176763
|
+
});
|
|
176764
|
+
return stream;
|
|
176765
|
+
}
|
|
176766
|
+
function createMouseInput(source) {
|
|
176767
|
+
const stdin = inkStream(source);
|
|
176768
|
+
const decoder = new StringDecoder("utf8");
|
|
176769
|
+
const listeners = new Set;
|
|
176770
|
+
let pending = "";
|
|
176771
|
+
const emit = (event) => {
|
|
176772
|
+
for (const listener of listeners)
|
|
176773
|
+
listener(event);
|
|
176774
|
+
};
|
|
176775
|
+
const onData = (chunk) => {
|
|
176776
|
+
const text = typeof chunk === "string" ? chunk : decoder.write(chunk);
|
|
176777
|
+
const result = filterReports(pending + text, emit);
|
|
176778
|
+
pending = result.pending;
|
|
176779
|
+
if (result.keys)
|
|
176780
|
+
stdin.write(result.keys);
|
|
176781
|
+
};
|
|
176782
|
+
source.on("data", onData);
|
|
176783
|
+
return {
|
|
176784
|
+
stdin,
|
|
176785
|
+
events: {
|
|
176786
|
+
subscribe(listener) {
|
|
176787
|
+
listeners.add(listener);
|
|
176788
|
+
return () => {
|
|
176789
|
+
listeners.delete(listener);
|
|
176790
|
+
};
|
|
176791
|
+
}
|
|
176792
|
+
},
|
|
176793
|
+
dispose() {
|
|
176794
|
+
source.off("data", onData);
|
|
176795
|
+
listeners.clear();
|
|
176796
|
+
pending = "";
|
|
176797
|
+
}
|
|
176798
|
+
};
|
|
176799
|
+
}
|
|
176800
|
+
var ENABLE_MOUSE = "\x1B[?1003h\x1B[?1006h", DISABLE_MOUSE = "\x1B[?1006l\x1B[?1003l", REPORT_PREFIX = "\x1B[<", MAX_PENDING_REPORT_LENGTH = 64, REPORT, PARTIAL_REPORT, BUTTON_MASK = 3, MOTION_BIT = 32, WHEEL_BIT = 64, BUTTONS;
|
|
176801
|
+
var init_mouse_input = __esm(() => {
|
|
176802
|
+
REPORT = /^\u001b\[<(\d+);(\d+);(\d+)([Mm])/;
|
|
176803
|
+
PARTIAL_REPORT = /^\u001b\[<(?:\d*|\d+;\d*|\d+;\d+;\d*)$/;
|
|
176804
|
+
BUTTONS = ["left", "middle", "right", "none"];
|
|
176805
|
+
});
|
|
176806
|
+
|
|
176182
176807
|
// src/tui/chat/exit-summary.ts
|
|
176183
176808
|
function formatChatExitSummary(state) {
|
|
176184
176809
|
const cost = (state.meta.costUsd ?? 0).toFixed(COST_DECIMALS2);
|
|
@@ -176190,6 +176815,9 @@ var COST_DECIMALS2 = 2, COST_PREFIX2 = "$", BULLET = "\u273B", SEPARATOR2 = " \x
|
|
|
176190
176815
|
|
|
176191
176816
|
// src/tui/chat/index.ts
|
|
176192
176817
|
function renderChat(props) {
|
|
176818
|
+
const source = _renderChatDeps.stdin();
|
|
176819
|
+
const mouse = _renderChatDeps.createMouseInput(source);
|
|
176820
|
+
const isTTY = source.isTTY;
|
|
176193
176821
|
_renderChatDeps.write(ENTER_ALT_SCREEN);
|
|
176194
176822
|
let restored = false;
|
|
176195
176823
|
let removeExit;
|
|
@@ -176198,10 +176826,18 @@ function renderChat(props) {
|
|
|
176198
176826
|
return;
|
|
176199
176827
|
restored = true;
|
|
176200
176828
|
removeExit?.();
|
|
176829
|
+
if (isTTY)
|
|
176830
|
+
_renderChatDeps.write(DISABLE_MOUSE);
|
|
176201
176831
|
_renderChatDeps.write(LEAVE_ALT_SCREEN);
|
|
176832
|
+
mouse.dispose();
|
|
176202
176833
|
};
|
|
176203
176834
|
try {
|
|
176204
|
-
const instance = _renderChatDeps.render(
|
|
176835
|
+
const instance = _renderChatDeps.render(import_react39.createElement(ChatApp, { ...props, mouse: mouse.events }), {
|
|
176836
|
+
exitOnCtrlC: false,
|
|
176837
|
+
stdin: mouse.stdin
|
|
176838
|
+
});
|
|
176839
|
+
if (isTTY)
|
|
176840
|
+
_renderChatDeps.write(ENABLE_MOUSE);
|
|
176205
176841
|
removeExit = _renderChatDeps.onExit(restore);
|
|
176206
176842
|
return {
|
|
176207
176843
|
...instance,
|
|
@@ -176218,17 +176854,20 @@ function renderChat(props) {
|
|
|
176218
176854
|
throw error;
|
|
176219
176855
|
}
|
|
176220
176856
|
}
|
|
176221
|
-
var
|
|
176857
|
+
var import_react39, _renderChatDeps;
|
|
176222
176858
|
var init_chat2 = __esm(async () => {
|
|
176859
|
+
init_mouse_input();
|
|
176223
176860
|
init_theme();
|
|
176224
176861
|
await __promiseAll([
|
|
176225
176862
|
init_build3(),
|
|
176226
176863
|
init_ChatApp(),
|
|
176227
176864
|
init_ChatApp()
|
|
176228
176865
|
]);
|
|
176229
|
-
|
|
176866
|
+
import_react39 = __toESM(require_react(), 1);
|
|
176230
176867
|
_renderChatDeps = {
|
|
176231
176868
|
render: render_default,
|
|
176869
|
+
stdin: () => process.stdin,
|
|
176870
|
+
createMouseInput,
|
|
176232
176871
|
write: (text) => {
|
|
176233
176872
|
process.stdout.write(text);
|
|
176234
176873
|
},
|
|
@@ -176364,10 +177003,25 @@ async function chatResources(repoRoot, config, deps) {
|
|
|
176364
177003
|
throw error;
|
|
176365
177004
|
}
|
|
176366
177005
|
}
|
|
177006
|
+
async function discoverModels(config, deps) {
|
|
177007
|
+
const requested = [
|
|
177008
|
+
...new Set([
|
|
177009
|
+
...tierModels(config).map((model) => model.slice(0, model.indexOf("/"))),
|
|
177010
|
+
...(config.agent?.native?.catalogOverrides ?? []).map(({ provider }) => provider)
|
|
177011
|
+
])
|
|
177012
|
+
];
|
|
177013
|
+
let availableProviders = [];
|
|
177014
|
+
try {
|
|
177015
|
+
const report = await deps.collectAuthList(requested);
|
|
177016
|
+
availableProviders = report.providers.filter(({ available }) => available).map(({ providerId }) => providerId);
|
|
177017
|
+
} catch {}
|
|
177018
|
+
return chatModelChoices({ config, availableProviders, listCatalogModels: deps.listCatalogModels });
|
|
177019
|
+
}
|
|
176367
177020
|
async function composeChat(options, deps, cwd) {
|
|
176368
177021
|
const naxDir = deps.findProjectDir(cwd);
|
|
176369
177022
|
const config = options.profile?.length ? await deps.loadConfig(naxDir ?? undefined, { profile: options.profile }) : await deps.loadConfig(naxDir ?? undefined);
|
|
176370
177023
|
const repoRoot = naxDir ? dirname48(naxDir) : cwd;
|
|
177024
|
+
const models = await discoverModels(config, deps);
|
|
176371
177025
|
const resources = await chatResources(repoRoot, config, deps);
|
|
176372
177026
|
const log = (stage, message) => deps.writeErr(`[${stage}] ${message}`);
|
|
176373
177027
|
const logger = getSafeLogger2() ?? { warn: log, error: log, info: log, debug: log };
|
|
@@ -176376,6 +177030,7 @@ async function composeChat(options, deps, cwd) {
|
|
|
176376
177030
|
let host;
|
|
176377
177031
|
try {
|
|
176378
177032
|
host = deps.createChatHost({
|
|
177033
|
+
models,
|
|
176379
177034
|
config,
|
|
176380
177035
|
cwd,
|
|
176381
177036
|
repoRoot,
|
|
@@ -176448,6 +177103,7 @@ var SIGNAL_EXIT_CODES, _chatCommandDeps;
|
|
|
176448
177103
|
var init_chat3 = __esm(async () => {
|
|
176449
177104
|
init_internal();
|
|
176450
177105
|
init_source();
|
|
177106
|
+
init_catalog();
|
|
176451
177107
|
init_chat();
|
|
176452
177108
|
init_config();
|
|
176453
177109
|
init_errors4();
|
|
@@ -176457,9 +177113,12 @@ var init_chat3 = __esm(async () => {
|
|
|
176457
177113
|
init_resources();
|
|
176458
177114
|
init_trust();
|
|
176459
177115
|
init_version();
|
|
177116
|
+
init_auth_list();
|
|
176460
177117
|
await init_chat2();
|
|
176461
177118
|
SIGNAL_EXIT_CODES = { SIGTERM: 143, SIGHUP: 129 };
|
|
176462
177119
|
_chatCommandDeps = {
|
|
177120
|
+
collectAuthList,
|
|
177121
|
+
listCatalogModels,
|
|
176463
177122
|
stdinIsTTY: () => process.stdin.isTTY === true,
|
|
176464
177123
|
ensureTrusted: async (cwd) => {
|
|
176465
177124
|
await ensureProjectTrusted(await normalizeTrustPath(resolveTrustRoot(cwd)), { interactive: true });
|
|
@@ -187044,7 +187703,7 @@ await init_build3();
|
|
|
187044
187703
|
// src/tui/App.tsx
|
|
187045
187704
|
init_internal();
|
|
187046
187705
|
await init_build3();
|
|
187047
|
-
var
|
|
187706
|
+
var import_react45 = __toESM(require_react(), 1);
|
|
187048
187707
|
|
|
187049
187708
|
// src/utils/queue-writer.ts
|
|
187050
187709
|
init_errors4();
|
|
@@ -187726,13 +188385,13 @@ function StatusBar({
|
|
|
187726
188385
|
// src/tui/components/StoriesPanel.tsx
|
|
187727
188386
|
init_internal();
|
|
187728
188387
|
await init_build3();
|
|
187729
|
-
var
|
|
188388
|
+
var import_react41 = __toESM(require_react(), 1);
|
|
187730
188389
|
|
|
187731
188390
|
// src/tui/hooks/useLayout.ts
|
|
187732
|
-
var
|
|
188391
|
+
var import_react40 = __toESM(require_react(), 1);
|
|
187733
188392
|
function useLayout() {
|
|
187734
|
-
const [layout, setLayout] =
|
|
187735
|
-
|
|
188393
|
+
const [layout, setLayout] = import_react40.useState(() => computeLayout());
|
|
188394
|
+
import_react40.useEffect(() => {
|
|
187736
188395
|
const handleResize = () => {
|
|
187737
188396
|
setLayout(computeLayout());
|
|
187738
188397
|
};
|
|
@@ -187798,8 +188457,8 @@ function StoriesPanel({
|
|
|
187798
188457
|
}) {
|
|
187799
188458
|
const maxVisible = compact ? COMPACT_MAX_VISIBLE_STORIES : MAX_VISIBLE_STORIES;
|
|
187800
188459
|
const needsScrolling = stories.length > maxVisible;
|
|
187801
|
-
const [scrollOffset, setScrollOffset] =
|
|
187802
|
-
|
|
188460
|
+
const [scrollOffset, setScrollOffset] = import_react41.useState(0);
|
|
188461
|
+
import_react41.useEffect(() => {
|
|
187803
188462
|
const runningIndex = stories.findIndex((s) => s.status === "running");
|
|
187804
188463
|
if (runningIndex !== -1 && needsScrolling) {
|
|
187805
188464
|
if (runningIndex < scrollOffset) {
|
|
@@ -187984,18 +188643,18 @@ function PostRunPhaseRow({ label, phase, compact }) {
|
|
|
187984
188643
|
}
|
|
187985
188644
|
|
|
187986
188645
|
// src/tui/hooks/useAgentStreamEvents.ts
|
|
187987
|
-
var
|
|
188646
|
+
var import_react42 = __toESM(require_react(), 1);
|
|
187988
188647
|
var RENDER_INTERVAL_MS = 150;
|
|
187989
188648
|
function useAgentStreamEvents(bus) {
|
|
187990
|
-
const activeCallsRef =
|
|
187991
|
-
const inputTokensRef =
|
|
187992
|
-
const outputTokensRef =
|
|
187993
|
-
const lastTokensRef =
|
|
187994
|
-
const dirtyRef =
|
|
187995
|
-
const [activeCalls, setActiveCalls] =
|
|
187996
|
-
const [inputTokens, setInputTokens] =
|
|
187997
|
-
const [outputTokens, setOutputTokens] =
|
|
187998
|
-
|
|
188649
|
+
const activeCallsRef = import_react42.useRef(new Map);
|
|
188650
|
+
const inputTokensRef = import_react42.useRef(0);
|
|
188651
|
+
const outputTokensRef = import_react42.useRef(0);
|
|
188652
|
+
const lastTokensRef = import_react42.useRef(new Map);
|
|
188653
|
+
const dirtyRef = import_react42.useRef(false);
|
|
188654
|
+
const [activeCalls, setActiveCalls] = import_react42.useState(new Map);
|
|
188655
|
+
const [inputTokens, setInputTokens] = import_react42.useState(0);
|
|
188656
|
+
const [outputTokens, setOutputTokens] = import_react42.useState(0);
|
|
188657
|
+
import_react42.useEffect(() => {
|
|
187999
188658
|
if (!bus)
|
|
188000
188659
|
return;
|
|
188001
188660
|
const unsubscribe = bus.onAgentStream((event) => {
|
|
@@ -188091,7 +188750,7 @@ function useAgentStreamEvents(bus) {
|
|
|
188091
188750
|
lastTokensRef.current.clear();
|
|
188092
188751
|
};
|
|
188093
188752
|
}, [bus]);
|
|
188094
|
-
|
|
188753
|
+
import_react42.useEffect(() => {
|
|
188095
188754
|
const interval = setInterval(() => {
|
|
188096
188755
|
if (!dirtyRef.current)
|
|
188097
188756
|
return;
|
|
@@ -188168,10 +188827,10 @@ function useKeyboard({ focus, currentStory, onAction, disabled = false }) {
|
|
|
188168
188827
|
|
|
188169
188828
|
// src/tui/hooks/usePipelineBusEvents.ts
|
|
188170
188829
|
init_pipeline2();
|
|
188171
|
-
var
|
|
188830
|
+
var import_react43 = __toESM(require_react(), 1);
|
|
188172
188831
|
var MAX_ESCALATION_LOG_ENTRIES = 5;
|
|
188173
188832
|
function usePipelineBusEvents(initialStories) {
|
|
188174
|
-
const [state, setState] =
|
|
188833
|
+
const [state, setState] = import_react43.useState(() => ({
|
|
188175
188834
|
stories: initialStories,
|
|
188176
188835
|
totalCost: 0,
|
|
188177
188836
|
runPaused: false,
|
|
@@ -188180,7 +188839,7 @@ function usePipelineBusEvents(initialStories) {
|
|
|
188180
188839
|
storySteps: {},
|
|
188181
188840
|
postRunPhases: {}
|
|
188182
188841
|
}));
|
|
188183
|
-
|
|
188842
|
+
import_react43.useEffect(() => {
|
|
188184
188843
|
const unsubStarted = pipelineEventBus.on("story:started", (event) => {
|
|
188185
188844
|
setState((prev) => ({
|
|
188186
188845
|
...prev,
|
|
@@ -188314,12 +188973,12 @@ function usePipelineBusEvents(initialStories) {
|
|
|
188314
188973
|
}
|
|
188315
188974
|
|
|
188316
188975
|
// src/tui/hooks/usePipelineEvents.ts
|
|
188317
|
-
var
|
|
188976
|
+
var import_react44 = __toESM(require_react(), 1);
|
|
188318
188977
|
var PRE_RUN_STAGES = new Set(["acceptance-setup"]);
|
|
188319
188978
|
function usePipelineEvents(events) {
|
|
188320
|
-
const [currentStage, setCurrentStage] =
|
|
188321
|
-
const [preRunPhases, setPreRunPhases] =
|
|
188322
|
-
|
|
188979
|
+
const [currentStage, setCurrentStage] = import_react44.useState(undefined);
|
|
188980
|
+
const [preRunPhases, setPreRunPhases] = import_react44.useState({});
|
|
188981
|
+
import_react44.useEffect(() => {
|
|
188323
188982
|
const onStageEnter = (stage) => {
|
|
188324
188983
|
setCurrentStage(stage);
|
|
188325
188984
|
if (PRE_RUN_STAGES.has(stage)) {
|
|
@@ -188346,8 +189005,8 @@ function usePipelineEvents(events) {
|
|
|
188346
189005
|
|
|
188347
189006
|
// src/tui/App.tsx
|
|
188348
189007
|
var jsx_dev_runtime13 = __toESM(require_jsx_dev_runtime(), 1);
|
|
188349
|
-
var MemoStoriesPanel =
|
|
188350
|
-
var MemoLiveActivityPanel =
|
|
189008
|
+
var MemoStoriesPanel = import_react45.memo(StoriesPanel);
|
|
189009
|
+
var MemoLiveActivityPanel = import_react45.memo(LiveActivityPanel);
|
|
188351
189010
|
function formatElapsed(ms) {
|
|
188352
189011
|
const mins = Math.floor(ms / 60000);
|
|
188353
189012
|
const secs = Math.floor(ms % 60000 / 1000);
|
|
@@ -188368,20 +189027,20 @@ function App2({ feature, version, stories: initialStories, events, queueFilePath
|
|
|
188368
189027
|
const busState = usePipelineBusEvents(initialStories);
|
|
188369
189028
|
const { currentStage, preRunPhases } = usePipelineEvents(events);
|
|
188370
189029
|
const { exit } = use_app_default();
|
|
188371
|
-
const startTimeRef =
|
|
188372
|
-
const [elapsedMs, setElapsedMs] =
|
|
188373
|
-
|
|
189030
|
+
const startTimeRef = import_react45.useRef(Date.now());
|
|
189031
|
+
const [elapsedMs, setElapsedMs] = import_react45.useState(0);
|
|
189032
|
+
import_react45.useEffect(() => {
|
|
188374
189033
|
if (busState.runSummary)
|
|
188375
189034
|
return;
|
|
188376
189035
|
const timer = setInterval(() => setElapsedMs(Date.now() - startTimeRef.current), 1000);
|
|
188377
189036
|
return () => clearInterval(timer);
|
|
188378
189037
|
}, [busState.runSummary]);
|
|
188379
|
-
const [focus, setFocus] =
|
|
188380
|
-
const [showHelp, setShowHelp] =
|
|
188381
|
-
const [showCost, setShowCost] =
|
|
188382
|
-
const [showQuitConfirm, setShowQuitConfirm] =
|
|
188383
|
-
const [showAbortConfirm, setShowAbortConfirm] =
|
|
188384
|
-
const [queueActionError, setQueueActionError] =
|
|
189038
|
+
const [focus, setFocus] = import_react45.useState("stories" /* Stories */);
|
|
189039
|
+
const [showHelp, setShowHelp] = import_react45.useState(false);
|
|
189040
|
+
const [showCost, setShowCost] = import_react45.useState(false);
|
|
189041
|
+
const [showQuitConfirm, setShowQuitConfirm] = import_react45.useState(false);
|
|
189042
|
+
const [showAbortConfirm, setShowAbortConfirm] = import_react45.useState(false);
|
|
189043
|
+
const [queueActionError, setQueueActionError] = import_react45.useState(undefined);
|
|
188385
189044
|
const { activeCalls, inputTokens, outputTokens } = useAgentStreamEvents(agentStreamEvents);
|
|
188386
189045
|
const isRunComplete = !!busState.runSummary;
|
|
188387
189046
|
const runningStories = busState.stories.filter((s) => s.status === "running");
|