@hncode/hncode 0.7.7 → 0.7.8
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/colors.js +586 -556
- package/src/tools/ptc.js +2 -2
- package/src/tools/read.js +3 -0
- package/src/tui.js +164 -52
package/src/tools/ptc.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ProgrammaticToolCall — let the model orchestrate tools with code instead of one round trip each.
|
|
2
|
+
* PTC (ProgrammaticToolCall) — let the model orchestrate tools with code instead of one round trip each.
|
|
3
3
|
*
|
|
4
4
|
* THE PROBLEM IT SOLVES: a task like "which of these forty files reference the removed symbol" is forty calls,
|
|
5
5
|
* each with its own inference pass, and every one of those results then sits in the context whether or not it
|
|
@@ -47,7 +47,7 @@ const DESCRIPTION = [
|
|
|
47
47
|
const BASE_DESCRIPTION = DESCRIPTION.join('\n');
|
|
48
48
|
|
|
49
49
|
export const spec = {
|
|
50
|
-
name: '
|
|
50
|
+
name: 'PTC',
|
|
51
51
|
// Built per read so a plugin that loaded after this module is named in the list the model is given.
|
|
52
52
|
get description() {
|
|
53
53
|
return BASE_DESCRIPTION + '\n\nCALLABLE TOOLS: ' + callableTools().join(', ') + '.'
|
package/src/tools/read.js
CHANGED
|
@@ -97,6 +97,9 @@ export const spec = {
|
|
|
97
97
|
: total;
|
|
98
98
|
let out = '';
|
|
99
99
|
out += `${args.path} (lines ${start}-${end} of ${total})\n`;
|
|
100
|
+
// THE NUMBER IS LEFT-ALIGNED AND PADDED ON THE RIGHT, not the other way round. `padStart` put the padding in
|
|
101
|
+
// FRONT, so `1` arrived as `" 1"` and the gutter read as right-aligned. The tab after it is what aligns the
|
|
102
|
+
// code, so all a number needs is to start in column 0.
|
|
100
103
|
for (let i = start; i <= end; i++) out += `${i}\t${lines[i - 1]}\n`;
|
|
101
104
|
// No trailing "truncated" banner: without an explicit end_line every line is returned, so the only way
|
|
102
105
|
// to stop early is a deliberate range request — the header already states which lines those were.
|
package/src/tui.js
CHANGED
|
@@ -218,6 +218,7 @@ export const COMMANDS = [
|
|
|
218
218
|
{ name: 'auto-trim', aliases: ['autotrim'], desc: 'Auto tool-result trimming: the threshold is a share of the WINDOW, `keep` a share of the tool-result TEXT', priority: 40, argumentHint: '[on|off | threshold <n> | keep <n>]' },
|
|
219
219
|
{ name: 'title', aliases: ['rename'], desc: 'Set or show session title (also sets window title)', priority: 60, argumentHint: '<title>' },
|
|
220
220
|
{ name: 'auto-title', desc: 'Let the model name the session from its first message (persisted)', priority: 60, argumentHint: '[on|off]' },
|
|
221
|
+
{ name: 'ptc', desc: 'PTC mode: every tool call goes through the programmatic sandbox, no direct tools', priority: 55, argumentHint: '[on|off]' },
|
|
221
222
|
{ name: 'status', desc: 'Show current session and runtime status', priority: 60 },
|
|
222
223
|
{ name: 'doctor', desc: 'Diagnose the environment: config, store, MCP, hooks, disk, git, terminal', priority: 60, argumentHint: '[--all] [--probe]' },
|
|
223
224
|
{ name: 'memory-profile', aliases: ['memprof'], desc: 'Where this session’s memory goes: text vs tool results vs tool arguments', priority: 60, argumentHint: '[--verbose]' },
|
|
@@ -323,6 +324,23 @@ export function findCommand(name) {
|
|
|
323
324
|
|| pluginCommands.find((c) => c.name === n || (c.aliases || []).includes(n));
|
|
324
325
|
}
|
|
325
326
|
|
|
327
|
+
/**
|
|
328
|
+
* Colour ONLY a complete command name at the start of a composer row.
|
|
329
|
+
*
|
|
330
|
+
* `/hel` is still being typed and stays plain; `/help` is a command and lights up in the theme accent.
|
|
331
|
+
* Everything after the first space is an argument and keeps whatever colour it already has.
|
|
332
|
+
*/
|
|
333
|
+
export function highlightCommandName(row) {
|
|
334
|
+
const s = String(row);
|
|
335
|
+
// A composer row starts with its `> ` or `! ` prompt glyph; the command follows it. The hint belongs on the
|
|
336
|
+
// WORD only, so the marker and every argument keep their own colour.
|
|
337
|
+
const m = /^(\s*(?:[>!]\s+)?)((?:\/)[^\s]*)(.*)$/.exec(s);
|
|
338
|
+
if (!m) return s;
|
|
339
|
+
const cmd = findCommand(m[2]);
|
|
340
|
+
if (!cmd) return s;
|
|
341
|
+
return m[1] + col(m[2], C.cyan + C.bold) + m[3];
|
|
342
|
+
}
|
|
343
|
+
|
|
326
344
|
// Check if a command name refers to a plugin command.
|
|
327
345
|
export function isPluginCommand(name) {
|
|
328
346
|
const n = String(name || '').replace(/^\//, '');
|
|
@@ -1831,15 +1849,18 @@ export function expandPastes(text, pastes) {
|
|
|
1831
1849
|
// colour. `highlightSelection` below documents this exact hazard; this function was missing it.
|
|
1832
1850
|
//
|
|
1833
1851
|
// `hoverId` is the paste number the pointer is over, when it is over one. That chip keeps its
|
|
1834
|
-
// background
|
|
1835
|
-
//
|
|
1836
|
-
//
|
|
1837
|
-
export function highlightPasteMarkers(row, hoverId = null) {
|
|
1852
|
+
// `surface` is the background the CALLER is about to paint under this row, or '' when the row has none. The
|
|
1853
|
+
// chip's own fill ends with a background reset, which would otherwise drop the rest of the row to the terminal
|
|
1854
|
+
// default; re-asserting the caller's surface right after keeps the row whole.
|
|
1855
|
+
export function highlightPasteMarkers(row, hoverId = null, surface = C.bg) {
|
|
1838
1856
|
const s = String(row);
|
|
1839
1857
|
if (!s.includes('[paste #')) return s;
|
|
1858
|
+
// `C.bgReset` alone drops the rest of the row to the terminal's default background, because the caller has not
|
|
1859
|
+
// applied the surface yet. Re-asserting it right after the reset keeps the chip a chip and leaves the row whole.
|
|
1840
1860
|
return s.replace(PASTE_MARKER_RE, (m, id) => {
|
|
1841
|
-
|
|
1842
|
-
return C.selBg + m +
|
|
1861
|
+
const after = C.bgReset + surface;
|
|
1862
|
+
if (Number(id) === hoverId) return C.hover + C.selBg + m + after;
|
|
1863
|
+
return C.selBg + m + after;
|
|
1843
1864
|
});
|
|
1844
1865
|
}
|
|
1845
1866
|
/**
|
|
@@ -2752,11 +2773,19 @@ function messageLines(msg, width, workspace, expanded, spin, pulseStart, rawMode
|
|
|
2752
2773
|
// Live output of a RUNNING command (Bash): rendered under the "Using …"
|
|
2753
2774
|
// row exactly like the finished "Used …" output, just not done yet. Only
|
|
2754
2775
|
// the tail is shown (capped) so a chatty command cannot flood the frame.
|
|
2755
|
-
if (msg.pending &&
|
|
2776
|
+
if (msg.pending && msg.toolName === 'Bash') {
|
|
2777
|
+
// THE OUTPUT AREA EXISTS BEFORE THERE IS ANY OUTPUT. A Bash call used to grow a row only once the
|
|
2778
|
+
// command produced its first byte, so the transcript shifted down at that moment and the tool row sat alone
|
|
2779
|
+
// until then — with no sign that this is where the output will appear. It opens with one empty surface row
|
|
2780
|
+
// and fills that row as data arrives.
|
|
2756
2781
|
const bodyW = Math.max(1, width - visualCol(' '));
|
|
2757
|
-
const rawLines = sanitizeText(msg.liveOutput).replace(/\r\n/g, '\n').split('\n');
|
|
2782
|
+
const rawLines = sanitizeText(msg.liveOutput || '').replace(/\r\n/g, '\n').split('\n');
|
|
2758
2783
|
const MAX_RUN_LINES = expanded ? Infinity : 8;
|
|
2759
|
-
|
|
2784
|
+
// A trailing newline leaves an empty element; keeping it drew two blank rows for an empty output.
|
|
2785
|
+
if (rawLines.length > 1 && rawLines[rawLines.length - 1] === '') rawLines.pop();
|
|
2786
|
+
const shown = rawLines.length ? rawLines.slice(-MAX_RUN_LINES) : [''];
|
|
2787
|
+
// The `↳` on the first row costs two columns, exactly as it does on the finished result.
|
|
2788
|
+
let liveEmitted = 0;
|
|
2760
2789
|
if (rawLines.length > MAX_RUN_LINES) {
|
|
2761
2790
|
const more = col(`… ${rawLines.length - MAX_RUN_LINES} earlier line(s)`, C.gray);
|
|
2762
2791
|
out.push({ text: C.termBg + fitAnsi(more.replace(/\x1b\[0m/g, `\x1b[0m${C.termBg}`), bodyW) + C.bgReset, ind: indent, raw: true });
|
|
@@ -2768,7 +2797,14 @@ function messageLines(msg, width, workspace, expanded, spin, pulseStart, rawMode
|
|
|
2768
2797
|
for (const t of (ln === '' ? [''] : wrapWords(ln, bodyW))) {
|
|
2769
2798
|
const painted = col(t, C.gray);
|
|
2770
2799
|
const surfaced = painted.replace(/\x1b\[0m/g, `\x1b[0m${C.termBg}`);
|
|
2771
|
-
|
|
2800
|
+
const firstLive = liveEmitted++ === 0;
|
|
2801
|
+
// `bodyW` ALREADY EXCLUDES THE MARKER — it is `width - 2`, and the marker is the two columns it took
|
|
2802
|
+
// off. Subtracting them again stopped the surface two columns short, so the page colour showed at the
|
|
2803
|
+
// right edge in the one column the scrollbar does not own.
|
|
2804
|
+
// The same `↳ ` the finished result puts on its first row, so the block does not shift right when the
|
|
2805
|
+
// command completes. Continuation rows indent by two spaces, matching the result block.
|
|
2806
|
+
const rowW = bodyW;
|
|
2807
|
+
out.push({ text: C.termBg + fitAnsi(surfaced, rowW) + C.bgReset, ind: firstLive ? '↳ ' : ' ', raw: true });
|
|
2772
2808
|
}
|
|
2773
2809
|
}
|
|
2774
2810
|
}
|
|
@@ -2832,12 +2868,12 @@ function messageLines(msg, width, workspace, expanded, spin, pulseStart, rawMode
|
|
|
2832
2868
|
const room = Math.max(1, width - visualCol(indent) - num.length - 1);
|
|
2833
2869
|
// The whole preview sits on the CODE SURFACE, number included, so the block reads as one recessed field.
|
|
2834
2870
|
if (!writeLang) {
|
|
2835
|
-
out.push({ text: C.codeBg + col(`${num} ${fitAnsi(ln, room)}`.replace(/\x1b\[0m/g, `\x1b[0m${C.codeBg}`), C.
|
|
2871
|
+
out.push({ text: C.codeBg + col(`${num} ${fitAnsi(ln, room)}`.replace(/\x1b\[0m/g, `\x1b[0m${C.codeBg}`), C.white) + C.bgReset, ind: i === 0 ? '↳ ' : indent, raw: true });
|
|
2836
2872
|
return;
|
|
2837
2873
|
}
|
|
2838
2874
|
const painted = paintCode(ln, writeLang, '', writeInComment);
|
|
2839
2875
|
writeInComment = painted.inComment;
|
|
2840
|
-
const writeRow = (col(num + ' ', C.
|
|
2876
|
+
const writeRow = (col(num + ' ', C.white) + fitAnsi(painted.text, room)).replace(/\x1b\[0m/g, `\x1b[0m${C.codeBg}`);
|
|
2841
2877
|
out.push({ text: C.codeBg + writeRow + C.bgReset, ind: i === 0 ? '↳ ' : indent, raw: true });
|
|
2842
2878
|
});
|
|
2843
2879
|
const shown = Math.min(lines.length, MAX);
|
|
@@ -2958,7 +2994,9 @@ function messageLines(msg, width, workspace, expanded, spin, pulseStart, rawMode
|
|
|
2958
2994
|
// `[error: …]` is kept: it carries the message, not just a code.
|
|
2959
2995
|
const visible = rawLines.filter((ln) => !/^\[exit code:/.test(ln.trim()));
|
|
2960
2996
|
const failed = msg.failed === true;
|
|
2961
|
-
|
|
2997
|
+
// A silent Bash keeps the ONE empty output row it had while running. Only Bash has this special area: an empty
|
|
2998
|
+
// Read/Grep result must not grow a phantom line merely because the command itself printed nothing.
|
|
2999
|
+
const shown = visible.length ? visible.slice(0, MAX_RESULT_LINES) : (msg.toolName === 'Bash' ? [''] : []);
|
|
2962
3000
|
|
|
2963
3001
|
// ---- DISPLAY ORDER -----------------------------------------------------
|
|
2964
3002
|
// The row reads as a block under the tool line, with ONE `↳` marker:
|
|
@@ -2996,7 +3034,9 @@ function messageLines(msg, width, workspace, expanded, spin, pulseStart, rawMode
|
|
|
2996
3034
|
}
|
|
2997
3035
|
const no = String(d.no || 0).padStart(wNo);
|
|
2998
3036
|
const mark = d.type === 'add' ? '+' : d.type === 'del' ? '-' : ' ';
|
|
2999
|
-
|
|
3037
|
+
// TABS ARE EXPANDED FIRST: `visualCol` counts one as zero columns, so an indented row measured short
|
|
3038
|
+
// and its background stopped before the right edge — the strip of page colour seen on Go diffs.
|
|
3039
|
+
const text = expandTabs(sanitizeText(d.text));
|
|
3000
3040
|
|
|
3001
3041
|
// The sign, line number and content share the line's addition/deletion background; syntax highlighting
|
|
3002
3042
|
// changes only the foreground. The wash runs to the right edge so adjacent changed rows read as one block.
|
|
@@ -3053,6 +3093,14 @@ function messageLines(msg, width, workspace, expanded, spin, pulseStart, rawMode
|
|
|
3053
3093
|
// The comment state travels between the rows, so a block comment that opens on one line and closes on the
|
|
3054
3094
|
// next stays grey all the way down.
|
|
3055
3095
|
const readLang = msg.readPath ? langForPath(msg.readPath) : null;
|
|
3096
|
+
// THE GUTTER IS ONE WIDTH FOR THE WHOLE BLOCK. The tool sends `N<TAB>text`, and the tab is what used to
|
|
3097
|
+
// place the code — so `1` and `10` started their text at different columns once the tab was expanded.
|
|
3098
|
+
// Padding the NUMBER to the widest one in this block keeps the digits left-aligned and the code aligned
|
|
3099
|
+
// under itself.
|
|
3100
|
+
const numW = shown.reduce((w, ln) => {
|
|
3101
|
+
const m = /^(\d+)\t/.exec(ln);
|
|
3102
|
+
return m ? Math.max(w, m[1].length) : w;
|
|
3103
|
+
}, 0);
|
|
3056
3104
|
let inComment = false;
|
|
3057
3105
|
shown.forEach((ln, idx) => {
|
|
3058
3106
|
const isErr = /^\[error:/.test(ln.trim());
|
|
@@ -3066,13 +3114,19 @@ function messageLines(msg, width, workspace, expanded, spin, pulseStart, rawMode
|
|
|
3066
3114
|
// while the terminal advanced to the next stop: the row was padded short and the previous frame's
|
|
3067
3115
|
// glyphs stayed visible behind it. Expand before measuring, but keep the first tab as the separator
|
|
3068
3116
|
// — the regex above already split on it.
|
|
3069
|
-
|
|
3070
|
-
|
|
3117
|
+
// tell the highlighter the first visible row is a comment — it coloured `of`, `switch`, `from` in a JSDoc
|
|
3118
|
+
// paragraph as keywords. A row that is plainly part of a block comment (` * …`, an opening `/**`, or the
|
|
3119
|
+
// closing `*/`) is painted as a comment on its own merits; the opener also seeds the rows that follow.
|
|
3120
|
+
const content = expandTabs(numbered[2]);
|
|
3121
|
+
const isBlockCommentRow = /^\s*(?:\/\*|\*|\*\/|\*\*)/.test(content);
|
|
3122
|
+
const painted = paintCode(content, readLang, '', inComment || isBlockCommentRow);
|
|
3123
|
+
if (/\/\*/.test(content) && !/\*\//.test(content)) inComment = true;
|
|
3124
|
+
else if (/\*\//.test(content)) inComment = false;
|
|
3071
3125
|
// THE SEPARATOR IS A TAB, AND `visualCol` COUNTS A TAB AS ZERO COLUMNS. A terminal advances it to the
|
|
3072
3126
|
// next stop, so the row was measured several columns short, the terminal wrapped it itself, and the tail
|
|
3073
|
-
//
|
|
3074
|
-
//
|
|
3075
|
-
const text = `${numbered[1]}
|
|
3127
|
+
// advances it to the next stop, so the row measured short and the terminal wrapped it itself. The
|
|
3128
|
+
// THE SEPARATOR IS TWO SPACES, NOT A TAB: `visualCol` counts a tab as zero columns while a terminal
|
|
3129
|
+
const text = `${col(numbered[1].padStart(numW), C.white)} ${painted.text}`;
|
|
3076
3130
|
// A Read row is TRUNCATED, not wrapped. `wrapAnsiWords` used to fold an overlong line onto a second
|
|
3077
3131
|
// row, and that second row — padded to full width by the frame, without a line number — was exactly
|
|
3078
3132
|
// what a differential painter could not reconcile with the previous frame: the leftover glyphs stayed
|
|
@@ -4625,8 +4679,10 @@ export function renderChatLines(state, w, viewport) {
|
|
|
4625
4679
|
// A USER MESSAGE IS DRAWN AS A FILLED SURFACE, the same one the composer uses: what was typed and what is
|
|
4626
4680
|
// being typed read as one kind of thing. The frame is gone for the same reason it left the composer — a box
|
|
4627
4681
|
// competes with the transcript and spends rows on chrome. A shell echo keeps its terminal surface instead.
|
|
4628
|
-
const surfaceFor = msg.role === 'bash' ? C.termBg
|
|
4629
|
-
|
|
4682
|
+
const surfaceFor = msg.role === 'bash' ? C.termBg
|
|
4683
|
+
: (msg.role === 'user' || msg.role === 'steer') ? C.composerBg
|
|
4684
|
+
: '';
|
|
4685
|
+
if (surfaceFor && !shared) {
|
|
4630
4686
|
for (let i = 0; i < ccc.rows.length; i++) {
|
|
4631
4687
|
const rowText = liveAt(ccc.rows[i], i);
|
|
4632
4688
|
if (isImageRow(rowText)) { out.push(rowText); continue; }
|
|
@@ -4723,10 +4779,7 @@ export function metricsSignature(state, n, w, expanded, innerW) {
|
|
|
4723
4779
|
mix(m.pluginLog && m.expanded ? 1 : 0);
|
|
4724
4780
|
mix(m._cache ? 1 : 0);
|
|
4725
4781
|
mix(m._count ? 1 : 0);
|
|
4726
|
-
//
|
|
4727
|
-
// the signature matched every frame and the transcript was never re-walked, so the animation froze
|
|
4728
|
-
// until the message itself was touched.
|
|
4729
|
-
if (m.pending) mix(Math.floor(Date.now() / STEP_MS));
|
|
4782
|
+
// The animation clock is deliberately NOT hashed here — see the note above the signature.
|
|
4730
4783
|
}
|
|
4731
4784
|
return h;
|
|
4732
4785
|
}
|
|
@@ -4834,7 +4887,12 @@ function fmtTokens(n) {
|
|
|
4834
4887
|
* quantity cannot read two ways on one screen.
|
|
4835
4888
|
*/
|
|
4836
4889
|
function scaleUnit(v) {
|
|
4837
|
-
|
|
4890
|
+
if (v < 100) return v.toFixed(1).replace(/\.0$/, '');
|
|
4891
|
+
const r = Math.round(v);
|
|
4892
|
+
// A value that ROUNDS to the whole number keeps its decimal: 1048576/1e6 is 1.048576, and printing `1` put it
|
|
4893
|
+
// in the same bucket as a plain million. `v === r` is the exact case.
|
|
4894
|
+
if (r >= 100 && Math.abs(v - r) <= 0.5) return String(r);
|
|
4895
|
+
return v.toFixed(1).replace(/\.0$/, '');
|
|
4838
4896
|
}
|
|
4839
4897
|
|
|
4840
4898
|
// Thousands separators for a plain count. fmtTokens rounds to k/M, which is right
|
|
@@ -5644,7 +5702,13 @@ function dimRange(row, from, to) {
|
|
|
5644
5702
|
* The floor exists for the same reason: a fill already at the page's own brightness has
|
|
5645
5703
|
* nowhere to go, and forcing it lower only makes it read as a hole.
|
|
5646
5704
|
*/
|
|
5647
|
-
|
|
5705
|
+
// HOW FAR A FILL RECEDES, as a fraction of ITS OWN DISTANCE FROM THE PAGE.
|
|
5706
|
+
//
|
|
5707
|
+
// A fixed multiplier treats every fill the same, and they are not: the page colour itself has nowhere to go, a
|
|
5708
|
+
// barely-off-page surface has almost nothing to lose, and a saturated accent band has the most to give. Measured
|
|
5709
|
+
// against the page, a flat 0.72 either left a dark fill untouched or crushed a bright one into the background.
|
|
5710
|
+
// The distance from the page IS "how much this stands out", so shrinking THAT is the only rule that behaves.
|
|
5711
|
+
const DIM_BACKGROUND_SCALE = 0.55;
|
|
5648
5712
|
const DIM_BACKGROUND_FLOOR = 28;
|
|
5649
5713
|
|
|
5650
5714
|
/**
|
|
@@ -5668,13 +5732,17 @@ const DIM_BACKGROUND_FLOOR = 28;
|
|
|
5668
5732
|
* does not implement is dropped silently, which looks exactly like "the fill vanished" — and
|
|
5669
5733
|
* that is what happened before this was noticed.
|
|
5670
5734
|
*/
|
|
5671
|
-
function dimmedBg(
|
|
5735
|
+
function dimmedBg(rgb) {
|
|
5672
5736
|
if (!TRUECOLOR) return '';
|
|
5673
|
-
|
|
5674
|
-
const
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5737
|
+
// The page, parsed once per call: this runs per cell while a picker is open, and `C.bg` is a string.
|
|
5738
|
+
const page = /48;2;(\d+);(\d+);(\d+)/.exec(C.bg);
|
|
5739
|
+
if (!page) return '';
|
|
5740
|
+
const base = [Number(page[1]), Number(page[2]), Number(page[3])];
|
|
5741
|
+
// Move each channel the given fraction of the way from the fill to the page. A fill already AT the page comes
|
|
5742
|
+
// out unchanged, and the caller then leaves it alone rather than drawing a hole.
|
|
5743
|
+
const toward = (v, i) => Math.round(base[i] + (v - base[i]) * (1 - DIM_BACKGROUND_SCALE));
|
|
5744
|
+
const out = [toward(rgb[0], 0), toward(rgb[1], 1), toward(rgb[2], 2)];
|
|
5745
|
+
if (out[0] === rgb[0] && out[1] === rgb[1] && out[2] === rgb[2]) return '';
|
|
5678
5746
|
return bgRgb(out[0], out[1], out[2]);
|
|
5679
5747
|
}
|
|
5680
5748
|
|
|
@@ -6648,10 +6716,12 @@ const queueH = takeover ? 0 : queuePanelHeight(state);
|
|
|
6648
6716
|
// covered. The payload is padded to the column before the rail instead of being cut, so the sequence
|
|
6649
6717
|
// survives intact and the rail is drawn where it always is.
|
|
6650
6718
|
if (isImageRow(row)) {
|
|
6651
|
-
const rail = fg + bg + glyphChar
|
|
6719
|
+
const rail = fg + bg + glyphChar;
|
|
6652
6720
|
row = row + rail;
|
|
6653
6721
|
} else {
|
|
6654
|
-
|
|
6722
|
+
// NO TRAILING RESET. The page-colour pass already closes the row, and the next row re-asserts its own
|
|
6723
|
+
// background at the front — a reset here only overwrote this cell's track colour or left a stray escape.
|
|
6724
|
+
row = fitAnsi(row, w - 1) + fg + bg + glyphChar;
|
|
6655
6725
|
}
|
|
6656
6726
|
}
|
|
6657
6727
|
// `body` IS INDEXED BY TRANSCRIPT ROW, so the padding must not be appended to it. The loop starts at
|
|
@@ -7438,9 +7508,9 @@ const queueH = takeover ? 0 : queuePanelHeight(state);
|
|
|
7438
7508
|
// that stops one column short of an edge reads as a damaged block rather than as an input field.
|
|
7439
7509
|
const CPAD = '';
|
|
7440
7510
|
const cInner = Math.max(1, insideW + 2); // the full terminal width: insideW is w - 2
|
|
7441
|
-
// NO
|
|
7442
|
-
//
|
|
7443
|
-
//
|
|
7511
|
+
// NO FILLED SURFACE. The input is separated from the transcript by the rule above it and from the status
|
|
7512
|
+
// line by the rule below; a grey block on top of that was a second, heavier boundary saying the same
|
|
7513
|
+
// thing. The prompt glyph and the text colours carry the rest.
|
|
7444
7514
|
for (let ri = 0; ri < composer.rows.length; ri++) {
|
|
7445
7515
|
addHit(lines.length, 0, cInner, { kind: 'composerRow', rowIdx: ri });
|
|
7446
7516
|
// Colour the prompt glyph like the transcript's user marker and keep the typed TEXT white. The prefix is the
|
|
@@ -7449,7 +7519,7 @@ const queueH = takeover ? 0 : queuePanelHeight(state);
|
|
|
7449
7519
|
// Which chip the pointer is over, if any. `state.pasteHover` is the paste NUMBER, set by the mousehover
|
|
7450
7520
|
// handler from the same index maths the expand gesture uses, so the highlight and the click can never
|
|
7451
7521
|
// disagree about which chip they mean.
|
|
7452
|
-
const styledRow = highlightPasteMarkers(rawRow, state.pasteHover);
|
|
7522
|
+
const styledRow = highlightCommandName(highlightPasteMarkers(rawRow, state.pasteHover));
|
|
7453
7523
|
const pre = composerInput(state).prefix;
|
|
7454
7524
|
const textW = Math.max(1, cInner - 2);
|
|
7455
7525
|
// Apply composer text selection highlight if a selection is active.
|
|
@@ -7481,18 +7551,18 @@ const queueH = takeover ? 0 : queuePanelHeight(state);
|
|
|
7481
7551
|
: textPart;
|
|
7482
7552
|
rowAnsi = ' ' + indent + C.white + fitAnsi(highlighted, Math.max(1, textW - contWidth)) + ' ';
|
|
7483
7553
|
}
|
|
7484
|
-
|
|
7485
|
-
// re-asserted after each one — the same trick the code and terminal surfaces use.
|
|
7486
|
-
const surfaced = rowAnsi.replace(/\x1b\[0m/g, `\x1b[0m${C.composerBg}`);
|
|
7487
|
-
lines.push(C.composerBg + fitAnsi(surfaced, insideW + 2) + C.bgReset);
|
|
7554
|
+
lines.push(fitAnsi(rowAnsi, insideW + 2));
|
|
7488
7555
|
}
|
|
7489
7556
|
// AND THE RULE UNDER IT, mirroring the one above: the input is bounded by two faint rules, so it reads as a
|
|
7490
7557
|
// field between the conversation and the status line rather than as a block touching both.
|
|
7491
7558
|
lines.push(col('─'.repeat(w), C.border));
|
|
7492
7559
|
}
|
|
7493
7560
|
|
|
7494
|
-
|
|
7495
|
-
|
|
7561
|
+
// NO LEFT MARGIN: the menu's rule sits in column 0, aligned with the composer's own edge, instead of one
|
|
7562
|
+
// column in and looking detached from it.
|
|
7563
|
+
const MPAD = '';
|
|
7564
|
+
// The row is `│ content │`, and `insideW` is `w - 2`, so the content gets two columns less.
|
|
7565
|
+
const mInner = Math.max(1, insideW - 2);
|
|
7496
7566
|
const menuRow = (content) => MPAD + col('│', C.border) + ' ' + fitAnsi(content, mInner) + ' ' + col('│', C.border);
|
|
7497
7567
|
if (state.menuOpen && state.menuList.length && !takeover) {
|
|
7498
7568
|
const totalMatches = state.menuList.length;
|
|
@@ -7575,10 +7645,12 @@ const queueH = takeover ? 0 : queuePanelHeight(state);
|
|
|
7575
7645
|
? (thinkLevel ? ` thinking ${thinkLevel}` : ' thinking')
|
|
7576
7646
|
: state.seenThinking ? ' thinking' : '';
|
|
7577
7647
|
const label = state.modelLabel || state.model || '';
|
|
7578
|
-
// Plan / Focus / Swarm are mutually exclusive modes, so at most one badge is
|
|
7579
|
-
//
|
|
7580
|
-
//
|
|
7581
|
-
|
|
7648
|
+
// Plan / Focus / Swarm / PTC are mutually exclusive modes, so at most one badge is shown. Swarm uses a
|
|
7649
|
+
// spring-green (cyan shifted toward green) to stay in the theme family while reading as its own thing next to
|
|
7650
|
+
// Plan's cyan. PTC comes first: it narrows the toolset harder than any of the others, and a user who turned it on
|
|
7651
|
+
// needs to see that from the status line alone.
|
|
7652
|
+
const modeBadge = state.ptcMode ? col('PTC', C.orange + C.bold)
|
|
7653
|
+
: state.plan ? col('Plan', C.cyan + C.bold)
|
|
7582
7654
|
: state.focus ? col('Focus', C.blue + C.bold)
|
|
7583
7655
|
: state.swarm ? col('Swarm', C.spring + C.bold)
|
|
7584
7656
|
: '';
|
|
@@ -7892,7 +7964,14 @@ const queueH = takeover ? 0 : queuePanelHeight(state);
|
|
|
7892
7964
|
}
|
|
7893
7965
|
}
|
|
7894
7966
|
|
|
7895
|
-
|
|
7967
|
+
// THE PAGE COLOUR IS THE BASE OF EVERY ROW, and it is re-asserted after every reset the row embeds: an
|
|
7968
|
+
// `ESC[0m` ends an inline span but also clears the background, so seeding only the front left most of the row
|
|
7969
|
+
// unpainted. A cell with its own background keeps it — that escape comes later and overrides this.
|
|
7970
|
+
let padded = lines.map((l) => {
|
|
7971
|
+
if (isImageRow(l)) return l; // a bitmap payload is not text; a trailing background would corrupt it
|
|
7972
|
+
const base = fitAnsi(l, w).replace(/\x1b\[0m/g, `\x1b[0m${C.bg}`);
|
|
7973
|
+
return C.bg + base + C.bgReset;
|
|
7974
|
+
});
|
|
7896
7975
|
// Mixin seam: beforeRender - plugins may rewrite the painted lines. Runs before the
|
|
7897
7976
|
// ANSI string is built so the change actually reaches the screen.
|
|
7898
7977
|
try { const out = runPatchSync('beforeRender', { lines: padded, state, cols: w, rows: h }, (c) => c); if (out && Array.isArray(out.lines)) padded = out.lines; } catch (e) {}
|
|
@@ -8526,6 +8605,9 @@ export function makeState({ cfg, session, opts }) {
|
|
|
8526
8605
|
plan: !!(session && session.plan),
|
|
8527
8606
|
planPath: (session && session.planPath) || null,
|
|
8528
8607
|
focus: !!(session && session.focus),
|
|
8608
|
+
// PTC mode is per-SESSION for the same reason as focus: it changes which tools the model is even offered, so a
|
|
8609
|
+
// resume that forgot it would quietly hand the model a different toolset than the one it was working with.
|
|
8610
|
+
ptcMode: !!(session && session.ptcMode),
|
|
8529
8611
|
// Swarm mode is per-SESSION (like plan/focus), not just per-config: it is
|
|
8530
8612
|
// restored here and written by persistState(). Reading only config.toml left
|
|
8531
8613
|
// it off after /sessions resume, /fork and a plain restart.
|
|
@@ -10374,6 +10456,26 @@ export async function dispatch(cmdRaw, arg, state, cfg, session, h, submit, stdo
|
|
|
10374
10456
|
: 'Auto title: OFF — the name comes only from /title.');
|
|
10375
10457
|
return;
|
|
10376
10458
|
}
|
|
10459
|
+
case 'ptc': {
|
|
10460
|
+
// PTC MODE: the only tool the model is given is `PTC`, and every real tool call happens inside its sandbox.
|
|
10461
|
+
//
|
|
10462
|
+
// WHY A MODE AND NOT A SUGGESTION. The tool's own description asks the model to prefer it for loops, and a
|
|
10463
|
+
// model is free to ignore that — a `for f in $(ls); do grep …; done` through Bash does the same work with the
|
|
10464
|
+
// same context cost the sandbox exists to avoid. The promise is only real when the direct path is gone.
|
|
10465
|
+
const a = raw.trim().toLowerCase();
|
|
10466
|
+
let want;
|
|
10467
|
+
if (a === 'on') want = true;
|
|
10468
|
+
else if (a === 'off') want = false;
|
|
10469
|
+
else if (a === '') { app(`PTC mode: ${state.ptcMode ? 'on' : 'off'}. /ptc [on|off]`); return; }
|
|
10470
|
+
else { appErr('Usage: /ptc [on|off]'); return; }
|
|
10471
|
+
state.ptcMode = want;
|
|
10472
|
+
if (session) session.ptcMode = want;
|
|
10473
|
+
try { sess.saveSession(session); } catch { /* a preference; a failed save must not block the mode */ }
|
|
10474
|
+
app(want
|
|
10475
|
+
? 'PTC mode: ON — the model gets only the PTC tool and reaches everything else through its sandbox.'
|
|
10476
|
+
: 'PTC mode: OFF — direct tool calls are available again.');
|
|
10477
|
+
return;
|
|
10478
|
+
}
|
|
10377
10479
|
case 'title': {
|
|
10378
10480
|
if (raw) {
|
|
10379
10481
|
session.title = raw.slice(0, 200);
|
|
@@ -12931,6 +13033,7 @@ export async function dispatch(cmdRaw, arg, state, cfg, session, h, submit, stdo
|
|
|
12931
13033
|
plan: session.plan,
|
|
12932
13034
|
planPath: session.planPath,
|
|
12933
13035
|
focus: session.focus,
|
|
13036
|
+
ptcMode: session.ptcMode,
|
|
12934
13037
|
swarm: session.swarm,
|
|
12935
13038
|
effort: session.effort,
|
|
12936
13039
|
theme: session.theme,
|
|
@@ -14710,7 +14813,13 @@ const agents = readAgentsMd(state.cwd || state.workspace || cfg.workspace, state
|
|
|
14710
14813
|
// Remember the value HERE, at the start, so that a /focus the user sets while the
|
|
14711
14814
|
// turn is running survives instead of being cancelled by the turn-end cleanup.
|
|
14712
14815
|
const focusAtTurnStart = !!state.focus;
|
|
14713
|
-
|
|
14816
|
+
// PTC MODE WINS OVER EVERY OTHER FILTER. It exists to make a specific promise — "every tool call goes through
|
|
14817
|
+
// the sandbox, so a loop over forty files costs one round trip and a handful of tokens" — and that promise is
|
|
14818
|
+
// only kept if the model CANNOT reach a tool directly. Leaving even one out (Bash above all) hands back the
|
|
14819
|
+
// whole machine and the guarantee evaporates.
|
|
14820
|
+
if (state.ptcMode) {
|
|
14821
|
+
cfg.toolFilter = ['PTC'];
|
|
14822
|
+
} else if (state.plan) {
|
|
14714
14823
|
cfg.toolFilter = ['Read', 'Grep', 'Glob'];
|
|
14715
14824
|
} else if (state.focus) {
|
|
14716
14825
|
cfg.toolFilter = ['Read', 'Write', 'Edit', 'Bash'];
|
|
@@ -14816,7 +14925,7 @@ const agents = readAgentsMd(state.cwd || state.workspace || cfg.workspace, state
|
|
|
14816
14925
|
const own = getTool(toolName);
|
|
14817
14926
|
if (own && own.autoApprove === true) return true;
|
|
14818
14927
|
}
|
|
14819
|
-
const safeTools = ['Read', 'Grep', 'Glob', 'FetchURL', 'WebSearch', 'TaskOutput', 'TaskList', 'TaskStop', 'TaskWait', 'TodoList', 'Goal', 'ActivateSkill', '
|
|
14928
|
+
const safeTools = ['Read', 'Grep', 'Glob', 'FetchURL', 'WebSearch', 'TaskOutput', 'TaskList', 'TaskStop', 'TaskWait', 'TodoList', 'Goal', 'ActivateSkill', 'PTC', 'FileLines', 'AgentList', 'AgentMessage', 'AgentInterrupt', 'AgentClose', 'TaskInput', 'SendMessage', 'TeamTaskCreate', 'TeamTaskUpdate', 'TeamTaskList', 'ListTeammates', 'Memory', 'AskUserQuestion'];
|
|
14820
14929
|
if (rule !== 'ask' && safeTools.includes(toolName)) return true;
|
|
14821
14930
|
// A read-only SHELL COMMAND (ls/git status/rg/cat …) is as safe as a
|
|
14822
14931
|
// read-only TOOL, so it runs without a prompt in Ask mode too — the user
|
|
@@ -15684,6 +15793,9 @@ const agents = readAgentsMd(state.cwd || state.workspace || cfg.workspace, state
|
|
|
15684
15793
|
// the current value) decides, so a /focus issued while the turn ran still stands.
|
|
15685
15794
|
if (focusAtTurnStart) state.focus = false;
|
|
15686
15795
|
session.focus = !!state.focus;
|
|
15796
|
+
// PTC mode PERSISTS, unlike focus: it is not a one-turn narrowing, it is a decision about how this session
|
|
15797
|
+
// works, and the user set it deliberately.
|
|
15798
|
+
session.ptcMode = !!state.ptcMode;
|
|
15687
15799
|
session.swarm = !!state.swarm;
|
|
15688
15800
|
// The turn's token totals, so a resumed session keeps the running cost rather
|
|
15689
15801
|
// than restarting it at zero (the numbers have to sum across the whole
|