@causyne/agent 1.20.31 → 1.20.32
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 +8 -0
- package/src/agentLoop.ts +7 -0
- package/src/mcp/mcpRegistry.js +3 -1
- package/src/mcp/mcpRegistry.ts +3 -1
- package/src/tools/memoryWrite.js +71 -89
- package/src/tools/memoryWrite.ts +108 -0
- package/src/tui/consoleGuard.js +85 -0
- package/src/tui/consoleGuard.ts +102 -0
- package/src/tui/messageActionPlacement.js +8 -3
- package/src/tui/messageActionPlacement.ts +8 -3
- package/src/tui/messageInteraction.js +184 -27
- package/src/tui/messageInteraction.ts +221 -45
- package/src/tui/mouseHover.js +4 -0
- package/src/tui/mouseHover.ts +5 -0
- package/src/tui/smartLinkClick.js +353 -0
- package/src/tui/smartLinkClick.ts +413 -0
package/package.json
CHANGED
package/src/agentLoop.js
CHANGED
|
@@ -1735,6 +1735,14 @@ export class AgentLoop {
|
|
|
1735
1735
|
}
|
|
1736
1736
|
this.userPrompt = null; // Clear so we don't push it again
|
|
1737
1737
|
this.attachments = null; // Clear attachments
|
|
1738
|
+
if (this.memoryManager && typeof this.memoryManager.saveHistory === 'function') {
|
|
1739
|
+
try {
|
|
1740
|
+
this.memoryManager.saveHistory(this.messages);
|
|
1741
|
+
}
|
|
1742
|
+
catch {
|
|
1743
|
+
// Best-effort early persistence so active turns are immediately forkable/revertable.
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1738
1746
|
}
|
|
1739
1747
|
this.stepsCompleted = 0;
|
|
1740
1748
|
// Fresh per task. A digest from a previous task would point at a step
|
package/src/agentLoop.ts
CHANGED
|
@@ -1831,6 +1831,13 @@ export class AgentLoop {
|
|
|
1831
1831
|
|
|
1832
1832
|
this.userPrompt = null; // Clear so we don't push it again
|
|
1833
1833
|
this.attachments = null; // Clear attachments
|
|
1834
|
+
if (this.memoryManager && typeof (this.memoryManager as any).saveHistory === 'function') {
|
|
1835
|
+
try {
|
|
1836
|
+
(this.memoryManager as any).saveHistory(this.messages);
|
|
1837
|
+
} catch {
|
|
1838
|
+
// Best-effort early persistence so active turns are immediately forkable/revertable.
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1834
1841
|
}
|
|
1835
1842
|
|
|
1836
1843
|
this.stepsCompleted = 0;
|
package/src/mcp/mcpRegistry.js
CHANGED
|
@@ -331,7 +331,9 @@ export async function discoverTools() {
|
|
|
331
331
|
}
|
|
332
332
|
catch (error) {
|
|
333
333
|
const message = error instanceof Error ? error.message : String(error);
|
|
334
|
-
|
|
334
|
+
if (process.env.CAUSYNE_DEBUG === '1') {
|
|
335
|
+
console.warn(`[MCP] ${server.name} unavailable: ${message}`);
|
|
336
|
+
}
|
|
335
337
|
return [];
|
|
336
338
|
}
|
|
337
339
|
}));
|
package/src/mcp/mcpRegistry.ts
CHANGED
|
@@ -355,7 +355,9 @@ export async function discoverTools(): Promise<DynamicToolDefinition[]> {
|
|
|
355
355
|
.concat(utilityDefinitions(server, client));
|
|
356
356
|
} catch (error) {
|
|
357
357
|
const message = error instanceof Error ? error.message : String(error);
|
|
358
|
-
|
|
358
|
+
if (process.env.CAUSYNE_DEBUG === '1') {
|
|
359
|
+
console.warn(`[MCP] ${server.name} unavailable: ${message}`);
|
|
360
|
+
}
|
|
359
361
|
return [];
|
|
360
362
|
}
|
|
361
363
|
}));
|
package/src/tools/memoryWrite.js
CHANGED
|
@@ -1,99 +1,81 @@
|
|
|
1
|
+
// @ts-expect-error Legacy memory module has no TypeScript declarations yet.
|
|
1
2
|
import { getMemory, saveMemory } from '../memory.js';
|
|
2
3
|
import { cortexDb } from '../cortex/vectorDb.js';
|
|
3
|
-
|
|
4
|
-
// Persistent memory write.
|
|
5
|
-
//
|
|
6
|
-
// This tool used to append facts to `{cwd}/.causyne_memory_store.json` — a file
|
|
7
|
-
// that nothing in the codebase ever reads. The facts the agent is actually shown
|
|
8
|
-
// come from `getMemoryContextString()`, which reads `~/.causyne/memory.json`, and
|
|
9
|
-
|
|
10
|
-
// never connected, so every fact the agent chose to remember was written into a
|
|
11
|
-
// per-project dead end and silently lost. It now writes where the agent reads.
|
|
12
|
-
|
|
13
4
|
const MAX_FACTS = 100;
|
|
14
|
-
|
|
15
5
|
export const memoryWrite = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
6
|
+
schema: {
|
|
7
|
+
name: 'memory_write',
|
|
8
|
+
description: 'Save a durable fact about the user, their machine, or their project into persistent memory. Facts saved here are injected into your system context on every future task, so record only things worth remembering across sessions (preferences, conventions, paths, stack choices). After completing a web or UI design, also pass creativePattern so you do not repeat the same aesthetic next time.',
|
|
9
|
+
parameters: {
|
|
10
|
+
type: 'object',
|
|
11
|
+
properties: {
|
|
12
|
+
fact: {
|
|
13
|
+
type: 'string',
|
|
14
|
+
description: 'The concise, durable fact to remember. One fact per call.'
|
|
15
|
+
},
|
|
16
|
+
creativePattern: {
|
|
17
|
+
type: 'object',
|
|
18
|
+
description: 'Optional. Record a completed design so future projects deliberately differ from it.',
|
|
19
|
+
properties: {
|
|
20
|
+
project: { type: 'string', description: 'What was built, e.g. "coffee roaster landing page".' },
|
|
21
|
+
designApproach: { type: 'string', description: 'The design movement committed to, e.g. "Swiss International", "Brutalism".' },
|
|
22
|
+
colorPalette: { type: 'string', description: 'The palette used, e.g. "warm neutrals + oxblood accent".' },
|
|
23
|
+
fonts: { type: 'string', description: 'Typefaces used, e.g. "Space Grotesk / Inter".' }
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
required: ['fact']
|
|
35
28
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
execute: async (args, dependencies) => {
|
|
42
|
-
if (!args || !args.fact) {
|
|
43
|
-
return { success: false, error: "Missing 'fact' parameter." };
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
try {
|
|
47
|
-
const memory = getMemory();
|
|
48
|
-
if (!Array.isArray(memory.facts)) memory.facts = [];
|
|
49
|
-
|
|
50
|
-
const fact = String(args.fact).trim();
|
|
51
|
-
const alreadyKnown = memory.facts.includes(fact);
|
|
52
|
-
|
|
53
|
-
if (!alreadyKnown) {
|
|
54
|
-
memory.facts.push(fact);
|
|
55
|
-
// Self-culling: keep the store bounded so it cannot grow into the
|
|
56
|
-
// system prompt without limit.
|
|
57
|
-
while (memory.facts.length > MAX_FACTS) {
|
|
58
|
-
memory.facts.shift();
|
|
29
|
+
},
|
|
30
|
+
execute: async (args, dependencies) => {
|
|
31
|
+
if (!args || !args.fact) {
|
|
32
|
+
return { success: false, error: "Missing 'fact' parameter." };
|
|
59
33
|
}
|
|
60
|
-
saveMemory(memory);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Anti-slop creative memory. saveCreativePattern() existed but had no
|
|
64
|
-
// caller anywhere, so getRecentCreativePatterns() always returned empty
|
|
65
|
-
// and the "DO NOT REPEAT RECENT PATTERNS" directive never once fired.
|
|
66
|
-
let creativeSaved = false;
|
|
67
|
-
if (args.creativePattern && args.creativePattern.designApproach) {
|
|
68
34
|
try {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
35
|
+
const memory = getMemory();
|
|
36
|
+
if (!Array.isArray(memory.facts))
|
|
37
|
+
memory.facts = [];
|
|
38
|
+
const fact = String(args.fact).trim();
|
|
39
|
+
const alreadyKnown = memory.facts.includes(fact);
|
|
40
|
+
if (!alreadyKnown) {
|
|
41
|
+
memory.facts.push(fact);
|
|
42
|
+
while (memory.facts.length > MAX_FACTS) {
|
|
43
|
+
memory.facts.shift();
|
|
44
|
+
}
|
|
45
|
+
saveMemory(memory);
|
|
46
|
+
}
|
|
47
|
+
let creativeSaved = false;
|
|
48
|
+
if (args.creativePattern && args.creativePattern.designApproach) {
|
|
49
|
+
try {
|
|
50
|
+
await cortexDb.saveCreativePattern({
|
|
51
|
+
project: args.creativePattern.project || 'untitled project',
|
|
52
|
+
designApproach: args.creativePattern.designApproach,
|
|
53
|
+
colorPalette: args.creativePattern.colorPalette || 'unspecified',
|
|
54
|
+
fonts: args.creativePattern.fonts || 'unspecified'
|
|
55
|
+
});
|
|
56
|
+
creativeSaved = true;
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// Optional Cortex dependencies may not be installed; standard local session memory remains active.
|
|
60
|
+
// Never write raw errors to console.error during a TUI session as that corrupts the composer viewport.
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (dependencies && typeof dependencies.broadcast === 'function') {
|
|
64
|
+
dependencies.broadcast({
|
|
65
|
+
type: 'agent_message',
|
|
66
|
+
content: `🧠 Persistent memory updated: "${fact}"`
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
const notes = [
|
|
70
|
+
alreadyKnown ? 'Fact already known, not duplicated.' : 'Fact saved.',
|
|
71
|
+
`Total persistent facts: ${memory.facts.length}.`,
|
|
72
|
+
creativeSaved ? 'Creative pattern recorded in the V5 Cortex.' : ''
|
|
73
|
+
].filter(Boolean);
|
|
74
|
+
return { success: true, output: notes.join(' ') };
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
78
|
+
return { success: false, error: `Failed to save memory: ${msg}` };
|
|
78
79
|
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (dependencies && dependencies.broadcast) {
|
|
82
|
-
dependencies.broadcast({
|
|
83
|
-
type: 'agent_message',
|
|
84
|
-
content: `🧠 Persistent memory updated: "${fact}"`
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const notes = [
|
|
89
|
-
alreadyKnown ? 'Fact already known, not duplicated.' : 'Fact saved.',
|
|
90
|
-
`Total persistent facts: ${memory.facts.length}.`,
|
|
91
|
-
creativeSaved ? 'Creative pattern recorded in the V5 Cortex.' : ''
|
|
92
|
-
].filter(Boolean);
|
|
93
|
-
|
|
94
|
-
return { success: true, output: notes.join(' ') };
|
|
95
|
-
} catch (e) {
|
|
96
|
-
return { success: false, error: `Failed to save memory: ${e.message}` };
|
|
97
80
|
}
|
|
98
|
-
}
|
|
99
81
|
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// @ts-expect-error Legacy memory module has no TypeScript declarations yet.
|
|
2
|
+
import { getMemory, saveMemory } from '../memory.js';
|
|
3
|
+
import { cortexDb } from '../cortex/vectorDb.js';
|
|
4
|
+
|
|
5
|
+
const MAX_FACTS = 100;
|
|
6
|
+
|
|
7
|
+
export interface CreativePatternInput {
|
|
8
|
+
project?: string;
|
|
9
|
+
designApproach?: string;
|
|
10
|
+
colorPalette?: string;
|
|
11
|
+
fonts?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface MemoryWriteArgs {
|
|
15
|
+
fact?: string;
|
|
16
|
+
creativePattern?: CreativePatternInput;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface MemoryWriteDependencies {
|
|
20
|
+
broadcast?: (event: { type: string; content: string }) => void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const memoryWrite = {
|
|
24
|
+
schema: {
|
|
25
|
+
name: 'memory_write',
|
|
26
|
+
description:
|
|
27
|
+
'Save a durable fact about the user, their machine, or their project into persistent memory. Facts saved here are injected into your system context on every future task, so record only things worth remembering across sessions (preferences, conventions, paths, stack choices). After completing a web or UI design, also pass creativePattern so you do not repeat the same aesthetic next time.',
|
|
28
|
+
parameters: {
|
|
29
|
+
type: 'object',
|
|
30
|
+
properties: {
|
|
31
|
+
fact: {
|
|
32
|
+
type: 'string',
|
|
33
|
+
description: 'The concise, durable fact to remember. One fact per call.'
|
|
34
|
+
},
|
|
35
|
+
creativePattern: {
|
|
36
|
+
type: 'object',
|
|
37
|
+
description: 'Optional. Record a completed design so future projects deliberately differ from it.',
|
|
38
|
+
properties: {
|
|
39
|
+
project: { type: 'string', description: 'What was built, e.g. "coffee roaster landing page".' },
|
|
40
|
+
designApproach: { type: 'string', description: 'The design movement committed to, e.g. "Swiss International", "Brutalism".' },
|
|
41
|
+
colorPalette: { type: 'string', description: 'The palette used, e.g. "warm neutrals + oxblood accent".' },
|
|
42
|
+
fonts: { type: 'string', description: 'Typefaces used, e.g. "Space Grotesk / Inter".' }
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
required: ['fact']
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
execute: async (
|
|
51
|
+
args: MemoryWriteArgs | null | undefined,
|
|
52
|
+
dependencies?: MemoryWriteDependencies
|
|
53
|
+
): Promise<{ success: boolean; output?: string; error?: string }> => {
|
|
54
|
+
if (!args || !args.fact) {
|
|
55
|
+
return { success: false, error: "Missing 'fact' parameter." };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
const memory = getMemory() as { facts?: string[] };
|
|
60
|
+
if (!Array.isArray(memory.facts)) memory.facts = [];
|
|
61
|
+
|
|
62
|
+
const fact = String(args.fact).trim();
|
|
63
|
+
const alreadyKnown = memory.facts.includes(fact);
|
|
64
|
+
|
|
65
|
+
if (!alreadyKnown) {
|
|
66
|
+
memory.facts.push(fact);
|
|
67
|
+
while (memory.facts.length > MAX_FACTS) {
|
|
68
|
+
memory.facts.shift();
|
|
69
|
+
}
|
|
70
|
+
saveMemory(memory);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let creativeSaved = false;
|
|
74
|
+
if (args.creativePattern && args.creativePattern.designApproach) {
|
|
75
|
+
try {
|
|
76
|
+
await cortexDb.saveCreativePattern({
|
|
77
|
+
project: args.creativePattern.project || 'untitled project',
|
|
78
|
+
designApproach: args.creativePattern.designApproach,
|
|
79
|
+
colorPalette: args.creativePattern.colorPalette || 'unspecified',
|
|
80
|
+
fonts: args.creativePattern.fonts || 'unspecified'
|
|
81
|
+
});
|
|
82
|
+
creativeSaved = true;
|
|
83
|
+
} catch {
|
|
84
|
+
// Optional Cortex dependencies may not be installed; standard local session memory remains active.
|
|
85
|
+
// Never write raw errors to console.error during a TUI session as that corrupts the composer viewport.
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (dependencies && typeof dependencies.broadcast === 'function') {
|
|
90
|
+
dependencies.broadcast({
|
|
91
|
+
type: 'agent_message',
|
|
92
|
+
content: `🧠 Persistent memory updated: "${fact}"`
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const notes = [
|
|
97
|
+
alreadyKnown ? 'Fact already known, not duplicated.' : 'Fact saved.',
|
|
98
|
+
`Total persistent facts: ${memory.facts.length}.`,
|
|
99
|
+
creativeSaved ? 'Creative pattern recorded in the V5 Cortex.' : ''
|
|
100
|
+
].filter(Boolean);
|
|
101
|
+
|
|
102
|
+
return { success: true, output: notes.join(' ') };
|
|
103
|
+
} catch (e) {
|
|
104
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
105
|
+
return { success: false, error: `Failed to save memory: ${msg}` };
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const activeStageHosts = new Set();
|
|
2
|
+
let stageMouseSessionDepth = 0;
|
|
3
|
+
let guardInstalled = false;
|
|
4
|
+
const originalConsole = {
|
|
5
|
+
log: console.log.bind(console),
|
|
6
|
+
info: console.info.bind(console),
|
|
7
|
+
warn: console.warn.bind(console),
|
|
8
|
+
error: console.error.bind(console)
|
|
9
|
+
};
|
|
10
|
+
export function isAnyStageReservedOnStdout() {
|
|
11
|
+
if (stageMouseSessionDepth > 0 && process.stdout?.isTTY) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
for (const host of activeStageHosts) {
|
|
15
|
+
if (host.stage?.reserved && (!host.out || host.out === process.stdout)) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
function ensureConsoleGuardInstalled() {
|
|
22
|
+
if (guardInstalled)
|
|
23
|
+
return;
|
|
24
|
+
guardInstalled = true;
|
|
25
|
+
const wrap = (fn) => (...args) => {
|
|
26
|
+
if (isAnyStageReservedOnStdout()) {
|
|
27
|
+
// Never write raw console output while the full-screen TUI Stage owns stdout,
|
|
28
|
+
// because the terminal cursor rests inside the composer input box and raw
|
|
29
|
+
// writes corrupt the composer rows and shift the physical cursor.
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
fn(...args);
|
|
33
|
+
};
|
|
34
|
+
console.log = wrap(originalConsole.log);
|
|
35
|
+
console.info = wrap(originalConsole.info);
|
|
36
|
+
console.warn = wrap(originalConsole.warn);
|
|
37
|
+
console.error = wrap(originalConsole.error);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Track TUI Stage open/close lifecycle so raw console writes cannot corrupt the composer box.
|
|
41
|
+
*/
|
|
42
|
+
export function setStageConsoleGuardActive(active) {
|
|
43
|
+
ensureConsoleGuardInstalled();
|
|
44
|
+
if (active) {
|
|
45
|
+
stageMouseSessionDepth = Math.max(1, stageMouseSessionDepth + 1);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
stageMouseSessionDepth = Math.max(0, stageMouseSessionDepth - 1);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Register a StageSurface host so raw console writes are suppressed while its Stage is reserved.
|
|
53
|
+
*/
|
|
54
|
+
export function registerStageConsoleGuard(host) {
|
|
55
|
+
ensureConsoleGuardInstalled();
|
|
56
|
+
activeStageHosts.add(host);
|
|
57
|
+
return () => {
|
|
58
|
+
activeStageHosts.delete(host);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const noticeTimers = new WeakMap();
|
|
62
|
+
/**
|
|
63
|
+
* Set a transient status notice on the prompt/composer host and auto-clear it after `ttlMs`
|
|
64
|
+
* if nothing else has overwritten `host.notice` in the meantime.
|
|
65
|
+
*/
|
|
66
|
+
export function setTransientNotice(host, message, ttlMs = 4000) {
|
|
67
|
+
const existing = noticeTimers.get(host);
|
|
68
|
+
if (existing) {
|
|
69
|
+
clearTimeout(existing);
|
|
70
|
+
noticeTimers.delete(host);
|
|
71
|
+
}
|
|
72
|
+
host.notice = message;
|
|
73
|
+
host.scheduleDraw();
|
|
74
|
+
if (!message || ttlMs <= 0)
|
|
75
|
+
return;
|
|
76
|
+
const timer = setTimeout(() => {
|
|
77
|
+
noticeTimers.delete(host);
|
|
78
|
+
if (host.notice === message) {
|
|
79
|
+
host.notice = '';
|
|
80
|
+
host.scheduleDraw();
|
|
81
|
+
}
|
|
82
|
+
}, ttlMs);
|
|
83
|
+
timer.unref?.();
|
|
84
|
+
noticeTimers.set(host, timer);
|
|
85
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
export interface ConsoleGuardStageHost {
|
|
2
|
+
out?: NodeJS.WriteStream | { rows?: number; columns?: number };
|
|
3
|
+
stage?: { reserved?: boolean; invalidate?: () => void };
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface TransientNoticeHost {
|
|
7
|
+
notice: string;
|
|
8
|
+
scheduleDraw(): void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const activeStageHosts = new Set<ConsoleGuardStageHost>();
|
|
12
|
+
let stageMouseSessionDepth = 0;
|
|
13
|
+
let guardInstalled = false;
|
|
14
|
+
|
|
15
|
+
const originalConsole = {
|
|
16
|
+
log: console.log.bind(console),
|
|
17
|
+
info: console.info.bind(console),
|
|
18
|
+
warn: console.warn.bind(console),
|
|
19
|
+
error: console.error.bind(console)
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export function isAnyStageReservedOnStdout(): boolean {
|
|
23
|
+
if (stageMouseSessionDepth > 0 && process.stdout?.isTTY) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
for (const host of activeStageHosts) {
|
|
27
|
+
if (host.stage?.reserved && (!host.out || host.out === process.stdout)) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function ensureConsoleGuardInstalled(): void {
|
|
35
|
+
if (guardInstalled) return;
|
|
36
|
+
guardInstalled = true;
|
|
37
|
+
|
|
38
|
+
const wrap = (fn: (...args: unknown[]) => void) => (...args: unknown[]): void => {
|
|
39
|
+
if (isAnyStageReservedOnStdout()) {
|
|
40
|
+
// Never write raw console output while the full-screen TUI Stage owns stdout,
|
|
41
|
+
// because the terminal cursor rests inside the composer input box and raw
|
|
42
|
+
// writes corrupt the composer rows and shift the physical cursor.
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
fn(...args);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
console.log = wrap(originalConsole.log);
|
|
49
|
+
console.info = wrap(originalConsole.info);
|
|
50
|
+
console.warn = wrap(originalConsole.warn);
|
|
51
|
+
console.error = wrap(originalConsole.error);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Track TUI Stage open/close lifecycle so raw console writes cannot corrupt the composer box.
|
|
56
|
+
*/
|
|
57
|
+
export function setStageConsoleGuardActive(active: boolean): void {
|
|
58
|
+
ensureConsoleGuardInstalled();
|
|
59
|
+
if (active) {
|
|
60
|
+
stageMouseSessionDepth = Math.max(1, stageMouseSessionDepth + 1);
|
|
61
|
+
} else {
|
|
62
|
+
stageMouseSessionDepth = Math.max(0, stageMouseSessionDepth - 1);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Register a StageSurface host so raw console writes are suppressed while its Stage is reserved.
|
|
68
|
+
*/
|
|
69
|
+
export function registerStageConsoleGuard(host: ConsoleGuardStageHost): () => void {
|
|
70
|
+
ensureConsoleGuardInstalled();
|
|
71
|
+
activeStageHosts.add(host);
|
|
72
|
+
return () => {
|
|
73
|
+
activeStageHosts.delete(host);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const noticeTimers = new WeakMap<TransientNoticeHost, ReturnType<typeof setTimeout>>();
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Set a transient status notice on the prompt/composer host and auto-clear it after `ttlMs`
|
|
81
|
+
* if nothing else has overwritten `host.notice` in the meantime.
|
|
82
|
+
*/
|
|
83
|
+
export function setTransientNotice(host: TransientNoticeHost, message: string, ttlMs = 4000): void {
|
|
84
|
+
const existing = noticeTimers.get(host);
|
|
85
|
+
if (existing) {
|
|
86
|
+
clearTimeout(existing);
|
|
87
|
+
noticeTimers.delete(host);
|
|
88
|
+
}
|
|
89
|
+
host.notice = message;
|
|
90
|
+
host.scheduleDraw();
|
|
91
|
+
if (!message || ttlMs <= 0) return;
|
|
92
|
+
|
|
93
|
+
const timer = setTimeout(() => {
|
|
94
|
+
noticeTimers.delete(host);
|
|
95
|
+
if (host.notice === message) {
|
|
96
|
+
host.notice = '';
|
|
97
|
+
host.scheduleDraw();
|
|
98
|
+
}
|
|
99
|
+
}, ttlMs);
|
|
100
|
+
timer.unref?.();
|
|
101
|
+
noticeTimers.set(host, timer);
|
|
102
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { truncate, visibleWidth } from './text.js';
|
|
2
|
-
|
|
1
|
+
import { padEnd, truncate, visibleWidth } from './text.js';
|
|
2
|
+
import { sliceFromColumn } from './turnRail.js';
|
|
3
|
+
/** Overlay a compact menu in the transcript viewport, near the selected message, without erasing left/right columns. */
|
|
3
4
|
export function placeMessageActionPanel(viewportRows, panel, contentWidth, stageTop, anchorY, count) {
|
|
4
5
|
if (!panel.length || viewportRows.length < panel.length || contentWidth < 8) {
|
|
5
6
|
return { rows: viewportRows, layout: null };
|
|
@@ -10,7 +11,11 @@ export function placeMessageActionPanel(viewportRows, panel, contentWidth, stage
|
|
|
10
11
|
const y = Math.max(0, Math.min(viewportRows.length - panel.length, anchor - Math.floor(panel.length / 2)));
|
|
11
12
|
const rows = viewportRows.slice();
|
|
12
13
|
for (let i = 0; i < panel.length; i++) {
|
|
13
|
-
rows[y + i]
|
|
14
|
+
const baseRow = rows[y + i] ?? '';
|
|
15
|
+
const leftPrefix = padEnd(truncate(baseRow, x, ''), x);
|
|
16
|
+
const cardChunk = padEnd(truncate(panel[i] ?? '', width, ''), width);
|
|
17
|
+
const rightSuffix = sliceFromColumn(baseRow, x + width);
|
|
18
|
+
rows[y + i] = `${leftPrefix}${cardChunk}${rightSuffix}`;
|
|
14
19
|
}
|
|
15
20
|
return { rows, layout: { x, y: stageTop + y, width, count } };
|
|
16
21
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { truncate, visibleWidth } from './text.js';
|
|
1
|
+
import { padEnd, truncate, visibleWidth } from './text.js';
|
|
2
|
+
import { sliceFromColumn } from './turnRail.js';
|
|
2
3
|
|
|
3
4
|
export interface MessageActionPlacement {
|
|
4
5
|
rows: string[];
|
|
5
6
|
layout: { x: number; y: number; width: number; count: number } | null;
|
|
6
7
|
}
|
|
7
8
|
|
|
8
|
-
/** Overlay a compact menu in the transcript viewport, near the selected message. */
|
|
9
|
+
/** Overlay a compact menu in the transcript viewport, near the selected message, without erasing left/right columns. */
|
|
9
10
|
export function placeMessageActionPanel(
|
|
10
11
|
viewportRows: string[], panel: string[], contentWidth: number,
|
|
11
12
|
stageTop: number, anchorY: number | null, count: number
|
|
@@ -19,7 +20,11 @@ export function placeMessageActionPanel(
|
|
|
19
20
|
const y = Math.max(0, Math.min(viewportRows.length - panel.length, anchor - Math.floor(panel.length / 2)));
|
|
20
21
|
const rows = viewportRows.slice();
|
|
21
22
|
for (let i = 0; i < panel.length; i++) {
|
|
22
|
-
rows[y + i]
|
|
23
|
+
const baseRow = rows[y + i] ?? '';
|
|
24
|
+
const leftPrefix = padEnd(truncate(baseRow, x, ''), x);
|
|
25
|
+
const cardChunk = padEnd(truncate(panel[i] ?? '', width, ''), width);
|
|
26
|
+
const rightSuffix = sliceFromColumn(baseRow, x + width);
|
|
27
|
+
rows[y + i] = `${leftPrefix}${cardChunk}${rightSuffix}`;
|
|
23
28
|
}
|
|
24
29
|
return { rows, layout: { x, y: stageTop + y, width, count } };
|
|
25
30
|
}
|