skyloom 1.12.0 → 1.13.1
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/.github/workflows/ci.yml +36 -36
- package/README.md +137 -46
- package/config/default.yaml +43 -47
- package/config/models.yaml +155 -155
- package/config/providers.yaml +39 -39
- package/config/skills/api_integrator/SKILL.md +15 -15
- package/config/skills/arch_designer/SKILL.md +13 -13
- package/config/skills/ci_cd_manager/SKILL.md +14 -14
- package/config/skills/code_analysis/SKILL.md +13 -13
- package/config/skills/code_generator/SKILL.md +12 -12
- package/config/skills/code_reviewer/SKILL.md +13 -13
- package/config/skills/content_writer/SKILL.md +14 -14
- package/config/skills/data_transformer/SKILL.md +15 -15
- package/config/skills/document_analysis/SKILL.md +13 -13
- package/config/skills/emotional_companion/SKILL.md +15 -15
- package/config/skills/performance_checker/SKILL.md +14 -14
- package/config/skills/security_auditor/SKILL.md +14 -14
- package/config/skills/self_evolve/SKILL.md +13 -13
- package/config/skills/sys_operator/SKILL.md +15 -15
- package/config/skills/task_planner/SKILL.md +14 -14
- package/config/skills/web_research/SKILL.md +14 -14
- package/config/skills/workflow_designer/SKILL.md +13 -13
- package/dist/agents/dew.js +52 -52
- package/dist/agents/fair.js +84 -84
- package/dist/agents/fog.js +30 -30
- package/dist/agents/frost.js +32 -32
- package/dist/agents/rain.js +32 -32
- package/dist/agents/snow.js +68 -68
- package/dist/cli/main.js +127 -74
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/tui.d.ts +52 -19
- package/dist/cli/tui.d.ts.map +1 -1
- package/dist/cli/tui.js +198 -265
- package/dist/cli/tui.js.map +1 -1
- package/dist/core/agent/task.d.ts +58 -0
- package/dist/core/agent/task.d.ts.map +1 -0
- package/dist/core/agent/task.js +83 -0
- package/dist/core/agent/task.js.map +1 -0
- package/dist/core/agent.d.ts +2 -45
- package/dist/core/agent.d.ts.map +1 -1
- package/dist/core/agent.js +61 -145
- package/dist/core/agent.js.map +1 -1
- package/dist/core/agent_helpers.d.ts +10 -0
- package/dist/core/agent_helpers.d.ts.map +1 -1
- package/dist/core/agent_helpers.js +39 -0
- package/dist/core/agent_helpers.js.map +1 -1
- package/dist/core/catalog.d.ts +71 -0
- package/dist/core/catalog.d.ts.map +1 -0
- package/dist/core/catalog.js +176 -0
- package/dist/core/catalog.js.map +1 -0
- package/dist/core/config.d.ts +8 -0
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +12 -4
- package/dist/core/config.js.map +1 -1
- package/dist/core/factory.js +16 -16
- package/dist/core/llm.d.ts +7 -0
- package/dist/core/llm.d.ts.map +1 -1
- package/dist/core/llm.js +139 -7
- package/dist/core/llm.js.map +1 -1
- package/dist/core/longdoc.js +5 -5
- package/dist/core/memory.d.ts.map +1 -1
- package/dist/core/memory.js +69 -62
- package/dist/core/memory.js.map +1 -1
- package/dist/core/theme.d.ts +46 -0
- package/dist/core/theme.d.ts.map +1 -0
- package/dist/core/theme.js +42 -0
- package/dist/core/theme.js.map +1 -0
- package/dist/web/server.js +542 -519
- package/dist/web/server.js.map +1 -1
- package/docs/AESTHETIC_DESIGN.md +144 -0
- package/docs/OPTIMIZATION_PLAN.md +178 -0
- package/package.json +60 -60
- package/scripts/install.js +48 -48
- package/scripts/link.js +10 -10
- package/setup.bat +79 -79
- package/skill-test-ty2fOA/test.md +10 -10
- package/src/agents/dew.ts +70 -70
- package/src/agents/fair.ts +102 -102
- package/src/agents/fog.ts +48 -48
- package/src/agents/frost.ts +50 -50
- package/src/agents/rain.ts +50 -50
- package/src/agents/snow.ts +239 -239
- package/src/cli/main.ts +417 -372
- package/src/cli/mode.ts +58 -58
- package/src/cli/tui.ts +174 -223
- package/src/core/agent/task.ts +100 -0
- package/src/core/agent.ts +1446 -1549
- package/src/core/agent_helpers.ts +496 -461
- package/src/core/arbitrate.ts +162 -162
- package/src/core/catalog.ts +178 -0
- package/src/core/checkpoint.ts +94 -94
- package/src/core/config.ts +20 -4
- package/src/core/estimate.ts +104 -104
- package/src/core/evolve.ts +191 -191
- package/src/core/factory.ts +627 -627
- package/src/core/filter.ts +103 -103
- package/src/core/graph.ts +156 -156
- package/src/core/icons.ts +53 -53
- package/src/core/index.ts +37 -37
- package/src/core/learn.ts +146 -146
- package/src/core/llm.ts +108 -5
- package/src/core/longdoc.ts +155 -155
- package/src/core/mcp_server.ts +176 -176
- package/src/core/memory.ts +1178 -1171
- package/src/core/profile.ts +255 -255
- package/src/core/router.ts +124 -124
- package/src/core/sandbox.ts +142 -142
- package/src/core/security.ts +243 -243
- package/src/core/skill.ts +342 -342
- package/src/core/theme.ts +65 -0
- package/src/core/tool_router.ts +193 -193
- package/src/core/vector.ts +152 -152
- package/src/core/workspace.ts +150 -150
- package/src/plugins/loader.ts +66 -66
- package/src/skills/loader.ts +46 -46
- package/src/sql.js.d.ts +29 -29
- package/src/tools/builtin.ts +380 -380
- package/src/tools/computer.ts +269 -269
- package/src/tools/delegate.ts +49 -49
- package/src/web/server.ts +660 -634
- package/src/web/tts.ts +93 -93
- package/tests/agent_helpers.test.ts +48 -0
- package/tests/bus.test.ts +121 -121
- package/tests/catalog.test.ts +86 -0
- package/tests/config.test.ts +41 -0
- package/tests/icons.test.ts +45 -45
- package/tests/memory.test.ts +147 -0
- package/tests/router.test.ts +86 -86
- package/tests/schemas.test.ts +51 -51
- package/tests/semantic.test.ts +83 -83
- package/tests/setup.ts +10 -10
- package/tests/skill.test.ts +172 -172
- package/tests/task.test.ts +60 -0
- package/tests/tool.test.ts +108 -108
- package/tests/tool_router.test.ts +71 -71
- package/tests/tui.test.ts +67 -0
- package/vitest.config.ts +17 -17
package/dist/cli/tui.d.ts
CHANGED
|
@@ -1,23 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 天空织机 TUI —
|
|
2
|
+
* 天空织机 TUI — a polished *linear* terminal interface.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* │ ≋ 雾 ▸ │ 用户消息右对齐 │
|
|
11
|
-
* │ ❉ 雪 │ │
|
|
12
|
-
* │ ∘ 露 │ │
|
|
13
|
-
* │ ⸽ 雨 │ │
|
|
14
|
-
* ├──────────┴──────────────────────────────┤
|
|
15
|
-
* │ ┌─ /fog /rain /frost /snow ───────┐│ ← command palette (popup)
|
|
16
|
-
* │ ▶ /fog Switch to Fog ││
|
|
17
|
-
* │ /rain Switch to Rain ││
|
|
18
|
-
* │ └──────────────────────────────────────┘│
|
|
19
|
-
* │ > hello world [send] │ ← input bar
|
|
20
|
-
* └─────────────────────────────────────────┘
|
|
4
|
+
* Design note: the previous version tried to be a full-screen app, redrawing
|
|
5
|
+
* the whole screen on every keystroke while the reply streamed linearly below
|
|
6
|
+
* it — the two fought, the conversation never persisted, and hand-rolled
|
|
7
|
+
* raw-mode editing mangled CJK width. This rewrite is linear (like Claude Code
|
|
8
|
+
* / opencode): real readline line-editing + a CJK-aware wrapping stream
|
|
9
|
+
* renderer. Robust, flicker-free, and it actually reads like a conversation.
|
|
21
10
|
*/
|
|
22
11
|
export interface TUIContext {
|
|
23
12
|
agent: any;
|
|
@@ -27,5 +16,49 @@ export interface TUIContext {
|
|
|
27
16
|
width: number;
|
|
28
17
|
height: number;
|
|
29
18
|
}
|
|
30
|
-
export declare
|
|
19
|
+
export declare const SLASH_COMMANDS: [string, string][];
|
|
20
|
+
/** Visual columns occupied by a single code point (CJK / fullwidth = 2). */
|
|
21
|
+
export declare function charWidth(cp: number): number;
|
|
22
|
+
/** Visual width of a string, ignoring ANSI color codes. */
|
|
23
|
+
export declare function visualWidth(s: string): number;
|
|
24
|
+
/** Pad a string (containing ANSI) to a visual width. */
|
|
25
|
+
export declare function padVisual(s: string, width: number): string;
|
|
26
|
+
/**
|
|
27
|
+
* Writes streamed text with a fixed left gutter, wrapping at the terminal
|
|
28
|
+
* width. English wraps on word boundaries; CJK wraps per glyph. Color is
|
|
29
|
+
* applied per flushed chunk so styling survives wrapping.
|
|
30
|
+
*/
|
|
31
|
+
export declare class StreamRenderer {
|
|
32
|
+
private col;
|
|
33
|
+
private word;
|
|
34
|
+
private atLineStart;
|
|
35
|
+
private out;
|
|
36
|
+
private gutter;
|
|
37
|
+
private maxCols;
|
|
38
|
+
private color;
|
|
39
|
+
constructor(out: NodeJS.WriteStream, opts?: {
|
|
40
|
+
gutter?: string;
|
|
41
|
+
color?: (s: string) => string;
|
|
42
|
+
});
|
|
43
|
+
/** Lazily emit the left gutter at the start of each visual line. */
|
|
44
|
+
private startLine;
|
|
45
|
+
private newline;
|
|
46
|
+
private flushWord;
|
|
47
|
+
/** Feed a chunk of streamed text. */
|
|
48
|
+
write(text: string): void;
|
|
49
|
+
/** Flush any buffered word (call before switching styles / ending). */
|
|
50
|
+
flush(): void;
|
|
51
|
+
}
|
|
52
|
+
/** The prompt string for an agent: a small mineral seal + chevron. */
|
|
53
|
+
export declare function promptFor(agentName: string): string;
|
|
54
|
+
/**
|
|
55
|
+
* Read one line with the agent-themed prompt. A fresh readline interface is
|
|
56
|
+
* created and closed per call — this deliberately avoids clashing with the
|
|
57
|
+
* separate readline prompts used by the setup wizard and tool-approval flow
|
|
58
|
+
* (two live interfaces on one stdin corrupt input). History is preserved
|
|
59
|
+
* manually across turns.
|
|
60
|
+
*/
|
|
61
|
+
export declare function readLine(agentName: string, out?: NodeJS.WriteStream): Promise<string>;
|
|
62
|
+
/** Render the inline slash-command palette (printed, not full-screen). */
|
|
63
|
+
export declare function renderPalette(filter: string): string;
|
|
31
64
|
//# sourceMappingURL=tui.d.ts.map
|
package/dist/cli/tui.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tui.d.ts","sourceRoot":"","sources":["../../src/cli/tui.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"tui.d.ts","sourceRoot":"","sources":["../../src/cli/tui.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAQH,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,GAAG,CAAC;IACX,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAGD,eAAO,MAAM,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAqB5C,CAAC;AAKF,4EAA4E;AAC5E,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAoB5C;AAID,2DAA2D;AAC3D,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAI7C;AAED,wDAAwD;AACxD,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAG1D;AAKD;;;;GAIG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,GAAG,CAAK;IAChB,OAAO,CAAC,IAAI,CAAM;IAClB,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,GAAG,CAAqB;IAChC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,KAAK,CAAwB;gBAEzB,GAAG,EAAE,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;KAAE;IAS9F,oEAAoE;IACpE,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,OAAO;IAEf,OAAO,CAAC,SAAS;IAUjB,qCAAqC;IACrC,KAAK,CAAC,IAAI,EAAE,MAAM;IAyBlB,uEAAuE;IACvE,KAAK;CACN;AAaD,sEAAsE;AACtE,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAGnD;AAKD;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,GAAE,MAAM,CAAC,WAA4B,GAAG,OAAO,CAAC,MAAM,CAAC,CAkBrG;AAED,0EAA0E;AAC1E,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAUpD"}
|
package/dist/cli/tui.js
CHANGED
|
@@ -1,24 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* 天空织机 TUI —
|
|
3
|
+
* 天空织机 TUI — a polished *linear* terminal interface.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* │ ≋ 雾 ▸ │ 用户消息右对齐 │
|
|
12
|
-
* │ ❉ 雪 │ │
|
|
13
|
-
* │ ∘ 露 │ │
|
|
14
|
-
* │ ⸽ 雨 │ │
|
|
15
|
-
* ├──────────┴──────────────────────────────┤
|
|
16
|
-
* │ ┌─ /fog /rain /frost /snow ───────┐│ ← command palette (popup)
|
|
17
|
-
* │ ▶ /fog Switch to Fog ││
|
|
18
|
-
* │ /rain Switch to Rain ││
|
|
19
|
-
* │ └──────────────────────────────────────┘│
|
|
20
|
-
* │ > hello world [send] │ ← input bar
|
|
21
|
-
* └─────────────────────────────────────────┘
|
|
5
|
+
* Design note: the previous version tried to be a full-screen app, redrawing
|
|
6
|
+
* the whole screen on every keystroke while the reply streamed linearly below
|
|
7
|
+
* it — the two fought, the conversation never persisted, and hand-rolled
|
|
8
|
+
* raw-mode editing mangled CJK width. This rewrite is linear (like Claude Code
|
|
9
|
+
* / opencode): real readline line-editing + a CJK-aware wrapping stream
|
|
10
|
+
* renderer. Robust, flicker-free, and it actually reads like a conversation.
|
|
22
11
|
*/
|
|
23
12
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
24
13
|
if (k2 === undefined) k2 = k;
|
|
@@ -57,274 +46,218 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
57
46
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
58
47
|
};
|
|
59
48
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
60
|
-
exports.
|
|
49
|
+
exports.StreamRenderer = exports.SLASH_COMMANDS = void 0;
|
|
50
|
+
exports.charWidth = charWidth;
|
|
51
|
+
exports.visualWidth = visualWidth;
|
|
52
|
+
exports.padVisual = padVisual;
|
|
53
|
+
exports.promptFor = promptFor;
|
|
54
|
+
exports.readLine = readLine;
|
|
55
|
+
exports.renderPalette = renderPalette;
|
|
61
56
|
const readline = __importStar(require("readline"));
|
|
62
57
|
const chalk_1 = __importDefault(require("chalk"));
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
["/
|
|
74
|
-
["/
|
|
75
|
-
["/
|
|
76
|
-
["/
|
|
77
|
-
["/
|
|
78
|
-
["/
|
|
79
|
-
["/retry", "重发上条"],
|
|
58
|
+
const theme_1 = require("../core/theme");
|
|
59
|
+
const TUI_VERSION = (() => { try {
|
|
60
|
+
return require("../../package.json").version;
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return "";
|
|
64
|
+
} })();
|
|
65
|
+
/* ── Slash commands (for tab-completion + the inline palette) ── */
|
|
66
|
+
exports.SLASH_COMMANDS = [
|
|
67
|
+
["/fog", "≋ 雾 · 探索洞察"],
|
|
68
|
+
["/rain", "⸽ 雨 · 创造产出"],
|
|
69
|
+
["/frost", "✱ 霜 · 精炼品质"],
|
|
70
|
+
["/snow", "❉ 雪 · 架构规划"],
|
|
71
|
+
["/dew", "∘ 露 · 可靠守护"],
|
|
72
|
+
["/fair", "☼ 晴 · 情感陪伴"],
|
|
73
|
+
["/help", "查看所有命令"],
|
|
80
74
|
["/setup", "配置向导"],
|
|
81
|
-
["/
|
|
82
|
-
["/
|
|
83
|
-
["/
|
|
84
|
-
["/task <goal>", "多Agent编排"],
|
|
75
|
+
["/model", "模型信息"],
|
|
76
|
+
["/cost", "费用统计"],
|
|
77
|
+
["/status", "状态总览"],
|
|
85
78
|
["/memory", "记忆状态"],
|
|
86
|
-
["/memory clear", "清除记忆"],
|
|
87
79
|
["/sessions", "会话列表"],
|
|
88
80
|
["/workspace", "工作空间"],
|
|
89
|
-
["/
|
|
81
|
+
["/compact", "压缩上下文"],
|
|
82
|
+
["/clear", "清屏"],
|
|
83
|
+
["/task ", "多 Agent 编排"],
|
|
84
|
+
["/mcp", "MCP 服务器"],
|
|
90
85
|
["/version", "版本信息"],
|
|
91
86
|
["/quit", "退出"],
|
|
92
87
|
];
|
|
93
|
-
/*
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
88
|
+
/* ════════════════════════════════════════
|
|
89
|
+
CJK-aware display width
|
|
90
|
+
════════════════════════════════════════ */
|
|
91
|
+
/** Visual columns occupied by a single code point (CJK / fullwidth = 2). */
|
|
92
|
+
function charWidth(cp) {
|
|
93
|
+
if (cp === 0)
|
|
94
|
+
return 0;
|
|
95
|
+
if (cp < 32 || (cp >= 0x7f && cp < 0xa0))
|
|
96
|
+
return 0; // control
|
|
97
|
+
// East-Asian wide / fullwidth ranges
|
|
98
|
+
if ((cp >= 0x1100 && cp <= 0x115f) || // Hangul Jamo
|
|
99
|
+
(cp >= 0x2e80 && cp <= 0x303e) || // CJK radicals, Kangxi, punctuation
|
|
100
|
+
(cp >= 0x3041 && cp <= 0x33ff) || // Hiragana…CJK symbols
|
|
101
|
+
(cp >= 0x3400 && cp <= 0x4dbf) || // CJK Ext A
|
|
102
|
+
(cp >= 0x4e00 && cp <= 0x9fff) || // CJK Unified
|
|
103
|
+
(cp >= 0xa000 && cp <= 0xa4cf) || // Yi
|
|
104
|
+
(cp >= 0xac00 && cp <= 0xd7a3) || // Hangul syllables
|
|
105
|
+
(cp >= 0xf900 && cp <= 0xfaff) || // CJK compat
|
|
106
|
+
(cp >= 0xfe10 && cp <= 0xfe19) ||
|
|
107
|
+
(cp >= 0xfe30 && cp <= 0xfe6f) || // CJK compat forms
|
|
108
|
+
(cp >= 0xff00 && cp <= 0xff60) || // Fullwidth forms
|
|
109
|
+
(cp >= 0xffe0 && cp <= 0xffe6) ||
|
|
110
|
+
(cp >= 0x1f300 && cp <= 0x1faff) // emoji / pictographs
|
|
111
|
+
)
|
|
112
|
+
return 2;
|
|
113
|
+
return 1;
|
|
97
114
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
: chalk_1.default.dim(B.v + " " + display[n].padEnd(W - 5) + B.v);
|
|
111
|
-
lines.push(line);
|
|
112
|
-
}
|
|
113
|
-
// Fill remaining space
|
|
114
|
-
for (let i = lines.length; i < h; i++) {
|
|
115
|
-
lines.push(chalk_1.default.dim(B.v + " ".repeat(W - 2) + B.v));
|
|
116
|
-
}
|
|
117
|
-
// Footer
|
|
118
|
-
try {
|
|
119
|
-
const cu = agent.contextUsage();
|
|
120
|
-
const pct = cu.pct || 0;
|
|
121
|
-
lines.push(chalk_1.default.dim(B.v + " ctx " + String(pct).padStart(3) + "%" + " ".repeat(W - 10) + B.v));
|
|
122
|
-
}
|
|
123
|
-
catch {
|
|
124
|
-
lines.push(chalk_1.default.dim(B.v + " ".repeat(W - 2) + B.v));
|
|
125
|
-
}
|
|
126
|
-
lines.push(chalk_1.default.dim(bar(B.bl, B.h, B.br, W - 2)));
|
|
127
|
-
return lines;
|
|
115
|
+
const ANSI_RE = /\x1b\[[0-9;]*m/g;
|
|
116
|
+
/** Visual width of a string, ignoring ANSI color codes. */
|
|
117
|
+
function visualWidth(s) {
|
|
118
|
+
let w = 0;
|
|
119
|
+
for (const ch of s.replace(ANSI_RE, ""))
|
|
120
|
+
w += charWidth(ch.codePointAt(0) || 0);
|
|
121
|
+
return w;
|
|
122
|
+
}
|
|
123
|
+
/** Pad a string (containing ANSI) to a visual width. */
|
|
124
|
+
function padVisual(s, width) {
|
|
125
|
+
const diff = width - visualWidth(s);
|
|
126
|
+
return diff > 0 ? s + " ".repeat(diff) : s;
|
|
128
127
|
}
|
|
129
|
-
/*
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
128
|
+
/* ════════════════════════════════════════
|
|
129
|
+
Streaming renderer — word-wrap aware, CJK aware
|
|
130
|
+
════════════════════════════════════════ */
|
|
131
|
+
/**
|
|
132
|
+
* Writes streamed text with a fixed left gutter, wrapping at the terminal
|
|
133
|
+
* width. English wraps on word boundaries; CJK wraps per glyph. Color is
|
|
134
|
+
* applied per flushed chunk so styling survives wrapping.
|
|
135
|
+
*/
|
|
136
|
+
class StreamRenderer {
|
|
137
|
+
constructor(out, opts) {
|
|
138
|
+
this.col = 0;
|
|
139
|
+
this.word = "";
|
|
140
|
+
this.atLineStart = true;
|
|
141
|
+
this.out = out;
|
|
142
|
+
this.gutter = opts?.gutter ?? " ";
|
|
143
|
+
this.color = opts?.color ?? ((s) => s);
|
|
144
|
+
const cols = out.columns || 80;
|
|
145
|
+
// content width excludes the gutter; clamp for readability
|
|
146
|
+
this.maxCols = Math.max(32, Math.min(cols - visualWidth(this.gutter) - 1, 96));
|
|
147
147
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
148
|
+
/** Lazily emit the left gutter at the start of each visual line. */
|
|
149
|
+
startLine() { if (this.atLineStart) {
|
|
150
|
+
this.out.write(this.gutter);
|
|
151
|
+
this.atLineStart = false;
|
|
152
|
+
} }
|
|
153
|
+
newline() { this.out.write("\n"); this.atLineStart = true; this.col = 0; }
|
|
154
|
+
flushWord() {
|
|
155
|
+
if (!this.word)
|
|
156
|
+
return;
|
|
157
|
+
const w = visualWidth(this.word);
|
|
158
|
+
if (this.col > 0 && this.col + w > this.maxCols)
|
|
159
|
+
this.newline();
|
|
160
|
+
this.startLine();
|
|
161
|
+
this.out.write(this.color(this.word));
|
|
162
|
+
this.col += w;
|
|
163
|
+
this.word = "";
|
|
160
164
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
165
|
+
/** Feed a chunk of streamed text. */
|
|
166
|
+
write(text) {
|
|
167
|
+
for (const ch of text) {
|
|
168
|
+
if (ch === "\r")
|
|
169
|
+
continue; // normalize CRLF / stray CR from providers
|
|
170
|
+
if (ch === "\n") {
|
|
171
|
+
this.flushWord();
|
|
172
|
+
this.newline();
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
if (ch === " " || ch === "\t") {
|
|
176
|
+
this.flushWord();
|
|
177
|
+
if (this.col > 0 && this.col < this.maxCols) {
|
|
178
|
+
this.startLine();
|
|
179
|
+
this.out.write(" ");
|
|
180
|
+
this.col += 1;
|
|
181
|
+
}
|
|
182
|
+
continue;
|
|
178
183
|
}
|
|
179
|
-
|
|
180
|
-
|
|
184
|
+
const cp = ch.codePointAt(0) || 0;
|
|
185
|
+
if (charWidth(cp) === 2) {
|
|
186
|
+
// CJK / wide: flush any pending latin word, then place this glyph
|
|
187
|
+
this.flushWord();
|
|
188
|
+
if (this.col > 0 && this.col + 2 > this.maxCols)
|
|
189
|
+
this.newline();
|
|
190
|
+
this.startLine();
|
|
191
|
+
this.out.write(this.color(ch));
|
|
192
|
+
this.col += 2;
|
|
181
193
|
}
|
|
182
194
|
else {
|
|
183
|
-
|
|
195
|
+
this.word += ch;
|
|
196
|
+
// very long unbroken token: hard-break to avoid overflow
|
|
197
|
+
if (visualWidth(this.word) >= this.maxCols)
|
|
198
|
+
this.flushWord();
|
|
184
199
|
}
|
|
185
|
-
remaining = remaining.slice(idx).trimStart();
|
|
186
200
|
}
|
|
187
201
|
}
|
|
188
|
-
|
|
202
|
+
/** Flush any buffered word (call before switching styles / ending). */
|
|
203
|
+
flush() { this.flushWord(); }
|
|
189
204
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
stdin.setRawMode(true);
|
|
234
|
-
stdin.resume();
|
|
235
|
-
render();
|
|
236
|
-
let escBuf = "";
|
|
237
|
-
stdin.on("data", (data) => {
|
|
238
|
-
const str = data.toString();
|
|
239
|
-
escBuf += str;
|
|
240
|
-
if (escBuf.startsWith("\x1b[") && escBuf.length >= 3) {
|
|
241
|
-
const code = escBuf[2];
|
|
242
|
-
escBuf = "";
|
|
243
|
-
if (code === "A") {
|
|
244
|
-
if (palette)
|
|
245
|
-
selIdx = Math.max(0, selIdx - 1);
|
|
246
|
-
render();
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
if (code === "B") {
|
|
250
|
-
if (palette) {
|
|
251
|
-
const all = [...AGENT_CMDS.map(c => c[1]), ...ACTION_CMDS.map(c => c[0])];
|
|
252
|
-
selIdx = Math.min(all.filter(a => a.includes(buf)).length - 1, selIdx + 1);
|
|
253
|
-
}
|
|
254
|
-
render();
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
if (code === "C") {
|
|
258
|
-
if (cursor < buf.length)
|
|
259
|
-
cursor++;
|
|
260
|
-
render();
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
if (code === "D") {
|
|
264
|
-
if (cursor > 0)
|
|
265
|
-
cursor--;
|
|
266
|
-
render();
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
for (const ch of escBuf) {
|
|
271
|
-
escBuf = "";
|
|
272
|
-
if (ch === "\x1b") {
|
|
273
|
-
palette = false;
|
|
274
|
-
render();
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
if (ch === "\r" || ch === "\n") {
|
|
278
|
-
if (palette) {
|
|
279
|
-
const all = [...AGENT_CMDS.map(c => c[1]), ...ACTION_CMDS.map(c => c[0])];
|
|
280
|
-
const filtered = all.filter(a => a.includes(buf));
|
|
281
|
-
if (filtered[selIdx])
|
|
282
|
-
buf = filtered[selIdx];
|
|
283
|
-
palette = false;
|
|
284
|
-
render();
|
|
285
|
-
stdin.setRawMode(false);
|
|
286
|
-
stdin.pause();
|
|
287
|
-
resolve(buf.trim());
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
stdin.setRawMode(false);
|
|
291
|
-
stdin.pause();
|
|
292
|
-
resolve(buf.trim());
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
if (ch === "\t") { /* ignore */
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
if (ch === "\x7f" || ch === "\b") {
|
|
299
|
-
if (cursor > 0) {
|
|
300
|
-
buf = buf.slice(0, cursor - 1) + buf.slice(cursor);
|
|
301
|
-
cursor--;
|
|
302
|
-
}
|
|
303
|
-
if (!buf)
|
|
304
|
-
palette = false;
|
|
305
|
-
render();
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
if (ch === "\x03") {
|
|
309
|
-
stdin.setRawMode(false);
|
|
310
|
-
stdin.pause();
|
|
311
|
-
resolve("/quit");
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
if (ch >= " ") {
|
|
315
|
-
buf = buf.slice(0, cursor) + ch + buf.slice(cursor);
|
|
316
|
-
cursor++;
|
|
317
|
-
if (ch === "/") {
|
|
318
|
-
palette = true;
|
|
319
|
-
selIdx = 0;
|
|
320
|
-
}
|
|
321
|
-
else if (palette)
|
|
322
|
-
selIdx = 0;
|
|
323
|
-
render();
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
205
|
+
exports.StreamRenderer = StreamRenderer;
|
|
206
|
+
/* ════════════════════════════════════════
|
|
207
|
+
Input — readline-based, robust line editing
|
|
208
|
+
════════════════════════════════════════ */
|
|
209
|
+
/** Tab-completer for slash commands. */
|
|
210
|
+
function slashCompleter(line) {
|
|
211
|
+
if (!line.startsWith("/"))
|
|
212
|
+
return [[], line];
|
|
213
|
+
const names = exports.SLASH_COMMANDS.map(([c]) => c.trimEnd());
|
|
214
|
+
const hits = names.filter((c) => c.startsWith(line));
|
|
215
|
+
return [hits.length ? hits : names, line];
|
|
216
|
+
}
|
|
217
|
+
/** The prompt string for an agent: a small mineral seal + chevron. */
|
|
218
|
+
function promptFor(agentName) {
|
|
219
|
+
const t = (0, theme_1.agentTheme)(agentName);
|
|
220
|
+
return chalk_1.default.hex(t.hex)(` ${t.symbol} ${t.kanji} `) + chalk_1.default.hex(theme_1.PALETTE.inkLight)("❯ ");
|
|
221
|
+
}
|
|
222
|
+
/** Cross-turn input history (↑/↓), shared by every per-turn reader. */
|
|
223
|
+
const inputHistory = [];
|
|
224
|
+
/**
|
|
225
|
+
* Read one line with the agent-themed prompt. A fresh readline interface is
|
|
226
|
+
* created and closed per call — this deliberately avoids clashing with the
|
|
227
|
+
* separate readline prompts used by the setup wizard and tool-approval flow
|
|
228
|
+
* (two live interfaces on one stdin corrupt input). History is preserved
|
|
229
|
+
* manually across turns.
|
|
230
|
+
*/
|
|
231
|
+
function readLine(agentName, out = process.stdout) {
|
|
232
|
+
return new Promise((resolve) => {
|
|
233
|
+
const rl = readline.createInterface({
|
|
234
|
+
input: process.stdin,
|
|
235
|
+
output: out,
|
|
236
|
+
completer: slashCompleter,
|
|
237
|
+
terminal: process.stdin.isTTY ?? false,
|
|
238
|
+
history: [...inputHistory],
|
|
239
|
+
historySize: 200,
|
|
240
|
+
});
|
|
241
|
+
rl.on("SIGINT", () => { out.write("\n" + chalk_1.default.dim(" 再会。\n")); rl.close(); process.exit(0); });
|
|
242
|
+
rl.question(promptFor(agentName), (answer) => {
|
|
243
|
+
const trimmed = answer.trim();
|
|
244
|
+
if (trimmed)
|
|
245
|
+
inputHistory.unshift(trimmed);
|
|
246
|
+
rl.close();
|
|
247
|
+
resolve(trimmed);
|
|
327
248
|
});
|
|
328
249
|
});
|
|
329
250
|
}
|
|
251
|
+
/** Render the inline slash-command palette (printed, not full-screen). */
|
|
252
|
+
function renderPalette(filter) {
|
|
253
|
+
const f = filter.toLowerCase();
|
|
254
|
+
const matches = exports.SLASH_COMMANDS.filter(([c]) => c.toLowerCase().startsWith(f));
|
|
255
|
+
const list = matches.length ? matches : exports.SLASH_COMMANDS;
|
|
256
|
+
const lines = list.slice(0, 12).map(([cmd, desc]) => {
|
|
257
|
+
const isAgent = ["/fog", "/rain", "/frost", "/snow", "/dew", "/fair"].includes(cmd.trim());
|
|
258
|
+
const name = isAgent ? chalk_1.default.hex((0, theme_1.agentTheme)(cmd.trim().slice(1)).hex)(cmd.padEnd(12)) : chalk_1.default.hex(theme_1.PALETTE.inkMid)(cmd.padEnd(12));
|
|
259
|
+
return " " + name + chalk_1.default.hex(theme_1.PALETTE.inkLight)(desc);
|
|
260
|
+
});
|
|
261
|
+
return chalk_1.default.dim(" 命令 · Tab 补全\n") + lines.join("\n") + "\n";
|
|
262
|
+
}
|
|
330
263
|
//# sourceMappingURL=tui.js.map
|