@causyne/agent 1.20.93 → 1.20.95
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/package.json +1 -1
- package/src/agentLoop.js +72 -74
- package/src/agentLoop.ts +72 -70
- package/src/budget/budgetPolicy.js +92 -0
- package/src/budget/budgetPolicy.ts +107 -0
- package/src/contextManager.js +2 -0
- package/src/historyPruner.js +16 -1
- package/src/historyPruner.ts +13 -1
- package/src/providers/antigravity.js +27 -43
- package/src/providers/antigravity.ts +35 -45
- package/src/sandbox.js +18 -12
- package/src/tokenTracker.js +24 -0
- package/src/tokenTracker.ts +25 -0
- package/src/tools/deferredMcpSearch.js +76 -38
- package/src/tools/deferredMcpSearch.ts +66 -28
- package/src/tools/readNativeSkill.js +34 -42
- package/src/tools/readNativeSkill.ts +38 -36
- package/src/tools/searchRelevance.js +70 -0
- package/src/tools/searchRelevance.ts +72 -0
- package/src/tools/toolSelfRepair.js +9 -4
- package/src/tools/toolSelfRepair.ts +9 -4
- package/src/tui/composerGeometry.js +45 -0
- package/src/tui/composerGeometry.ts +80 -0
- package/src/tui/homeView.js +10 -6
- package/src/tui/homeView.ts +10 -6
- package/src/tui/lineEditor.js +8 -0
- package/src/tui/prompt.js +9 -4
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Causyne Agent — word-level relevance for tool and skill discovery.
|
|
3
|
+
*
|
|
4
|
+
* Substring matching made short query words hit unrelated entries ("and"
|
|
5
|
+
* inside "command", "kill" inside "skill", "git" inside "digit"), so one
|
|
6
|
+
* capability search could unlock a dozen irrelevant tool schemas. Matching is
|
|
7
|
+
* done on whole words with a bounded prefix rule instead. Deterministic,
|
|
8
|
+
* synchronous, linear-time, and never compiles user-supplied patterns.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** English function words and search meta-words that carry no capability signal. */
|
|
12
|
+
const STOPWORDS = new Set([
|
|
13
|
+
'and', 'the', 'for', 'with', 'from', 'into', 'onto', 'that', 'this', 'these', 'those',
|
|
14
|
+
'using', 'use', 'via', 'any', 'all', 'are', 'was', 'were', 'can', 'how', 'what', 'which',
|
|
15
|
+
'when', 'where', 'who', 'why', 'you', 'your', 'our', 'its', 'not', 'but', 'has', 'have',
|
|
16
|
+
'should', 'would', 'could', 'please', 'about', 'also', 'then', 'than', 'them', 'they',
|
|
17
|
+
'there', 'some', 'more', 'most', 'each', 'other', 'only', 'own', 'same', 'such', 'very',
|
|
18
|
+
'just', 'like', 'need', 'want', 'help', 'let', 'get', 'take', 'out', 'over', 'under', 'per',
|
|
19
|
+
'capability', 'capabilities', 'matching'
|
|
20
|
+
]);
|
|
21
|
+
|
|
22
|
+
/** Upper bound on distinct query terms, so scoring cost stays constant. */
|
|
23
|
+
export const MAX_RELEVANCE_TERMS = 16;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Lower-case text and fold British -ise/-isation spellings onto -ize/-ization
|
|
27
|
+
* so "optimisation" and "optimization" compare equal. Applied identically to
|
|
28
|
+
* queries and catalog text.
|
|
29
|
+
*/
|
|
30
|
+
export function normalizeSpelling(text: string): string {
|
|
31
|
+
return text.toLowerCase().replace(/is(ations?|ing|ed|es|e)\b/g, 'iz$1');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Distinct meaningful query terms: alphanumeric words longer than two characters. */
|
|
35
|
+
export function queryTerms(query: string): string[] {
|
|
36
|
+
const terms: string[] = [];
|
|
37
|
+
for (const word of normalizeSpelling(String(query || '')).split(/[^a-z0-9]+/)) {
|
|
38
|
+
if (word.length <= 2 || STOPWORDS.has(word) || terms.includes(word)) continue;
|
|
39
|
+
terms.push(word);
|
|
40
|
+
if (terms.length >= MAX_RELEVANCE_TERMS) break;
|
|
41
|
+
}
|
|
42
|
+
return terms;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Whole words of catalog text, splitting snake_case, kebab-case and camelCase names. */
|
|
46
|
+
export function wordsOf(text: string): Set<string> {
|
|
47
|
+
const spaced = String(text || '').replace(/([a-z0-9])([A-Z])/g, '$1 $2');
|
|
48
|
+
return new Set(normalizeSpelling(spaced).split(/[^a-z0-9]+/).filter(word => word.length > 0));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* A term matches a word exactly, or as a bounded stem: "build" matches
|
|
53
|
+
* "builds"/"builder", and "screenshots" matches "screenshot". Short words
|
|
54
|
+
* never match as a fragment of a longer one.
|
|
55
|
+
*/
|
|
56
|
+
export function termMatches(term: string, words: Set<string>): boolean {
|
|
57
|
+
if (words.has(term)) return true;
|
|
58
|
+
for (const word of words) {
|
|
59
|
+
if (term.length >= 4 && word.startsWith(term)) return true;
|
|
60
|
+
if (word.length >= 4 && term.startsWith(word) && term.length - word.length <= 3) return true;
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Minimum number of distinct query terms an entry must match. A multi-word
|
|
67
|
+
* capability description is not satisfied by an entry that shares only one
|
|
68
|
+
* generic word with it (for example "build" in "android build optimization").
|
|
69
|
+
*/
|
|
70
|
+
export function requiredCoverage(termCount: number): number {
|
|
71
|
+
return termCount >= 3 ? 2 : 1;
|
|
72
|
+
}
|
|
@@ -978,9 +978,10 @@ export function coerceArgumentTypes(toolName, args, schema) {
|
|
|
978
978
|
/**
|
|
979
979
|
* Automatically normalize relative file paths to absolute paths using cwd.
|
|
980
980
|
*/
|
|
981
|
-
export function normalizePaths(args, cwd = process.cwd(), schema) {
|
|
981
|
+
export function normalizePaths(args, cwd = process.cwd(), schema, options = {}) {
|
|
982
982
|
const repairs = [];
|
|
983
983
|
const modified = { ...args };
|
|
984
|
+
const skipKeys = new Set(options.skipKeys || []);
|
|
984
985
|
const targetSchema = schema?.properties?.target;
|
|
985
986
|
const hasEnumTarget = Boolean(targetSchema && 'enum' in targetSchema);
|
|
986
987
|
const pathKeys = [
|
|
@@ -1007,12 +1008,14 @@ export function normalizePaths(args, cwd = process.cwd(), schema) {
|
|
|
1007
1008
|
return rawValue;
|
|
1008
1009
|
};
|
|
1009
1010
|
for (const key of pathKeys) {
|
|
1011
|
+
if (skipKeys.has(key))
|
|
1012
|
+
continue;
|
|
1010
1013
|
const val = modified[key];
|
|
1011
1014
|
if (typeof val === 'string' && val.trim() !== '') {
|
|
1012
1015
|
modified[key] = normalizeOne(val, key);
|
|
1013
1016
|
}
|
|
1014
1017
|
}
|
|
1015
|
-
if (Array.isArray(modified.target_directories)) {
|
|
1018
|
+
if (!skipKeys.has('target_directories') && Array.isArray(modified.target_directories)) {
|
|
1016
1019
|
modified.target_directories = modified.target_directories.map((entry, idx) => {
|
|
1017
1020
|
if (typeof entry !== 'string' || entry.trim() === '')
|
|
1018
1021
|
return entry;
|
|
@@ -1099,8 +1102,10 @@ export function selfRepairToolCall(toolCall, toolSchema, options = {}) {
|
|
|
1099
1102
|
// 3. Coerce argument types
|
|
1100
1103
|
const typeResult = coerceArgumentTypes(canonicalName, aliasResult.args, toolSchema);
|
|
1101
1104
|
allRepairs.push(...typeResult.repairs);
|
|
1102
|
-
// 4. Normalize filesystem paths
|
|
1103
|
-
const pathResult =
|
|
1105
|
+
// 4. Normalize filesystem paths (fs_read_skill uses relative skill-bundle paths, never cwd paths)
|
|
1106
|
+
const pathResult = canonicalName === 'fs_read_skill'
|
|
1107
|
+
? { args: typeResult.args, repaired: false, repairs: [] }
|
|
1108
|
+
: normalizePaths(typeResult.args, options.cwd || process.cwd(), toolSchema);
|
|
1104
1109
|
allRepairs.push(...pathResult.repairs);
|
|
1105
1110
|
const browserResult = canonicalName === 'browser_act'
|
|
1106
1111
|
? repairBrowserActions(pathResult.args, options.cwd || process.cwd())
|
|
@@ -1011,10 +1011,12 @@ export function coerceArgumentTypes(
|
|
|
1011
1011
|
export function normalizePaths(
|
|
1012
1012
|
args: Record<string, unknown>,
|
|
1013
1013
|
cwd: string = process.cwd(),
|
|
1014
|
-
schema?: ParameterSchema
|
|
1014
|
+
schema?: ParameterSchema,
|
|
1015
|
+
options: { skipKeys?: ReadonlySet<string> | Iterable<string> } = {}
|
|
1015
1016
|
): RepairResult {
|
|
1016
1017
|
const repairs: string[] = [];
|
|
1017
1018
|
const modified = { ...args };
|
|
1019
|
+
const skipKeys = new Set(options.skipKeys || []);
|
|
1018
1020
|
const targetSchema = schema?.properties?.target;
|
|
1019
1021
|
const hasEnumTarget = Boolean(targetSchema && 'enum' in targetSchema);
|
|
1020
1022
|
const pathKeys = [
|
|
@@ -1043,13 +1045,14 @@ export function normalizePaths(
|
|
|
1043
1045
|
};
|
|
1044
1046
|
|
|
1045
1047
|
for (const key of pathKeys) {
|
|
1048
|
+
if (skipKeys.has(key)) continue;
|
|
1046
1049
|
const val = modified[key];
|
|
1047
1050
|
if (typeof val === 'string' && val.trim() !== '') {
|
|
1048
1051
|
modified[key] = normalizeOne(val, key);
|
|
1049
1052
|
}
|
|
1050
1053
|
}
|
|
1051
1054
|
|
|
1052
|
-
if (Array.isArray(modified.target_directories)) {
|
|
1055
|
+
if (!skipKeys.has('target_directories') && Array.isArray(modified.target_directories)) {
|
|
1053
1056
|
modified.target_directories = modified.target_directories.map((entry, idx) => {
|
|
1054
1057
|
if (typeof entry !== 'string' || entry.trim() === '') return entry;
|
|
1055
1058
|
return normalizeOne(entry, `target_directories[${idx}]`);
|
|
@@ -1148,8 +1151,10 @@ export function selfRepairToolCall(
|
|
|
1148
1151
|
const typeResult = coerceArgumentTypes(canonicalName, aliasResult.args, toolSchema);
|
|
1149
1152
|
allRepairs.push(...typeResult.repairs);
|
|
1150
1153
|
|
|
1151
|
-
// 4. Normalize filesystem paths
|
|
1152
|
-
const pathResult =
|
|
1154
|
+
// 4. Normalize filesystem paths (fs_read_skill uses relative skill-bundle paths, never cwd paths)
|
|
1155
|
+
const pathResult = canonicalName === 'fs_read_skill'
|
|
1156
|
+
? { args: typeResult.args, repaired: false, repairs: [] }
|
|
1157
|
+
: normalizePaths(typeResult.args, options.cwd || process.cwd(), toolSchema);
|
|
1153
1158
|
allRepairs.push(...pathResult.repairs);
|
|
1154
1159
|
|
|
1155
1160
|
const browserResult = canonicalName === 'browser_act'
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export function composerGeometry(requestedWidth, barColumns, gutterColumns) {
|
|
2
|
+
const width = Number.isFinite(requestedWidth)
|
|
3
|
+
? Math.max(4, Math.trunc(requestedWidth))
|
|
4
|
+
: 80;
|
|
5
|
+
const boxWidth = width - 1; // never occupy the terminal's deferred-wrap cell
|
|
6
|
+
const glyph = Number.isFinite(barColumns) ? Math.max(0, Math.trunc(barColumns)) : 1;
|
|
7
|
+
const gutter = Number.isFinite(gutterColumns) ? Math.max(0, Math.trunc(gutterColumns)) : 1;
|
|
8
|
+
const inset = Math.min(glyph + gutter, Math.max(0, boxWidth - 2));
|
|
9
|
+
const bodyWidth = Math.max(1, boxWidth - inset);
|
|
10
|
+
const editorWidth = Math.max(1, bodyWidth - 1); // reserve a full cursor cell
|
|
11
|
+
return { boxWidth, inset, bodyWidth, editorWidth, maxCaretCol: boxWidth - 1 };
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* In a small terminal the editor is more important than the full brand banner.
|
|
15
|
+
* This helper never loses the caret or returns more rows than the Stage owns.
|
|
16
|
+
* The ordinary roomy Home composition is unchanged.
|
|
17
|
+
*/
|
|
18
|
+
export function fitHomeContent(logoRows, promptRows, stageHeight, caretRow, requestedSpacer) {
|
|
19
|
+
const available = Number.isFinite(stageHeight)
|
|
20
|
+
? Math.max(1, Math.trunc(stageHeight))
|
|
21
|
+
: 24;
|
|
22
|
+
const prompt = promptRows.length ? [...promptRows] : [''];
|
|
23
|
+
const caret = Number.isFinite(caretRow)
|
|
24
|
+
? Math.max(0, Math.min(prompt.length - 1, Math.trunc(caretRow)))
|
|
25
|
+
: 0;
|
|
26
|
+
const promptCount = Math.min(available, prompt.length);
|
|
27
|
+
const start = prompt.length > available
|
|
28
|
+
? Math.min(Math.max(0, caret - Math.floor(available / 2)), prompt.length - available)
|
|
29
|
+
: 0;
|
|
30
|
+
const visiblePrompt = prompt.slice(start, start + promptCount);
|
|
31
|
+
const remaining = available - visiblePrompt.length;
|
|
32
|
+
// A cropped rotor/wordmark looks broken. On cramped terminals, hide the
|
|
33
|
+
// banner as a whole rather than displaying an arbitrary bottom fragment.
|
|
34
|
+
const showLogo = logoRows.length > 0 && remaining >= logoRows.length;
|
|
35
|
+
const visibleLogo = showLogo ? [...logoRows] : [];
|
|
36
|
+
const spacer = showLogo
|
|
37
|
+
? Math.min(Math.max(0, Number.isFinite(requestedSpacer) ? Math.trunc(requestedSpacer) : 0), remaining - logoRows.length)
|
|
38
|
+
: 0;
|
|
39
|
+
return {
|
|
40
|
+
logoRows: visibleLogo,
|
|
41
|
+
promptRows: visiblePrompt,
|
|
42
|
+
spacer,
|
|
43
|
+
caretRow: Math.max(0, Math.min(visiblePrompt.length - 1, caret - start))
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Causyne composer geometry. This module owns column arithmetic, never I/O.
|
|
3
|
+
*
|
|
4
|
+
* `barBlock` consumes the left bar + gutter. A painted block is exactly
|
|
5
|
+
* `boxWidth` cells, but the editing surface must reserve a caret cell so a
|
|
6
|
+
* full row cannot position the terminal cursor in the clipped right margin.
|
|
7
|
+
*/
|
|
8
|
+
export interface ComposerGeometry {
|
|
9
|
+
boxWidth: number;
|
|
10
|
+
inset: number;
|
|
11
|
+
bodyWidth: number;
|
|
12
|
+
editorWidth: number;
|
|
13
|
+
maxCaretCol: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function composerGeometry(
|
|
17
|
+
requestedWidth: number,
|
|
18
|
+
barColumns: number,
|
|
19
|
+
gutterColumns: number
|
|
20
|
+
): ComposerGeometry {
|
|
21
|
+
const width = Number.isFinite(requestedWidth)
|
|
22
|
+
? Math.max(4, Math.trunc(requestedWidth))
|
|
23
|
+
: 80;
|
|
24
|
+
const boxWidth = width - 1; // never occupy the terminal's deferred-wrap cell
|
|
25
|
+
const glyph = Number.isFinite(barColumns) ? Math.max(0, Math.trunc(barColumns)) : 1;
|
|
26
|
+
const gutter = Number.isFinite(gutterColumns) ? Math.max(0, Math.trunc(gutterColumns)) : 1;
|
|
27
|
+
const inset = Math.min(glyph + gutter, Math.max(0, boxWidth - 2));
|
|
28
|
+
const bodyWidth = Math.max(1, boxWidth - inset);
|
|
29
|
+
const editorWidth = Math.max(1, bodyWidth - 1); // reserve a full cursor cell
|
|
30
|
+
return { boxWidth, inset, bodyWidth, editorWidth, maxCaretCol: boxWidth - 1 };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface FittedHomeContent {
|
|
34
|
+
/** Full banner, or none when the terminal cannot show it without clipping. */
|
|
35
|
+
logoRows: string[];
|
|
36
|
+
/** Composer rows kept as a contiguous window around the editing caret. */
|
|
37
|
+
promptRows: string[];
|
|
38
|
+
spacer: number;
|
|
39
|
+
caretRow: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* In a small terminal the editor is more important than the full brand banner.
|
|
44
|
+
* This helper never loses the caret or returns more rows than the Stage owns.
|
|
45
|
+
* The ordinary roomy Home composition is unchanged.
|
|
46
|
+
*/
|
|
47
|
+
export function fitHomeContent(
|
|
48
|
+
logoRows: readonly string[],
|
|
49
|
+
promptRows: readonly string[],
|
|
50
|
+
stageHeight: number,
|
|
51
|
+
caretRow: number,
|
|
52
|
+
requestedSpacer: number
|
|
53
|
+
): FittedHomeContent {
|
|
54
|
+
const available = Number.isFinite(stageHeight)
|
|
55
|
+
? Math.max(1, Math.trunc(stageHeight))
|
|
56
|
+
: 24;
|
|
57
|
+
const prompt = promptRows.length ? [...promptRows] : [''];
|
|
58
|
+
const caret = Number.isFinite(caretRow)
|
|
59
|
+
? Math.max(0, Math.min(prompt.length - 1, Math.trunc(caretRow)))
|
|
60
|
+
: 0;
|
|
61
|
+
const promptCount = Math.min(available, prompt.length);
|
|
62
|
+
const start = prompt.length > available
|
|
63
|
+
? Math.min(Math.max(0, caret - Math.floor(available / 2)), prompt.length - available)
|
|
64
|
+
: 0;
|
|
65
|
+
const visiblePrompt = prompt.slice(start, start + promptCount);
|
|
66
|
+
const remaining = available - visiblePrompt.length;
|
|
67
|
+
// A cropped rotor/wordmark looks broken. On cramped terminals, hide the
|
|
68
|
+
// banner as a whole rather than displaying an arbitrary bottom fragment.
|
|
69
|
+
const showLogo = logoRows.length > 0 && remaining >= logoRows.length;
|
|
70
|
+
const visibleLogo = showLogo ? [...logoRows] : [];
|
|
71
|
+
const spacer = showLogo
|
|
72
|
+
? Math.min(Math.max(0, Number.isFinite(requestedSpacer) ? Math.trunc(requestedSpacer) : 0), remaining - logoRows.length)
|
|
73
|
+
: 0;
|
|
74
|
+
return {
|
|
75
|
+
logoRows: visibleLogo,
|
|
76
|
+
promptRows: visiblePrompt,
|
|
77
|
+
spacer,
|
|
78
|
+
caretRow: Math.max(0, Math.min(visiblePrompt.length - 1, caret - start))
|
|
79
|
+
};
|
|
80
|
+
}
|
package/src/tui/homeView.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { sessionBanner } from './banner.js';
|
|
2
2
|
import { centerRows } from './layout.js';
|
|
3
|
+
import { fitHomeContent } from './composerGeometry.js';
|
|
3
4
|
import { panelRows } from './overlay.js';
|
|
4
5
|
/** A modal before the first conversation belongs to the centered home view. */
|
|
5
6
|
export function isStartupDialog(surface) {
|
|
@@ -45,17 +46,20 @@ export function placeHome(info, promptRows, columns, height, caretRow, caretCol)
|
|
|
45
46
|
const available = Math.max(1, Math.floor(height));
|
|
46
47
|
const logo = centerRows(sessionBanner(info, columns, { height: available }), columns).rows;
|
|
47
48
|
const spacer = available >= 25 ? 2 : 1;
|
|
48
|
-
|
|
49
|
+
// When the window is short, preserve the composer and editing caret first.
|
|
50
|
+
// The logo yields height; it must never push a wrapped draft off-screen.
|
|
51
|
+
const fitted = fitHomeContent(logo, promptRows, available, caretRow, spacer);
|
|
52
|
+
const required = fitted.logoRows.length + fitted.spacer + fitted.promptRows.length;
|
|
49
53
|
const top = Math.max(0, Math.floor((available - required) / 2));
|
|
50
54
|
const rows = [
|
|
51
55
|
...Array(top).fill(''),
|
|
52
|
-
...
|
|
53
|
-
...Array(spacer).fill(''),
|
|
54
|
-
...promptRows
|
|
56
|
+
...fitted.logoRows,
|
|
57
|
+
...Array(fitted.spacer).fill(''),
|
|
58
|
+
...fitted.promptRows
|
|
55
59
|
];
|
|
56
60
|
return {
|
|
57
|
-
rows
|
|
58
|
-
caretRow:
|
|
61
|
+
rows,
|
|
62
|
+
caretRow: top + fitted.logoRows.length + fitted.spacer + fitted.caretRow,
|
|
59
63
|
caretCol: Math.max(0, Math.min(caretCol, columns - 2))
|
|
60
64
|
};
|
|
61
65
|
}
|
package/src/tui/homeView.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { sessionBanner, type BannerInfo } from './banner.js';
|
|
2
2
|
import { centerRows } from './layout.js';
|
|
3
|
+
import { fitHomeContent } from './composerGeometry.js';
|
|
3
4
|
import { panelRows } from './overlay.js';
|
|
4
5
|
|
|
5
6
|
export interface PlacedView {
|
|
@@ -74,17 +75,20 @@ export function placeHome(
|
|
|
74
75
|
const available = Math.max(1, Math.floor(height));
|
|
75
76
|
const logo = centerRows(sessionBanner(info, columns, { height: available }), columns).rows;
|
|
76
77
|
const spacer = available >= 25 ? 2 : 1;
|
|
77
|
-
|
|
78
|
+
// When the window is short, preserve the composer and editing caret first.
|
|
79
|
+
// The logo yields height; it must never push a wrapped draft off-screen.
|
|
80
|
+
const fitted = fitHomeContent(logo, promptRows, available, caretRow, spacer);
|
|
81
|
+
const required = fitted.logoRows.length + fitted.spacer + fitted.promptRows.length;
|
|
78
82
|
const top = Math.max(0, Math.floor((available - required) / 2));
|
|
79
83
|
const rows = [
|
|
80
84
|
...Array<string>(top).fill(''),
|
|
81
|
-
...
|
|
82
|
-
...Array<string>(spacer).fill(''),
|
|
83
|
-
...promptRows
|
|
85
|
+
...fitted.logoRows,
|
|
86
|
+
...Array<string>(fitted.spacer).fill(''),
|
|
87
|
+
...fitted.promptRows
|
|
84
88
|
];
|
|
85
89
|
return {
|
|
86
|
-
rows
|
|
87
|
-
caretRow:
|
|
90
|
+
rows,
|
|
91
|
+
caretRow: top + fitted.logoRows.length + fitted.spacer + fitted.caretRow,
|
|
88
92
|
caretCol: Math.max(0, Math.min(caretCol, columns - 2))
|
|
89
93
|
};
|
|
90
94
|
}
|
package/src/tui/lineEditor.js
CHANGED
|
@@ -376,6 +376,14 @@ export class LineEditor {
|
|
|
376
376
|
while (pos <= line.length) {
|
|
377
377
|
if (pos === line.length) {
|
|
378
378
|
if (isCurrentLine && pos === this.col && !placed) {
|
|
379
|
+
// An exact-width final row has no cell after its last glyph.
|
|
380
|
+
// Move the caret onto an empty continuation row instead of
|
|
381
|
+
// positioning it outside the editing surface. Preserve text.
|
|
382
|
+
if (used >= budget && pos > 0) {
|
|
383
|
+
rows.push(row);
|
|
384
|
+
row = prefix;
|
|
385
|
+
used = 0;
|
|
386
|
+
}
|
|
379
387
|
cursorRow = rows.length;
|
|
380
388
|
cursorCol = prefixWidth + used;
|
|
381
389
|
placed = true;
|
package/src/tui/prompt.js
CHANGED
|
@@ -24,6 +24,7 @@ import { PromptHistory } from './history.js';
|
|
|
24
24
|
import { FileIndex, suggest, applyCompletion, detectTrigger, renderPicker, MAX_VISIBLE } from './completion.js';
|
|
25
25
|
import { paint, dim, bold, GLYPHS, terminalWidth, HAS_COLOR } from './theme.js';
|
|
26
26
|
import { barBlock, GUTTER } from './block.js';
|
|
27
|
+
import { composerGeometry } from './composerGeometry.js';
|
|
27
28
|
import { visibleWidth, truncate, wrapBlock, shortenHome, safeDisplay, stripAnsi } from './text.js';
|
|
28
29
|
import { pickExample, fitHints } from './banner.js';
|
|
29
30
|
import { panelRows } from './overlay.js';
|
|
@@ -1603,10 +1604,14 @@ export class ChatPrompt {
|
|
|
1603
1604
|
// surface you are writing INTO. Every row of the block is inset by the same
|
|
1604
1605
|
// gutter, so the caret column is a constant rather than a special case for
|
|
1605
1606
|
// row 0 — which is also one fewer thing for erase() to get wrong.
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
const
|
|
1607
|
+
// Reserve one editor cell for the caret. The left bar and gutter are
|
|
1608
|
+
// consumed by barBlock; the remaining full-width body is not all editable.
|
|
1609
|
+
// This prevents a full sentence from placing the cursor beyond the fill.
|
|
1610
|
+
const { boxWidth, inset, editorWidth } = composerGeometry(
|
|
1611
|
+
width, visibleWidth(GLYPHS.barHeavy || GLYPHS.bar), GUTTER
|
|
1612
|
+
);
|
|
1613
|
+
const inner = editorWidth;
|
|
1614
|
+
const layout = this.editor.render(editorWidth, '');
|
|
1610
1615
|
|
|
1611
1616
|
// Scroll the editor internally rather than growing without bound: keep a
|
|
1612
1617
|
// window of MAX_PROMPT_ROWS that always contains the caret.
|