@kmugalkhod/lightcode 0.18.4 → 0.19.0
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/assets/web/{index-kj8t3m63.js → index-1cpyqcg4.js} +56 -56
- package/assets/web/index.html +1 -1
- package/cli.js +94 -47
- package/package.json +1 -1
- package/server.js +408 -151
package/assets/web/index.html
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
<meta name="theme-color" content="#0B0B0C" />
|
|
8
8
|
<title>Lightcode</title>
|
|
9
9
|
|
|
10
|
-
<link rel="stylesheet" crossorigin href="./index-5dh9c5av.css"><script type="module" crossorigin src="./index-
|
|
10
|
+
<link rel="stylesheet" crossorigin href="./index-5dh9c5av.css"><script type="module" crossorigin src="./index-1cpyqcg4.js"></script></head>
|
|
11
11
|
<body>
|
|
12
12
|
<!--
|
|
13
13
|
THESIS: One local coding workspace shared with the CLI; this surface rejects dashboard-card clutter and keeps the project conversation central.
|
package/cli.js
CHANGED
|
@@ -124,7 +124,7 @@ var init_logger = __esm(() => {
|
|
|
124
124
|
});
|
|
125
125
|
|
|
126
126
|
// packages/shared/src/version.ts
|
|
127
|
-
var lightcodeVersion = "0.
|
|
127
|
+
var lightcodeVersion = "0.19.0";
|
|
128
128
|
|
|
129
129
|
// packages/shared/src/index.ts
|
|
130
130
|
var productName = "Lightcode";
|
|
@@ -1110,7 +1110,7 @@ var init_route_registry = __esm(() => {
|
|
|
1110
1110
|
});
|
|
1111
1111
|
|
|
1112
1112
|
// packages/ai/src/constants.ts
|
|
1113
|
-
var MAX_TOOL_TEXT_OUTPUT_CHARS = 12000, DEFAULT_TOOL_TEXT_OUTPUT_CHARS = 6000, MAX_TOOL_LIST_ENTRIES = 200, MAX_TOOL_SEARCH_RESULTS = 200, ANTHROPIC_TOOL_OPTIONAL_PARAMETER_BUDGET = 24, TODO_CONTENT_MAX_CHARS = 200, TODO_ACTIVE_FORM_MAX_CHARS = 80, PROGRESS_NOTE_PRUNE_MIN_CHARS = 200;
|
|
1113
|
+
var MAX_TOOL_TEXT_OUTPUT_CHARS = 12000, DEFAULT_TOOL_TEXT_OUTPUT_CHARS = 6000, READ_FILE_OUTPUT_CHARS = 24000, MAX_TOOL_LIST_ENTRIES = 200, MAX_TOOL_SEARCH_RESULTS = 200, ANTHROPIC_TOOL_OPTIONAL_PARAMETER_BUDGET = 24, TODO_CONTENT_MAX_CHARS = 200, TODO_ACTIVE_FORM_MAX_CHARS = 80, PROGRESS_NOTE_PRUNE_MIN_CHARS = 200;
|
|
1114
1114
|
|
|
1115
1115
|
// packages/ai/src/coding-agent-modes.ts
|
|
1116
1116
|
import { z } from "zod";
|
|
@@ -2485,14 +2485,15 @@ var init_schema8 = __esm(() => {
|
|
|
2485
2485
|
|
|
2486
2486
|
// packages/ai/src/read-file/schema.ts
|
|
2487
2487
|
import { z as z18 } from "zod";
|
|
2488
|
-
var readFileDescription
|
|
2488
|
+
var readFileDescription, readFileInputSchema, readFileProviderInputSchema, readFileOutputSchema;
|
|
2489
2489
|
var init_schema9 = __esm(() => {
|
|
2490
2490
|
init_base_schemas();
|
|
2491
|
+
readFileDescription = "Read file content from the working directory. Returns whole lines, up to about 24,000 characters (roughly 600 lines) per call, so read a file in one call instead of in slices. " + "If the file is longer, the result stops at endLine and nextStartLine says where to continue. " + "To inspect one spot in a large file, grep for it first, then read a generous startLine/endLine range around it.";
|
|
2491
2492
|
readFileInputSchema = z18.object({
|
|
2492
2493
|
path: boundedPathSchema,
|
|
2493
2494
|
startLine: positiveLineSchema.optional(),
|
|
2494
2495
|
endLine: positiveLineSchema.optional(),
|
|
2495
|
-
maxChars: integerRangeSchema(1,
|
|
2496
|
+
maxChars: integerRangeSchema(1, READ_FILE_OUTPUT_CHARS, "maxChars").optional()
|
|
2496
2497
|
}).superRefine((value, ctx) => {
|
|
2497
2498
|
if (value.startLine !== undefined && value.endLine !== undefined && value.endLine < value.startLine) {
|
|
2498
2499
|
ctx.addIssue({
|
|
@@ -2513,7 +2514,8 @@ var init_schema9 = __esm(() => {
|
|
|
2513
2514
|
endLine: z18.number().int().min(1),
|
|
2514
2515
|
content: z18.string(),
|
|
2515
2516
|
totalLines: z18.number().int().nonnegative(),
|
|
2516
|
-
truncated: z18.boolean()
|
|
2517
|
+
truncated: z18.boolean(),
|
|
2518
|
+
nextStartLine: z18.number().int().min(1).optional()
|
|
2517
2519
|
});
|
|
2518
2520
|
});
|
|
2519
2521
|
|
|
@@ -2833,7 +2835,7 @@ var init_tool_registry = __esm(() => {
|
|
|
2833
2835
|
permissionMode: "read-only",
|
|
2834
2836
|
execution: "server",
|
|
2835
2837
|
availability: "git-workspace",
|
|
2836
|
-
activation: "
|
|
2838
|
+
activation: "core",
|
|
2837
2839
|
outputPolicy: "artifact-if-large"
|
|
2838
2840
|
},
|
|
2839
2841
|
git_diff: {
|
|
@@ -2846,7 +2848,7 @@ var init_tool_registry = __esm(() => {
|
|
|
2846
2848
|
permissionMode: "read-only",
|
|
2847
2849
|
execution: "server",
|
|
2848
2850
|
availability: "git-workspace",
|
|
2849
|
-
activation: "
|
|
2851
|
+
activation: "core",
|
|
2850
2852
|
outputPolicy: "artifact-if-large"
|
|
2851
2853
|
},
|
|
2852
2854
|
git_log: {
|
|
@@ -2859,7 +2861,7 @@ var init_tool_registry = __esm(() => {
|
|
|
2859
2861
|
permissionMode: "read-only",
|
|
2860
2862
|
execution: "server",
|
|
2861
2863
|
availability: "git-workspace",
|
|
2862
|
-
activation: "
|
|
2864
|
+
activation: "core",
|
|
2863
2865
|
outputPolicy: "artifact-if-large"
|
|
2864
2866
|
},
|
|
2865
2867
|
git_show: {
|
|
@@ -2872,7 +2874,7 @@ var init_tool_registry = __esm(() => {
|
|
|
2872
2874
|
permissionMode: "read-only",
|
|
2873
2875
|
execution: "server",
|
|
2874
2876
|
availability: "git-workspace",
|
|
2875
|
-
activation: "
|
|
2877
|
+
activation: "core",
|
|
2876
2878
|
outputPolicy: "artifact-if-large"
|
|
2877
2879
|
},
|
|
2878
2880
|
tool_search: {
|
|
@@ -3279,6 +3281,7 @@ var init_agent_tools = __esm(() => {
|
|
|
3279
3281
|
contextWindow: z26.number().int().positive().optional(),
|
|
3280
3282
|
preserveRecentTokens: z26.number().int().nonnegative().optional(),
|
|
3281
3283
|
originalInputTokens: z26.number().int().nonnegative().optional(),
|
|
3284
|
+
promptCacheActive: z26.boolean().optional(),
|
|
3282
3285
|
assemblyAbortSignal: z26.custom().optional(),
|
|
3283
3286
|
turnKey: z26.string().min(1).max(200).optional()
|
|
3284
3287
|
});
|
|
@@ -3608,10 +3611,10 @@ ${environmentContext.trim()}` : "");
|
|
|
3608
3611
|
var cwdPromptPlaceholder = "{cwd}", defaultCodingAgentSystemPrompt, toolCallingDisciplineAddendum;
|
|
3609
3612
|
var init_coding_agent_prompt = __esm(() => {
|
|
3610
3613
|
init_coding_agent_modes();
|
|
3611
|
-
defaultCodingAgentSystemPrompt = "You are a coding agent working inside the user's project at this working directory: {cwd}. " + 'You can already see the project \u2014 proactively read it. When the user asks you to review, explain, or work on "my code"/"this", inspect the working directory yourself with list_files, glob_search, grep, and read_file; NEVER ask the user to paste or share code that lives in this directory \u2014 open it. ' + "Use tools for filesystem and codebase tasks instead of guessing, and only interact with files under the working directory. " + "Prefer dedicated tools \u2014 glob_search for paths, grep for text search, structured git tools for repository inspection \u2014 and bash only when those are not enough. " + "Check the available skill descriptions for every task. When a skill is explicitly named or clearly matches the task, load it with the skill tool before acting and follow its instructions within the user's scope and tool permissions. Skill files may be installed outside the workspace; use the skill tool to read their relative supporting resources. Never claim to have used a skill you have not loaded. " + `Inspect context before risky operations. Progress notes: before a major tool action you may emit ONE short note (one sentence, ~15 words) saying what you are about to do. After a tool returns, mention a finding only if it changes your plan, and state it as fact grounded in what the tool actually returned \u2014 cite the file/line/symbol. NEVER claim you found, changed, or fixed something before a tool result confirms it. Skip notes for routine reads, and do not restate the todo list in prose.
|
|
3614
|
+
defaultCodingAgentSystemPrompt = "You are a coding agent working inside the user's project at this working directory: {cwd}. " + 'You can already see the project \u2014 proactively read it. When the user asks you to review, explain, or work on "my code"/"this", inspect the working directory yourself with list_files, glob_search, grep, and read_file; NEVER ask the user to paste or share code that lives in this directory \u2014 open it. ' + "Use tools for filesystem and codebase tasks instead of guessing, and only interact with files under the working directory. " + "Prefer dedicated tools \u2014 glob_search for paths, grep for text search, structured git tools for repository inspection \u2014 and bash only when those are not enough. " + "Gather context efficiently \u2014 every tool round trip costs the user seconds. The environment section maps the repository's files: use it to go straight to the right paths instead of listing directories. Locate before you read: use grep or glob_search to find the relevant files and line numbers, then read whole files (read_file returns up to about 600 lines per call) or, in larger files, a range of a few hundred lines around the spot \u2014 never many small slices, and never re-read content you already have. When several reads or searches do not depend on each other, request them together in one step. Skip generated output (dist/, build/, minified bundles, node_modules) unless the task is about it. Stop exploring once you have enough evidence to act or answer. " + "Check the available skill descriptions for every task. When a skill is explicitly named or clearly matches the task, load it with the skill tool before acting and follow its instructions within the user's scope and tool permissions. Skill files may be installed outside the workspace; use the skill tool to read their relative supporting resources. Never claim to have used a skill you have not loaded. " + `Inspect context before risky operations. Progress notes: before a major tool action you may emit ONE short note (one sentence, ~15 words) saying what you are about to do. After a tool returns, mention a finding only if it changes your plan, and state it as fact grounded in what the tool actually returned \u2014 cite the file/line/symbol. NEVER claim you found, changed, or fixed something before a tool result confirms it. Skip notes for routine reads, and do not restate the todo list in prose.
|
|
3612
3615
|
|
|
3613
3616
|
` + `Task list discipline \u2014 use the todo_write tool to keep a visible, evolving checklist:
|
|
3614
|
-
` + `- Create the list
|
|
3617
|
+
` + `- Create the list in your first step. For any task with roughly three or more distinct steps, or any multi-file or multi-stage work, call todo_write in your first response with every step listed and all of them set to pending \u2014 request it together with your first reads or searches, not as a separate step, and always before any edit.
|
|
3615
3618
|
` + `- Keep exactly ONE item in_progress at a time. Mark an item in_progress immediately before you start it; never have two items in_progress at once.
|
|
3616
3619
|
` + `- Mark an item completed only after a tool result confirms it is actually done (test passed, file written, build clean) \u2014 not on intent. Do this the MOMENT it is confirmed; do not batch completions or wait until the end of the turn.
|
|
3617
3620
|
` + `- Completions are monotonic: once a task is completed, do not silently move it back to pending or in_progress. Reopen it only if it genuinely regressed.
|
|
@@ -3623,7 +3626,7 @@ var init_coding_agent_prompt = __esm(() => {
|
|
|
3623
3626
|
` + `When the task is complete, end with a short summary (a few lines) grounded in the todos you actually completed and the real file diffs \u2014 name the files you edited, do not list steps you did not verify, and do not repeat the todo card verbatim. If anything is incomplete or you are blocked, say so plainly.
|
|
3624
3627
|
|
|
3625
3628
|
` + "Long-running processes (dev servers, watchers): never run them as plain foreground bash \u2014 the bash tool enforces a timeout and will kill them. Start them detached with output redirected to a log " + '(Windows: start /B cmd /c "npm run dev > dev.log 2>&1"; Unix: nohup npm run dev > dev.log 2>&1 &), then read the log to confirm startup and the actual port (do not assume the default). ' + "Never kill processes or free ports you did not open yourself.";
|
|
3626
|
-
toolCallingDisciplineAddendum = "Invoke tools only through the function-calling interface. " + "Never write tool calls as XML or plain text such as <tool_call>, <function_call>, <invoke>, or bare JSON in your message. " + "Tool arguments must be valid JSON matching the tool's schema. " + "
|
|
3629
|
+
toolCallingDisciplineAddendum = "Invoke tools only through the function-calling interface. " + "Never write tool calls as XML or plain text such as <tool_call>, <function_call>, <invoke>, or bare JSON in your message. " + "Tool arguments must be valid JSON matching the tool's schema. " + "You may request several independent tool calls in one response; wait for their results before making calls that depend on them.";
|
|
3627
3630
|
});
|
|
3628
3631
|
|
|
3629
3632
|
// packages/ai/src/common/coerce-tool-input.ts
|
|
@@ -4021,20 +4024,26 @@ function collectTextFromUnknown(value) {
|
|
|
4021
4024
|
}
|
|
4022
4025
|
return "";
|
|
4023
4026
|
}
|
|
4024
|
-
function
|
|
4027
|
+
function getUserTexts(messages, prompt) {
|
|
4028
|
+
const texts = [];
|
|
4025
4029
|
if (Array.isArray(messages)) {
|
|
4026
|
-
for (
|
|
4027
|
-
const message = messages[index];
|
|
4030
|
+
for (const message of messages) {
|
|
4028
4031
|
if (!isRecord4(message) || message.role !== "user") {
|
|
4029
4032
|
continue;
|
|
4030
4033
|
}
|
|
4031
4034
|
const text = collectTextFromUnknown(message).trim();
|
|
4032
4035
|
if (text) {
|
|
4033
|
-
|
|
4036
|
+
texts.push(text);
|
|
4034
4037
|
}
|
|
4035
4038
|
}
|
|
4036
4039
|
}
|
|
4037
|
-
|
|
4040
|
+
if (texts.length === 0) {
|
|
4041
|
+
const promptText = collectTextFromUnknown(prompt).trim();
|
|
4042
|
+
if (promptText) {
|
|
4043
|
+
texts.push(promptText);
|
|
4044
|
+
}
|
|
4045
|
+
}
|
|
4046
|
+
return texts;
|
|
4038
4047
|
}
|
|
4039
4048
|
function escapeRegExp(value) {
|
|
4040
4049
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -4060,23 +4069,20 @@ function selectCodingAgentIntentTools({
|
|
|
4060
4069
|
messages,
|
|
4061
4070
|
availableSkillNames = []
|
|
4062
4071
|
}) {
|
|
4063
|
-
const
|
|
4064
|
-
|
|
4065
|
-
if (!normalizedText || casualPromptPattern.test(normalizedText)) {
|
|
4072
|
+
const userTexts = getUserTexts(messages, prompt);
|
|
4073
|
+
if (userTexts.every((text) => casualPromptPattern.test(text))) {
|
|
4066
4074
|
return [];
|
|
4067
4075
|
}
|
|
4076
|
+
const latestText = userTexts.at(-1) ?? "";
|
|
4068
4077
|
const modeTools = getRegistryToolsForMode(mode);
|
|
4069
4078
|
const selected = new Set(modeTools.filter((toolName) => codingToolRegistry[toolName].activation === "core"));
|
|
4070
|
-
if (
|
|
4071
|
-
addTools(selected, gitToolNames);
|
|
4072
|
-
}
|
|
4073
|
-
if (webIntentPattern.test(userText)) {
|
|
4079
|
+
if (webIntentPattern.test(latestText)) {
|
|
4074
4080
|
addTools(selected, webToolNames);
|
|
4075
4081
|
}
|
|
4076
|
-
if (mcpIntentPattern.test(
|
|
4082
|
+
if (userTexts.some((text) => mcpIntentPattern.test(text))) {
|
|
4077
4083
|
addTools(selected, mcpToolNames);
|
|
4078
4084
|
}
|
|
4079
|
-
if (skillIntentPattern.test(
|
|
4085
|
+
if (userTexts.some((text) => skillIntentPattern.test(text) || requestsAvailableSkill(text, availableSkillNames))) {
|
|
4080
4086
|
selected.add("skill");
|
|
4081
4087
|
}
|
|
4082
4088
|
return modeTools.filter((toolName) => selected.has(toolName));
|
|
@@ -4156,21 +4162,14 @@ function limitProviderActiveTools(tools, maxTools = maxProviderActiveTools) {
|
|
|
4156
4162
|
const toolSet = new Set(tools);
|
|
4157
4163
|
return providerToolPriority.filter((toolName) => toolSet.has(toolName)).slice(0, maxTools);
|
|
4158
4164
|
}
|
|
4159
|
-
var casualPromptPattern,
|
|
4165
|
+
var casualPromptPattern, webIntentPattern, mcpIntentPattern, skillIntentPattern, webToolNames, mcpToolNames, maxProviderActiveTools = 24, providerToolPriority;
|
|
4160
4166
|
var init_intent_tool_selection = __esm(() => {
|
|
4161
4167
|
init_coding_agent_modes();
|
|
4162
4168
|
init_tool_registry();
|
|
4163
4169
|
casualPromptPattern = /^(hi|hello|hey|how are you|how r you|what'?s up|whats up|sup|thanks|thank you|ok|okay|yes|no|nice|cool|great)[\s?!.,]*$/i;
|
|
4164
|
-
gitIntentPattern = /(?:\bgit\b|\bcommits?\b|\bstaged?\b|\bunstaged\b|\buntracked\b|\bworking tree\b|\brepositor(?:y|ies)\s+(?:status|diff|history|changes))/i;
|
|
4165
4170
|
webIntentPattern = /(?:\bhttps?:\/\/|\bwww\.|\bweb(?:site|page)?\b|\binternet\b|\bonline\b|\burl\b|\bbrowser\b|\bsearch\s+(?:the\s+)?web\b|\bbrowse\s+(?:the\s+web|online|for)\b|\blook\s+up\b|\b(?:latest|current|recent|today'?s)\s+(?:news|price|weather|docs?|documentation|release|version)\b)/i;
|
|
4166
4171
|
mcpIntentPattern = /(?:\bmcp\b|\bmodel context protocol\b)/i;
|
|
4167
4172
|
skillIntentPattern = /\bskills?\b/i;
|
|
4168
|
-
gitToolNames = [
|
|
4169
|
-
"git_status",
|
|
4170
|
-
"git_diff",
|
|
4171
|
-
"git_log",
|
|
4172
|
-
"git_show"
|
|
4173
|
-
];
|
|
4174
4173
|
webToolNames = [
|
|
4175
4174
|
"web_fetch",
|
|
4176
4175
|
"web_search"
|
|
@@ -5733,19 +5732,44 @@ async function executeReadFile(input, workspaceContext = getDefaultWorkspaceCont
|
|
|
5733
5732
|
const fileContent = await fs4.readFile(resolvedPath, "utf8");
|
|
5734
5733
|
const lines = fileContent.split(/\r?\n/);
|
|
5735
5734
|
const { start, end } = clampLineRange(lines.length, parsedInput.startLine, parsedInput.endLine);
|
|
5736
|
-
const
|
|
5737
|
-
|
|
5738
|
-
const
|
|
5739
|
-
const truncated = truncateText(selectedContent, maxChars);
|
|
5735
|
+
const maxChars = parsedInput.maxChars ?? READ_FILE_OUTPUT_CHARS;
|
|
5736
|
+
const taken = takeWholeLines(lines.slice(start - 1, end), maxChars);
|
|
5737
|
+
const lastLine = start + taken.lineCount - 1;
|
|
5740
5738
|
return readFileOutputSchema.parse({
|
|
5741
5739
|
path: relativePath,
|
|
5742
5740
|
startLine: start,
|
|
5743
|
-
endLine:
|
|
5744
|
-
content:
|
|
5741
|
+
endLine: lastLine,
|
|
5742
|
+
content: taken.text,
|
|
5745
5743
|
totalLines: lines.length,
|
|
5746
|
-
truncated:
|
|
5744
|
+
truncated: taken.truncated,
|
|
5745
|
+
...lastLine < end ? { nextStartLine: lastLine + 1 } : {}
|
|
5747
5746
|
});
|
|
5748
5747
|
}
|
|
5748
|
+
function takeWholeLines(lines, maxChars) {
|
|
5749
|
+
let used = 0;
|
|
5750
|
+
let lineCount = 0;
|
|
5751
|
+
for (const line of lines) {
|
|
5752
|
+
const cost = line.length + (lineCount > 0 ? 1 : 0);
|
|
5753
|
+
if (used + cost > maxChars) {
|
|
5754
|
+
break;
|
|
5755
|
+
}
|
|
5756
|
+
used += cost;
|
|
5757
|
+
lineCount += 1;
|
|
5758
|
+
}
|
|
5759
|
+
if (lineCount === 0 && lines.length > 0) {
|
|
5760
|
+
return {
|
|
5761
|
+
text: truncateText(lines[0] ?? "", maxChars).text,
|
|
5762
|
+
lineCount: 1,
|
|
5763
|
+
truncated: true
|
|
5764
|
+
};
|
|
5765
|
+
}
|
|
5766
|
+
return {
|
|
5767
|
+
text: lines.slice(0, lineCount).join(`
|
|
5768
|
+
`),
|
|
5769
|
+
lineCount,
|
|
5770
|
+
truncated: lineCount < lines.length
|
|
5771
|
+
};
|
|
5772
|
+
}
|
|
5749
5773
|
var init_runtime8 = __esm(() => {
|
|
5750
5774
|
init_resolve_within_workspace();
|
|
5751
5775
|
init_output_utils();
|
|
@@ -7049,10 +7073,12 @@ function buildProviderView(options) {
|
|
|
7049
7073
|
}
|
|
7050
7074
|
const tokenBoundedCutoffIndex = computeTokenBoundedCompactionCutoffIndex(messages, preserveRecentTokens, afterAnchorIndex);
|
|
7051
7075
|
const userIndicesAfterAnchor = messages.map((message, index) => ({ message, index })).filter(({ message, index }) => index >= afterAnchorIndex && message.role === "user").map(({ index }) => index);
|
|
7052
|
-
const
|
|
7076
|
+
const rollingKeepUserTurns = Math.max(1, Math.ceil(config.uncachedRollingCompactionUserTurns / 2));
|
|
7077
|
+
const rollingTurnCutoffIndex = userIndicesAfterAnchor.length > rollingKeepUserTurns ? userIndicesAfterAnchor[userIndicesAfterAnchor.length - rollingKeepUserTurns] ?? afterAnchorIndex : afterAnchorIndex;
|
|
7053
7078
|
const overCompactThreshold = triggerTokens(estimate.tokens) > config.compactAtFraction * inputBudgetTokens;
|
|
7079
|
+
const rollingActive = (options.rollingCompaction ?? options.cacheActive === false) && config.aggressivePruneWhenUncached;
|
|
7054
7080
|
const userTurnsAfterAnchor = messages.slice(afterAnchorIndex).filter((message) => message.role === "user").length;
|
|
7055
|
-
const rollingThresholdReached =
|
|
7081
|
+
const rollingThresholdReached = rollingActive && userTurnsAfterAnchor > (options.continueRolling ? rollingKeepUserTurns : config.uncachedRollingCompactionUserTurns);
|
|
7056
7082
|
const compactionCutoffIndex = rollingThresholdReached ? Math.max(tokenBoundedCutoffIndex, rollingTurnCutoffIndex) : tokenBoundedCutoffIndex;
|
|
7057
7083
|
const coveredMessages = capCoverageToTokenBudget(messages.slice(afterAnchorIndex, compactionCutoffIndex), config.maxCoverageTokensPerCompaction);
|
|
7058
7084
|
let compactionBlockedReason = null;
|
|
@@ -7509,6 +7535,14 @@ import path12 from "path";
|
|
|
7509
7535
|
import {
|
|
7510
7536
|
toolModelMessageSchema
|
|
7511
7537
|
} from "ai";
|
|
7538
|
+
function resolveToolOutputArtifactThresholds({
|
|
7539
|
+
promptCacheActive
|
|
7540
|
+
}) {
|
|
7541
|
+
return {
|
|
7542
|
+
thresholdCharacters: promptCacheActive ? DEFAULT_CURRENT_TURN_TOOL_OUTPUT_THRESHOLD_CHARACTERS : DEFAULT_TOOL_OUTPUT_ARTIFACT_THRESHOLD_CHARACTERS,
|
|
7543
|
+
currentTurnThresholdCharacters: DEFAULT_CURRENT_TURN_TOOL_OUTPUT_THRESHOLD_CHARACTERS
|
|
7544
|
+
};
|
|
7545
|
+
}
|
|
7512
7546
|
function isRecord10(value) {
|
|
7513
7547
|
return typeof value === "object" && value !== null;
|
|
7514
7548
|
}
|
|
@@ -7688,12 +7722,19 @@ async function artifactizeLargeToolOutputs(messages, options = {}) {
|
|
|
7688
7722
|
if (previewCharacters < MIN_TOOL_OUTPUT_ARTIFACT_PREVIEW_CHARACTERS) {
|
|
7689
7723
|
throw new RangeError(`Tool-output artifact previews must allow at least ${MIN_TOOL_OUTPUT_ARTIFACT_PREVIEW_CHARACTERS} characters.`);
|
|
7690
7724
|
}
|
|
7725
|
+
const currentTurnThreshold = Math.max(0, Math.floor(options.currentTurnThresholdCharacters ?? thresholdCharacters));
|
|
7726
|
+
let currentTurnStart = 0;
|
|
7727
|
+
messages.forEach((message, index) => {
|
|
7728
|
+
if (message.role === "user")
|
|
7729
|
+
currentTurnStart = index + 1;
|
|
7730
|
+
});
|
|
7691
7731
|
const uniqueArtifacts = new Map;
|
|
7692
7732
|
let artifactizedOutputs = 0;
|
|
7693
7733
|
let savedCharacters = 0;
|
|
7694
7734
|
const providerMessages = [];
|
|
7695
|
-
for (const message of messages) {
|
|
7735
|
+
for (const [index, message] of messages.entries()) {
|
|
7696
7736
|
options.signal?.throwIfAborted();
|
|
7737
|
+
const limit = index >= currentTurnStart ? currentTurnThreshold : thresholdCharacters;
|
|
7697
7738
|
if (!Array.isArray(message.content)) {
|
|
7698
7739
|
providerMessages.push(message);
|
|
7699
7740
|
continue;
|
|
@@ -7707,7 +7748,7 @@ async function artifactizeLargeToolOutputs(messages, options = {}) {
|
|
|
7707
7748
|
}
|
|
7708
7749
|
const output = part.output;
|
|
7709
7750
|
const serialized = serializeToolResultOutput(output);
|
|
7710
|
-
if (serialized.length <=
|
|
7751
|
+
if (serialized.length <= limit) {
|
|
7711
7752
|
providerContent.push(part);
|
|
7712
7753
|
continue;
|
|
7713
7754
|
}
|
|
@@ -7791,7 +7832,7 @@ async function toolOutputArtifactExists(handleOrDigest, dataDir = getLightcodeDa
|
|
|
7791
7832
|
throw error;
|
|
7792
7833
|
}
|
|
7793
7834
|
}
|
|
7794
|
-
var TOOL_OUTPUT_ARTIFACT_HANDLE_PREFIX = "lightcode-artifact://tool-output/sha256/", DEFAULT_TOOL_OUTPUT_ARTIFACT_THRESHOLD_CHARACTERS, DEFAULT_TOOL_OUTPUT_ARTIFACT_PREVIEW_CHARACTERS = 2400, MIN_TOOL_OUTPUT_ARTIFACT_PREVIEW_CHARACTERS = 512, SHA256_PATTERN, ARTIFACT_PREVIEW_MARKER = "[Lightcode tool-output artifact]";
|
|
7835
|
+
var TOOL_OUTPUT_ARTIFACT_HANDLE_PREFIX = "lightcode-artifact://tool-output/sha256/", DEFAULT_TOOL_OUTPUT_ARTIFACT_THRESHOLD_CHARACTERS, DEFAULT_CURRENT_TURN_TOOL_OUTPUT_THRESHOLD_CHARACTERS = 32000, DEFAULT_TOOL_OUTPUT_ARTIFACT_PREVIEW_CHARACTERS = 2400, MIN_TOOL_OUTPUT_ARTIFACT_PREVIEW_CHARACTERS = 512, SHA256_PATTERN, ARTIFACT_PREVIEW_MARKER = "[Lightcode tool-output artifact]";
|
|
7795
7836
|
var init_tool_output_artifacts = __esm(() => {
|
|
7796
7837
|
init_src();
|
|
7797
7838
|
DEFAULT_TOOL_OUTPUT_ARTIFACT_THRESHOLD_CHARACTERS = DEFAULT_TOOL_TEXT_OUTPUT_CHARS;
|
|
@@ -9210,7 +9251,10 @@ function createCodingAgent({
|
|
|
9210
9251
|
originalInputTokens: context.originalInputTokens
|
|
9211
9252
|
});
|
|
9212
9253
|
const artifactized = await artifactizeLargeToolOutputs(messages, {
|
|
9213
|
-
signal: context.assemblyAbortSignal
|
|
9254
|
+
signal: context.assemblyAbortSignal,
|
|
9255
|
+
...resolveToolOutputArtifactThresholds({
|
|
9256
|
+
promptCacheActive: context.promptCacheActive ?? false
|
|
9257
|
+
})
|
|
9214
9258
|
});
|
|
9215
9259
|
const assembled = assembler.assembleModelMessages(artifactized.messages, {
|
|
9216
9260
|
preserveRecentTokens: context.preserveRecentTokens
|
|
@@ -9276,6 +9320,7 @@ function createCodingAgent({
|
|
|
9276
9320
|
reservedOutputTokens: options.maxOutputTokens,
|
|
9277
9321
|
preserveRecentTokens: options.preserveRecentTokens,
|
|
9278
9322
|
originalInputTokens: options.originalInputTokens,
|
|
9323
|
+
promptCacheActive: options.promptCacheActive,
|
|
9279
9324
|
assemblyAbortSignal: options.assemblyAbortSignal
|
|
9280
9325
|
},
|
|
9281
9326
|
instructions
|
|
@@ -16560,6 +16605,7 @@ __export(exports_runtime, {
|
|
|
16560
16605
|
resolveWithinWorkspace: () => resolveWithinWorkspace,
|
|
16561
16606
|
resolveWebSearchCapability: () => resolveWebSearchCapability,
|
|
16562
16607
|
resolveWebSearchApiKeys: () => resolveWebSearchApiKeys,
|
|
16608
|
+
resolveToolOutputArtifactThresholds: () => resolveToolOutputArtifactThresholds,
|
|
16563
16609
|
resolveProviderWebSearchAccess: () => resolveProviderWebSearchAccess,
|
|
16564
16610
|
resolvePreserveRecentTokens: () => resolvePreserveRecentTokens,
|
|
16565
16611
|
resolveMaxOutputTokens: () => resolveMaxOutputTokens,
|
|
@@ -16805,6 +16851,7 @@ __export(exports_runtime, {
|
|
|
16805
16851
|
DEFAULT_PRUNE_QUANTIZE_USER_TURNS: () => DEFAULT_PRUNE_QUANTIZE_USER_TURNS,
|
|
16806
16852
|
DEFAULT_PRUNE_MIN_OUTPUT_CHARS: () => DEFAULT_PRUNE_MIN_OUTPUT_CHARS,
|
|
16807
16853
|
DEFAULT_INPUT_BUDGET_SAFETY_FRACTION: () => DEFAULT_INPUT_BUDGET_SAFETY_FRACTION,
|
|
16854
|
+
DEFAULT_CURRENT_TURN_TOOL_OUTPUT_THRESHOLD_CHARACTERS: () => DEFAULT_CURRENT_TURN_TOOL_OUTPUT_THRESHOLD_CHARACTERS,
|
|
16808
16855
|
DEFAULT_CONTEXT_WINDOW_TOKENS: () => DEFAULT_CONTEXT_WINDOW_TOKENS,
|
|
16809
16856
|
CheckpointConflictError: () => CheckpointConflictError,
|
|
16810
16857
|
ANTHROPIC_TOOL_OPTIONAL_PARAMETER_BUDGET: () => ANTHROPIC_TOOL_OPTIONAL_PARAMETER_BUDGET
|