@nathapp/nax 0.91.7-canary.3 → 0.91.7-canary.4
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 +854 -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.4",
|
|
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.4",
|
|
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("cceac3b"))
|
|
77457
|
+
return "cceac3b";
|
|
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,139 @@ 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
|
+
input.onCopy?.(selectedText(input.lines, range));
|
|
175748
|
+
}
|
|
175749
|
+
}
|
|
175750
|
+
function useMouseSelection(input) {
|
|
175751
|
+
const latest = import_react33.useRef(input);
|
|
175752
|
+
latest.current = input;
|
|
175753
|
+
const gesture = import_react33.useRef({ dragging: false });
|
|
175754
|
+
const [selection, setSelection] = import_react33.useState();
|
|
175755
|
+
const [total, setTotal] = import_react33.useState(input.lines.length);
|
|
175756
|
+
if (total !== input.lines.length) {
|
|
175757
|
+
setTotal(input.lines.length);
|
|
175758
|
+
gesture.current = { dragging: false };
|
|
175759
|
+
setSelection(undefined);
|
|
175760
|
+
}
|
|
175761
|
+
import_react33.useEffect(() => {
|
|
175762
|
+
if (!input.active || !input.mouse)
|
|
175763
|
+
return;
|
|
175764
|
+
return input.mouse.subscribe((event) => {
|
|
175765
|
+
if (event.button !== "left")
|
|
175766
|
+
return;
|
|
175767
|
+
const { geometry } = latest.current;
|
|
175768
|
+
const point = transcriptPointAt(geometry, event.x, event.y);
|
|
175769
|
+
const current = gesture.current;
|
|
175770
|
+
if (event.kind === "press") {
|
|
175771
|
+
current.selection = point ? { anchor: point, focus: point } : undefined;
|
|
175772
|
+
current.dragging = point !== undefined;
|
|
175773
|
+
setSelection(undefined);
|
|
175774
|
+
} else if (event.kind === "drag" && current.dragging && current.selection && point) {
|
|
175775
|
+
current.selection = { ...current.selection, focus: point };
|
|
175776
|
+
setSelection(current.selection);
|
|
175777
|
+
} else if (event.kind === "release" && current.dragging) {
|
|
175778
|
+
finishSelection(current, latest.current);
|
|
175779
|
+
}
|
|
175780
|
+
});
|
|
175781
|
+
}, [input.active, input.mouse]);
|
|
175782
|
+
return selection;
|
|
175783
|
+
}
|
|
175784
|
+
var import_react33;
|
|
175785
|
+
var init_use_mouse_selection = __esm(async () => {
|
|
175786
|
+
await init_selection();
|
|
175787
|
+
import_react33 = __toESM(require_react(), 1);
|
|
175788
|
+
});
|
|
175789
|
+
|
|
175363
175790
|
// src/tui/chat/TranscriptViewport.tsx
|
|
175364
175791
|
function viewRows(height) {
|
|
175365
175792
|
return Number.isFinite(height) ? Math.max(MIN_VIEWPORT_ROWS, Math.trunc(height)) : MIN_VIEWPORT_ROWS;
|
|
@@ -175432,11 +175859,14 @@ function TranscriptViewport({
|
|
|
175432
175859
|
height,
|
|
175433
175860
|
theme,
|
|
175434
175861
|
active = true,
|
|
175862
|
+
mouse,
|
|
175863
|
+
top = 0,
|
|
175864
|
+
onCopy,
|
|
175435
175865
|
followToken = 0
|
|
175436
175866
|
}) {
|
|
175437
175867
|
const rows = viewRows(height);
|
|
175438
175868
|
const total = lines.length;
|
|
175439
|
-
const [memory, setMemory] =
|
|
175869
|
+
const [memory, setMemory] = import_react34.useState({
|
|
175440
175870
|
state: INITIAL_VIEWPORT,
|
|
175441
175871
|
total,
|
|
175442
175872
|
height: rows,
|
|
@@ -175445,6 +175875,19 @@ function TranscriptViewport({
|
|
|
175445
175875
|
if (memory.total !== total || memory.height !== rows || memory.token !== followToken) {
|
|
175446
175876
|
setMemory(nextMemory(memory, total, rows, followToken));
|
|
175447
175877
|
}
|
|
175878
|
+
import_react34.useEffect(() => {
|
|
175879
|
+
if (!active || !mouse)
|
|
175880
|
+
return;
|
|
175881
|
+
return mouse.subscribe((event) => {
|
|
175882
|
+
if (event.kind !== "wheelUp" && event.kind !== "wheelDown")
|
|
175883
|
+
return;
|
|
175884
|
+
const action = { type: event.kind };
|
|
175885
|
+
setMemory((previous) => ({
|
|
175886
|
+
...previous,
|
|
175887
|
+
state: reduceViewport(previous.state, action, previous.total, previous.height)
|
|
175888
|
+
}));
|
|
175889
|
+
});
|
|
175890
|
+
}, [active, mouse]);
|
|
175448
175891
|
use_input_default((_input, key) => {
|
|
175449
175892
|
const action = viewportAction(key);
|
|
175450
175893
|
if (action === undefined)
|
|
@@ -175454,22 +175897,32 @@ function TranscriptViewport({
|
|
|
175454
175897
|
state: reduceViewport(previous.state, action, previous.total, previous.height)
|
|
175455
175898
|
}));
|
|
175456
175899
|
}, { isActive: active });
|
|
175900
|
+
const selection = useMouseSelection({
|
|
175901
|
+
mouse,
|
|
175902
|
+
active,
|
|
175903
|
+
lines,
|
|
175904
|
+
onCopy,
|
|
175905
|
+
geometry: { top, height: rows, total, offset: memory.state.offset, unseen: memory.state.unseen }
|
|
175906
|
+
});
|
|
175457
175907
|
const { start, end } = visibleRange(total, rows, memory.state.offset);
|
|
175908
|
+
const visible = lines.slice(start, end).map((line, index) => selection ? highlightLine(line, start + index, selection) : line);
|
|
175458
175909
|
return /* @__PURE__ */ jsx_dev_runtime6.jsxDEV(ViewportRows, {
|
|
175459
|
-
visible
|
|
175910
|
+
visible,
|
|
175460
175911
|
rows,
|
|
175461
175912
|
unseen: memory.state.unseen,
|
|
175462
175913
|
theme
|
|
175463
175914
|
}, undefined, false, undefined, this);
|
|
175464
175915
|
}
|
|
175465
|
-
var
|
|
175916
|
+
var import_react34, jsx_dev_runtime6, MIN_VIEWPORT_ROWS = 1, ROW_HEIGHT = 1, BLANK_ROW = " ", UNSEEN_MARKER = "\u2193", UNSEEN_LABEL = "new lines (End)";
|
|
175466
175917
|
var init_TranscriptViewport = __esm(async () => {
|
|
175467
175918
|
init_viewport();
|
|
175468
175919
|
await __promiseAll([
|
|
175469
175920
|
init_build3(),
|
|
175470
|
-
|
|
175921
|
+
init_selection(),
|
|
175922
|
+
init_styled_line(),
|
|
175923
|
+
init_use_mouse_selection()
|
|
175471
175924
|
]);
|
|
175472
|
-
|
|
175925
|
+
import_react34 = __toESM(require_react(), 1);
|
|
175473
175926
|
jsx_dev_runtime6 = __toESM(require_jsx_dev_runtime(), 1);
|
|
175474
175927
|
});
|
|
175475
175928
|
|
|
@@ -175603,6 +176056,69 @@ function reduceTranscript(entries, event) {
|
|
|
175603
176056
|
}
|
|
175604
176057
|
var AGENT_RUN_TOOL2 = "nax-agents__run", COMPACTION_NOTICE = "conversation compacted";
|
|
175605
176058
|
|
|
176059
|
+
// src/tui/chat/clipboard.ts
|
|
176060
|
+
function osc52(text) {
|
|
176061
|
+
return `\x1B]52;c;${Buffer.from(text, "utf8").toString("base64")}\x07`;
|
|
176062
|
+
}
|
|
176063
|
+
async function copyToClipboard(text) {
|
|
176064
|
+
_clipboardDeps.write(osc52(text));
|
|
176065
|
+
if (_clipboardDeps.platform !== "darwin")
|
|
176066
|
+
return;
|
|
176067
|
+
try {
|
|
176068
|
+
await _clipboardDeps.spawnCopy(text);
|
|
176069
|
+
} catch {}
|
|
176070
|
+
}
|
|
176071
|
+
var _clipboardDeps;
|
|
176072
|
+
var init_clipboard = __esm(() => {
|
|
176073
|
+
_clipboardDeps = {
|
|
176074
|
+
write: (text) => {
|
|
176075
|
+
process.stdout.write(text);
|
|
176076
|
+
},
|
|
176077
|
+
platform: process.platform,
|
|
176078
|
+
spawn: Bun.spawn,
|
|
176079
|
+
spawnCopy: async (text) => {
|
|
176080
|
+
const child = _clipboardDeps.spawn(["pbcopy"], {
|
|
176081
|
+
stdin: new TextEncoder().encode(text),
|
|
176082
|
+
stdout: "ignore",
|
|
176083
|
+
stderr: "ignore"
|
|
176084
|
+
});
|
|
176085
|
+
return child.exited;
|
|
176086
|
+
}
|
|
176087
|
+
};
|
|
176088
|
+
});
|
|
176089
|
+
|
|
176090
|
+
// src/tui/chat/use-clipboard-feedback.ts
|
|
176091
|
+
function footerHint(input) {
|
|
176092
|
+
if (input.quitArmed)
|
|
176093
|
+
return "quit";
|
|
176094
|
+
if (input.clearArmed)
|
|
176095
|
+
return "clear";
|
|
176096
|
+
if (input.busy)
|
|
176097
|
+
return "busy";
|
|
176098
|
+
if (input.expanded)
|
|
176099
|
+
return "expanded";
|
|
176100
|
+
return "idle";
|
|
176101
|
+
}
|
|
176102
|
+
function useClipboardFeedback(mouse) {
|
|
176103
|
+
const [copiedChars, setCopiedChars] = import_react35.useState();
|
|
176104
|
+
use_input_default(() => setCopiedChars(undefined));
|
|
176105
|
+
import_react35.useEffect(() => mouse?.subscribe((event) => {
|
|
176106
|
+
if (event.kind === "press")
|
|
176107
|
+
setCopiedChars(undefined);
|
|
176108
|
+
}), [mouse]);
|
|
176109
|
+
const onCopy = import_react35.useCallback((text) => {
|
|
176110
|
+
copyToClipboard(text);
|
|
176111
|
+
setCopiedChars(text.length);
|
|
176112
|
+
}, []);
|
|
176113
|
+
return { copiedChars, onCopy };
|
|
176114
|
+
}
|
|
176115
|
+
var import_react35;
|
|
176116
|
+
var init_use_clipboard_feedback = __esm(async () => {
|
|
176117
|
+
init_clipboard();
|
|
176118
|
+
await init_build3();
|
|
176119
|
+
import_react35 = __toESM(require_react(), 1);
|
|
176120
|
+
});
|
|
176121
|
+
|
|
175606
176122
|
// src/tui/chat/use-slash-menu-keys.ts
|
|
175607
176123
|
function useSlashMenuKeys({
|
|
175608
176124
|
items,
|
|
@@ -175610,7 +176126,7 @@ function useSlashMenuKeys({
|
|
|
175610
176126
|
initialDismissal,
|
|
175611
176127
|
blocked
|
|
175612
176128
|
}) {
|
|
175613
|
-
const live =
|
|
176129
|
+
const live = import_react36.useRef({ query: initialQuery, dismissed: initialDismissal });
|
|
175614
176130
|
return {
|
|
175615
176131
|
ownsKeys: () => slashMenuQueryState({ items, query: live.current.query, dismissed: live.current.dismissed, blocked }).open,
|
|
175616
176132
|
sawPrompt: (text) => {
|
|
@@ -175621,10 +176137,10 @@ function useSlashMenuKeys({
|
|
|
175621
176137
|
}
|
|
175622
176138
|
};
|
|
175623
176139
|
}
|
|
175624
|
-
var
|
|
176140
|
+
var import_react36;
|
|
175625
176141
|
var init_use_slash_menu_keys = __esm(async () => {
|
|
175626
176142
|
await init_slash_menu();
|
|
175627
|
-
|
|
176143
|
+
import_react36 = __toESM(require_react(), 1);
|
|
175628
176144
|
});
|
|
175629
176145
|
|
|
175630
176146
|
// src/tui/chat/useChatKeys.ts
|
|
@@ -175636,12 +176152,12 @@ function clearTimer(handle) {
|
|
|
175636
176152
|
}
|
|
175637
176153
|
function useChatKeys({ host, running, refresh, onError }) {
|
|
175638
176154
|
const { exit } = use_app_default();
|
|
175639
|
-
const queued =
|
|
175640
|
-
const interruptedAt =
|
|
175641
|
-
const quitExpiry =
|
|
175642
|
-
const switching =
|
|
175643
|
-
const closing =
|
|
175644
|
-
const [locked, setLocked] =
|
|
176155
|
+
const queued = import_react37.useRef(undefined);
|
|
176156
|
+
const interruptedAt = import_react37.useRef(undefined);
|
|
176157
|
+
const quitExpiry = import_react37.useRef(undefined);
|
|
176158
|
+
const switching = import_react37.useRef(undefined);
|
|
176159
|
+
const closing = import_react37.useRef(false);
|
|
176160
|
+
const [locked, setLocked] = import_react37.useState(false);
|
|
175645
176161
|
function armQuit() {
|
|
175646
176162
|
clearTimer(quitExpiry);
|
|
175647
176163
|
quitExpiry.current = setTimeout(() => {
|
|
@@ -175649,7 +176165,7 @@ function useChatKeys({ host, running, refresh, onError }) {
|
|
|
175649
176165
|
refresh();
|
|
175650
176166
|
}, DOUBLE_INTERRUPT_MS);
|
|
175651
176167
|
}
|
|
175652
|
-
|
|
176168
|
+
import_react37.useEffect(() => () => clearTimer(quitExpiry), []);
|
|
175653
176169
|
function quitArmed() {
|
|
175654
176170
|
const armedAt = interruptedAt.current;
|
|
175655
176171
|
return armedAt !== undefined && _chatKeyDeps.now() - armedAt < DOUBLE_INTERRUPT_MS;
|
|
@@ -175729,11 +176245,11 @@ function useChatKeys({ host, running, refresh, onError }) {
|
|
|
175729
176245
|
}
|
|
175730
176246
|
};
|
|
175731
176247
|
}
|
|
175732
|
-
var
|
|
176248
|
+
var import_react37, DOUBLE_INTERRUPT_MS = 2000, _chatKeyDeps;
|
|
175733
176249
|
var init_useChatKeys = __esm(async () => {
|
|
175734
176250
|
init_chat();
|
|
175735
176251
|
await init_build3();
|
|
175736
|
-
|
|
176252
|
+
import_react37 = __toESM(require_react(), 1);
|
|
175737
176253
|
_chatKeyDeps = { now: () => Date.now() };
|
|
175738
176254
|
});
|
|
175739
176255
|
|
|
@@ -175765,17 +176281,6 @@ function welcomeEntry(host) {
|
|
|
175765
176281
|
mcpConnected: servers.filter((server) => lastServerEvent(events, server.id)?.kind === "connected").length
|
|
175766
176282
|
};
|
|
175767
176283
|
}
|
|
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
176284
|
function stopTurn(status) {
|
|
175780
176285
|
return status.running ? { ...status, running: false } : status;
|
|
175781
176286
|
}
|
|
@@ -175799,37 +176304,39 @@ function slashSink(title, append) {
|
|
|
175799
176304
|
}
|
|
175800
176305
|
function ChatApp({
|
|
175801
176306
|
host,
|
|
176307
|
+
mouse,
|
|
175802
176308
|
theme = DEFAULT_THEME,
|
|
175803
176309
|
version = NAX_VERSION,
|
|
175804
176310
|
cwd = host.repoRoot,
|
|
175805
176311
|
home = ""
|
|
175806
176312
|
}) {
|
|
175807
176313
|
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
|
|
176314
|
+
const { copiedChars, onCopy } = useClipboardFeedback(mouse);
|
|
176315
|
+
const [size, setSize] = import_react38.useState(() => terminalSize2(stdout));
|
|
176316
|
+
const [entries, setEntries] = import_react38.useState(() => [welcomeEntry(host)]);
|
|
176317
|
+
const [status, setStatus] = import_react38.useState(IDLE_STATUS);
|
|
176318
|
+
const [draft, setDraft] = import_react38.useState(EMPTY_DRAFT);
|
|
176319
|
+
const [busy, setBusy] = import_react38.useState(false);
|
|
176320
|
+
const [clearArmed, setClearArmed] = import_react38.useState(false);
|
|
176321
|
+
const [answerDraft, setAnswerDraft] = import_react38.useState(NO_ANSWER2);
|
|
176322
|
+
const [hint, setHint] = import_react38.useState(undefined);
|
|
176323
|
+
const [nowMs, setNowMs] = import_react38.useState(() => Date.now());
|
|
176324
|
+
const [expanded, setExpanded] = import_react38.useState(false);
|
|
176325
|
+
const [dismissedQuery, setDismissedQuery] = import_react38.useState(undefined);
|
|
176326
|
+
const [followToken, setFollowToken] = import_react38.useState(0);
|
|
176327
|
+
const inputHandle = import_react38.useRef(undefined);
|
|
176328
|
+
const sending = import_react38.useRef(false);
|
|
176329
|
+
const [, refresh] = import_react38.useState(0);
|
|
176330
|
+
const update = import_react38.useCallback(() => refresh((revision) => revision + 1), []);
|
|
176331
|
+
const append = import_react38.useCallback((entry) => {
|
|
175825
176332
|
setEntries((rows) => [...rows, entry]);
|
|
175826
176333
|
}, []);
|
|
175827
|
-
const showError =
|
|
176334
|
+
const showError = import_react38.useCallback((error) => append({ kind: "error", text: errorMessage(error) }), [append]);
|
|
175828
176335
|
const keys = useChatKeys({ host, running: sending, refresh: update, onError: showError });
|
|
175829
176336
|
const picker = useChatPicker({ host, runControl: keys.runControl, onError: showError });
|
|
175830
176337
|
const ask = host.asks.pending()[0];
|
|
175831
176338
|
const turnRunning = busy || status.running;
|
|
175832
|
-
const menuItems =
|
|
176339
|
+
const menuItems = import_react38.useMemo(() => slashMenuItems(host), [host]);
|
|
175833
176340
|
const slashKeys = useSlashMenuKeys({
|
|
175834
176341
|
items: menuItems,
|
|
175835
176342
|
initialQuery: draft.editor.text,
|
|
@@ -175843,7 +176350,8 @@ function ChatApp({
|
|
|
175843
176350
|
blocked: bottomBlocked(ask, picker.model)
|
|
175844
176351
|
});
|
|
175845
176352
|
const working = workingLine(status, nowMs, theme.glyphs);
|
|
175846
|
-
const
|
|
176353
|
+
const usableRows = size.rows - FRAME_SLACK_ROWS;
|
|
176354
|
+
const bottomBudget = Math.max(1, usableRows - HEADER_ROWS - (working ? WORKING_ROWS : 0) - FOOTER_ROWS - MIN_VIEWPORT_ROWS2);
|
|
175847
176355
|
const menuRows = menuRowsFor({ rows: menu.rows, budget: bottomBudget });
|
|
175848
176356
|
function menuShown() {
|
|
175849
176357
|
return menu.open && menuRows > 0;
|
|
@@ -175866,15 +176374,15 @@ function ChatApp({
|
|
|
175866
176374
|
return;
|
|
175867
176375
|
host.cancel();
|
|
175868
176376
|
});
|
|
175869
|
-
|
|
176377
|
+
import_react38.useEffect(() => {
|
|
175870
176378
|
const onResize = () => setSize(terminalSize2(stdout));
|
|
175871
176379
|
stdout.on("resize", onResize);
|
|
175872
176380
|
return () => {
|
|
175873
176381
|
stdout.off("resize", onResize);
|
|
175874
176382
|
};
|
|
175875
176383
|
}, [stdout]);
|
|
175876
|
-
|
|
175877
|
-
|
|
176384
|
+
import_react38.useEffect(() => host.asks.onChange(update), [host, update]);
|
|
176385
|
+
import_react38.useEffect(() => {
|
|
175878
176386
|
const resourceNotice = host.resourceNotice?.();
|
|
175879
176387
|
if (resourceNotice)
|
|
175880
176388
|
append({ kind: "notice", text: resourceNotice });
|
|
@@ -175882,15 +176390,15 @@ function ChatApp({
|
|
|
175882
176390
|
const state = host.current();
|
|
175883
176391
|
const notice = host.notice();
|
|
175884
176392
|
const warn = state.mode === "full" && state.sandbox?.kind === "unavailable";
|
|
175885
|
-
|
|
176393
|
+
import_react38.useEffect(() => {
|
|
175886
176394
|
if (notice)
|
|
175887
176395
|
append({ kind: "notice", text: notice });
|
|
175888
176396
|
}, [notice, append]);
|
|
175889
|
-
|
|
176397
|
+
import_react38.useEffect(() => {
|
|
175890
176398
|
if (warn)
|
|
175891
176399
|
append({ kind: "warning", text: SANDBOX_WARNING });
|
|
175892
176400
|
}, [warn, append]);
|
|
175893
|
-
|
|
176401
|
+
import_react38.useEffect(() => {
|
|
175894
176402
|
if (!status.running)
|
|
175895
176403
|
return;
|
|
175896
176404
|
let handle;
|
|
@@ -175907,7 +176415,7 @@ function ChatApp({
|
|
|
175907
176415
|
clearTimeout(handle);
|
|
175908
176416
|
};
|
|
175909
176417
|
}, [status.running]);
|
|
175910
|
-
const handleEvent =
|
|
176418
|
+
const handleEvent = import_react38.useCallback((event) => {
|
|
175911
176419
|
setEntries((rows) => reduceTranscript(rows, event));
|
|
175912
176420
|
setStatus((current) => reduceTurnStatus(current, event));
|
|
175913
176421
|
if (event.type === "turn_start")
|
|
@@ -176003,7 +176511,8 @@ function ChatApp({
|
|
|
176003
176511
|
const footer = footerModel({
|
|
176004
176512
|
state,
|
|
176005
176513
|
status,
|
|
176006
|
-
hint: footerHint({ quitArmed: keys.quitArmed(), clearArmed, busy: turnRunning, expanded }),
|
|
176514
|
+
hint: copiedChars === undefined ? footerHint({ quitArmed: keys.quitArmed(), clearArmed, busy: turnRunning, expanded }) : "copied",
|
|
176515
|
+
copiedChars,
|
|
176007
176516
|
glyphs: theme.glyphs
|
|
176008
176517
|
});
|
|
176009
176518
|
const inputBudget = Math.max(1, bottomBudget - INPUT_RULE_ROWS - menuRows);
|
|
@@ -176026,7 +176535,7 @@ function ChatApp({
|
|
|
176026
176535
|
input: inputBottomRows + menuRows,
|
|
176027
176536
|
budget: bottomBudget
|
|
176028
176537
|
});
|
|
176029
|
-
const viewportHeight = Math.max(MIN_VIEWPORT_ROWS2,
|
|
176538
|
+
const viewportHeight = Math.max(MIN_VIEWPORT_ROWS2, usableRows - HEADER_ROWS - (working ? WORKING_ROWS : 0) - bottomRows - FOOTER_ROWS);
|
|
176030
176539
|
return /* @__PURE__ */ jsx_dev_runtime7.jsxDEV(Box_default, {
|
|
176031
176540
|
flexDirection: "column",
|
|
176032
176541
|
width: columns,
|
|
@@ -176041,6 +176550,9 @@ function ChatApp({
|
|
|
176041
176550
|
}, index, false, undefined, this))
|
|
176042
176551
|
}, undefined, false, undefined, this),
|
|
176043
176552
|
/* @__PURE__ */ jsx_dev_runtime7.jsxDEV(TranscriptViewport, {
|
|
176553
|
+
mouse,
|
|
176554
|
+
top: HEADER_ROWS,
|
|
176555
|
+
onCopy,
|
|
176044
176556
|
lines,
|
|
176045
176557
|
height: viewportHeight,
|
|
176046
176558
|
theme,
|
|
@@ -176080,7 +176592,9 @@ function ChatApp({
|
|
|
176080
176592
|
budget: bottomBudget,
|
|
176081
176593
|
active: !keys.locked,
|
|
176082
176594
|
onChoose: picker.choose,
|
|
176083
|
-
onCancel: picker.cancel
|
|
176595
|
+
onCancel: picker.cancel,
|
|
176596
|
+
onQuery: picker.setQuery,
|
|
176597
|
+
query: picker.model.query
|
|
176084
176598
|
}, undefined, false, undefined, this)
|
|
176085
176599
|
}, undefined, false, undefined, this) : /* @__PURE__ */ jsx_dev_runtime7.jsxDEV(Box_default, {
|
|
176086
176600
|
height: bottomRows,
|
|
@@ -176140,7 +176654,7 @@ function ChatApp({
|
|
|
176140
176654
|
]
|
|
176141
176655
|
}, undefined, true, undefined, this);
|
|
176142
176656
|
}
|
|
176143
|
-
var
|
|
176657
|
+
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
176658
|
var init_ChatApp = __esm(async () => {
|
|
176145
176659
|
init_internal();
|
|
176146
176660
|
init_prompts();
|
|
@@ -176161,10 +176675,11 @@ var init_ChatApp = __esm(async () => {
|
|
|
176161
176675
|
init_slash_menu(),
|
|
176162
176676
|
init_styled_line(),
|
|
176163
176677
|
init_TranscriptViewport(),
|
|
176678
|
+
init_use_clipboard_feedback(),
|
|
176164
176679
|
init_use_slash_menu_keys(),
|
|
176165
176680
|
init_useChatKeys()
|
|
176166
176681
|
]);
|
|
176167
|
-
|
|
176682
|
+
import_react38 = __toESM(require_react(), 1);
|
|
176168
176683
|
jsx_dev_runtime7 = __toESM(require_jsx_dev_runtime(), 1);
|
|
176169
176684
|
DEFAULT_THEME = resolveChatTheme({ env: {}, colorLevel: 0 });
|
|
176170
176685
|
LISTING_TITLES = new Map([
|
|
@@ -176179,6 +176694,114 @@ var init_ChatApp = __esm(async () => {
|
|
|
176179
176694
|
NO_ANSWER2 = { requestId: "", draft: EMPTY_DRAFT };
|
|
176180
176695
|
});
|
|
176181
176696
|
|
|
176697
|
+
// src/tui/chat/mouse-input.ts
|
|
176698
|
+
import { PassThrough as PassThrough3 } from "stream";
|
|
176699
|
+
import { StringDecoder } from "string_decoder";
|
|
176700
|
+
function parseSgrMouse(sequence) {
|
|
176701
|
+
const match = REPORT.exec(sequence);
|
|
176702
|
+
if (!match || match[0] !== sequence)
|
|
176703
|
+
return;
|
|
176704
|
+
const bits = Number(match[1]);
|
|
176705
|
+
const buttonIndex = bits & BUTTON_MASK;
|
|
176706
|
+
const x = Number(match[2]);
|
|
176707
|
+
const y = Number(match[3]);
|
|
176708
|
+
if (bits & WHEEL_BIT) {
|
|
176709
|
+
if (buttonIndex > 1)
|
|
176710
|
+
return;
|
|
176711
|
+
return { kind: buttonIndex === 0 ? "wheelUp" : "wheelDown", button: "none", x, y };
|
|
176712
|
+
}
|
|
176713
|
+
const button = BUTTONS[buttonIndex] ?? "none";
|
|
176714
|
+
const kind = match[4] === "m" ? "release" : bits & MOTION_BIT ? button === "none" ? "move" : "drag" : "press";
|
|
176715
|
+
return { kind, button, x, y };
|
|
176716
|
+
}
|
|
176717
|
+
function filterReports(text, emit) {
|
|
176718
|
+
let keys = "";
|
|
176719
|
+
let cursor = 0;
|
|
176720
|
+
let start = text.indexOf(REPORT_PREFIX);
|
|
176721
|
+
while (start !== -1) {
|
|
176722
|
+
keys += text.slice(cursor, start);
|
|
176723
|
+
const tail = text.slice(start);
|
|
176724
|
+
const match = REPORT.exec(tail);
|
|
176725
|
+
if (match) {
|
|
176726
|
+
const event = parseSgrMouse(match[0]);
|
|
176727
|
+
if (event)
|
|
176728
|
+
emit(event);
|
|
176729
|
+
cursor = start + match[0].length;
|
|
176730
|
+
} else {
|
|
176731
|
+
if (tail.length <= MAX_PENDING_REPORT_LENGTH && PARTIAL_REPORT.exec(tail)?.[0] === tail) {
|
|
176732
|
+
return { keys, pending: tail };
|
|
176733
|
+
}
|
|
176734
|
+
keys += REPORT_PREFIX;
|
|
176735
|
+
cursor = start + REPORT_PREFIX.length;
|
|
176736
|
+
}
|
|
176737
|
+
start = text.indexOf(REPORT_PREFIX, cursor);
|
|
176738
|
+
}
|
|
176739
|
+
return { keys: keys + text.slice(cursor), pending: "" };
|
|
176740
|
+
}
|
|
176741
|
+
function inkStream(source) {
|
|
176742
|
+
const stream = Object.assign(new PassThrough3, {
|
|
176743
|
+
get isTTY() {
|
|
176744
|
+
return source.isTTY;
|
|
176745
|
+
},
|
|
176746
|
+
setRawMode(mode) {
|
|
176747
|
+
source.setRawMode(mode);
|
|
176748
|
+
return stream;
|
|
176749
|
+
},
|
|
176750
|
+
ref() {
|
|
176751
|
+
source.ref();
|
|
176752
|
+
return stream;
|
|
176753
|
+
},
|
|
176754
|
+
unref() {
|
|
176755
|
+
source.unref();
|
|
176756
|
+
return stream;
|
|
176757
|
+
},
|
|
176758
|
+
get isRaw() {
|
|
176759
|
+
return source.isRaw;
|
|
176760
|
+
}
|
|
176761
|
+
});
|
|
176762
|
+
return stream;
|
|
176763
|
+
}
|
|
176764
|
+
function createMouseInput(source) {
|
|
176765
|
+
const stdin = inkStream(source);
|
|
176766
|
+
const decoder = new StringDecoder("utf8");
|
|
176767
|
+
const listeners = new Set;
|
|
176768
|
+
let pending = "";
|
|
176769
|
+
const emit = (event) => {
|
|
176770
|
+
for (const listener of listeners)
|
|
176771
|
+
listener(event);
|
|
176772
|
+
};
|
|
176773
|
+
const onData = (chunk) => {
|
|
176774
|
+
const text = typeof chunk === "string" ? chunk : decoder.write(chunk);
|
|
176775
|
+
const result = filterReports(pending + text, emit);
|
|
176776
|
+
pending = result.pending;
|
|
176777
|
+
if (result.keys)
|
|
176778
|
+
stdin.write(result.keys);
|
|
176779
|
+
};
|
|
176780
|
+
source.on("data", onData);
|
|
176781
|
+
return {
|
|
176782
|
+
stdin,
|
|
176783
|
+
events: {
|
|
176784
|
+
subscribe(listener) {
|
|
176785
|
+
listeners.add(listener);
|
|
176786
|
+
return () => {
|
|
176787
|
+
listeners.delete(listener);
|
|
176788
|
+
};
|
|
176789
|
+
}
|
|
176790
|
+
},
|
|
176791
|
+
dispose() {
|
|
176792
|
+
source.off("data", onData);
|
|
176793
|
+
listeners.clear();
|
|
176794
|
+
pending = "";
|
|
176795
|
+
}
|
|
176796
|
+
};
|
|
176797
|
+
}
|
|
176798
|
+
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;
|
|
176799
|
+
var init_mouse_input = __esm(() => {
|
|
176800
|
+
REPORT = /^\u001b\[<(\d+);(\d+);(\d+)([Mm])/;
|
|
176801
|
+
PARTIAL_REPORT = /^\u001b\[<(?:\d*|\d+;\d*|\d+;\d+;\d*)$/;
|
|
176802
|
+
BUTTONS = ["left", "middle", "right", "none"];
|
|
176803
|
+
});
|
|
176804
|
+
|
|
176182
176805
|
// src/tui/chat/exit-summary.ts
|
|
176183
176806
|
function formatChatExitSummary(state) {
|
|
176184
176807
|
const cost = (state.meta.costUsd ?? 0).toFixed(COST_DECIMALS2);
|
|
@@ -176190,6 +176813,9 @@ var COST_DECIMALS2 = 2, COST_PREFIX2 = "$", BULLET = "\u273B", SEPARATOR2 = " \x
|
|
|
176190
176813
|
|
|
176191
176814
|
// src/tui/chat/index.ts
|
|
176192
176815
|
function renderChat(props) {
|
|
176816
|
+
const source = _renderChatDeps.stdin();
|
|
176817
|
+
const mouse = _renderChatDeps.createMouseInput(source);
|
|
176818
|
+
const isTTY = source.isTTY;
|
|
176193
176819
|
_renderChatDeps.write(ENTER_ALT_SCREEN);
|
|
176194
176820
|
let restored = false;
|
|
176195
176821
|
let removeExit;
|
|
@@ -176198,10 +176824,19 @@ function renderChat(props) {
|
|
|
176198
176824
|
return;
|
|
176199
176825
|
restored = true;
|
|
176200
176826
|
removeExit?.();
|
|
176827
|
+
if (isTTY)
|
|
176828
|
+
_renderChatDeps.write(DISABLE_MOUSE);
|
|
176201
176829
|
_renderChatDeps.write(LEAVE_ALT_SCREEN);
|
|
176830
|
+
mouse.dispose();
|
|
176202
176831
|
};
|
|
176203
176832
|
try {
|
|
176204
|
-
const instance = _renderChatDeps.render(
|
|
176833
|
+
const instance = _renderChatDeps.render(import_react39.createElement(ChatApp, { ...props, mouse: mouse.events }), {
|
|
176834
|
+
exitOnCtrlC: false,
|
|
176835
|
+
incrementalRendering: true,
|
|
176836
|
+
stdin: mouse.stdin
|
|
176837
|
+
});
|
|
176838
|
+
if (isTTY)
|
|
176839
|
+
_renderChatDeps.write(ENABLE_MOUSE);
|
|
176205
176840
|
removeExit = _renderChatDeps.onExit(restore);
|
|
176206
176841
|
return {
|
|
176207
176842
|
...instance,
|
|
@@ -176218,17 +176853,20 @@ function renderChat(props) {
|
|
|
176218
176853
|
throw error;
|
|
176219
176854
|
}
|
|
176220
176855
|
}
|
|
176221
|
-
var
|
|
176856
|
+
var import_react39, _renderChatDeps;
|
|
176222
176857
|
var init_chat2 = __esm(async () => {
|
|
176858
|
+
init_mouse_input();
|
|
176223
176859
|
init_theme();
|
|
176224
176860
|
await __promiseAll([
|
|
176225
176861
|
init_build3(),
|
|
176226
176862
|
init_ChatApp(),
|
|
176227
176863
|
init_ChatApp()
|
|
176228
176864
|
]);
|
|
176229
|
-
|
|
176865
|
+
import_react39 = __toESM(require_react(), 1);
|
|
176230
176866
|
_renderChatDeps = {
|
|
176231
176867
|
render: render_default,
|
|
176868
|
+
stdin: () => process.stdin,
|
|
176869
|
+
createMouseInput,
|
|
176232
176870
|
write: (text) => {
|
|
176233
176871
|
process.stdout.write(text);
|
|
176234
176872
|
},
|
|
@@ -176364,10 +177002,25 @@ async function chatResources(repoRoot, config, deps) {
|
|
|
176364
177002
|
throw error;
|
|
176365
177003
|
}
|
|
176366
177004
|
}
|
|
177005
|
+
async function discoverModels(config, deps) {
|
|
177006
|
+
const requested = [
|
|
177007
|
+
...new Set([
|
|
177008
|
+
...tierModels(config).map((model) => model.slice(0, model.indexOf("/"))),
|
|
177009
|
+
...(config.agent?.native?.catalogOverrides ?? []).map(({ provider }) => provider)
|
|
177010
|
+
])
|
|
177011
|
+
];
|
|
177012
|
+
let availableProviders = [];
|
|
177013
|
+
try {
|
|
177014
|
+
const report = await deps.collectAuthList(requested);
|
|
177015
|
+
availableProviders = report.providers.filter(({ available }) => available).map(({ providerId }) => providerId);
|
|
177016
|
+
} catch {}
|
|
177017
|
+
return chatModelChoices({ config, availableProviders, listCatalogModels: deps.listCatalogModels });
|
|
177018
|
+
}
|
|
176367
177019
|
async function composeChat(options, deps, cwd) {
|
|
176368
177020
|
const naxDir = deps.findProjectDir(cwd);
|
|
176369
177021
|
const config = options.profile?.length ? await deps.loadConfig(naxDir ?? undefined, { profile: options.profile }) : await deps.loadConfig(naxDir ?? undefined);
|
|
176370
177022
|
const repoRoot = naxDir ? dirname48(naxDir) : cwd;
|
|
177023
|
+
const models = await discoverModels(config, deps);
|
|
176371
177024
|
const resources = await chatResources(repoRoot, config, deps);
|
|
176372
177025
|
const log = (stage, message) => deps.writeErr(`[${stage}] ${message}`);
|
|
176373
177026
|
const logger = getSafeLogger2() ?? { warn: log, error: log, info: log, debug: log };
|
|
@@ -176376,6 +177029,7 @@ async function composeChat(options, deps, cwd) {
|
|
|
176376
177029
|
let host;
|
|
176377
177030
|
try {
|
|
176378
177031
|
host = deps.createChatHost({
|
|
177032
|
+
models,
|
|
176379
177033
|
config,
|
|
176380
177034
|
cwd,
|
|
176381
177035
|
repoRoot,
|
|
@@ -176448,6 +177102,7 @@ var SIGNAL_EXIT_CODES, _chatCommandDeps;
|
|
|
176448
177102
|
var init_chat3 = __esm(async () => {
|
|
176449
177103
|
init_internal();
|
|
176450
177104
|
init_source();
|
|
177105
|
+
init_catalog();
|
|
176451
177106
|
init_chat();
|
|
176452
177107
|
init_config();
|
|
176453
177108
|
init_errors4();
|
|
@@ -176457,9 +177112,12 @@ var init_chat3 = __esm(async () => {
|
|
|
176457
177112
|
init_resources();
|
|
176458
177113
|
init_trust();
|
|
176459
177114
|
init_version();
|
|
177115
|
+
init_auth_list();
|
|
176460
177116
|
await init_chat2();
|
|
176461
177117
|
SIGNAL_EXIT_CODES = { SIGTERM: 143, SIGHUP: 129 };
|
|
176462
177118
|
_chatCommandDeps = {
|
|
177119
|
+
collectAuthList,
|
|
177120
|
+
listCatalogModels,
|
|
176463
177121
|
stdinIsTTY: () => process.stdin.isTTY === true,
|
|
176464
177122
|
ensureTrusted: async (cwd) => {
|
|
176465
177123
|
await ensureProjectTrusted(await normalizeTrustPath(resolveTrustRoot(cwd)), { interactive: true });
|
|
@@ -187044,7 +187702,7 @@ await init_build3();
|
|
|
187044
187702
|
// src/tui/App.tsx
|
|
187045
187703
|
init_internal();
|
|
187046
187704
|
await init_build3();
|
|
187047
|
-
var
|
|
187705
|
+
var import_react45 = __toESM(require_react(), 1);
|
|
187048
187706
|
|
|
187049
187707
|
// src/utils/queue-writer.ts
|
|
187050
187708
|
init_errors4();
|
|
@@ -187726,13 +188384,13 @@ function StatusBar({
|
|
|
187726
188384
|
// src/tui/components/StoriesPanel.tsx
|
|
187727
188385
|
init_internal();
|
|
187728
188386
|
await init_build3();
|
|
187729
|
-
var
|
|
188387
|
+
var import_react41 = __toESM(require_react(), 1);
|
|
187730
188388
|
|
|
187731
188389
|
// src/tui/hooks/useLayout.ts
|
|
187732
|
-
var
|
|
188390
|
+
var import_react40 = __toESM(require_react(), 1);
|
|
187733
188391
|
function useLayout() {
|
|
187734
|
-
const [layout, setLayout] =
|
|
187735
|
-
|
|
188392
|
+
const [layout, setLayout] = import_react40.useState(() => computeLayout());
|
|
188393
|
+
import_react40.useEffect(() => {
|
|
187736
188394
|
const handleResize = () => {
|
|
187737
188395
|
setLayout(computeLayout());
|
|
187738
188396
|
};
|
|
@@ -187798,8 +188456,8 @@ function StoriesPanel({
|
|
|
187798
188456
|
}) {
|
|
187799
188457
|
const maxVisible = compact ? COMPACT_MAX_VISIBLE_STORIES : MAX_VISIBLE_STORIES;
|
|
187800
188458
|
const needsScrolling = stories.length > maxVisible;
|
|
187801
|
-
const [scrollOffset, setScrollOffset] =
|
|
187802
|
-
|
|
188459
|
+
const [scrollOffset, setScrollOffset] = import_react41.useState(0);
|
|
188460
|
+
import_react41.useEffect(() => {
|
|
187803
188461
|
const runningIndex = stories.findIndex((s) => s.status === "running");
|
|
187804
188462
|
if (runningIndex !== -1 && needsScrolling) {
|
|
187805
188463
|
if (runningIndex < scrollOffset) {
|
|
@@ -187984,18 +188642,18 @@ function PostRunPhaseRow({ label, phase, compact }) {
|
|
|
187984
188642
|
}
|
|
187985
188643
|
|
|
187986
188644
|
// src/tui/hooks/useAgentStreamEvents.ts
|
|
187987
|
-
var
|
|
188645
|
+
var import_react42 = __toESM(require_react(), 1);
|
|
187988
188646
|
var RENDER_INTERVAL_MS = 150;
|
|
187989
188647
|
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
|
-
|
|
188648
|
+
const activeCallsRef = import_react42.useRef(new Map);
|
|
188649
|
+
const inputTokensRef = import_react42.useRef(0);
|
|
188650
|
+
const outputTokensRef = import_react42.useRef(0);
|
|
188651
|
+
const lastTokensRef = import_react42.useRef(new Map);
|
|
188652
|
+
const dirtyRef = import_react42.useRef(false);
|
|
188653
|
+
const [activeCalls, setActiveCalls] = import_react42.useState(new Map);
|
|
188654
|
+
const [inputTokens, setInputTokens] = import_react42.useState(0);
|
|
188655
|
+
const [outputTokens, setOutputTokens] = import_react42.useState(0);
|
|
188656
|
+
import_react42.useEffect(() => {
|
|
187999
188657
|
if (!bus)
|
|
188000
188658
|
return;
|
|
188001
188659
|
const unsubscribe = bus.onAgentStream((event) => {
|
|
@@ -188091,7 +188749,7 @@ function useAgentStreamEvents(bus) {
|
|
|
188091
188749
|
lastTokensRef.current.clear();
|
|
188092
188750
|
};
|
|
188093
188751
|
}, [bus]);
|
|
188094
|
-
|
|
188752
|
+
import_react42.useEffect(() => {
|
|
188095
188753
|
const interval = setInterval(() => {
|
|
188096
188754
|
if (!dirtyRef.current)
|
|
188097
188755
|
return;
|
|
@@ -188168,10 +188826,10 @@ function useKeyboard({ focus, currentStory, onAction, disabled = false }) {
|
|
|
188168
188826
|
|
|
188169
188827
|
// src/tui/hooks/usePipelineBusEvents.ts
|
|
188170
188828
|
init_pipeline2();
|
|
188171
|
-
var
|
|
188829
|
+
var import_react43 = __toESM(require_react(), 1);
|
|
188172
188830
|
var MAX_ESCALATION_LOG_ENTRIES = 5;
|
|
188173
188831
|
function usePipelineBusEvents(initialStories) {
|
|
188174
|
-
const [state, setState] =
|
|
188832
|
+
const [state, setState] = import_react43.useState(() => ({
|
|
188175
188833
|
stories: initialStories,
|
|
188176
188834
|
totalCost: 0,
|
|
188177
188835
|
runPaused: false,
|
|
@@ -188180,7 +188838,7 @@ function usePipelineBusEvents(initialStories) {
|
|
|
188180
188838
|
storySteps: {},
|
|
188181
188839
|
postRunPhases: {}
|
|
188182
188840
|
}));
|
|
188183
|
-
|
|
188841
|
+
import_react43.useEffect(() => {
|
|
188184
188842
|
const unsubStarted = pipelineEventBus.on("story:started", (event) => {
|
|
188185
188843
|
setState((prev) => ({
|
|
188186
188844
|
...prev,
|
|
@@ -188314,12 +188972,12 @@ function usePipelineBusEvents(initialStories) {
|
|
|
188314
188972
|
}
|
|
188315
188973
|
|
|
188316
188974
|
// src/tui/hooks/usePipelineEvents.ts
|
|
188317
|
-
var
|
|
188975
|
+
var import_react44 = __toESM(require_react(), 1);
|
|
188318
188976
|
var PRE_RUN_STAGES = new Set(["acceptance-setup"]);
|
|
188319
188977
|
function usePipelineEvents(events) {
|
|
188320
|
-
const [currentStage, setCurrentStage] =
|
|
188321
|
-
const [preRunPhases, setPreRunPhases] =
|
|
188322
|
-
|
|
188978
|
+
const [currentStage, setCurrentStage] = import_react44.useState(undefined);
|
|
188979
|
+
const [preRunPhases, setPreRunPhases] = import_react44.useState({});
|
|
188980
|
+
import_react44.useEffect(() => {
|
|
188323
188981
|
const onStageEnter = (stage) => {
|
|
188324
188982
|
setCurrentStage(stage);
|
|
188325
188983
|
if (PRE_RUN_STAGES.has(stage)) {
|
|
@@ -188346,8 +189004,8 @@ function usePipelineEvents(events) {
|
|
|
188346
189004
|
|
|
188347
189005
|
// src/tui/App.tsx
|
|
188348
189006
|
var jsx_dev_runtime13 = __toESM(require_jsx_dev_runtime(), 1);
|
|
188349
|
-
var MemoStoriesPanel =
|
|
188350
|
-
var MemoLiveActivityPanel =
|
|
189007
|
+
var MemoStoriesPanel = import_react45.memo(StoriesPanel);
|
|
189008
|
+
var MemoLiveActivityPanel = import_react45.memo(LiveActivityPanel);
|
|
188351
189009
|
function formatElapsed(ms) {
|
|
188352
189010
|
const mins = Math.floor(ms / 60000);
|
|
188353
189011
|
const secs = Math.floor(ms % 60000 / 1000);
|
|
@@ -188368,20 +189026,20 @@ function App2({ feature, version, stories: initialStories, events, queueFilePath
|
|
|
188368
189026
|
const busState = usePipelineBusEvents(initialStories);
|
|
188369
189027
|
const { currentStage, preRunPhases } = usePipelineEvents(events);
|
|
188370
189028
|
const { exit } = use_app_default();
|
|
188371
|
-
const startTimeRef =
|
|
188372
|
-
const [elapsedMs, setElapsedMs] =
|
|
188373
|
-
|
|
189029
|
+
const startTimeRef = import_react45.useRef(Date.now());
|
|
189030
|
+
const [elapsedMs, setElapsedMs] = import_react45.useState(0);
|
|
189031
|
+
import_react45.useEffect(() => {
|
|
188374
189032
|
if (busState.runSummary)
|
|
188375
189033
|
return;
|
|
188376
189034
|
const timer = setInterval(() => setElapsedMs(Date.now() - startTimeRef.current), 1000);
|
|
188377
189035
|
return () => clearInterval(timer);
|
|
188378
189036
|
}, [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] =
|
|
189037
|
+
const [focus, setFocus] = import_react45.useState("stories" /* Stories */);
|
|
189038
|
+
const [showHelp, setShowHelp] = import_react45.useState(false);
|
|
189039
|
+
const [showCost, setShowCost] = import_react45.useState(false);
|
|
189040
|
+
const [showQuitConfirm, setShowQuitConfirm] = import_react45.useState(false);
|
|
189041
|
+
const [showAbortConfirm, setShowAbortConfirm] = import_react45.useState(false);
|
|
189042
|
+
const [queueActionError, setQueueActionError] = import_react45.useState(undefined);
|
|
188385
189043
|
const { activeCalls, inputTokens, outputTokens } = useAgentStreamEvents(agentStreamEvents);
|
|
188386
189044
|
const isRunComplete = !!busState.runSummary;
|
|
188387
189045
|
const runningStories = busState.stories.filter((s) => s.status === "running");
|