@causyne/agent 1.20.100 → 1.20.104
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/bin/causyne.js +18 -1
- package/package.json +1 -1
- package/src/agentLoop.js +101 -41
- package/src/agentLoop.ts +96 -42
- package/src/autoUpdate.js +4 -4
- package/src/autoUpdate.ts +4 -4
- package/src/cliMode.js +2 -0
- package/src/compiledSkills.d.ts +5 -0
- package/src/launchIntent.js +120 -9
- package/src/launchIntent.ts +123 -9
- package/src/observer/evidence.js +2 -1
- package/src/observer/evidence.ts +2 -1
- package/src/observer.js +39 -4
- package/src/observer.ts +35 -5
- package/src/plugins/pluginManager.d.ts +7 -0
- package/src/promptMentions.js +1 -1
- package/src/promptMentions.ts +1 -1
- package/src/skills/skillResourceSafety.js +7 -2
- package/src/skills/skillResourceSafety.ts +8 -2
- package/src/skillsManager.js +224 -234
- package/src/skillsManager.ts +354 -0
- package/src/timeMachine.js +20 -8
- package/src/timeMachine.ts +20 -8
- package/src/tools/createSkill.js +92 -104
- package/src/tools/createSkill.ts +142 -0
- package/src/tools/fsEdit.js +104 -91
- package/src/tools/fsEdit.ts +144 -0
- package/src/tools/gitExec.js +64 -24
- package/src/tools/multiEdit.js +105 -93
- package/src/tools/multiEdit.ts +145 -0
- package/src/tui/chatRenderer.js +14 -6
- package/src/tui/mouseHover.js +0 -4
- package/src/tui/mouseHover.ts +0 -4
- package/src/tui/prompt.js +12 -0
- package/src/tui/sessionSidebar.js +5 -3
- package/src/tui/sessionSidebar.ts +5 -3
- package/src/tui/stageSurface.js +64 -17
- package/src/userSkills.js +2 -2
- package/src/userSkills.ts +3 -2
- package/src/skillsManager.d.ts +0 -7
package/src/tui/mouseHover.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import { setStageConsoleGuardActive } from './consoleGuard.js';
|
|
2
1
|
/**
|
|
3
2
|
* Terminal-wide motion reports (?1003h) allow hover feedback, but hijack native mouse selection.
|
|
4
3
|
* Disabled by default so users can freely select, drag, and copy text in the terminal.
|
|
5
4
|
* Opt-in via CAUSYNE_MOUSE_HOVER=1.
|
|
6
5
|
*/
|
|
7
6
|
export function mouseHoverTracking(enabled, env = process.env) {
|
|
8
|
-
if (env === process.env) {
|
|
9
|
-
setStageConsoleGuardActive(enabled);
|
|
10
|
-
}
|
|
11
7
|
if (String(env.CAUSYNE_MOUSE_HOVER ?? '0') !== '1')
|
|
12
8
|
return '';
|
|
13
9
|
return enabled ? '\x1b[?1003h' : '\x1b[?1003l';
|
package/src/tui/mouseHover.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { setStageConsoleGuardActive } from './consoleGuard.js';
|
|
2
1
|
|
|
3
2
|
/**
|
|
4
3
|
* Terminal-wide motion reports (?1003h) allow hover feedback, but hijack native mouse selection.
|
|
@@ -6,9 +5,6 @@ import { setStageConsoleGuardActive } from './consoleGuard.js';
|
|
|
6
5
|
* Opt-in via CAUSYNE_MOUSE_HOVER=1.
|
|
7
6
|
*/
|
|
8
7
|
export function mouseHoverTracking(enabled: boolean, env: NodeJS.ProcessEnv = process.env): string {
|
|
9
|
-
if (env === process.env) {
|
|
10
|
-
setStageConsoleGuardActive(enabled);
|
|
11
|
-
}
|
|
12
8
|
if (String(env.CAUSYNE_MOUSE_HOVER ?? '0') !== '1') return '';
|
|
13
9
|
return enabled ? '\x1b[?1003h' : '\x1b[?1003l';
|
|
14
10
|
}
|
package/src/tui/prompt.js
CHANGED
|
@@ -131,6 +131,7 @@ export class ChatPrompt {
|
|
|
131
131
|
|
|
132
132
|
this.busy = false;
|
|
133
133
|
this.active = false;
|
|
134
|
+
this.exitHook = null;
|
|
134
135
|
this.drawnRows = 0;
|
|
135
136
|
this.usageCard = null;
|
|
136
137
|
|
|
@@ -194,6 +195,13 @@ export class ChatPrompt {
|
|
|
194
195
|
this.input.resume();
|
|
195
196
|
this.input.on('data', this.handleData);
|
|
196
197
|
this.out.write(bracketedPaste(true));
|
|
198
|
+
// Node's normal exit does not guarantee ChatPrompt.stop() is called.
|
|
199
|
+
// Always restore bracketed paste and raw stdin when the process exits.
|
|
200
|
+
this.exitHook = () => {
|
|
201
|
+
try { this.out.write(bracketedPaste(false)); } catch { /* terminal already closed */ }
|
|
202
|
+
try { this.input.setRawMode(false); } catch { /* stdin already closed */ }
|
|
203
|
+
};
|
|
204
|
+
process.once('exit', this.exitHook);
|
|
197
205
|
// Rows are laid out against the terminal width; without this they stay stale
|
|
198
206
|
// until the next keystroke, and a narrowed terminal wraps rows that erase()
|
|
199
207
|
// is still counting as one.
|
|
@@ -219,6 +227,10 @@ export class ChatPrompt {
|
|
|
219
227
|
this.input.off('data', this.handleData);
|
|
220
228
|
try { this.input.setRawMode(false); } catch (e) { /* already closed */ }
|
|
221
229
|
this.input.pause();
|
|
230
|
+
if (this.exitHook) {
|
|
231
|
+
process.removeListener('exit', this.exitHook);
|
|
232
|
+
this.exitHook = null;
|
|
233
|
+
}
|
|
222
234
|
}
|
|
223
235
|
|
|
224
236
|
/**
|
|
@@ -3,7 +3,9 @@ import { padEnd, safeDisplay, truncate } from './text.js';
|
|
|
3
3
|
// @ts-expect-error theme.js has no TypeScript declaration yet.
|
|
4
4
|
import { bold, dim, fill, paint } from './theme.js';
|
|
5
5
|
export const SIDEBAR_WIDTH = 42;
|
|
6
|
-
|
|
6
|
+
// A 42-column sidebar is only useful if the conversation retains a readable width.
|
|
7
|
+
// Narrow IDE terminals should prioritize the user's complete message over metadata.
|
|
8
|
+
export const SIDEBAR_THRESHOLD = 160;
|
|
7
9
|
/** A side panel is useful only when a readable conversation column remains. */
|
|
8
10
|
export function sidebarVisible(columns, home = false) {
|
|
9
11
|
if (typeof process !== 'undefined' && process.env) {
|
|
@@ -22,11 +24,11 @@ export function sessionMainWidth(columns, home = false) {
|
|
|
22
24
|
export function sessionComposerWidth(columns) {
|
|
23
25
|
const available = Number.isFinite(columns) ? Math.max(20, Math.floor(columns)) : 80;
|
|
24
26
|
if (available <= 112) {
|
|
25
|
-
return Math.max(20, available -
|
|
27
|
+
return Math.max(20, available - 4);
|
|
26
28
|
}
|
|
27
29
|
// Dynamic readable measure scaling on wide terminals:
|
|
28
30
|
const readableMeasure = Math.round(109 + 20 * Math.log2(available / 112));
|
|
29
|
-
return Math.min(available -
|
|
31
|
+
return Math.min(available - 4, Math.max(20, readableMeasure));
|
|
30
32
|
}
|
|
31
33
|
/** Render only facts the runtime can actually report. */
|
|
32
34
|
export function sessionSidebarRows(facts, height) {
|
|
@@ -4,7 +4,9 @@ import { padEnd, safeDisplay, truncate } from './text.js';
|
|
|
4
4
|
import { bold, dim, fill, paint } from './theme.js';
|
|
5
5
|
|
|
6
6
|
export const SIDEBAR_WIDTH = 42;
|
|
7
|
-
|
|
7
|
+
// A 42-column sidebar is only useful if the conversation retains a readable width.
|
|
8
|
+
// Narrow IDE terminals should prioritize the user's complete message over metadata.
|
|
9
|
+
export const SIDEBAR_THRESHOLD = 160;
|
|
8
10
|
|
|
9
11
|
export interface SidebarFacts {
|
|
10
12
|
title?: string;
|
|
@@ -37,11 +39,11 @@ export function sessionMainWidth(columns: number, home = false): number {
|
|
|
37
39
|
export function sessionComposerWidth(columns: number): number {
|
|
38
40
|
const available = Number.isFinite(columns) ? Math.max(20, Math.floor(columns)) : 80;
|
|
39
41
|
if (available <= 112) {
|
|
40
|
-
return Math.max(20, available -
|
|
42
|
+
return Math.max(20, available - 4);
|
|
41
43
|
}
|
|
42
44
|
// Dynamic readable measure scaling on wide terminals:
|
|
43
45
|
const readableMeasure = Math.round(109 + 20 * Math.log2(available / 112));
|
|
44
|
-
return Math.min(available -
|
|
46
|
+
return Math.min(available - 4, Math.max(20, readableMeasure));
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
/** Render only facts the runtime can actually report. */
|
package/src/tui/stageSurface.js
CHANGED
|
@@ -60,6 +60,44 @@ const RAIL_BUDGET = RAIL_WIDTH + 1;
|
|
|
60
60
|
// The interactive turn rail takes three columns at the left of each row.
|
|
61
61
|
const TURN_RAIL_BUDGET = 3;
|
|
62
62
|
|
|
63
|
+
// Count a prefix of terminal control sequences with a deterministic scan.
|
|
64
|
+
// This preserves CSI, OSC (BEL/ST), and two-byte ESC codes without regex
|
|
65
|
+
// backtracking on long or malformed terminal output.
|
|
66
|
+
export function leadingAnsiControlEnd(row) {
|
|
67
|
+
if (typeof row !== 'string') return 0;
|
|
68
|
+
let index = 0;
|
|
69
|
+
while (row.charCodeAt(index) === 27) {
|
|
70
|
+
let cursor = index + 1;
|
|
71
|
+
const kind = row.charCodeAt(cursor);
|
|
72
|
+
if (kind === 91) { // ESC [
|
|
73
|
+
cursor++;
|
|
74
|
+
while (row.charCodeAt(cursor) >= 48 && row.charCodeAt(cursor) <= 63) cursor++;
|
|
75
|
+
while (row.charCodeAt(cursor) >= 32 && row.charCodeAt(cursor) <= 47) cursor++;
|
|
76
|
+
const final = row.charCodeAt(cursor);
|
|
77
|
+
if (final >= 64 && final <= 126) {
|
|
78
|
+
index = cursor + 1;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
} else if (kind === 93) { // ESC ] ... BEL or ESC backslash
|
|
82
|
+
cursor++;
|
|
83
|
+
while (cursor < row.length && row.charCodeAt(cursor) !== 7 && row.charCodeAt(cursor) !== 27) cursor++;
|
|
84
|
+
if (row.charCodeAt(cursor) === 7) {
|
|
85
|
+
index = cursor + 1;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (row.charCodeAt(cursor) === 27 && row.charCodeAt(cursor + 1) === 92) {
|
|
89
|
+
index = cursor + 2;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
} else if ((kind >= 64 && kind <= 90) || (kind >= 92 && kind <= 95)) {
|
|
93
|
+
index = cursor + 1;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
return index;
|
|
99
|
+
}
|
|
100
|
+
|
|
63
101
|
// Which marker wins when several frames fall in the same rail row. A proportional
|
|
64
102
|
// rail on a long session compresses dozens of frames per row, and what you want
|
|
65
103
|
// to see at a glance is the thing that went wrong or the thing you can roll back
|
|
@@ -265,7 +303,7 @@ export class StageSurface {
|
|
|
265
303
|
}
|
|
266
304
|
|
|
267
305
|
enableMouse() {
|
|
268
|
-
if (!this.mouseWanted || this.mouseOn) return false;
|
|
306
|
+
if (!this.mouseWanted || this.mouseOn || !this.stage.reserved) return false;
|
|
269
307
|
this.out.write(mouseTracking(true));
|
|
270
308
|
this.out.write(mouseHoverTracking(true, this.env));
|
|
271
309
|
this.mouseCaptured = true;
|
|
@@ -273,12 +311,14 @@ export class StageSurface {
|
|
|
273
311
|
return true;
|
|
274
312
|
}
|
|
275
313
|
|
|
276
|
-
disableMouse() {
|
|
277
|
-
if (!this.mouseOn) return false;
|
|
278
|
-
|
|
314
|
+
disableMouse(force = false) {
|
|
315
|
+
if (!force && !this.mouseOn && !this.mouseCaptured) return false;
|
|
316
|
+
// Restore terminal motion modes, including stale tracking from an interrupted turn.
|
|
317
|
+
this.out.write(mouseHoverTracking(false, { ...this.env, CAUSYNE_MOUSE_HOVER: '1' }));
|
|
279
318
|
this.out.write(mouseTracking(false));
|
|
280
319
|
this.mouseCaptured = false;
|
|
281
320
|
this.mouseOn = false;
|
|
321
|
+
this.detached = false;
|
|
282
322
|
return true;
|
|
283
323
|
}
|
|
284
324
|
|
|
@@ -310,9 +350,8 @@ export class StageSurface {
|
|
|
310
350
|
}
|
|
311
351
|
|
|
312
352
|
close() {
|
|
313
|
-
//
|
|
314
|
-
|
|
315
|
-
this.disableMouse();
|
|
353
|
+
// Force the terminal to release tracking, even if internal flags were stale.
|
|
354
|
+
this.disableMouse(true);
|
|
316
355
|
if (this.unregisterConsoleGuard) {
|
|
317
356
|
this.unregisterConsoleGuard();
|
|
318
357
|
this.unregisterConsoleGuard = null;
|
|
@@ -477,6 +516,16 @@ export class StageSurface {
|
|
|
477
516
|
if (budget > 0) {
|
|
478
517
|
this.viewport.resize({ height: budget, width: contentWidth });
|
|
479
518
|
rows = alignTranscriptRows(this.viewport.rows(), contentRows);
|
|
519
|
+
// In follow mode, the viewport can land on the blank separator between
|
|
520
|
+
// two assistant frames after enough replies to fill the band. Show a
|
|
521
|
+
// subtle boundary marker in that same row instead of a visible void.
|
|
522
|
+
// Do not shift row indices: rails, hover targets and reading anchors
|
|
523
|
+
// are keyed to the original transcript row positions.
|
|
524
|
+
if (this.viewport.following && this.viewport.maxScrollTop() > 0
|
|
525
|
+
&& rows.length > 0 && stripAnsi(rows[0] || '').trim() === ''
|
|
526
|
+
&& rows.some(row => stripAnsi(row).trim() !== '')) {
|
|
527
|
+
rows[0] = paint('rule', ` ${GLYPHS.dot} `);
|
|
528
|
+
}
|
|
480
529
|
this.decorate(rows, contentWidth);
|
|
481
530
|
markHoveredMessage(rows, this, contentWidth);
|
|
482
531
|
if (rail) this.attachRail(rows, contentWidth);
|
|
@@ -727,10 +776,10 @@ export class StageSurface {
|
|
|
727
776
|
let row = rows[i] || '';
|
|
728
777
|
if (hasTurns && railResult) {
|
|
729
778
|
const leftCell = railResult.cells[i] || ' ';
|
|
730
|
-
const
|
|
731
|
-
if (
|
|
732
|
-
const leadEscapes =
|
|
733
|
-
row = `${leadEscapes} ${leftCell} ${row.slice(
|
|
779
|
+
const leadEnd = leadingAnsiControlEnd(row);
|
|
780
|
+
if (row.slice(leadEnd, leadEnd + 3) === ' ') {
|
|
781
|
+
const leadEscapes = row.slice(0, leadEnd);
|
|
782
|
+
row = `${leadEscapes} ${leftCell} ${row.slice(leadEnd + 3)}`;
|
|
734
783
|
} else if (stripAnsi(row).length === 0) {
|
|
735
784
|
row = leftCell !== ' ' ? ` ${leftCell} ` : '';
|
|
736
785
|
} else {
|
|
@@ -766,7 +815,8 @@ export class StageSurface {
|
|
|
766
815
|
|
|
767
816
|
/** Take it back, once the user is driving the band again. */
|
|
768
817
|
captureMouse() {
|
|
769
|
-
|
|
818
|
+
// Home and suspended stages must not arm modes their teardown cannot observe.
|
|
819
|
+
if (!this.mouseWanted || !this.mouseOn || !this.stage.reserved || this.mouseCaptured) return false;
|
|
770
820
|
this.out.write(mouseTracking(true));
|
|
771
821
|
this.out.write(mouseHoverTracking(true, this.env));
|
|
772
822
|
this.mouseCaptured = true;
|
|
@@ -789,11 +839,8 @@ export function createStageSurface({ out = process.stdout, env = process.env, co
|
|
|
789
839
|
if (env.CAUSYNE_SIMPLE_INPUT === '1') return null;
|
|
790
840
|
if (stageHeight(out, env) < 1) return null;
|
|
791
841
|
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
: env;
|
|
795
|
-
|
|
796
|
-
const surface = new StageSurface({ out, env: effectiveEnv, config, speed, openingWidth });
|
|
842
|
+
// Terminal-wide motion tracking is opt-in, never silently enabled by the TUI.
|
|
843
|
+
const surface = new StageSurface({ out, env, config, speed, openingWidth });
|
|
797
844
|
if (!surface.open()) return null;
|
|
798
845
|
return surface;
|
|
799
846
|
}
|
package/src/userSkills.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { causyneHome } from './utils/paths.js';
|
|
4
|
-
import { assertSkillFileSafe, assertSkillTreeSafe, writeSkillFileSafely } from './skills/skillResourceSafety.js';
|
|
4
|
+
import { assertSkillFileSafe, assertSkillTreeSafe, writeSkillFileSafely, isPathWithin } from './skills/skillResourceSafety.js';
|
|
5
5
|
// Bounds. Every one of these protects the context window, which is the resource
|
|
6
6
|
// a skill library actually spends.
|
|
7
7
|
export const MAX_USER_SKILLS = 200;
|
|
@@ -224,7 +224,7 @@ export function writeUserSkill({ domain, name, content, overwrite = false }, roo
|
|
|
224
224
|
// segment has been joined. Validation above already makes this unreachable.
|
|
225
225
|
const resolvedRoot = path.resolve(root);
|
|
226
226
|
const resolvedFile = path.resolve(file);
|
|
227
|
-
if (resolvedFile
|
|
227
|
+
if (!isPathWithin(resolvedFile, resolvedRoot)) {
|
|
228
228
|
return { ok: false, error: 'refusing to write outside the skills directory' };
|
|
229
229
|
}
|
|
230
230
|
if (!overwrite && fs.existsSync(file)) {
|
package/src/userSkills.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { causyneHome } from './utils/paths.js';
|
|
|
4
4
|
import {
|
|
5
5
|
assertSkillFileSafe,
|
|
6
6
|
assertSkillTreeSafe,
|
|
7
|
-
writeSkillFileSafely
|
|
7
|
+
writeSkillFileSafely,
|
|
8
|
+
isPathWithin
|
|
8
9
|
} from './skills/skillResourceSafety.js';
|
|
9
10
|
|
|
10
11
|
export interface UserSkill {
|
|
@@ -256,7 +257,7 @@ export function writeUserSkill(
|
|
|
256
257
|
// segment has been joined. Validation above already makes this unreachable.
|
|
257
258
|
const resolvedRoot = path.resolve(root);
|
|
258
259
|
const resolvedFile = path.resolve(file);
|
|
259
|
-
if (resolvedFile
|
|
260
|
+
if (!isPathWithin(resolvedFile, resolvedRoot)) {
|
|
260
261
|
return { ok: false, error: 'refusing to write outside the skills directory' };
|
|
261
262
|
}
|
|
262
263
|
|
package/src/skillsManager.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export function detectWorkspaceDomains(...args: any[]): any;
|
|
2
|
-
export function ensureSkillRepo(...args: any[]): any;
|
|
3
|
-
export function getSkillDomainHeader(...args: any[]): any;
|
|
4
|
-
export function listCompiledSkills(): Array<{ id: string; name: string; domain: string; description?: string; source?: string }>;
|
|
5
|
-
export function readCompiledSkill(domain: string, skillId: string): string;
|
|
6
|
-
export function invalidateUserSkills(): void;
|
|
7
|
-
export function userSkillProblems(): string[];
|