@kolisachint/hoocode-agent 0.4.111 → 0.4.113
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/CHANGELOG.md +73 -0
- package/dist/cli/args.d.ts +1 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +8 -3
- package/dist/cli/args.js.map +1 -1
- package/dist/core/extensions/loader.d.ts +10 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +17 -2
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/plugins/marketplace.d.ts +36 -5
- package/dist/core/extensions/plugins/marketplace.d.ts.map +1 -1
- package/dist/core/extensions/plugins/marketplace.js +63 -17
- package/dist/core/extensions/plugins/marketplace.js.map +1 -1
- package/dist/core/scheduler.d.ts +8 -2
- package/dist/core/scheduler.d.ts.map +1 -1
- package/dist/core/scheduler.js +9 -3
- package/dist/core/scheduler.js.map +1 -1
- package/dist/core/settings-defaults.d.ts +1 -1
- package/dist/core/settings-defaults.d.ts.map +1 -1
- package/dist/core/settings-defaults.js +2 -2
- package/dist/core/settings-defaults.js.map +1 -1
- package/dist/core/settings-types.d.ts.map +1 -1
- package/dist/core/settings-types.js.map +1 -1
- package/dist/core/subagent-events.d.ts +21 -0
- package/dist/core/subagent-events.d.ts.map +1 -0
- package/dist/core/subagent-events.js +25 -0
- package/dist/core/subagent-events.js.map +1 -0
- package/dist/core/subagent-pool.d.ts +5 -4
- package/dist/core/subagent-pool.d.ts.map +1 -1
- package/dist/core/subagent-pool.js +7 -9
- package/dist/core/subagent-pool.js.map +1 -1
- package/dist/core/tools/subagent.d.ts +15 -3
- package/dist/core/tools/subagent.d.ts.map +1 -1
- package/dist/core/tools/subagent.js +27 -14
- package/dist/core/tools/subagent.js.map +1 -1
- package/dist/extensions/core/loop.d.ts.map +1 -1
- package/dist/extensions/core/loop.js +4 -1
- package/dist/extensions/core/loop.js.map +1 -1
- package/dist/extensions/core/marketplace.d.ts +5 -3
- package/dist/extensions/core/marketplace.d.ts.map +1 -1
- package/dist/extensions/core/marketplace.js +37 -15
- package/dist/extensions/core/marketplace.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +27 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +150 -7
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +18 -0
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/task-panel.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-panel.js +5 -2
- package/dist/modes/interactive/components/task-panel.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +17 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +78 -5
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts +4 -0
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +12 -3
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +12 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +75 -4
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/voice/voice-controller.d.ts.map +1 -1
- package/dist/modes/interactive/voice/voice-controller.js +9 -5
- package/dist/modes/interactive/voice/voice-controller.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +10 -3
- package/dist/modes/print-mode.js.map +1 -1
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package.json +1 -1
- package/package.json +4 -4
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
* /plugin — marketplace add/list + plugin install/list/remove.
|
|
3
3
|
*
|
|
4
4
|
* `/plugin` installs plugins from marketplaces (a git repo or local dir with a
|
|
5
|
-
*
|
|
6
|
-
* index). Installed plugins are placed in
|
|
7
|
-
*
|
|
5
|
+
* native `.agents-plugin/marketplace.json`, Claude `.claude-plugin/marketplace.json`,
|
|
6
|
+
* or Copilot-style `.github/marketplace.json` index). Installed plugins are placed in
|
|
7
|
+
* `.agents/plugins/<name>` (the primary, cross-vendor home) and loaded by the plugin
|
|
8
|
+
* loader after a reload. Plugins hand-placed under `.hoocode/plugins/` are still
|
|
9
|
+
* discovered and can be removed, but new installs go to `.agents/`.
|
|
8
10
|
*
|
|
9
11
|
* /plugin marketplace add <git-url|path>
|
|
10
12
|
* /plugin marketplace list
|
|
@@ -22,11 +24,24 @@ function isGitSource(loc) {
|
|
|
22
24
|
return /^https?:\/\//.test(loc) || loc.startsWith("git@") || loc.endsWith(".git");
|
|
23
25
|
}
|
|
24
26
|
export function setupMarketplace(pi) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
// `.agents/` is the primary, cross-vendor home for installed plugins and the
|
|
28
|
+
// added-marketplace registry, matching the "`.agents/` first" policy. Legacy
|
|
29
|
+
// `.hoocode/plugins/` is still discovered and honored by `remove`.
|
|
30
|
+
const storePath = (cwd) => join(cwd, ".agents", "marketplaces.json");
|
|
31
|
+
const legacyStorePath = (cwd) => join(cwd, ".hoocode", "marketplaces.json");
|
|
32
|
+
const pluginsDir = (cwd) => join(cwd, ".agents", "plugins");
|
|
33
|
+
const legacyPluginsDir = (cwd) => join(cwd, ".hoocode", "plugins");
|
|
34
|
+
const cacheDir = (cwd) => join(cwd, ".agents", "marketplace-cache");
|
|
35
|
+
// Read the registry from `.agents/` first, falling back to the legacy
|
|
36
|
+
// `.hoocode/` location so marketplaces added before the move stay visible.
|
|
37
|
+
const readStore = (cwd) => {
|
|
38
|
+
const primary = readMarketplaceStore(storePath(cwd));
|
|
39
|
+
if (primary.length > 0 || existsSync(storePath(cwd)))
|
|
40
|
+
return primary;
|
|
41
|
+
return readMarketplaceStore(legacyStorePath(cwd));
|
|
42
|
+
};
|
|
28
43
|
const findPlugin = (cwd, name) => {
|
|
29
|
-
for (const record of
|
|
44
|
+
for (const record of readStore(cwd)) {
|
|
30
45
|
const market = parseMarketplaceDir(record.dir);
|
|
31
46
|
const entry = market?.plugins.find((p) => p.name === name);
|
|
32
47
|
if (market && entry)
|
|
@@ -46,14 +61,15 @@ export function setupMarketplace(pi) {
|
|
|
46
61
|
if (trimmed.startsWith("marketplace")) {
|
|
47
62
|
const sub = trimmed.slice("marketplace".length).trim();
|
|
48
63
|
if (sub === "list" || sub === "") {
|
|
49
|
-
const records =
|
|
64
|
+
const records = readStore(cwd);
|
|
50
65
|
if (records.length === 0) {
|
|
51
66
|
ctx.ui.notify("No marketplaces. Add one with /plugin marketplace add <git-url|path>.", "info");
|
|
52
67
|
return;
|
|
53
68
|
}
|
|
54
69
|
const lines = records.map((r) => {
|
|
55
70
|
const market = parseMarketplaceDir(r.dir);
|
|
56
|
-
|
|
71
|
+
const platforms = market && market.supportPlatform.length > 1 ? ` · ${market.supportPlatform.join(", ")}` : "";
|
|
72
|
+
return `${market?.name ?? r.location} — ${market?.plugins.length ?? 0} plugin(s)${platforms} [${r.location}]`;
|
|
57
73
|
});
|
|
58
74
|
ctx.ui.notify(lines.join("\n"), "info");
|
|
59
75
|
return;
|
|
@@ -84,10 +100,10 @@ export function setupMarketplace(pi) {
|
|
|
84
100
|
}
|
|
85
101
|
const market = parseMarketplaceDir(dir);
|
|
86
102
|
if (!market) {
|
|
87
|
-
ctx.ui.notify("No marketplace manifest found (.claude-plugin
|
|
103
|
+
ctx.ui.notify("No marketplace manifest found (.agents-plugin/, .claude-plugin/, or .github/marketplace.json).", "error");
|
|
88
104
|
return;
|
|
89
105
|
}
|
|
90
|
-
const records =
|
|
106
|
+
const records = readStore(cwd).filter((r) => r.location !== loc);
|
|
91
107
|
records.push({ location: loc, dir });
|
|
92
108
|
writeMarketplaceStore(storePath(cwd), records);
|
|
93
109
|
ctx.ui.notify(`Added marketplace "${market.name}" (${market.plugins.length} plugin(s)).`, "info");
|
|
@@ -98,7 +114,7 @@ export function setupMarketplace(pi) {
|
|
|
98
114
|
}
|
|
99
115
|
// ── list available plugins ──────────────────────────────────────────
|
|
100
116
|
if (trimmed === "list" || trimmed === "") {
|
|
101
|
-
const records =
|
|
117
|
+
const records = readStore(cwd);
|
|
102
118
|
const lines = [];
|
|
103
119
|
for (const record of records) {
|
|
104
120
|
const market = parseMarketplaceDir(record.dir);
|
|
@@ -150,12 +166,18 @@ export function setupMarketplace(pi) {
|
|
|
150
166
|
ctx.ui.notify("Usage: /plugin remove <name>", "warning");
|
|
151
167
|
return;
|
|
152
168
|
}
|
|
153
|
-
|
|
154
|
-
|
|
169
|
+
// Remove from `.agents/` first, then the legacy `.hoocode/` location.
|
|
170
|
+
const candidates = [
|
|
171
|
+
join(pluginsDir(cwd), sanitizeForDir(name)),
|
|
172
|
+
join(legacyPluginsDir(cwd), sanitizeForDir(name)),
|
|
173
|
+
];
|
|
174
|
+
const installed = candidates.filter((p) => existsSync(p));
|
|
175
|
+
if (installed.length === 0) {
|
|
155
176
|
ctx.ui.notify(`Plugin "${name}" is not installed.`, "info");
|
|
156
177
|
return;
|
|
157
178
|
}
|
|
158
|
-
|
|
179
|
+
for (const p of installed)
|
|
180
|
+
rmSync(p, { recursive: true, force: true });
|
|
159
181
|
ctx.ui.notify(`Removed "${name}" — reloading…`, "info");
|
|
160
182
|
await ctx.reload();
|
|
161
183
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marketplace.js","sourceRoot":"","sources":["../../../src/extensions/core/marketplace.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS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I,IAAI,EAAE,SAAS,CAAC,CAAC;oBACzF,OAAO;gBACR,CAAC;gBAED,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,cAAc,IAAI,oBAAgB,EAAE,MAAM,CAAC,CAAC;gBAC1D,MAAM,GAAG,CAAC,MAAM,EAAE,CAAC;gBACnB,OAAO;YACR,CAAC;YAED,iLAAuE;YACvE,IAAI,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAClC,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;gBACnD,IAAI,CAAC,IAAI,EAAE,CAAC;oBACX,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,8BAA8B,EAAE,SAAS,CAAC,CAAC;oBACzD,OAAO;gBACR,CAAC;gBACD,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC;gBACzD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;oBACvB,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,WAAW,IAAI,qBAAqB,EAAE,MAAM,CAAC,CAAC;oBAC5D,OAAO;gBACR,CAAC;gBACD,MAAM,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC/C,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,YAAY,IAAI,oBAAgB,EAAE,MAAM,CAAC,CAAC;gBACxD,MAAM,GAAG,CAAC,MAAM,EAAE,CAAC;gBACnB,OAAO;YACR,CAAC;YAED,GAAG,CAAC,EAAE,CAAC,MAAM,CACZ,qGAAqG,EACrG,SAAS,CACT,CAAC;QAAA,CACF;KACD,CAAC,CAAC;AAAA,CACH","sourcesContent":["/**\n * /plugin — marketplace add/list + plugin install/list/remove.\n *\n * `/plugin` installs plugins from marketplaces (a git repo or local dir with a\n * Claude `.claude-plugin/marketplace.json` or Copilot-style `.github/marketplace.json`\n * index). Installed plugins are placed in `.hoocode/plugins/<name>` and loaded by the\n * plugin loader after a reload.\n *\n * /plugin marketplace add <git-url|path>\n * /plugin marketplace list\n * /plugin list list available plugins across marketplaces\n * /plugin install <name>\n * /plugin remove <name>\n */\n\nimport { cpSync, existsSync, mkdirSync, rmSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport {\n\tparseMarketplaceDir,\n\treadMarketplaceStore,\n\tresolvePluginSource,\n\twriteMarketplaceStore,\n} from \"../../core/extensions/plugins/marketplace.js\";\nimport type { ExtensionAPI, ExtensionCommandContext } from \"../../core/extensions/types.js\";\n\nfunction sanitizeForDir(s: string): string {\n\treturn s.replace(/[^a-zA-Z0-9._-]+/g, \"_\").slice(0, 80);\n}\n\nfunction isGitSource(loc: string): boolean {\n\treturn /^https?:\\/\\//.test(loc) || loc.startsWith(\"git@\") || loc.endsWith(\".git\");\n}\n\nexport function setupMarketplace(pi: ExtensionAPI): void {\n\tconst storePath = (cwd: string) => join(cwd, \".hoocode\", \"marketplaces.json\");\n\tconst pluginsDir = (cwd: string) => join(cwd, \".hoocode\", \"plugins\");\n\tconst cacheDir = (cwd: string) => join(cwd, \".hoocode\", \"marketplace-cache\");\n\n\tconst findPlugin = (cwd: string, name: string) => {\n\t\tfor (const record of readMarketplaceStore(storePath(cwd))) {\n\t\t\tconst market = parseMarketplaceDir(record.dir);\n\t\t\tconst entry = market?.plugins.find((p) => p.name === name);\n\t\t\tif (market && entry) return { market, entry };\n\t\t}\n\t\treturn undefined;\n\t};\n\n\tpi.registerCommand(\"plugin\", {\n\t\tdescription:\n\t\t\t\"Manage plugin marketplaces. /plugin marketplace add <git-url|path> | /plugin marketplace list | /plugin list | /plugin install <name> | /plugin remove <name>\",\n\t\tgetArgumentCompletions: (prefix: string) =>\n\t\t\t[\"marketplace\", \"list\", \"install\", \"remove\"]\n\t\t\t\t.filter((s) => s.startsWith(prefix))\n\t\t\t\t.map((s) => ({ value: s, label: s })),\n\t\thandler: async (args: string, ctx: ExtensionCommandContext): Promise<void> => {\n\t\t\tconst trimmed = args.trim();\n\t\t\tconst cwd = ctx.cwd;\n\n\t\t\t// ── marketplace add / list ──────────────────────────────────────────\n\t\t\tif (trimmed.startsWith(\"marketplace\")) {\n\t\t\t\tconst sub = trimmed.slice(\"marketplace\".length).trim();\n\n\t\t\t\tif (sub === \"list\" || sub === \"\") {\n\t\t\t\t\tconst records = readMarketplaceStore(storePath(cwd));\n\t\t\t\t\tif (records.length === 0) {\n\t\t\t\t\t\tctx.ui.notify(\"No marketplaces. Add one with /plugin marketplace add <git-url|path>.\", \"info\");\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tconst lines = records.map((r) => {\n\t\t\t\t\t\tconst market = parseMarketplaceDir(r.dir);\n\t\t\t\t\t\treturn `${market?.name ?? r.location} — ${market?.plugins.length ?? 0} plugin(s) [${r.location}]`;\n\t\t\t\t\t});\n\t\t\t\t\tctx.ui.notify(lines.join(\"\\n\"), \"info\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (sub.startsWith(\"add\")) {\n\t\t\t\t\tconst loc = sub.slice(\"add\".length).trim();\n\t\t\t\t\tif (!loc) {\n\t\t\t\t\t\tctx.ui.notify(\"Usage: /plugin marketplace add <git-url|path>\", \"warning\");\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tlet dir: string;\n\t\t\t\t\tif (isGitSource(loc)) {\n\t\t\t\t\t\tdir = join(cacheDir(cwd), sanitizeForDir(loc));\n\t\t\t\t\t\trmSync(dir, { recursive: true, force: true });\n\t\t\t\t\t\tmkdirSync(cacheDir(cwd), { recursive: true });\n\t\t\t\t\t\tconst res = await pi.exec(\"git\", [\"clone\", \"--depth\", \"1\", loc, dir]);\n\t\t\t\t\t\tif (res.code !== 0) {\n\t\t\t\t\t\t\tctx.ui.notify(`Clone failed: ${res.stderr || res.stdout}`, \"error\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tdir = resolvePluginSource(loc, cwd).kind === \"local\" ? join(cwd, loc) : loc;\n\t\t\t\t\t\tif (!existsSync(dir)) {\n\t\t\t\t\t\t\tctx.ui.notify(`Path not found: ${dir}`, \"error\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tconst market = parseMarketplaceDir(dir);\n\t\t\t\t\tif (!market) {\n\t\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t\t\"No marketplace manifest found (.claude-plugin/ or .github/marketplace.json).\",\n\t\t\t\t\t\t\t\"error\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst records = readMarketplaceStore(storePath(cwd)).filter((r) => r.location !== loc);\n\t\t\t\t\trecords.push({ location: loc, dir });\n\t\t\t\t\twriteMarketplaceStore(storePath(cwd), records);\n\t\t\t\t\tctx.ui.notify(`Added marketplace \"${market.name}\" (${market.plugins.length} plugin(s)).`, \"info\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tctx.ui.notify(\"Usage: /plugin marketplace add <git-url|path> | /plugin marketplace list\", \"warning\");\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// ── list available plugins ──────────────────────────────────────────\n\t\t\tif (trimmed === \"list\" || trimmed === \"\") {\n\t\t\t\tconst records = readMarketplaceStore(storePath(cwd));\n\t\t\t\tconst lines: string[] = [];\n\t\t\t\tfor (const record of records) {\n\t\t\t\t\tconst market = parseMarketplaceDir(record.dir);\n\t\t\t\t\tfor (const p of market?.plugins ?? []) {\n\t\t\t\t\t\tlines.push(`${p.name} — ${p.description ?? p.source}`);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tctx.ui.notify(lines.length ? lines.join(\"\\n\") : \"No plugins available. Add a marketplace first.\", \"info\");\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// ── install <name> ──────────────────────────────────────────────────\n\t\t\tif (trimmed.startsWith(\"install\")) {\n\t\t\t\tconst name = trimmed.slice(\"install\".length).trim();\n\t\t\t\tif (!name) {\n\t\t\t\t\tctx.ui.notify(\"Usage: /plugin install <name>\", \"warning\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst found = findPlugin(cwd, name);\n\t\t\t\tif (!found) {\n\t\t\t\t\tctx.ui.notify(`Plugin \"${name}\" not found in any marketplace.`, \"error\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst resolved = resolvePluginSource(found.entry.source, found.market.root);\n\t\t\t\tconst dest = join(pluginsDir(cwd), sanitizeForDir(name));\n\t\t\t\trmSync(dest, { recursive: true, force: true });\n\t\t\t\tmkdirSync(pluginsDir(cwd), { recursive: true });\n\n\t\t\t\tif (resolved.kind === \"local\") {\n\t\t\t\t\tcpSync(resolved.path, dest, { recursive: true });\n\t\t\t\t} else if (resolved.kind === \"git\") {\n\t\t\t\t\tconst res = await pi.exec(\"git\", [\"clone\", \"--depth\", \"1\", resolved.url, dest]);\n\t\t\t\t\tif (res.code !== 0) {\n\t\t\t\t\t\tctx.ui.notify(`Clone failed: ${res.stderr || res.stdout}`, \"error\");\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tctx.ui.notify(`npm plugin sources are not supported yet (${resolved.spec}).`, \"warning\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tctx.ui.notify(`Installed \"${name}\" — reloading…`, \"info\");\n\t\t\t\tawait ctx.reload();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// ── remove <name> ───────────────────────────────────────────────────\n\t\t\tif (trimmed.startsWith(\"remove\")) {\n\t\t\t\tconst name = trimmed.slice(\"remove\".length).trim();\n\t\t\t\tif (!name) {\n\t\t\t\t\tctx.ui.notify(\"Usage: /plugin remove <name>\", \"warning\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst dest = join(pluginsDir(cwd), sanitizeForDir(name));\n\t\t\t\tif (!existsSync(dest)) {\n\t\t\t\t\tctx.ui.notify(`Plugin \"${name}\" is not installed.`, \"info\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\trmSync(dest, { recursive: true, force: true });\n\t\t\t\tctx.ui.notify(`Removed \"${name}\" — reloading…`, \"info\");\n\t\t\t\tawait ctx.reload();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tctx.ui.notify(\n\t\t\t\t\"Usage: /plugin marketplace add|list | /plugin list | /plugin install <name> | /plugin remove <name>\",\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t},\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"marketplace.js","sourceRoot":"","sources":["../../../src/extensions/core/marketplace.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACN,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,GACrB,MAAM,8CAA8C,CAAC;AAGtD,SAAS,cAAc,CAAC,CAAS,EAAU;IAC1C,OAAO,CAAC,CAAC,OAAO,CAAC,mBAAmB,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAAA,CACxD;AAED,SAAS,WAAW,CAAC,GAAW,EAAW;IAC1C,OAAO,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAAA,CAClF;AAED,MAAM,UAAU,gBAAgB,CAAC,EAAgB,EAAQ;IACxD,6EAA6E;IA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AC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;gBACvE,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,YAAY,IAAI,oBAAgB,EAAE,MAAM,CAAC,CAAC;gBACxD,MAAM,GAAG,CAAC,MAAM,EAAE,CAAC;gBACnB,OAAO;YACR,CAAC;YAED,GAAG,CAAC,EAAE,CAAC,MAAM,CACZ,qGAAqG,EACrG,SAAS,CACT,CAAC;QAAA,CACF;KACD,CAAC,CAAC;AAAA,CACH","sourcesContent":["/**\n * /plugin — marketplace add/list + plugin install/list/remove.\n *\n * `/plugin` installs plugins from marketplaces (a git repo or local dir with a\n * native `.agents-plugin/marketplace.json`, Claude `.claude-plugin/marketplace.json`,\n * or Copilot-style `.github/marketplace.json` index). Installed plugins are placed in\n * `.agents/plugins/<name>` (the primary, cross-vendor home) and loaded by the plugin\n * loader after a reload. Plugins hand-placed under `.hoocode/plugins/` are still\n * discovered and can be removed, but new installs go to `.agents/`.\n *\n * /plugin marketplace add <git-url|path>\n * /plugin marketplace list\n * /plugin list list available plugins across marketplaces\n * /plugin install <name>\n * /plugin remove <name>\n */\n\nimport { cpSync, existsSync, mkdirSync, rmSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport {\n\tparseMarketplaceDir,\n\treadMarketplaceStore,\n\tresolvePluginSource,\n\twriteMarketplaceStore,\n} from \"../../core/extensions/plugins/marketplace.js\";\nimport type { ExtensionAPI, ExtensionCommandContext } from \"../../core/extensions/types.js\";\n\nfunction sanitizeForDir(s: string): string {\n\treturn s.replace(/[^a-zA-Z0-9._-]+/g, \"_\").slice(0, 80);\n}\n\nfunction isGitSource(loc: string): boolean {\n\treturn /^https?:\\/\\//.test(loc) || loc.startsWith(\"git@\") || loc.endsWith(\".git\");\n}\n\nexport function setupMarketplace(pi: ExtensionAPI): void {\n\t// `.agents/` is the primary, cross-vendor home for installed plugins and the\n\t// added-marketplace registry, matching the \"`.agents/` first\" policy. Legacy\n\t// `.hoocode/plugins/` is still discovered and honored by `remove`.\n\tconst storePath = (cwd: string) => join(cwd, \".agents\", \"marketplaces.json\");\n\tconst legacyStorePath = (cwd: string) => join(cwd, \".hoocode\", \"marketplaces.json\");\n\tconst pluginsDir = (cwd: string) => join(cwd, \".agents\", \"plugins\");\n\tconst legacyPluginsDir = (cwd: string) => join(cwd, \".hoocode\", \"plugins\");\n\tconst cacheDir = (cwd: string) => join(cwd, \".agents\", \"marketplace-cache\");\n\n\t// Read the registry from `.agents/` first, falling back to the legacy\n\t// `.hoocode/` location so marketplaces added before the move stay visible.\n\tconst readStore = (cwd: string) => {\n\t\tconst primary = readMarketplaceStore(storePath(cwd));\n\t\tif (primary.length > 0 || existsSync(storePath(cwd))) return primary;\n\t\treturn readMarketplaceStore(legacyStorePath(cwd));\n\t};\n\n\tconst findPlugin = (cwd: string, name: string) => {\n\t\tfor (const record of readStore(cwd)) {\n\t\t\tconst market = parseMarketplaceDir(record.dir);\n\t\t\tconst entry = market?.plugins.find((p) => p.name === name);\n\t\t\tif (market && entry) return { market, entry };\n\t\t}\n\t\treturn undefined;\n\t};\n\n\tpi.registerCommand(\"plugin\", {\n\t\tdescription:\n\t\t\t\"Manage plugin marketplaces. /plugin marketplace add <git-url|path> | /plugin marketplace list | /plugin list | /plugin install <name> | /plugin remove <name>\",\n\t\tgetArgumentCompletions: (prefix: string) =>\n\t\t\t[\"marketplace\", \"list\", \"install\", \"remove\"]\n\t\t\t\t.filter((s) => s.startsWith(prefix))\n\t\t\t\t.map((s) => ({ value: s, label: s })),\n\t\thandler: async (args: string, ctx: ExtensionCommandContext): Promise<void> => {\n\t\t\tconst trimmed = args.trim();\n\t\t\tconst cwd = ctx.cwd;\n\n\t\t\t// ── marketplace add / list ──────────────────────────────────────────\n\t\t\tif (trimmed.startsWith(\"marketplace\")) {\n\t\t\t\tconst sub = trimmed.slice(\"marketplace\".length).trim();\n\n\t\t\t\tif (sub === \"list\" || sub === \"\") {\n\t\t\t\t\tconst records = readStore(cwd);\n\t\t\t\t\tif (records.length === 0) {\n\t\t\t\t\t\tctx.ui.notify(\"No marketplaces. Add one with /plugin marketplace add <git-url|path>.\", \"info\");\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tconst lines = records.map((r) => {\n\t\t\t\t\t\tconst market = parseMarketplaceDir(r.dir);\n\t\t\t\t\t\tconst platforms =\n\t\t\t\t\t\t\tmarket && market.supportPlatform.length > 1 ? ` · ${market.supportPlatform.join(\", \")}` : \"\";\n\t\t\t\t\t\treturn `${market?.name ?? r.location} — ${market?.plugins.length ?? 0} plugin(s)${platforms} [${r.location}]`;\n\t\t\t\t\t});\n\t\t\t\t\tctx.ui.notify(lines.join(\"\\n\"), \"info\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (sub.startsWith(\"add\")) {\n\t\t\t\t\tconst loc = sub.slice(\"add\".length).trim();\n\t\t\t\t\tif (!loc) {\n\t\t\t\t\t\tctx.ui.notify(\"Usage: /plugin marketplace add <git-url|path>\", \"warning\");\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tlet dir: string;\n\t\t\t\t\tif (isGitSource(loc)) {\n\t\t\t\t\t\tdir = join(cacheDir(cwd), sanitizeForDir(loc));\n\t\t\t\t\t\trmSync(dir, { recursive: true, force: true });\n\t\t\t\t\t\tmkdirSync(cacheDir(cwd), { recursive: true });\n\t\t\t\t\t\tconst res = await pi.exec(\"git\", [\"clone\", \"--depth\", \"1\", loc, dir]);\n\t\t\t\t\t\tif (res.code !== 0) {\n\t\t\t\t\t\t\tctx.ui.notify(`Clone failed: ${res.stderr || res.stdout}`, \"error\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tdir = resolvePluginSource(loc, cwd).kind === \"local\" ? join(cwd, loc) : loc;\n\t\t\t\t\t\tif (!existsSync(dir)) {\n\t\t\t\t\t\t\tctx.ui.notify(`Path not found: ${dir}`, \"error\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tconst market = parseMarketplaceDir(dir);\n\t\t\t\t\tif (!market) {\n\t\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t\t\"No marketplace manifest found (.agents-plugin/, .claude-plugin/, or .github/marketplace.json).\",\n\t\t\t\t\t\t\t\"error\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst records = readStore(cwd).filter((r) => r.location !== loc);\n\t\t\t\t\trecords.push({ location: loc, dir });\n\t\t\t\t\twriteMarketplaceStore(storePath(cwd), records);\n\t\t\t\t\tctx.ui.notify(`Added marketplace \"${market.name}\" (${market.plugins.length} plugin(s)).`, \"info\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tctx.ui.notify(\"Usage: /plugin marketplace add <git-url|path> | /plugin marketplace list\", \"warning\");\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// ── list available plugins ──────────────────────────────────────────\n\t\t\tif (trimmed === \"list\" || trimmed === \"\") {\n\t\t\t\tconst records = readStore(cwd);\n\t\t\t\tconst lines: string[] = [];\n\t\t\t\tfor (const record of records) {\n\t\t\t\t\tconst market = parseMarketplaceDir(record.dir);\n\t\t\t\t\tfor (const p of market?.plugins ?? []) {\n\t\t\t\t\t\tlines.push(`${p.name} — ${p.description ?? p.source}`);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tctx.ui.notify(lines.length ? lines.join(\"\\n\") : \"No plugins available. Add a marketplace first.\", \"info\");\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// ── install <name> ──────────────────────────────────────────────────\n\t\t\tif (trimmed.startsWith(\"install\")) {\n\t\t\t\tconst name = trimmed.slice(\"install\".length).trim();\n\t\t\t\tif (!name) {\n\t\t\t\t\tctx.ui.notify(\"Usage: /plugin install <name>\", \"warning\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst found = findPlugin(cwd, name);\n\t\t\t\tif (!found) {\n\t\t\t\t\tctx.ui.notify(`Plugin \"${name}\" not found in any marketplace.`, \"error\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst resolved = resolvePluginSource(found.entry.source, found.market.root);\n\t\t\t\tconst dest = join(pluginsDir(cwd), sanitizeForDir(name));\n\t\t\t\trmSync(dest, { recursive: true, force: true });\n\t\t\t\tmkdirSync(pluginsDir(cwd), { recursive: true });\n\n\t\t\t\tif (resolved.kind === \"local\") {\n\t\t\t\t\tcpSync(resolved.path, dest, { recursive: true });\n\t\t\t\t} else if (resolved.kind === \"git\") {\n\t\t\t\t\tconst res = await pi.exec(\"git\", [\"clone\", \"--depth\", \"1\", resolved.url, dest]);\n\t\t\t\t\tif (res.code !== 0) {\n\t\t\t\t\t\tctx.ui.notify(`Clone failed: ${res.stderr || res.stdout}`, \"error\");\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tctx.ui.notify(`npm plugin sources are not supported yet (${resolved.spec}).`, \"warning\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tctx.ui.notify(`Installed \"${name}\" — reloading…`, \"info\");\n\t\t\t\tawait ctx.reload();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// ── remove <name> ───────────────────────────────────────────────────\n\t\t\tif (trimmed.startsWith(\"remove\")) {\n\t\t\t\tconst name = trimmed.slice(\"remove\".length).trim();\n\t\t\t\tif (!name) {\n\t\t\t\t\tctx.ui.notify(\"Usage: /plugin remove <name>\", \"warning\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// Remove from `.agents/` first, then the legacy `.hoocode/` location.\n\t\t\t\tconst candidates = [\n\t\t\t\t\tjoin(pluginsDir(cwd), sanitizeForDir(name)),\n\t\t\t\t\tjoin(legacyPluginsDir(cwd), sanitizeForDir(name)),\n\t\t\t\t];\n\t\t\t\tconst installed = candidates.filter((p) => existsSync(p));\n\t\t\t\tif (installed.length === 0) {\n\t\t\t\t\tctx.ui.notify(`Plugin \"${name}\" is not installed.`, \"info\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tfor (const p of installed) rmSync(p, { recursive: true, force: true });\n\t\t\t\tctx.ui.notify(`Removed \"${name}\" — reloading…`, \"info\");\n\t\t\t\tawait ctx.reload();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tctx.ui.notify(\n\t\t\t\t\"Usage: /plugin marketplace add|list | /plugin list | /plugin install <name> | /plugin remove <name>\",\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t},\n\t});\n}\n"]}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import type { AssistantMessage } from "@kolisachint/hoocode-ai";
|
|
2
2
|
import { Container, type MarkdownTheme } from "@kolisachint/hoocode-tui";
|
|
3
|
+
/**
|
|
4
|
+
* Split markdown into chunks at blank-line boundaries where each chunk lexes
|
|
5
|
+
* independently to the same blocks the whole text would. Prefix-stable:
|
|
6
|
+
* appending text never changes earlier boundaries (decisions depend only on
|
|
7
|
+
* preceding fence parity and the lines adjacent to each gap), so during
|
|
8
|
+
* streaming every chunk except the last is byte-identical across updates and
|
|
9
|
+
* its Markdown render cache keeps hitting. Exported for tests.
|
|
10
|
+
*/
|
|
11
|
+
export declare function segmentStreamingMarkdown(text: string): string[];
|
|
3
12
|
/**
|
|
4
13
|
* Component that renders a complete assistant message
|
|
5
14
|
*/
|
|
@@ -10,11 +19,28 @@ export declare class AssistantMessageComponent extends Container {
|
|
|
10
19
|
private hiddenThinkingLabel;
|
|
11
20
|
private lastMessage?;
|
|
12
21
|
private hasToolCalls;
|
|
22
|
+
private markdownCache;
|
|
13
23
|
constructor(message?: AssistantMessage, hideThinkingBlock?: boolean, markdownTheme?: MarkdownTheme, hiddenThinkingLabel?: string);
|
|
14
24
|
invalidate(): void;
|
|
25
|
+
private reuseMarkdown;
|
|
26
|
+
/** Set when the current children include streaming segments; the next
|
|
27
|
+
* non-streaming (final/rebuild) render purges their cache entries. */
|
|
28
|
+
private hasSegmentedBlocks;
|
|
29
|
+
/**
|
|
30
|
+
* Add one markdown content block. Large blocks still being streamed are
|
|
31
|
+
* segmented at stable boundaries so only the tail chunk re-parses per
|
|
32
|
+
* update; every earlier chunk is byte-stable and stays cached. The final
|
|
33
|
+
* (non-streaming) render collapses back to one canonical Markdown, so any
|
|
34
|
+
* segmentation artifact is transient by construction.
|
|
35
|
+
*/
|
|
36
|
+
private addMarkdownBlock;
|
|
15
37
|
setHideThinkingBlock(hide: boolean): void;
|
|
16
38
|
setHiddenThinkingLabel(label: string): void;
|
|
39
|
+
/** OSC-zone wrap memo: Container.render returns the same array across
|
|
40
|
+
* frames when nothing changed, so it must not be mutated — the wrapped
|
|
41
|
+
* copy is cached keyed on the source array's identity. */
|
|
42
|
+
private zoneMemo?;
|
|
17
43
|
render(width: number): string[];
|
|
18
|
-
updateContent(message: AssistantMessage): void;
|
|
44
|
+
updateContent(message: AssistantMessage, streaming?: boolean): void;
|
|
19
45
|
}
|
|
20
46
|
//# sourceMappingURL=assistant-message.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assistant-message.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/assistant-message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,SAAS,EAAY,KAAK,aAAa,EAAgB,MAAM,0BAA0B,CAAC;AAOjG;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,SAAS;IACvD,OAAO,CAAC,gBAAgB,CAAY;IACpC,OAAO,CAAC,iBAAiB,CAAU;IACnC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,mBAAmB,CAAS;IACpC,OAAO,CAAC,WAAW,CAAC,CAAmB;IACvC,OAAO,CAAC,YAAY,CAAS;IAE7B,YACC,OAAO,CAAC,EAAE,gBAAgB,EAC1B,iBAAiB,UAAQ,EACzB,aAAa,GAAE,aAAkC,EACjD,mBAAmB,SAAgB,EAenC;IAEQ,UAAU,IAAI,IAAI,CAK1B;IAED,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAKxC;IAED,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAK1C;IAEQ,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CASvC;IAED,aAAa,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAyE7C;CACD","sourcesContent":["import type { AssistantMessage } from \"@kolisachint/hoocode-ai\";\nimport { Container, Markdown, type MarkdownTheme, Spacer, Text } from \"@kolisachint/hoocode-tui\";\nimport { getMarkdownTheme, theme } from \"../theme/theme.js\";\n\nconst OSC133_ZONE_START = \"\\x1b]133;A\\x07\";\nconst OSC133_ZONE_END = \"\\x1b]133;B\\x07\";\nconst OSC133_ZONE_FINAL = \"\\x1b]133;C\\x07\";\n\n/**\n * Component that renders a complete assistant message\n */\nexport class AssistantMessageComponent extends Container {\n\tprivate contentContainer: Container;\n\tprivate hideThinkingBlock: boolean;\n\tprivate markdownTheme: MarkdownTheme;\n\tprivate hiddenThinkingLabel: string;\n\tprivate lastMessage?: AssistantMessage;\n\tprivate hasToolCalls = false;\n\n\tconstructor(\n\t\tmessage?: AssistantMessage,\n\t\thideThinkingBlock = false,\n\t\tmarkdownTheme: MarkdownTheme = getMarkdownTheme(),\n\t\thiddenThinkingLabel = \"Thinking...\",\n\t) {\n\t\tsuper();\n\n\t\tthis.hideThinkingBlock = hideThinkingBlock;\n\t\tthis.markdownTheme = markdownTheme;\n\t\tthis.hiddenThinkingLabel = hiddenThinkingLabel;\n\n\t\t// Container for text/thinking content\n\t\tthis.contentContainer = new Container();\n\t\tthis.addChild(this.contentContainer);\n\n\t\tif (message) {\n\t\t\tthis.updateContent(message);\n\t\t}\n\t}\n\n\toverride invalidate(): void {\n\t\tsuper.invalidate();\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\tsetHideThinkingBlock(hide: boolean): void {\n\t\tthis.hideThinkingBlock = hide;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\tsetHiddenThinkingLabel(label: string): void {\n\t\tthis.hiddenThinkingLabel = label;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\toverride render(width: number): string[] {\n\t\tconst lines = super.render(width);\n\t\tif (this.hasToolCalls || lines.length === 0) {\n\t\t\treturn lines;\n\t\t}\n\n\t\tlines[0] = OSC133_ZONE_START + lines[0];\n\t\tlines[lines.length - 1] = OSC133_ZONE_END + OSC133_ZONE_FINAL + lines[lines.length - 1];\n\t\treturn lines;\n\t}\n\n\tupdateContent(message: AssistantMessage): void {\n\t\tthis.lastMessage = message;\n\n\t\t// Clear content container\n\t\tthis.contentContainer.clear();\n\n\t\tconst hasVisibleContent = message.content.some(\n\t\t\t(c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()),\n\t\t);\n\n\t\tif (hasVisibleContent) {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t}\n\n\t\t// Render content in order\n\t\tfor (let i = 0; i < message.content.length; i++) {\n\t\t\tconst content = message.content[i];\n\t\t\tif (content.type === \"text\" && content.text.trim()) {\n\t\t\t\t// Assistant text messages with no background - trim the text\n\t\t\t\t// Set paddingY=0 to avoid extra spacing before tool executions\n\t\t\t\tthis.contentContainer.addChild(new Markdown(content.text.trim(), 1, 0, this.markdownTheme));\n\t\t\t} else if (content.type === \"thinking\" && content.thinking.trim()) {\n\t\t\t\t// Add spacing only when another visible assistant content block follows.\n\t\t\t\t// This avoids a superfluous blank line before separately-rendered tool execution blocks.\n\t\t\t\tconst hasVisibleContentAfter = message.content\n\t\t\t\t\t.slice(i + 1)\n\t\t\t\t\t.some((c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()));\n\n\t\t\t\tif (this.hideThinkingBlock) {\n\t\t\t\t\t// Show static thinking label when hidden\n\t\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\t\tnew Text(theme.italic(theme.fg(\"thinkingText\", this.hiddenThinkingLabel)), 1, 0),\n\t\t\t\t\t);\n\t\t\t\t\tif (hasVisibleContentAfter) {\n\t\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Thinking traces in thinkingText color, italic, with ✻ prefix\n\t\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\t\tnew Markdown(`✻ ${content.thinking.trim()}`, 1, 0, this.markdownTheme, {\n\t\t\t\t\t\t\tcolor: (text: string) => theme.fg(\"thinkingText\", text),\n\t\t\t\t\t\t\titalic: true,\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t\tif (hasVisibleContentAfter) {\n\t\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Check if aborted - show after partial content\n\t\t// But only if there are no tool calls (tool execution components will show the error)\n\t\tconst hasToolCalls = message.content.some((c) => c.type === \"toolCall\");\n\t\tthis.hasToolCalls = hasToolCalls;\n\t\tif (!hasToolCalls) {\n\t\t\tif (message.stopReason === \"aborted\") {\n\t\t\t\tconst abortMessage =\n\t\t\t\t\tmessage.errorMessage && message.errorMessage !== \"Request was aborted\"\n\t\t\t\t\t\t? message.errorMessage\n\t\t\t\t\t\t: \"Operation aborted\";\n\t\t\t\tif (hasVisibleContent) {\n\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t} else {\n\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t}\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", abortMessage), 1, 0));\n\t\t\t} else if (message.stopReason === \"error\") {\n\t\t\t\tconst errorMsg = message.errorMessage || \"Unknown error\";\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", `Error: ${errorMsg}`), 1, 0));\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"assistant-message.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/assistant-message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,SAAS,EAAmC,KAAK,aAAa,EAAgB,MAAM,0BAA0B,CAAC;AAkCxH;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAiC/D;AAED;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,SAAS;IACvD,OAAO,CAAC,gBAAgB,CAAY;IACpC,OAAO,CAAC,iBAAiB,CAAU;IACnC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,mBAAmB,CAAS;IACpC,OAAO,CAAC,WAAW,CAAC,CAAmB;IACvC,OAAO,CAAC,YAAY,CAAS;IAM7B,OAAO,CAAC,aAAa,CAAqD;IAE1E,YACC,OAAO,CAAC,EAAE,gBAAgB,EAC1B,iBAAiB,UAAQ,EACzB,aAAa,GAAE,aAAkC,EACjD,mBAAmB,SAAgB,EAenC;IAEQ,UAAU,IAAI,IAAI,CAW1B;IAED,OAAO,CAAC,aAAa;IAcrB;0EACsE;IACtE,OAAO,CAAC,kBAAkB,CAAS;IAEnC;;;;;;OAMG;IACH,OAAO,CAAC,gBAAgB;IAexB,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAKxC;IAED,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAK1C;IAED;;8DAE0D;IAC1D,OAAO,CAAC,QAAQ,CAAC,CAAmC;IAE3C,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAcvC;IAED,aAAa,CAAC,OAAO,EAAE,gBAAgB,EAAE,SAAS,UAAQ,GAAG,IAAI,CAgFhE;CACD","sourcesContent":["import type { AssistantMessage } from \"@kolisachint/hoocode-ai\";\nimport { Container, type DefaultTextStyle, Markdown, type MarkdownTheme, Spacer, Text } from \"@kolisachint/hoocode-tui\";\nimport { getMarkdownTheme, theme } from \"../theme/theme.js\";\n\nconst OSC133_ZONE_START = \"\\x1b]133;A\\x07\";\nconst OSC133_ZONE_END = \"\\x1b]133;B\\x07\";\nconst OSC133_ZONE_FINAL = \"\\x1b]133;C\\x07\";\n\n// Streaming messages below this size render as a single Markdown; above it the\n// text is segmented at stable block boundaries so each throttle tick re-parses\n// only the growing tail instead of the whole accumulated message.\nconst SEGMENT_MIN_CHARS = 2048;\n\nconst LIST_ITEM_RE = /^ {0,3}(?:[-*+] |\\d{1,9}[.)] )/;\nconst FENCE_RE = /^ {0,3}(?:```|~~~)/;\nconst LINK_DEF_RE = /^ {0,3}\\[[^\\]]+\\]: /m;\nconst SETEXT_UNDERLINE_RE = /^ {0,3}(?:=+|-+)\\s*$/;\n\n/** True when a blank-line gap between `prev` and `next` (both non-blank) is a\n * safe place to cut the markdown into independently-parseable chunks. */\nfunction isSafeBoundary(prev: string, next: string): boolean {\n\t// Indented continuation (loose list item body, indented code) binds to the\n\t// block above the gap.\n\tif (/^\\s/.test(next)) return false;\n\t// A blank line between two list items is a loose list, not two lists.\n\tif (LIST_ITEM_RE.test(prev) && LIST_ITEM_RE.test(next)) return false;\n\t// Tables and raw HTML blocks can span blank lines in surprising ways.\n\tif (next.startsWith(\"|\") || prev.trimStart().startsWith(\"|\")) return false;\n\tif (next.startsWith(\"<\") || prev.trimStart().startsWith(\"<\")) return false;\n\t// A bare ===/--- line after the gap could lex as setext underline or hr\n\t// differently without its preceding text; keep it attached.\n\tif (SETEXT_UNDERLINE_RE.test(next)) return false;\n\treturn true;\n}\n\n/**\n * Split markdown into chunks at blank-line boundaries where each chunk lexes\n * independently to the same blocks the whole text would. Prefix-stable:\n * appending text never changes earlier boundaries (decisions depend only on\n * preceding fence parity and the lines adjacent to each gap), so during\n * streaming every chunk except the last is byte-identical across updates and\n * its Markdown render cache keeps hitting. Exported for tests.\n */\nexport function segmentStreamingMarkdown(text: string): string[] {\n\t// Reference-style link/footnote definitions resolve across the whole\n\t// document; segmenting would break lookups from other chunks.\n\tif (LINK_DEF_RE.test(text)) return [text];\n\tconst lines = text.split(\"\\n\");\n\tconst chunks: string[] = [];\n\tlet chunkStart = 0;\n\tlet fenceOpen = false;\n\tlet prevNonblank = \"\";\n\tlet i = 0;\n\twhile (i < lines.length) {\n\t\tconst line = lines[i];\n\t\tif (FENCE_RE.test(line)) fenceOpen = !fenceOpen;\n\t\tif (line.trim() === \"\" && !fenceOpen) {\n\t\t\tlet j = i + 1;\n\t\t\twhile (j < lines.length && lines[j].trim() === \"\") j++;\n\t\t\t// Only cut when the gap has content on both sides; a trailing blank\n\t\t\t// run stays attached so the decision never has to be revisited.\n\t\t\tif (j < lines.length && chunkStart < i && isSafeBoundary(prevNonblank, lines[j])) {\n\t\t\t\tchunks.push(lines.slice(chunkStart, i).join(\"\\n\"));\n\t\t\t\tchunkStart = j;\n\t\t\t}\n\t\t\ti = j;\n\t\t\tcontinue;\n\t\t}\n\t\tif (line.trim() !== \"\") prevNonblank = line;\n\t\ti++;\n\t}\n\tconst last = lines.slice(chunkStart).join(\"\\n\");\n\tif (last.trim() !== \"\") {\n\t\tchunks.push(last);\n\t}\n\treturn chunks.length > 0 ? chunks : [text];\n}\n\n/**\n * Component that renders a complete assistant message\n */\nexport class AssistantMessageComponent extends Container {\n\tprivate contentContainer: Container;\n\tprivate hideThinkingBlock: boolean;\n\tprivate markdownTheme: MarkdownTheme;\n\tprivate hiddenThinkingLabel: string;\n\tprivate lastMessage?: AssistantMessage;\n\tprivate hasToolCalls = false;\n\t// Markdown children reused across streaming updates, keyed by content index +\n\t// kind. Markdown caches its rendered lines by (text, width); recreating the\n\t// instances on every streamed delta discarded those caches and re-parsed the\n\t// entire message (thinking trace included) per frame. Reuse keeps finished\n\t// blocks cached so only the block whose text actually changed re-parses.\n\tprivate markdownCache = new Map<string, { md: Markdown; text: string }>();\n\n\tconstructor(\n\t\tmessage?: AssistantMessage,\n\t\thideThinkingBlock = false,\n\t\tmarkdownTheme: MarkdownTheme = getMarkdownTheme(),\n\t\thiddenThinkingLabel = \"Thinking...\",\n\t) {\n\t\tsuper();\n\n\t\tthis.hideThinkingBlock = hideThinkingBlock;\n\t\tthis.markdownTheme = markdownTheme;\n\t\tthis.hiddenThinkingLabel = hiddenThinkingLabel;\n\n\t\t// Container for text/thinking content\n\t\tthis.contentContainer = new Container();\n\t\tthis.addChild(this.contentContainer);\n\n\t\tif (message) {\n\t\t\tthis.updateContent(message);\n\t\t}\n\t}\n\n\toverride invalidate(): void {\n\t\t// Cached Markdown blocks may be detached right now (e.g. hidden thinking);\n\t\t// drop their render caches too so a theme/width change can't resurface\n\t\t// stale styling when they re-attach.\n\t\tfor (const { md } of this.markdownCache.values()) {\n\t\t\tmd.invalidate();\n\t\t}\n\t\tsuper.invalidate();\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\tprivate reuseMarkdown(key: string, text: string, style?: DefaultTextStyle): Markdown {\n\t\tconst entry = this.markdownCache.get(key);\n\t\tif (entry) {\n\t\t\tif (entry.text !== text) {\n\t\t\t\tentry.md.setText(text);\n\t\t\t\tentry.text = text;\n\t\t\t}\n\t\t\treturn entry.md;\n\t\t}\n\t\tconst md = new Markdown(text, 1, 0, this.markdownTheme, style);\n\t\tthis.markdownCache.set(key, { md, text });\n\t\treturn md;\n\t}\n\n\t/** Set when the current children include streaming segments; the next\n\t * non-streaming (final/rebuild) render purges their cache entries. */\n\tprivate hasSegmentedBlocks = false;\n\n\t/**\n\t * Add one markdown content block. Large blocks still being streamed are\n\t * segmented at stable boundaries so only the tail chunk re-parses per\n\t * update; every earlier chunk is byte-stable and stays cached. The final\n\t * (non-streaming) render collapses back to one canonical Markdown, so any\n\t * segmentation artifact is transient by construction.\n\t */\n\tprivate addMarkdownBlock(keyBase: string, text: string, streaming: boolean, style?: DefaultTextStyle): void {\n\t\tif (streaming && text.length >= SEGMENT_MIN_CHARS) {\n\t\t\tconst chunks = segmentStreamingMarkdown(text);\n\t\t\tif (chunks.length > 1) {\n\t\t\t\tfor (let k = 0; k < chunks.length; k++) {\n\t\t\t\t\tif (k > 0) this.contentContainer.addChild(new Spacer(1));\n\t\t\t\t\tthis.contentContainer.addChild(this.reuseMarkdown(`${keyBase}:seg:${k}`, chunks[k], style));\n\t\t\t\t}\n\t\t\t\tthis.hasSegmentedBlocks = true;\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tthis.contentContainer.addChild(this.reuseMarkdown(keyBase, text, style));\n\t}\n\n\tsetHideThinkingBlock(hide: boolean): void {\n\t\tthis.hideThinkingBlock = hide;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\tsetHiddenThinkingLabel(label: string): void {\n\t\tthis.hiddenThinkingLabel = label;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\t/** OSC-zone wrap memo: Container.render returns the same array across\n\t * frames when nothing changed, so it must not be mutated — the wrapped\n\t * copy is cached keyed on the source array's identity. */\n\tprivate zoneMemo?: { src: string[]; out: string[] };\n\n\toverride render(width: number): string[] {\n\t\tconst lines = super.render(width);\n\t\tif (this.hasToolCalls || lines.length === 0) {\n\t\t\treturn lines;\n\t\t}\n\n\t\tif (this.zoneMemo?.src === lines) {\n\t\t\treturn this.zoneMemo.out;\n\t\t}\n\t\tconst out = lines.slice();\n\t\tout[0] = OSC133_ZONE_START + out[0];\n\t\tout[out.length - 1] = OSC133_ZONE_END + OSC133_ZONE_FINAL + out[out.length - 1];\n\t\tthis.zoneMemo = { src: lines, out };\n\t\treturn out;\n\t}\n\n\tupdateContent(message: AssistantMessage, streaming = false): void {\n\t\tthis.lastMessage = message;\n\n\t\t// A final/rebuild render replaces streaming segments with the canonical\n\t\t// single-Markdown form; drop the segment cache entries they used.\n\t\tif (!streaming && this.hasSegmentedBlocks) {\n\t\t\tfor (const key of this.markdownCache.keys()) {\n\t\t\t\tif (key.includes(\":seg:\")) this.markdownCache.delete(key);\n\t\t\t}\n\t\t\tthis.hasSegmentedBlocks = false;\n\t\t}\n\n\t\t// Clear content container\n\t\tthis.contentContainer.clear();\n\n\t\tconst hasVisibleContent = message.content.some(\n\t\t\t(c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()),\n\t\t);\n\n\t\tif (hasVisibleContent) {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t}\n\n\t\t// Render content in order\n\t\tfor (let i = 0; i < message.content.length; i++) {\n\t\t\tconst content = message.content[i];\n\t\t\tif (content.type === \"text\" && content.text.trim()) {\n\t\t\t\t// Assistant text messages with no background - trim the text\n\t\t\t\t// Set paddingY=0 to avoid extra spacing before tool executions\n\t\t\t\tthis.addMarkdownBlock(`${i}:text`, content.text.trim(), streaming);\n\t\t\t} else if (content.type === \"thinking\" && content.thinking.trim()) {\n\t\t\t\t// Add spacing only when another visible assistant content block follows.\n\t\t\t\t// This avoids a superfluous blank line before separately-rendered tool execution blocks.\n\t\t\t\tconst hasVisibleContentAfter = message.content\n\t\t\t\t\t.slice(i + 1)\n\t\t\t\t\t.some((c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()));\n\n\t\t\t\tif (this.hideThinkingBlock) {\n\t\t\t\t\t// Show static thinking label when hidden\n\t\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\t\tnew Text(theme.italic(theme.fg(\"thinkingText\", this.hiddenThinkingLabel)), 1, 0),\n\t\t\t\t\t);\n\t\t\t\t\tif (hasVisibleContentAfter) {\n\t\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Thinking traces in thinkingText color, italic, with ✻ prefix\n\t\t\t\t\tthis.addMarkdownBlock(`${i}:thinking`, `✻ ${content.thinking.trim()}`, streaming, {\n\t\t\t\t\t\tcolor: (text: string) => theme.fg(\"thinkingText\", text),\n\t\t\t\t\t\titalic: true,\n\t\t\t\t\t});\n\t\t\t\t\tif (hasVisibleContentAfter) {\n\t\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Check if aborted - show after partial content\n\t\t// But only if there are no tool calls (tool execution components will show the error)\n\t\tconst hasToolCalls = message.content.some((c) => c.type === \"toolCall\");\n\t\tthis.hasToolCalls = hasToolCalls;\n\t\tif (!hasToolCalls) {\n\t\t\tif (message.stopReason === \"aborted\") {\n\t\t\t\tconst abortMessage =\n\t\t\t\t\tmessage.errorMessage && message.errorMessage !== \"Request was aborted\"\n\t\t\t\t\t\t? message.errorMessage\n\t\t\t\t\t\t: \"Operation aborted\";\n\t\t\t\tif (hasVisibleContent) {\n\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t} else {\n\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t}\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", abortMessage), 1, 0));\n\t\t\t} else if (message.stopReason === \"error\") {\n\t\t\t\tconst errorMsg = message.errorMessage || \"Unknown error\";\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", `Error: ${errorMsg}`), 1, 0));\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
@@ -3,6 +3,81 @@ import { getMarkdownTheme, theme } from "../theme/theme.js";
|
|
|
3
3
|
const OSC133_ZONE_START = "\x1b]133;A\x07";
|
|
4
4
|
const OSC133_ZONE_END = "\x1b]133;B\x07";
|
|
5
5
|
const OSC133_ZONE_FINAL = "\x1b]133;C\x07";
|
|
6
|
+
// Streaming messages below this size render as a single Markdown; above it the
|
|
7
|
+
// text is segmented at stable block boundaries so each throttle tick re-parses
|
|
8
|
+
// only the growing tail instead of the whole accumulated message.
|
|
9
|
+
const SEGMENT_MIN_CHARS = 2048;
|
|
10
|
+
const LIST_ITEM_RE = /^ {0,3}(?:[-*+] |\d{1,9}[.)] )/;
|
|
11
|
+
const FENCE_RE = /^ {0,3}(?:```|~~~)/;
|
|
12
|
+
const LINK_DEF_RE = /^ {0,3}\[[^\]]+\]: /m;
|
|
13
|
+
const SETEXT_UNDERLINE_RE = /^ {0,3}(?:=+|-+)\s*$/;
|
|
14
|
+
/** True when a blank-line gap between `prev` and `next` (both non-blank) is a
|
|
15
|
+
* safe place to cut the markdown into independently-parseable chunks. */
|
|
16
|
+
function isSafeBoundary(prev, next) {
|
|
17
|
+
// Indented continuation (loose list item body, indented code) binds to the
|
|
18
|
+
// block above the gap.
|
|
19
|
+
if (/^\s/.test(next))
|
|
20
|
+
return false;
|
|
21
|
+
// A blank line between two list items is a loose list, not two lists.
|
|
22
|
+
if (LIST_ITEM_RE.test(prev) && LIST_ITEM_RE.test(next))
|
|
23
|
+
return false;
|
|
24
|
+
// Tables and raw HTML blocks can span blank lines in surprising ways.
|
|
25
|
+
if (next.startsWith("|") || prev.trimStart().startsWith("|"))
|
|
26
|
+
return false;
|
|
27
|
+
if (next.startsWith("<") || prev.trimStart().startsWith("<"))
|
|
28
|
+
return false;
|
|
29
|
+
// A bare ===/--- line after the gap could lex as setext underline or hr
|
|
30
|
+
// differently without its preceding text; keep it attached.
|
|
31
|
+
if (SETEXT_UNDERLINE_RE.test(next))
|
|
32
|
+
return false;
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Split markdown into chunks at blank-line boundaries where each chunk lexes
|
|
37
|
+
* independently to the same blocks the whole text would. Prefix-stable:
|
|
38
|
+
* appending text never changes earlier boundaries (decisions depend only on
|
|
39
|
+
* preceding fence parity and the lines adjacent to each gap), so during
|
|
40
|
+
* streaming every chunk except the last is byte-identical across updates and
|
|
41
|
+
* its Markdown render cache keeps hitting. Exported for tests.
|
|
42
|
+
*/
|
|
43
|
+
export function segmentStreamingMarkdown(text) {
|
|
44
|
+
// Reference-style link/footnote definitions resolve across the whole
|
|
45
|
+
// document; segmenting would break lookups from other chunks.
|
|
46
|
+
if (LINK_DEF_RE.test(text))
|
|
47
|
+
return [text];
|
|
48
|
+
const lines = text.split("\n");
|
|
49
|
+
const chunks = [];
|
|
50
|
+
let chunkStart = 0;
|
|
51
|
+
let fenceOpen = false;
|
|
52
|
+
let prevNonblank = "";
|
|
53
|
+
let i = 0;
|
|
54
|
+
while (i < lines.length) {
|
|
55
|
+
const line = lines[i];
|
|
56
|
+
if (FENCE_RE.test(line))
|
|
57
|
+
fenceOpen = !fenceOpen;
|
|
58
|
+
if (line.trim() === "" && !fenceOpen) {
|
|
59
|
+
let j = i + 1;
|
|
60
|
+
while (j < lines.length && lines[j].trim() === "")
|
|
61
|
+
j++;
|
|
62
|
+
// Only cut when the gap has content on both sides; a trailing blank
|
|
63
|
+
// run stays attached so the decision never has to be revisited.
|
|
64
|
+
if (j < lines.length && chunkStart < i && isSafeBoundary(prevNonblank, lines[j])) {
|
|
65
|
+
chunks.push(lines.slice(chunkStart, i).join("\n"));
|
|
66
|
+
chunkStart = j;
|
|
67
|
+
}
|
|
68
|
+
i = j;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (line.trim() !== "")
|
|
72
|
+
prevNonblank = line;
|
|
73
|
+
i++;
|
|
74
|
+
}
|
|
75
|
+
const last = lines.slice(chunkStart).join("\n");
|
|
76
|
+
if (last.trim() !== "") {
|
|
77
|
+
chunks.push(last);
|
|
78
|
+
}
|
|
79
|
+
return chunks.length > 0 ? chunks : [text];
|
|
80
|
+
}
|
|
6
81
|
/**
|
|
7
82
|
* Component that renders a complete assistant message
|
|
8
83
|
*/
|
|
@@ -13,6 +88,12 @@ export class AssistantMessageComponent extends Container {
|
|
|
13
88
|
hiddenThinkingLabel;
|
|
14
89
|
lastMessage;
|
|
15
90
|
hasToolCalls = false;
|
|
91
|
+
// Markdown children reused across streaming updates, keyed by content index +
|
|
92
|
+
// kind. Markdown caches its rendered lines by (text, width); recreating the
|
|
93
|
+
// instances on every streamed delta discarded those caches and re-parsed the
|
|
94
|
+
// entire message (thinking trace included) per frame. Reuse keeps finished
|
|
95
|
+
// blocks cached so only the block whose text actually changed re-parses.
|
|
96
|
+
markdownCache = new Map();
|
|
16
97
|
constructor(message, hideThinkingBlock = false, markdownTheme = getMarkdownTheme(), hiddenThinkingLabel = "Thinking...") {
|
|
17
98
|
super();
|
|
18
99
|
this.hideThinkingBlock = hideThinkingBlock;
|
|
@@ -26,11 +107,55 @@ export class AssistantMessageComponent extends Container {
|
|
|
26
107
|
}
|
|
27
108
|
}
|
|
28
109
|
invalidate() {
|
|
110
|
+
// Cached Markdown blocks may be detached right now (e.g. hidden thinking);
|
|
111
|
+
// drop their render caches too so a theme/width change can't resurface
|
|
112
|
+
// stale styling when they re-attach.
|
|
113
|
+
for (const { md } of this.markdownCache.values()) {
|
|
114
|
+
md.invalidate();
|
|
115
|
+
}
|
|
29
116
|
super.invalidate();
|
|
30
117
|
if (this.lastMessage) {
|
|
31
118
|
this.updateContent(this.lastMessage);
|
|
32
119
|
}
|
|
33
120
|
}
|
|
121
|
+
reuseMarkdown(key, text, style) {
|
|
122
|
+
const entry = this.markdownCache.get(key);
|
|
123
|
+
if (entry) {
|
|
124
|
+
if (entry.text !== text) {
|
|
125
|
+
entry.md.setText(text);
|
|
126
|
+
entry.text = text;
|
|
127
|
+
}
|
|
128
|
+
return entry.md;
|
|
129
|
+
}
|
|
130
|
+
const md = new Markdown(text, 1, 0, this.markdownTheme, style);
|
|
131
|
+
this.markdownCache.set(key, { md, text });
|
|
132
|
+
return md;
|
|
133
|
+
}
|
|
134
|
+
/** Set when the current children include streaming segments; the next
|
|
135
|
+
* non-streaming (final/rebuild) render purges their cache entries. */
|
|
136
|
+
hasSegmentedBlocks = false;
|
|
137
|
+
/**
|
|
138
|
+
* Add one markdown content block. Large blocks still being streamed are
|
|
139
|
+
* segmented at stable boundaries so only the tail chunk re-parses per
|
|
140
|
+
* update; every earlier chunk is byte-stable and stays cached. The final
|
|
141
|
+
* (non-streaming) render collapses back to one canonical Markdown, so any
|
|
142
|
+
* segmentation artifact is transient by construction.
|
|
143
|
+
*/
|
|
144
|
+
addMarkdownBlock(keyBase, text, streaming, style) {
|
|
145
|
+
if (streaming && text.length >= SEGMENT_MIN_CHARS) {
|
|
146
|
+
const chunks = segmentStreamingMarkdown(text);
|
|
147
|
+
if (chunks.length > 1) {
|
|
148
|
+
for (let k = 0; k < chunks.length; k++) {
|
|
149
|
+
if (k > 0)
|
|
150
|
+
this.contentContainer.addChild(new Spacer(1));
|
|
151
|
+
this.contentContainer.addChild(this.reuseMarkdown(`${keyBase}:seg:${k}`, chunks[k], style));
|
|
152
|
+
}
|
|
153
|
+
this.hasSegmentedBlocks = true;
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
this.contentContainer.addChild(this.reuseMarkdown(keyBase, text, style));
|
|
158
|
+
}
|
|
34
159
|
setHideThinkingBlock(hide) {
|
|
35
160
|
this.hideThinkingBlock = hide;
|
|
36
161
|
if (this.lastMessage) {
|
|
@@ -43,17 +168,35 @@ export class AssistantMessageComponent extends Container {
|
|
|
43
168
|
this.updateContent(this.lastMessage);
|
|
44
169
|
}
|
|
45
170
|
}
|
|
171
|
+
/** OSC-zone wrap memo: Container.render returns the same array across
|
|
172
|
+
* frames when nothing changed, so it must not be mutated — the wrapped
|
|
173
|
+
* copy is cached keyed on the source array's identity. */
|
|
174
|
+
zoneMemo;
|
|
46
175
|
render(width) {
|
|
47
176
|
const lines = super.render(width);
|
|
48
177
|
if (this.hasToolCalls || lines.length === 0) {
|
|
49
178
|
return lines;
|
|
50
179
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
180
|
+
if (this.zoneMemo?.src === lines) {
|
|
181
|
+
return this.zoneMemo.out;
|
|
182
|
+
}
|
|
183
|
+
const out = lines.slice();
|
|
184
|
+
out[0] = OSC133_ZONE_START + out[0];
|
|
185
|
+
out[out.length - 1] = OSC133_ZONE_END + OSC133_ZONE_FINAL + out[out.length - 1];
|
|
186
|
+
this.zoneMemo = { src: lines, out };
|
|
187
|
+
return out;
|
|
54
188
|
}
|
|
55
|
-
updateContent(message) {
|
|
189
|
+
updateContent(message, streaming = false) {
|
|
56
190
|
this.lastMessage = message;
|
|
191
|
+
// A final/rebuild render replaces streaming segments with the canonical
|
|
192
|
+
// single-Markdown form; drop the segment cache entries they used.
|
|
193
|
+
if (!streaming && this.hasSegmentedBlocks) {
|
|
194
|
+
for (const key of this.markdownCache.keys()) {
|
|
195
|
+
if (key.includes(":seg:"))
|
|
196
|
+
this.markdownCache.delete(key);
|
|
197
|
+
}
|
|
198
|
+
this.hasSegmentedBlocks = false;
|
|
199
|
+
}
|
|
57
200
|
// Clear content container
|
|
58
201
|
this.contentContainer.clear();
|
|
59
202
|
const hasVisibleContent = message.content.some((c) => (c.type === "text" && c.text.trim()) || (c.type === "thinking" && c.thinking.trim()));
|
|
@@ -66,7 +209,7 @@ export class AssistantMessageComponent extends Container {
|
|
|
66
209
|
if (content.type === "text" && content.text.trim()) {
|
|
67
210
|
// Assistant text messages with no background - trim the text
|
|
68
211
|
// Set paddingY=0 to avoid extra spacing before tool executions
|
|
69
|
-
this.
|
|
212
|
+
this.addMarkdownBlock(`${i}:text`, content.text.trim(), streaming);
|
|
70
213
|
}
|
|
71
214
|
else if (content.type === "thinking" && content.thinking.trim()) {
|
|
72
215
|
// Add spacing only when another visible assistant content block follows.
|
|
@@ -83,10 +226,10 @@ export class AssistantMessageComponent extends Container {
|
|
|
83
226
|
}
|
|
84
227
|
else {
|
|
85
228
|
// Thinking traces in thinkingText color, italic, with ✻ prefix
|
|
86
|
-
this.
|
|
229
|
+
this.addMarkdownBlock(`${i}:thinking`, `✻ ${content.thinking.trim()}`, streaming, {
|
|
87
230
|
color: (text) => theme.fg("thinkingText", text),
|
|
88
231
|
italic: true,
|
|
89
|
-
})
|
|
232
|
+
});
|
|
90
233
|
if (hasVisibleContentAfter) {
|
|
91
234
|
this.contentContainer.addChild(new Spacer(1));
|
|
92
235
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assistant-message.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/assistant-message.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAsB,MAAM,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AACjG,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE5D,MAAM,iBAAiB,GAAG,gBAAgB,CAAC;AAC3C,MAAM,eAAe,GAAG,gBAAgB,CAAC;AACzC,MAAM,iBAAiB,GAAG,gBAAgB,CAAC;AAE3C;;GAEG;AACH,MAAM,OAAO,yBAA0B,SAAQ,SAAS;IAC/C,gBAAgB,CAAY;IAC5B,iBAAiB,CAAU;IAC3B,aAAa,CAAgB;IAC7B,mBAAmB,CAAS;IAC5B,WAAW,CAAoB;IAC/B,YAAY,GAAG,KAAK,CAAC;IAE7B,YACC,OAA0B,EAC1B,iBAAiB,GAAG,KAAK,EACzB,aAAa,GAAkB,gBAAgB,EAAE,EACjD,mBAAmB,GAAG,aAAa,EAClC;QACD,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QAC3C,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;QAE/C,sCAAsC;QACtC,IAAI,CAAC,gBAAgB,GA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AC,CAAC,CAAC;YACzF,CAAC;QACF,CAAC;IAAA,CACD;CACD","sourcesContent":["import type { AssistantMessage } from \"@kolisachint/hoocode-ai\";\nimport { Container, Markdown, type MarkdownTheme, Spacer, Text } from \"@kolisachint/hoocode-tui\";\nimport { getMarkdownTheme, theme } from \"../theme/theme.js\";\n\nconst OSC133_ZONE_START = \"\\x1b]133;A\\x07\";\nconst OSC133_ZONE_END = \"\\x1b]133;B\\x07\";\nconst OSC133_ZONE_FINAL = \"\\x1b]133;C\\x07\";\n\n/**\n * Component that renders a complete assistant message\n */\nexport class AssistantMessageComponent extends Container {\n\tprivate contentContainer: Container;\n\tprivate hideThinkingBlock: boolean;\n\tprivate markdownTheme: MarkdownTheme;\n\tprivate hiddenThinkingLabel: string;\n\tprivate lastMessage?: AssistantMessage;\n\tprivate hasToolCalls = false;\n\n\tconstructor(\n\t\tmessage?: AssistantMessage,\n\t\thideThinkingBlock = false,\n\t\tmarkdownTheme: MarkdownTheme = getMarkdownTheme(),\n\t\thiddenThinkingLabel = \"Thinking...\",\n\t) {\n\t\tsuper();\n\n\t\tthis.hideThinkingBlock = hideThinkingBlock;\n\t\tthis.markdownTheme = markdownTheme;\n\t\tthis.hiddenThinkingLabel = hiddenThinkingLabel;\n\n\t\t// Container for text/thinking content\n\t\tthis.contentContainer = new Container();\n\t\tthis.addChild(this.contentContainer);\n\n\t\tif (message) {\n\t\t\tthis.updateContent(message);\n\t\t}\n\t}\n\n\toverride invalidate(): void {\n\t\tsuper.invalidate();\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\tsetHideThinkingBlock(hide: boolean): void {\n\t\tthis.hideThinkingBlock = hide;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\tsetHiddenThinkingLabel(label: string): void {\n\t\tthis.hiddenThinkingLabel = label;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\toverride render(width: number): string[] {\n\t\tconst lines = super.render(width);\n\t\tif (this.hasToolCalls || lines.length === 0) {\n\t\t\treturn lines;\n\t\t}\n\n\t\tlines[0] = OSC133_ZONE_START + lines[0];\n\t\tlines[lines.length - 1] = OSC133_ZONE_END + OSC133_ZONE_FINAL + lines[lines.length - 1];\n\t\treturn lines;\n\t}\n\n\tupdateContent(message: AssistantMessage): void {\n\t\tthis.lastMessage = message;\n\n\t\t// Clear content container\n\t\tthis.contentContainer.clear();\n\n\t\tconst hasVisibleContent = message.content.some(\n\t\t\t(c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()),\n\t\t);\n\n\t\tif (hasVisibleContent) {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t}\n\n\t\t// Render content in order\n\t\tfor (let i = 0; i < message.content.length; i++) {\n\t\t\tconst content = message.content[i];\n\t\t\tif (content.type === \"text\" && content.text.trim()) {\n\t\t\t\t// Assistant text messages with no background - trim the text\n\t\t\t\t// Set paddingY=0 to avoid extra spacing before tool executions\n\t\t\t\tthis.contentContainer.addChild(new Markdown(content.text.trim(), 1, 0, this.markdownTheme));\n\t\t\t} else if (content.type === \"thinking\" && content.thinking.trim()) {\n\t\t\t\t// Add spacing only when another visible assistant content block follows.\n\t\t\t\t// This avoids a superfluous blank line before separately-rendered tool execution blocks.\n\t\t\t\tconst hasVisibleContentAfter = message.content\n\t\t\t\t\t.slice(i + 1)\n\t\t\t\t\t.some((c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()));\n\n\t\t\t\tif (this.hideThinkingBlock) {\n\t\t\t\t\t// Show static thinking label when hidden\n\t\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\t\tnew Text(theme.italic(theme.fg(\"thinkingText\", this.hiddenThinkingLabel)), 1, 0),\n\t\t\t\t\t);\n\t\t\t\t\tif (hasVisibleContentAfter) {\n\t\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Thinking traces in thinkingText color, italic, with ✻ prefix\n\t\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\t\tnew Markdown(`✻ ${content.thinking.trim()}`, 1, 0, this.markdownTheme, {\n\t\t\t\t\t\t\tcolor: (text: string) => theme.fg(\"thinkingText\", text),\n\t\t\t\t\t\t\titalic: true,\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t\tif (hasVisibleContentAfter) {\n\t\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Check if aborted - show after partial content\n\t\t// But only if there are no tool calls (tool execution components will show the error)\n\t\tconst hasToolCalls = message.content.some((c) => c.type === \"toolCall\");\n\t\tthis.hasToolCalls = hasToolCalls;\n\t\tif (!hasToolCalls) {\n\t\t\tif (message.stopReason === \"aborted\") {\n\t\t\t\tconst abortMessage =\n\t\t\t\t\tmessage.errorMessage && message.errorMessage !== \"Request was aborted\"\n\t\t\t\t\t\t? message.errorMessage\n\t\t\t\t\t\t: \"Operation aborted\";\n\t\t\t\tif (hasVisibleContent) {\n\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t} else {\n\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t}\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", abortMessage), 1, 0));\n\t\t\t} else if (message.stopReason === \"error\") {\n\t\t\t\tconst errorMsg = message.errorMessage || \"Unknown error\";\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", `Error: ${errorMsg}`), 1, 0));\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"assistant-message.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/assistant-message.ts"],"names":[],"mappings":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AK,SAAS,EAAE,CAAC;gBACtC,MAAM,YAAY,GACjB,OAAO,CAAC,YAAY,IAAI,OAAO,CAAC,YAAY,KAAK,qBAAqB;oBACrE,CAAC,CAAC,OAAO,CAAC,YAAY;oBACtB,CAAC,CAAC,mBAAmB,CAAC;gBACxB,IAAI,iBAAiB,EAAE,CAAC;oBACvB,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC/C,CAAC;qBAAM,CAAC;oBACP,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC/C,CAAC;gBACD,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YACjF,CAAC;iBAAM,IAAI,OAAO,CAAC,UAAU,KAAK,OAAO,EAAE,CAAC;gBAC3C,MAAM,QAAQ,GAAG,OAAO,CAAC,YAAY,IAAI,eAAe,CAAC;gBACzD,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC9C,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,QAAQ,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YACzF,CAAC;QACF,CAAC;IAAA,CACD;CACD","sourcesContent":["import type { AssistantMessage } from \"@kolisachint/hoocode-ai\";\nimport { Container, type DefaultTextStyle, Markdown, type MarkdownTheme, Spacer, Text } from \"@kolisachint/hoocode-tui\";\nimport { getMarkdownTheme, theme } from \"../theme/theme.js\";\n\nconst OSC133_ZONE_START = \"\\x1b]133;A\\x07\";\nconst OSC133_ZONE_END = \"\\x1b]133;B\\x07\";\nconst OSC133_ZONE_FINAL = \"\\x1b]133;C\\x07\";\n\n// Streaming messages below this size render as a single Markdown; above it the\n// text is segmented at stable block boundaries so each throttle tick re-parses\n// only the growing tail instead of the whole accumulated message.\nconst SEGMENT_MIN_CHARS = 2048;\n\nconst LIST_ITEM_RE = /^ {0,3}(?:[-*+] |\\d{1,9}[.)] )/;\nconst FENCE_RE = /^ {0,3}(?:```|~~~)/;\nconst LINK_DEF_RE = /^ {0,3}\\[[^\\]]+\\]: /m;\nconst SETEXT_UNDERLINE_RE = /^ {0,3}(?:=+|-+)\\s*$/;\n\n/** True when a blank-line gap between `prev` and `next` (both non-blank) is a\n * safe place to cut the markdown into independently-parseable chunks. */\nfunction isSafeBoundary(prev: string, next: string): boolean {\n\t// Indented continuation (loose list item body, indented code) binds to the\n\t// block above the gap.\n\tif (/^\\s/.test(next)) return false;\n\t// A blank line between two list items is a loose list, not two lists.\n\tif (LIST_ITEM_RE.test(prev) && LIST_ITEM_RE.test(next)) return false;\n\t// Tables and raw HTML blocks can span blank lines in surprising ways.\n\tif (next.startsWith(\"|\") || prev.trimStart().startsWith(\"|\")) return false;\n\tif (next.startsWith(\"<\") || prev.trimStart().startsWith(\"<\")) return false;\n\t// A bare ===/--- line after the gap could lex as setext underline or hr\n\t// differently without its preceding text; keep it attached.\n\tif (SETEXT_UNDERLINE_RE.test(next)) return false;\n\treturn true;\n}\n\n/**\n * Split markdown into chunks at blank-line boundaries where each chunk lexes\n * independently to the same blocks the whole text would. Prefix-stable:\n * appending text never changes earlier boundaries (decisions depend only on\n * preceding fence parity and the lines adjacent to each gap), so during\n * streaming every chunk except the last is byte-identical across updates and\n * its Markdown render cache keeps hitting. Exported for tests.\n */\nexport function segmentStreamingMarkdown(text: string): string[] {\n\t// Reference-style link/footnote definitions resolve across the whole\n\t// document; segmenting would break lookups from other chunks.\n\tif (LINK_DEF_RE.test(text)) return [text];\n\tconst lines = text.split(\"\\n\");\n\tconst chunks: string[] = [];\n\tlet chunkStart = 0;\n\tlet fenceOpen = false;\n\tlet prevNonblank = \"\";\n\tlet i = 0;\n\twhile (i < lines.length) {\n\t\tconst line = lines[i];\n\t\tif (FENCE_RE.test(line)) fenceOpen = !fenceOpen;\n\t\tif (line.trim() === \"\" && !fenceOpen) {\n\t\t\tlet j = i + 1;\n\t\t\twhile (j < lines.length && lines[j].trim() === \"\") j++;\n\t\t\t// Only cut when the gap has content on both sides; a trailing blank\n\t\t\t// run stays attached so the decision never has to be revisited.\n\t\t\tif (j < lines.length && chunkStart < i && isSafeBoundary(prevNonblank, lines[j])) {\n\t\t\t\tchunks.push(lines.slice(chunkStart, i).join(\"\\n\"));\n\t\t\t\tchunkStart = j;\n\t\t\t}\n\t\t\ti = j;\n\t\t\tcontinue;\n\t\t}\n\t\tif (line.trim() !== \"\") prevNonblank = line;\n\t\ti++;\n\t}\n\tconst last = lines.slice(chunkStart).join(\"\\n\");\n\tif (last.trim() !== \"\") {\n\t\tchunks.push(last);\n\t}\n\treturn chunks.length > 0 ? chunks : [text];\n}\n\n/**\n * Component that renders a complete assistant message\n */\nexport class AssistantMessageComponent extends Container {\n\tprivate contentContainer: Container;\n\tprivate hideThinkingBlock: boolean;\n\tprivate markdownTheme: MarkdownTheme;\n\tprivate hiddenThinkingLabel: string;\n\tprivate lastMessage?: AssistantMessage;\n\tprivate hasToolCalls = false;\n\t// Markdown children reused across streaming updates, keyed by content index +\n\t// kind. Markdown caches its rendered lines by (text, width); recreating the\n\t// instances on every streamed delta discarded those caches and re-parsed the\n\t// entire message (thinking trace included) per frame. Reuse keeps finished\n\t// blocks cached so only the block whose text actually changed re-parses.\n\tprivate markdownCache = new Map<string, { md: Markdown; text: string }>();\n\n\tconstructor(\n\t\tmessage?: AssistantMessage,\n\t\thideThinkingBlock = false,\n\t\tmarkdownTheme: MarkdownTheme = getMarkdownTheme(),\n\t\thiddenThinkingLabel = \"Thinking...\",\n\t) {\n\t\tsuper();\n\n\t\tthis.hideThinkingBlock = hideThinkingBlock;\n\t\tthis.markdownTheme = markdownTheme;\n\t\tthis.hiddenThinkingLabel = hiddenThinkingLabel;\n\n\t\t// Container for text/thinking content\n\t\tthis.contentContainer = new Container();\n\t\tthis.addChild(this.contentContainer);\n\n\t\tif (message) {\n\t\t\tthis.updateContent(message);\n\t\t}\n\t}\n\n\toverride invalidate(): void {\n\t\t// Cached Markdown blocks may be detached right now (e.g. hidden thinking);\n\t\t// drop their render caches too so a theme/width change can't resurface\n\t\t// stale styling when they re-attach.\n\t\tfor (const { md } of this.markdownCache.values()) {\n\t\t\tmd.invalidate();\n\t\t}\n\t\tsuper.invalidate();\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\tprivate reuseMarkdown(key: string, text: string, style?: DefaultTextStyle): Markdown {\n\t\tconst entry = this.markdownCache.get(key);\n\t\tif (entry) {\n\t\t\tif (entry.text !== text) {\n\t\t\t\tentry.md.setText(text);\n\t\t\t\tentry.text = text;\n\t\t\t}\n\t\t\treturn entry.md;\n\t\t}\n\t\tconst md = new Markdown(text, 1, 0, this.markdownTheme, style);\n\t\tthis.markdownCache.set(key, { md, text });\n\t\treturn md;\n\t}\n\n\t/** Set when the current children include streaming segments; the next\n\t * non-streaming (final/rebuild) render purges their cache entries. */\n\tprivate hasSegmentedBlocks = false;\n\n\t/**\n\t * Add one markdown content block. Large blocks still being streamed are\n\t * segmented at stable boundaries so only the tail chunk re-parses per\n\t * update; every earlier chunk is byte-stable and stays cached. The final\n\t * (non-streaming) render collapses back to one canonical Markdown, so any\n\t * segmentation artifact is transient by construction.\n\t */\n\tprivate addMarkdownBlock(keyBase: string, text: string, streaming: boolean, style?: DefaultTextStyle): void {\n\t\tif (streaming && text.length >= SEGMENT_MIN_CHARS) {\n\t\t\tconst chunks = segmentStreamingMarkdown(text);\n\t\t\tif (chunks.length > 1) {\n\t\t\t\tfor (let k = 0; k < chunks.length; k++) {\n\t\t\t\t\tif (k > 0) this.contentContainer.addChild(new Spacer(1));\n\t\t\t\t\tthis.contentContainer.addChild(this.reuseMarkdown(`${keyBase}:seg:${k}`, chunks[k], style));\n\t\t\t\t}\n\t\t\t\tthis.hasSegmentedBlocks = true;\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tthis.contentContainer.addChild(this.reuseMarkdown(keyBase, text, style));\n\t}\n\n\tsetHideThinkingBlock(hide: boolean): void {\n\t\tthis.hideThinkingBlock = hide;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\tsetHiddenThinkingLabel(label: string): void {\n\t\tthis.hiddenThinkingLabel = label;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\t/** OSC-zone wrap memo: Container.render returns the same array across\n\t * frames when nothing changed, so it must not be mutated — the wrapped\n\t * copy is cached keyed on the source array's identity. */\n\tprivate zoneMemo?: { src: string[]; out: string[] };\n\n\toverride render(width: number): string[] {\n\t\tconst lines = super.render(width);\n\t\tif (this.hasToolCalls || lines.length === 0) {\n\t\t\treturn lines;\n\t\t}\n\n\t\tif (this.zoneMemo?.src === lines) {\n\t\t\treturn this.zoneMemo.out;\n\t\t}\n\t\tconst out = lines.slice();\n\t\tout[0] = OSC133_ZONE_START + out[0];\n\t\tout[out.length - 1] = OSC133_ZONE_END + OSC133_ZONE_FINAL + out[out.length - 1];\n\t\tthis.zoneMemo = { src: lines, out };\n\t\treturn out;\n\t}\n\n\tupdateContent(message: AssistantMessage, streaming = false): void {\n\t\tthis.lastMessage = message;\n\n\t\t// A final/rebuild render replaces streaming segments with the canonical\n\t\t// single-Markdown form; drop the segment cache entries they used.\n\t\tif (!streaming && this.hasSegmentedBlocks) {\n\t\t\tfor (const key of this.markdownCache.keys()) {\n\t\t\t\tif (key.includes(\":seg:\")) this.markdownCache.delete(key);\n\t\t\t}\n\t\t\tthis.hasSegmentedBlocks = false;\n\t\t}\n\n\t\t// Clear content container\n\t\tthis.contentContainer.clear();\n\n\t\tconst hasVisibleContent = message.content.some(\n\t\t\t(c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()),\n\t\t);\n\n\t\tif (hasVisibleContent) {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t}\n\n\t\t// Render content in order\n\t\tfor (let i = 0; i < message.content.length; i++) {\n\t\t\tconst content = message.content[i];\n\t\t\tif (content.type === \"text\" && content.text.trim()) {\n\t\t\t\t// Assistant text messages with no background - trim the text\n\t\t\t\t// Set paddingY=0 to avoid extra spacing before tool executions\n\t\t\t\tthis.addMarkdownBlock(`${i}:text`, content.text.trim(), streaming);\n\t\t\t} else if (content.type === \"thinking\" && content.thinking.trim()) {\n\t\t\t\t// Add spacing only when another visible assistant content block follows.\n\t\t\t\t// This avoids a superfluous blank line before separately-rendered tool execution blocks.\n\t\t\t\tconst hasVisibleContentAfter = message.content\n\t\t\t\t\t.slice(i + 1)\n\t\t\t\t\t.some((c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()));\n\n\t\t\t\tif (this.hideThinkingBlock) {\n\t\t\t\t\t// Show static thinking label when hidden\n\t\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\t\tnew Text(theme.italic(theme.fg(\"thinkingText\", this.hiddenThinkingLabel)), 1, 0),\n\t\t\t\t\t);\n\t\t\t\t\tif (hasVisibleContentAfter) {\n\t\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Thinking traces in thinkingText color, italic, with ✻ prefix\n\t\t\t\t\tthis.addMarkdownBlock(`${i}:thinking`, `✻ ${content.thinking.trim()}`, streaming, {\n\t\t\t\t\t\tcolor: (text: string) => theme.fg(\"thinkingText\", text),\n\t\t\t\t\t\titalic: true,\n\t\t\t\t\t});\n\t\t\t\t\tif (hasVisibleContentAfter) {\n\t\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Check if aborted - show after partial content\n\t\t// But only if there are no tool calls (tool execution components will show the error)\n\t\tconst hasToolCalls = message.content.some((c) => c.type === \"toolCall\");\n\t\tthis.hasToolCalls = hasToolCalls;\n\t\tif (!hasToolCalls) {\n\t\t\tif (message.stopReason === \"aborted\") {\n\t\t\t\tconst abortMessage =\n\t\t\t\t\tmessage.errorMessage && message.errorMessage !== \"Request was aborted\"\n\t\t\t\t\t\t? message.errorMessage\n\t\t\t\t\t\t: \"Operation aborted\";\n\t\t\t\tif (hasVisibleContent) {\n\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t} else {\n\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t}\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", abortMessage), 1, 0));\n\t\t\t} else if (message.stopReason === \"error\") {\n\t\t\t\tconst errorMsg = message.errorMessage || \"Unknown error\";\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", `Error: ${errorMsg}`), 1, 0));\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-editor.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/custom-editor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,KAAK,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAClG,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"custom-editor.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/custom-editor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,KAAK,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAClG,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAYtF;;GAEG;AACH,qBAAa,YAAa,SAAQ,MAAM;IACvC,OAAO,CAAC,WAAW,CAAqB;IACjC,cAAc,EAAE,GAAG,CAAC,aAAa,EAAE,MAAM,IAAI,CAAC,CAAa;IAG3D,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IACjC,2EAA2E;IACpE,mBAAmB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IAEvD,YAAY,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,kBAAkB,EAAE,OAAO,CAAC,EAAE,aAAa,EAGjG;IAED;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,IAAI,GAAG,IAAI,CAEzD;IAED,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CA0D9B;CACD","sourcesContent":["import { Editor, type EditorOptions, type EditorTheme, type TUI } from \"@kolisachint/hoocode-tui\";\nimport type { AppKeybinding, KeybindingsManager } from \"../../../core/keybindings.js\";\n\n/** True when the input contains no control bytes (C0 range or DEL), i.e. it is\n * ordinary typed/pasted text that no keybinding chord can encode to. */\nfunction isPlainText(data: string): boolean {\n\tfor (let i = 0; i < data.length; i++) {\n\t\tconst code = data.charCodeAt(i);\n\t\tif (code < 32 || code === 127) return false;\n\t}\n\treturn data.length > 0;\n}\n\n/**\n * Custom editor that handles app-level keybindings for coding-agent.\n */\nexport class CustomEditor extends Editor {\n\tprivate keybindings: KeybindingsManager;\n\tpublic actionHandlers: Map<AppKeybinding, () => void> = new Map();\n\n\t// Special handlers that can be dynamically replaced\n\tpublic onEscape?: () => void;\n\tpublic onCtrlD?: () => void;\n\tpublic onPasteImage?: () => void;\n\t/** Handler for extension-registered shortcuts. Returns true if handled. */\n\tpublic onExtensionShortcut?: (data: string) => boolean;\n\n\tconstructor(tui: TUI, theme: EditorTheme, keybindings: KeybindingsManager, options?: EditorOptions) {\n\t\tsuper(tui, theme, options);\n\t\tthis.keybindings = keybindings;\n\t}\n\n\t/**\n\t * Register a handler for an app action.\n\t */\n\tonAction(action: AppKeybinding, handler: () => void): void {\n\t\tthis.actionHandlers.set(action, handler);\n\t}\n\n\thandleInput(data: string): void {\n\t\t// Check extension-registered shortcuts first\n\t\tif (this.onExtensionShortcut?.(data)) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Plain printable input (typed characters, paste payloads) can never match\n\t\t// an app keybinding — those all arrive as control characters or escape\n\t\t// sequences. Hand the text straight to the editor so per-keystroke cost\n\t\t// stays flat no matter how many app actions get registered.\n\t\tif (isPlainText(data)) {\n\t\t\tsuper.handleInput(data);\n\t\t\treturn;\n\t\t}\n\n\t\t// Check for paste image keybinding\n\t\tif (this.keybindings.matches(data, \"app.clipboard.pasteImage\")) {\n\t\t\tthis.onPasteImage?.();\n\t\t\treturn;\n\t\t}\n\n\t\t// Check app keybindings first\n\n\t\t// Escape/interrupt - only if autocomplete is NOT active\n\t\tif (this.keybindings.matches(data, \"app.interrupt\")) {\n\t\t\tif (!this.isShowingAutocomplete()) {\n\t\t\t\t// Use dynamic onEscape if set, otherwise registered handler\n\t\t\t\tconst handler = this.onEscape ?? this.actionHandlers.get(\"app.interrupt\");\n\t\t\t\tif (handler) {\n\t\t\t\t\thandler();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Let parent handle escape for autocomplete cancellation\n\t\t\tsuper.handleInput(data);\n\t\t\treturn;\n\t\t}\n\n\t\t// Exit (Ctrl+D) - only when editor is empty\n\t\tif (this.keybindings.matches(data, \"app.exit\")) {\n\t\t\tif (this.getText().length === 0) {\n\t\t\t\tconst handler = this.onCtrlD ?? this.actionHandlers.get(\"app.exit\");\n\t\t\t\tif (handler) handler();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// Fall through to editor handling for delete-char-forward when not empty\n\t\t}\n\n\t\t// Check all other app actions\n\t\tfor (const [action, handler] of this.actionHandlers) {\n\t\t\tif (action !== \"app.interrupt\" && action !== \"app.exit\" && this.keybindings.matches(data, action)) {\n\t\t\t\thandler();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// Pass to parent for editor handling\n\t\tsuper.handleInput(data);\n\t}\n}\n"]}
|