@causyne/agent 1.20.12 → 1.20.14

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.
Files changed (72) hide show
  1. package/LICENSE +1 -1
  2. package/package.json +1 -1
  3. package/src/SmartTools.js +33 -0
  4. package/src/SmartTools.ts +37 -0
  5. package/src/acp/client.js +157 -4
  6. package/src/acp/client.ts +152 -5
  7. package/src/agentLoop.js +857 -178
  8. package/src/agentLoop.ts +865 -183
  9. package/src/browser/browserRuntime.js +8 -1
  10. package/src/browser/browserRuntime.ts +8 -1
  11. package/src/browser/causyneBrowser.js +20 -4
  12. package/src/browser/causyneBrowser.ts +20 -4
  13. package/src/browser/urlPolicy.js +35 -0
  14. package/src/browser/urlPolicy.ts +34 -0
  15. package/src/cliMode.js +6 -2
  16. package/src/commands.js +14 -0
  17. package/src/contextManager.d.ts +1 -0
  18. package/src/core/contextCompactor.js +277 -0
  19. package/src/core/contextCompactor.ts +353 -0
  20. package/src/decideTools.js +157 -0
  21. package/src/decideTools.ts +195 -0
  22. package/src/decisionPolicy.js +5 -3
  23. package/src/decisionPolicy.ts +5 -3
  24. package/src/implementationPlan.js +284 -0
  25. package/src/implementationPlan.ts +275 -0
  26. package/src/observer/coldObserver.js +10 -4
  27. package/src/observer/coldObserver.ts +15 -7
  28. package/src/observer/evidence.js +11 -5
  29. package/src/observer/evidence.ts +13 -6
  30. package/src/observer.js +196 -0
  31. package/src/observer.ts +287 -0
  32. package/src/providers/acp.js +362 -109
  33. package/src/providers/acp.ts +359 -111
  34. package/src/providers/antigravity.js +133 -105
  35. package/src/providers/antigravity.ts +130 -109
  36. package/src/providers/base.d.ts +3 -0
  37. package/src/providers/budgetEnforcer.js +13 -0
  38. package/src/providers/budgetEnforcer.ts +13 -3
  39. package/src/provisioning/capabilityProvisioner.js +14 -10
  40. package/src/sandbox.js +4 -2
  41. package/src/saveTools.js +146 -0
  42. package/src/saveTools.ts +169 -0
  43. package/src/session/cachePressure.js +77 -0
  44. package/src/session/cachePressure.ts +122 -0
  45. package/src/smartToolsUse.js +69 -12
  46. package/src/smartToolsUse.ts +103 -12
  47. package/src/taskShape.js +7 -7
  48. package/src/taskShape.ts +7 -7
  49. package/src/timeMachine.js +55 -20
  50. package/src/timeMachine.ts +64 -20
  51. package/src/toolPacks.js +217 -310
  52. package/src/toolPacks.ts +505 -0
  53. package/src/tools/deferredMcpSearch.js +21 -13
  54. package/src/tools/deferredMcpSearch.ts +23 -15
  55. package/src/tools/updatePlan.js +2 -2
  56. package/src/tools/updatePlan.ts +2 -2
  57. package/src/toolsList.js +203 -0
  58. package/src/toolsList.ts +224 -0
  59. package/src/tui/chatRenderer.js +49 -14
  60. package/src/tui/codeStreamRenderer.js +16 -5
  61. package/src/tui/codeStreamRenderer.ts +14 -4
  62. package/src/tui/prompt.js +4 -2
  63. package/src/tui/sessionSidebar.js +10 -2
  64. package/src/tui/sessionSidebar.ts +10 -3
  65. package/src/tui/stageSurface.js +27 -1
  66. package/src/tui/text.d.ts +1 -0
  67. package/src/tui/turnRail.js +274 -0
  68. package/src/tui/turnRail.ts +334 -0
  69. package/src/types/contracts.ts +103 -0
  70. package/src/verificationPlan.js +141 -0
  71. package/src/verificationPlan.ts +166 -0
  72. package/src/toolPacks.d.ts +0 -10
@@ -1,6 +1,7 @@
1
1
  import type { ParameterSchema } from './toolSelfRepair.js';
2
2
  interface ToolDefinition { name: string; description?: string; parameters?: ParameterSchema; input_schema?: ParameterSchema; }
3
- interface SearchArgs { query?: string; pack?: string; limit?: number; }
3
+ interface SearchArgs { query?: string; names?: string[]; pack?: string; limit?: number; }
4
+ interface SearchContext { parentLoop?: { searchableTools?: () => Promise<ToolDefinition[]> }; }
4
5
  interface SearchResult { success: boolean; output?: string; error?: string; _unlock_tools?: string[]; _unlock_packs?: string[]; }
5
6
  // registry.js imports THIS module to build its tool table, so a static import
6
7
  // back the other way is a cycle: whichever side loads first sees the other as
@@ -11,6 +12,7 @@ async function toolDefinitions(): Promise<ToolDefinition[]> {
11
12
  const { getSearchableToolDefinitions } = await import('./registry.js');
12
13
  return getSearchableToolDefinitions();
13
14
  }
15
+ import { buildToolsList } from '../toolsList.js';
14
16
  import { PACKS, PACK_NAMES, packForTool, isCoreTool, isResidentTool } from '../toolPacks.js';
15
17
 
16
18
  /** Max skills returned alongside the tool matches, so one search stays cheap. */
@@ -118,7 +120,7 @@ function buildPattern(query: string): RegExp | null {
118
120
  export const deferredMcpSearch = {
119
121
  schema: {
120
122
  name: 'tool.search',
121
- description: 'Search your full native tool catalogue and load additional tool schemas on demand. Causyne keeps specialised capability packs (game development, media generation, browser and vision, system control, advanced orchestration) out of your context until you need them. Call this whenever a task needs a capability you cannot currently see — the matching tools become callable immediately on your next turn. Accepts natural language ("generate music", "godot scene", "kill process on port", "read a pdf") or a regular expression.',
123
+ description: 'Discover tools or skills from the live catalog. Select exact names, describe a capability, or explicitly load a pack. Selected schemas appear next turn; execution permissions still apply.',
122
124
  parameters: {
123
125
  type: 'object',
124
126
  properties: {
@@ -126,6 +128,7 @@ export const deferredMcpSearch = {
126
128
  type: 'string',
127
129
  description: 'What capability you need. Natural language or a regex pattern matched against tool names, descriptions and argument descriptions.'
128
130
  },
131
+ names: { type: 'array', items: { type: 'string' }, description: 'Exact tool names selected from the compact catalog. Loads only these schemas.' },
129
132
  pack: {
130
133
  type: 'string',
131
134
  enum: [...PACK_NAMES, 'all'],
@@ -135,15 +138,25 @@ export const deferredMcpSearch = {
135
138
  type: 'integer',
136
139
  description: 'Maximum number of tools to return. Defaults to 8.'
137
140
  }
138
- },
139
- required: ['query']
141
+ }
140
142
  }
141
143
  },
142
144
 
143
- async execute(args: SearchArgs): Promise<SearchResult> {
145
+ async execute(args: SearchArgs, context: SearchContext = {}): Promise<SearchResult> {
144
146
  try {
145
147
  const query = String(args.query || '').trim();
146
148
  const requestedPack = args.pack ? String(args.pack).toLowerCase() : null;
149
+ const definitions = context.parentLoop?.searchableTools
150
+ ? await context.parentLoop.searchableTools() : await toolDefinitions();
151
+ const hints = new Map(buildToolsList(definitions).map((entry) => [entry.name, entry.hint]));
152
+ if (Array.isArray(args.names) && args.names.length > 0) {
153
+ const available = new Map(definitions.map((definition) => [definition.name.toLowerCase(), definition.name]));
154
+ const chosen = [...new Set(args.names.map((name) => available.get(String(name).toLowerCase())).filter((name): name is string => Boolean(name)))];
155
+ if (chosen.length !== new Set(args.names.map((name) => String(name).toLowerCase())).size) {
156
+ return { success: false, error: 'One or more selected tools are unavailable under the current policy. Select exact names from the current catalog.' };
157
+ }
158
+ return { success: true, output: `Selected ${chosen.length} tool schemas for your next turn:\n${chosen.map((name) => `- ${name}: ${hints.get(name) || 'tool'}`).join('\n')}`, _unlock_tools: chosen };
159
+ }
147
160
 
148
161
  if (!query && !requestedPack) {
149
162
  return { success: false, error: 'Provide a "query" describing the capability you need, or a "pack" name to load.' };
@@ -152,11 +165,11 @@ export const deferredMcpSearch = {
152
165
  // Whole-pack load. Cheaper than five searches when the agent already
153
166
  // knows it is starting a game or a media pipeline.
154
167
  if (requestedPack && requestedPack !== 'all' && Object.hasOwn(PACKS, requestedPack)) {
155
- const packTools = (await toolDefinitions()).filter(d => packForTool(d.name) === requestedPack);
168
+ const packTools = definitions.filter(d => packForTool(d.name) === requestedPack);
156
169
  return {
157
170
  success: true,
158
171
  output: `Loaded capability pack "${requestedPack}" (${packTools.length} tools). These are now callable:\n` +
159
- packTools.map(d => `- ${d.name}: ${d.description || ''}`).join('\n'),
172
+ packTools.map(d => `- ${d.name}: ${hints.get(d.name) || 'tool'}`).join('\n'),
160
173
  _unlock_packs: [requestedPack],
161
174
  _unlock_tools: packTools.map(d => d.name)
162
175
  };
@@ -167,7 +180,6 @@ export const deferredMcpSearch = {
167
180
  const terms = lower.split(/[^a-z0-9_]+/).filter(t => t.length > 2);
168
181
  const pattern = buildPattern(query);
169
182
 
170
- const definitions = await toolDefinitions();
171
183
  const exact = definitions.find(definition => definition.name.toLowerCase() === lower);
172
184
  const scored = (exact ? [exact] : definitions)
173
185
  .map(definition => ({ definition, score: scoreTool(definition, terms, pattern) }))
@@ -206,13 +218,9 @@ export const deferredMcpSearch = {
206
218
  // schema deferral only RESIDENT_TOOLS ship, and a non-resident core
207
219
  // tool found here would have been reported as "already loaded" and
208
220
  // then stayed invisible forever.
209
- if (!isResidentTool(definition.name)) {
210
- unlockTools.push(definition.name);
211
- }
212
- const state = isResidentTool(definition.name)
213
- ? 'already loaded'
214
- : (isCoreTool(definition.name) ? 'core' : `pack: ${pack || 'custom'}`);
215
- lines.push(`- ${definition.name} (${state}): ${definition.description || ''}`);
221
+ if (!isResidentTool(definition.name)) unlockTools.push(definition.name);
222
+ const state = isCoreTool(definition.name) ? 'core' : `pack: ${pack || 'custom'}`;
223
+ lines.push(`- ${definition.name} (${state}): ${hints.get(definition.name) || 'tool'}`);
216
224
  }
217
225
 
218
226
  // Skills are searched alongside tools because `tool_search` is the only
@@ -3,8 +3,8 @@ function healPlanArgs(raw) {
3
3
  if (!raw || typeof raw !== 'object' || Array.isArray(raw))
4
4
  return raw;
5
5
  const input = { ...raw };
6
- if (!input.plan && (input.steps || input.items || input.tasks)) {
7
- input.plan = input.steps || input.items || input.tasks;
6
+ if (!input.plan && (input.steps || input.items || input.tasks || input.todos || input.entries)) {
7
+ input.plan = input.steps || input.items || input.tasks || input.todos || input.entries;
8
8
  }
9
9
  if (Array.isArray(input.plan)) {
10
10
  let activeSeen = false;
@@ -9,8 +9,8 @@ interface ToolContext {
9
9
  function healPlanArgs(raw: unknown): unknown {
10
10
  if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return raw;
11
11
  const input = { ...(raw as Record<string, unknown>) };
12
- if (!input.plan && (input.steps || input.items || input.tasks)) {
13
- input.plan = input.steps || input.items || input.tasks;
12
+ if (!input.plan && (input.steps || input.items || input.tasks || input.todos || input.entries)) {
13
+ input.plan = input.steps || input.items || input.tasks || input.todos || input.entries;
14
14
  }
15
15
  if (Array.isArray(input.plan)) {
16
16
  let activeSeen = false;
@@ -0,0 +1,203 @@
1
+ /**
2
+ * @file src/toolsList.ts
3
+ * ToolsList — stage 1 of the tool pipeline.
4
+ *
5
+ * user intent -> ToolsList -> decideTools -> SmartTools -> saveTools -> AgentLoop
6
+ *
7
+ * This is the one place that tells a model what Causyne Agent owns. Each tool is
8
+ * a single dense line written for a model, not a person: a name and the shortest
9
+ * phrase that lets the model decide whether it needs it. It is NOT a schema.
10
+ * Schemas are expensive and are loaded only for the tools decideTools admits.
11
+ *
12
+ * Every provider receives this compact catalog beside selected full schemas.
13
+ * ACP native tools remain independent of this host-tool discovery surface.
14
+ *
15
+ * Authorship: Strict TypeScript (Causyne Agent).
16
+ */
17
+ /**
18
+ * Curated one-line purposes. Order inside a group is the order shown, and is
19
+ * stable on purpose: the list sits in the cached prompt prefix, so reshuffling
20
+ * it would invalidate the cache for every request of every task.
21
+ */
22
+ const CATALOGUE = {
23
+ core: {
24
+ sysRun: 'run shell command and wait',
25
+ sysRunBg: 'start long-running process (server, watcher)',
26
+ terminal_persistent_shell: 'stateful shell, cd/env persist',
27
+ fs_read: 'read file or line range',
28
+ fs_write: 'create or overwrite file',
29
+ fs_edit: 'replace a block in a file',
30
+ MultiEdit: 'several edits to one file',
31
+ fs_list: 'directory tree',
32
+ fs_search: 'text search across files',
33
+ fs_find: 'find files by name',
34
+ fs_move: 'move or rename',
35
+ fs_delete: 'delete to trash',
36
+ gitOp: 'git command',
37
+ code_search_ripgrep: 'regex or symbol search in codebase',
38
+ codebase_search: 'semantic code lookup',
39
+ code_verify_syntax: 'syntax or compile check of a file',
40
+ web_search: 'search the web',
41
+ web_fetch: 'fetch a public URL',
42
+ update_plan: 'visible checklist, one active step',
43
+ request_decision: 'ask the user to pick a direction',
44
+ memory_write: 'save durable user fact or design pattern',
45
+ fs_read_skill: 'read a bundled skill by id',
46
+ skill_create: 'save a reusable skill',
47
+ tool_search: 'find and load any tool on this list'
48
+ },
49
+ system: {
50
+ process_list: 'list processes',
51
+ proc_term: 'terminate a process',
52
+ desktop_open: 'open file, URL or app natively',
53
+ clipboard: 'read or write clipboard',
54
+ ax_snapshot: 'read an app window as accessibility text',
55
+ desktop_act: 'press, type or click in a GUI app',
56
+ computer_use: 'vision-grounded GUI actions',
57
+ archive: 'zip, unzip, tar',
58
+ printer_print: 'print a file',
59
+ printer_list_printers: 'list printers',
60
+ printer_get_status: 'printer status'
61
+ },
62
+ web: {
63
+ browser_act: 'browse, preview local HTML, snapshot, interact',
64
+ screenshot: 'capture screen for visual check',
65
+ vision_inspect_ui: 'look at a live screen with vision',
66
+ view_image: 'view an image file',
67
+ astryx_oracle: 'Astryx design-system docs',
68
+ ui_forge: 'generate accessible UI components'
69
+ },
70
+ media: {
71
+ generate_media_via_api: 'image, audio or video from a paid or free API',
72
+ execute_procedural_media: 'make media with code (SVG, canvas, numpy)',
73
+ check_system_specs: 'RAM, CPU, GPU, disk',
74
+ manage_local_dependencies: 'request capabilities, local dependencies',
75
+ blender_act: 'Blender 3D scene and render',
76
+ creative_apps: 'drive installed creative apps',
77
+ native_engine: 'headless film, photo, sound, CAD, deck engines',
78
+ resolve_act: 'DaVinci Resolve',
79
+ palmier_act: 'Palmier automation',
80
+ document_forge: 'produce PDF, documents, screenplays',
81
+ open_source_tool_provisioner: 'discover and install open-source AI tools'
82
+ },
83
+ advanced: {
84
+ tool_forge: 'create a custom tool',
85
+ plugin_manager: 'manage plugins',
86
+ pdf_read: 'read PDF text',
87
+ code_list_symbols: 'list symbols in a file',
88
+ code_search_ast: 'AST definition search',
89
+ agent_subagent_orchestrate: 'delegate a bounded sub-task',
90
+ peer_agent_delegate: 'delegate to an external ACP agent'
91
+ },
92
+ game: {
93
+ godot_act: 'Godot 4 project automation',
94
+ game_build_html5: 'build an HTML5 game',
95
+ game_asset_fetch: 'download CC0 assets',
96
+ game_asset_harvest: 'harvest CC0 3D, 2D, audio',
97
+ game_lore_forge: 'lore and worldbuilding',
98
+ game_dialogue_tree_gen: 'NPC dialogue trees',
99
+ game_quest_arc_builder: 'quest arcs',
100
+ game_animation_rig: 'rigging and animation',
101
+ game_ai_behavior_tree: 'enemy AI, behavior trees',
102
+ game_cinematic_sequencer: 'cutscenes, camera',
103
+ game_audio_synth: 'synthesize WAV audio',
104
+ game_vfx_emitter_gen: 'particle effects',
105
+ game_shader_forge: 'gdshader',
106
+ game_scene_build: 'build or inspect .tscn scenes',
107
+ game_entity_spawner: 'entity prefabs',
108
+ game_tilemap_gen: 'maps and dungeons',
109
+ game_ui_hud_builder: 'menu and HUD scenes',
110
+ game_economy_balancer: 'balance stats and economy',
111
+ game_data_forge: 'item and enemy data JSON',
112
+ game_web_runtime_inspector: 'headless runtime error gate',
113
+ game_canvas_audit: 'canvas render audit'
114
+ }
115
+ };
116
+ const GROUP_ORDER = ['core', 'system', 'web', 'media', 'advanced', 'game'];
117
+ const CURATED_NAMES = new Set(GROUP_ORDER.flatMap((group) => Object.keys(CATALOGUE[group])));
118
+ /** All registered plugin and MCP IDs remain discoverable; only their hints are shortened. */
119
+ export const MAX_CUSTOM_TOOLS = Number.POSITIVE_INFINITY;
120
+ const MAX_CUSTOM_HINT = 56;
121
+ function firstSentence(text) {
122
+ const flat = text.replace(/[\x00-\x1f\x7f-\x9f]/g, ' ').replace(/\s+/g, ' ').trim();
123
+ const stop = flat.search(/[.!?](?:\s|$)/);
124
+ const sentence = stop > 0 ? flat.slice(0, stop) : flat;
125
+ return sentence.length > MAX_CUSTOM_HINT ? `${sentence.slice(0, MAX_CUSTOM_HINT - 1).trimEnd()}…` : sentence;
126
+ }
127
+ /** True when a tool has a hand-written line, which every native tool must. */
128
+ export function isCuratedTool(name) {
129
+ return CURATED_NAMES.has(name);
130
+ }
131
+ export function curatedToolNames() {
132
+ return [...CURATED_NAMES];
133
+ }
134
+ /**
135
+ * Build the list. Native tools come first in curated order; anything else the
136
+ * registry reports (plugins, MCP servers, forged tools) follows as `custom`.
137
+ */
138
+ export function buildToolsList(definitions) {
139
+ const entries = [];
140
+ const filterAvailable = Array.isArray(definitions);
141
+ const available = filterAvailable ? new Set(definitions.map((definition) => definition.name)) : null;
142
+ for (const group of GROUP_ORDER) {
143
+ for (const [name, hint] of Object.entries(CATALOGUE[group])) {
144
+ if (!available || available.has(name))
145
+ entries.push({ name, group, hint });
146
+ }
147
+ }
148
+ const seen = new Set(entries.map((entry) => entry.name));
149
+ let custom = 0;
150
+ for (const definition of (definitions ? [...definitions] : []).sort((a, b) => a.name.localeCompare(b.name))) {
151
+ const name = String(definition.name || '');
152
+ if (!/^[A-Za-z0-9_.:@/-]{1,200}$/.test(name) || seen.has(name))
153
+ continue;
154
+ seen.add(name);
155
+ if (custom >= MAX_CUSTOM_TOOLS)
156
+ continue;
157
+ custom += 1;
158
+ entries.push({ name, group: 'custom', hint: firstSentence(definition.description || '') || 'custom tool' });
159
+ }
160
+ return entries;
161
+ }
162
+ /** Names the registry reports that exceed the bound and are reachable only through tool_search. */
163
+ export function omittedCustomCount(definitions) {
164
+ const unknown = new Set();
165
+ for (const definition of definitions) {
166
+ const name = String(definition.name || '');
167
+ if (name && !CURATED_NAMES.has(name))
168
+ unknown.add(name);
169
+ }
170
+ return Math.max(0, unknown.size - MAX_CUSTOM_TOOLS);
171
+ }
172
+ /**
173
+ * The compact form injected into the first request of every provider. One line
174
+ * per group; names and purposes only.
175
+ */
176
+ export function renderToolsList(entries, omitted = 0) {
177
+ const lines = [
178
+ '# TOOLS LIST — everything Causyne Agent owns, as `name: purpose`.',
179
+ 'Names/purposes only; these are not argument schemas or grants. Choose the needed names with `tool_search` (names array), then use their loaded schemas. Revisit this catalog when the task changes. Peer-native tools remain available independently.'
180
+ ];
181
+ const groups = [...GROUP_ORDER, 'custom'];
182
+ for (const group of groups) {
183
+ const members = entries.filter((entry) => entry.group === group);
184
+ if (members.length === 0)
185
+ continue;
186
+ lines.push(`${group}: ${members.map((entry) => `${entry.name}: ${entry.hint}`).join(' | ')}`);
187
+ }
188
+ if (omitted > 0)
189
+ lines.push(`+${omitted} more custom tools: reach them with tool_search.`);
190
+ return lines.join('\n');
191
+ }
192
+ /** The same list as a Markdown table, for docs and for humans reading a transcript. */
193
+ export function renderToolsListMarkdown(entries) {
194
+ const rows = entries.map((entry) => `| \`${entry.name}\` | ${entry.group} | ${entry.hint} |`);
195
+ return ['| Tool | Group | Purpose |', '| --- | --- | --- |', ...rows].join('\n');
196
+ }
197
+ /** Resolve a free-text need against the list. Used by decideTools for plan and request text. */
198
+ export function findListedTool(entries, name) {
199
+ const wanted = String(name || '').trim().toLowerCase();
200
+ if (!wanted)
201
+ return null;
202
+ return entries.find((entry) => entry.name.toLowerCase() === wanted) ?? null;
203
+ }
@@ -0,0 +1,224 @@
1
+ /**
2
+ * @file src/toolsList.ts
3
+ * ToolsList — stage 1 of the tool pipeline.
4
+ *
5
+ * user intent -> ToolsList -> decideTools -> SmartTools -> saveTools -> AgentLoop
6
+ *
7
+ * This is the one place that tells a model what Causyne Agent owns. Each tool is
8
+ * a single dense line written for a model, not a person: a name and the shortest
9
+ * phrase that lets the model decide whether it needs it. It is NOT a schema.
10
+ * Schemas are expensive and are loaded only for the tools decideTools admits.
11
+ *
12
+ * Every provider receives this compact catalog beside selected full schemas.
13
+ * ACP native tools remain independent of this host-tool discovery surface.
14
+ *
15
+ * Authorship: Strict TypeScript (Causyne Agent).
16
+ */
17
+
18
+ export type ToolGroup = 'core' | 'system' | 'web' | 'media' | 'advanced' | 'game' | 'custom';
19
+
20
+ export interface ToolListEntry {
21
+ readonly name: string;
22
+ readonly group: ToolGroup;
23
+ readonly hint: string;
24
+ }
25
+
26
+ export interface ToolDefinitionSummary {
27
+ readonly name: string;
28
+ readonly description?: string | undefined;
29
+ }
30
+
31
+ /**
32
+ * Curated one-line purposes. Order inside a group is the order shown, and is
33
+ * stable on purpose: the list sits in the cached prompt prefix, so reshuffling
34
+ * it would invalidate the cache for every request of every task.
35
+ */
36
+ const CATALOGUE: Readonly<Record<Exclude<ToolGroup, 'custom'>, Readonly<Record<string, string>>>> = {
37
+ core: {
38
+ sysRun: 'run shell command and wait',
39
+ sysRunBg: 'start long-running process (server, watcher)',
40
+ terminal_persistent_shell: 'stateful shell, cd/env persist',
41
+ fs_read: 'read file or line range',
42
+ fs_write: 'create or overwrite file',
43
+ fs_edit: 'replace a block in a file',
44
+ MultiEdit: 'several edits to one file',
45
+ fs_list: 'directory tree',
46
+ fs_search: 'text search across files',
47
+ fs_find: 'find files by name',
48
+ fs_move: 'move or rename',
49
+ fs_delete: 'delete to trash',
50
+ gitOp: 'git command',
51
+ code_search_ripgrep: 'regex or symbol search in codebase',
52
+ codebase_search: 'semantic code lookup',
53
+ code_verify_syntax: 'syntax or compile check of a file',
54
+ web_search: 'search the web',
55
+ web_fetch: 'fetch a public URL',
56
+ update_plan: 'visible checklist, one active step',
57
+ request_decision: 'ask the user to pick a direction',
58
+ memory_write: 'save durable user fact or design pattern',
59
+ fs_read_skill: 'read a bundled skill by id',
60
+ skill_create: 'save a reusable skill',
61
+ tool_search: 'find and load any tool on this list'
62
+ },
63
+ system: {
64
+ process_list: 'list processes',
65
+ proc_term: 'terminate a process',
66
+ desktop_open: 'open file, URL or app natively',
67
+ clipboard: 'read or write clipboard',
68
+ ax_snapshot: 'read an app window as accessibility text',
69
+ desktop_act: 'press, type or click in a GUI app',
70
+ computer_use: 'vision-grounded GUI actions',
71
+ archive: 'zip, unzip, tar',
72
+ printer_print: 'print a file',
73
+ printer_list_printers: 'list printers',
74
+ printer_get_status: 'printer status'
75
+ },
76
+ web: {
77
+ browser_act: 'browse, preview local HTML, snapshot, interact',
78
+ screenshot: 'capture screen for visual check',
79
+ vision_inspect_ui: 'look at a live screen with vision',
80
+ view_image: 'view an image file',
81
+ astryx_oracle: 'Astryx design-system docs',
82
+ ui_forge: 'generate accessible UI components'
83
+ },
84
+ media: {
85
+ generate_media_via_api: 'image, audio or video from a paid or free API',
86
+ execute_procedural_media: 'make media with code (SVG, canvas, numpy)',
87
+ check_system_specs: 'RAM, CPU, GPU, disk',
88
+ manage_local_dependencies: 'request capabilities, local dependencies',
89
+ blender_act: 'Blender 3D scene and render',
90
+ creative_apps: 'drive installed creative apps',
91
+ native_engine: 'headless film, photo, sound, CAD, deck engines',
92
+ resolve_act: 'DaVinci Resolve',
93
+ palmier_act: 'Palmier automation',
94
+ document_forge: 'produce PDF, documents, screenplays',
95
+ open_source_tool_provisioner: 'discover and install open-source AI tools'
96
+ },
97
+ advanced: {
98
+ tool_forge: 'create a custom tool',
99
+ plugin_manager: 'manage plugins',
100
+ pdf_read: 'read PDF text',
101
+ code_list_symbols: 'list symbols in a file',
102
+ code_search_ast: 'AST definition search',
103
+ agent_subagent_orchestrate: 'delegate a bounded sub-task',
104
+ peer_agent_delegate: 'delegate to an external ACP agent'
105
+ },
106
+ game: {
107
+ godot_act: 'Godot 4 project automation',
108
+ game_build_html5: 'build an HTML5 game',
109
+ game_asset_fetch: 'download CC0 assets',
110
+ game_asset_harvest: 'harvest CC0 3D, 2D, audio',
111
+ game_lore_forge: 'lore and worldbuilding',
112
+ game_dialogue_tree_gen: 'NPC dialogue trees',
113
+ game_quest_arc_builder: 'quest arcs',
114
+ game_animation_rig: 'rigging and animation',
115
+ game_ai_behavior_tree: 'enemy AI, behavior trees',
116
+ game_cinematic_sequencer: 'cutscenes, camera',
117
+ game_audio_synth: 'synthesize WAV audio',
118
+ game_vfx_emitter_gen: 'particle effects',
119
+ game_shader_forge: 'gdshader',
120
+ game_scene_build: 'build or inspect .tscn scenes',
121
+ game_entity_spawner: 'entity prefabs',
122
+ game_tilemap_gen: 'maps and dungeons',
123
+ game_ui_hud_builder: 'menu and HUD scenes',
124
+ game_economy_balancer: 'balance stats and economy',
125
+ game_data_forge: 'item and enemy data JSON',
126
+ game_web_runtime_inspector: 'headless runtime error gate',
127
+ game_canvas_audit: 'canvas render audit'
128
+ }
129
+ };
130
+
131
+ const GROUP_ORDER: readonly Exclude<ToolGroup, 'custom'>[] = ['core', 'system', 'web', 'media', 'advanced', 'game'];
132
+
133
+ const CURATED_NAMES: ReadonlySet<string> = new Set(
134
+ GROUP_ORDER.flatMap((group) => Object.keys(CATALOGUE[group]))
135
+ );
136
+
137
+ /** All registered plugin and MCP IDs remain discoverable; only their hints are shortened. */
138
+ export const MAX_CUSTOM_TOOLS = Number.POSITIVE_INFINITY;
139
+ const MAX_CUSTOM_HINT = 56;
140
+
141
+ function firstSentence(text: string): string {
142
+ const flat = text.replace(/[\x00-\x1f\x7f-\x9f]/g, ' ').replace(/\s+/g, ' ').trim();
143
+ const stop = flat.search(/[.!?](?:\s|$)/);
144
+ const sentence = stop > 0 ? flat.slice(0, stop) : flat;
145
+ return sentence.length > MAX_CUSTOM_HINT ? `${sentence.slice(0, MAX_CUSTOM_HINT - 1).trimEnd()}…` : sentence;
146
+ }
147
+
148
+ /** True when a tool has a hand-written line, which every native tool must. */
149
+ export function isCuratedTool(name: string): boolean {
150
+ return CURATED_NAMES.has(name);
151
+ }
152
+
153
+ export function curatedToolNames(): string[] {
154
+ return [...CURATED_NAMES];
155
+ }
156
+
157
+ /**
158
+ * Build the list. Native tools come first in curated order; anything else the
159
+ * registry reports (plugins, MCP servers, forged tools) follows as `custom`.
160
+ */
161
+ export function buildToolsList(definitions?: readonly ToolDefinitionSummary[]): ToolListEntry[] {
162
+ const entries: ToolListEntry[] = [];
163
+ const filterAvailable = Array.isArray(definitions);
164
+ const available = filterAvailable ? new Set(definitions.map((definition) => definition.name)) : null;
165
+ for (const group of GROUP_ORDER) {
166
+ for (const [name, hint] of Object.entries(CATALOGUE[group])) {
167
+ if (!available || available.has(name)) entries.push({ name, group, hint });
168
+ }
169
+ }
170
+ const seen = new Set(entries.map((entry) => entry.name));
171
+ let custom = 0;
172
+ for (const definition of (definitions ? [...definitions] : []).sort((a, b) => a.name.localeCompare(b.name))) {
173
+ const name = String(definition.name || '');
174
+ if (!/^[A-Za-z0-9_.:@/-]{1,200}$/.test(name) || seen.has(name)) continue;
175
+ seen.add(name);
176
+ if (custom >= MAX_CUSTOM_TOOLS) continue;
177
+ custom += 1;
178
+ entries.push({ name, group: 'custom', hint: firstSentence(definition.description || '') || 'custom tool' });
179
+ }
180
+ return entries;
181
+ }
182
+
183
+ /** Names the registry reports that exceed the bound and are reachable only through tool_search. */
184
+ export function omittedCustomCount(definitions: readonly ToolDefinitionSummary[]): number {
185
+ const unknown = new Set<string>();
186
+ for (const definition of definitions) {
187
+ const name = String(definition.name || '');
188
+ if (name && !CURATED_NAMES.has(name)) unknown.add(name);
189
+ }
190
+ return Math.max(0, unknown.size - MAX_CUSTOM_TOOLS);
191
+ }
192
+
193
+ /**
194
+ * The compact form injected into the first request of every provider. One line
195
+ * per group; names and purposes only.
196
+ */
197
+ export function renderToolsList(entries: readonly ToolListEntry[], omitted = 0): string {
198
+ const lines: string[] = [
199
+ '# TOOLS LIST — everything Causyne Agent owns, as `name: purpose`.',
200
+ 'Names/purposes only; these are not argument schemas or grants. Choose the needed names with `tool_search` (names array), then use their loaded schemas. Revisit this catalog when the task changes. Peer-native tools remain available independently.'
201
+ ];
202
+ const groups: ToolGroup[] = [...GROUP_ORDER, 'custom'];
203
+ for (const group of groups) {
204
+ const members = entries.filter((entry) => entry.group === group);
205
+ if (members.length === 0) continue;
206
+ lines.push(`${group}: ${members.map((entry) => `${entry.name}: ${entry.hint}`).join(' | ')}`);
207
+ }
208
+ if (omitted > 0) lines.push(`+${omitted} more custom tools: reach them with tool_search.`);
209
+ return lines.join('\n');
210
+ }
211
+
212
+ /** The same list as a Markdown table, for docs and for humans reading a transcript. */
213
+ export function renderToolsListMarkdown(entries: readonly ToolListEntry[]): string {
214
+ const rows = entries.map((entry) => `| \`${entry.name}\` | ${entry.group} | ${entry.hint} |`);
215
+ return ['| Tool | Group | Purpose |', '| --- | --- | --- |', ...rows].join('\n');
216
+ }
217
+
218
+ /** Resolve a free-text need against the list. Used by decideTools for plan and request text. */
219
+ export function findListedTool(entries: readonly ToolListEntry[], name: string): ToolListEntry | null {
220
+ const wanted = String(name || '').trim().toLowerCase();
221
+ if (!wanted) return null;
222
+ return entries.find((entry) => entry.name.toLowerCase() === wanted) ?? null;
223
+ }
224
+
@@ -286,6 +286,8 @@ export class ChatRenderer {
286
286
  * stream is identical to what it has always been.
287
287
  */
288
288
  frame(kind, produce, meta = null) {
289
+ if (kind !== 'assistant') this._activeAssistant = false;
290
+ if (kind !== 'reasoning') this._activeReasoning = false;
289
291
  if (!this.transcript) { produce(); return; }
290
292
  this.transcript.append({
291
293
  kind,
@@ -587,16 +589,40 @@ export class ChatRenderer {
587
589
 
588
590
  onAgentMessage(msg) {
589
591
  const content = safeDisplay(msg.content || '');
590
- this.frame('assistant', () => {
591
- // Prose, not chrome: wrapped to a readable measure even on a wide terminal.
592
- const width = this.measure();
593
- this.write();
594
- this.write(`${paint('agent', GLYPHS.arrow)} ${bold(paint('agent', 'Causyne'))}`);
595
- for (const line of renderMarkdown(content, width - 2)) {
596
- this.write(line ? ' ' + line : '');
592
+ const isStreaming = Boolean(msg.streaming);
593
+
594
+ const tailIsAssistant = !this.transcript
595
+ || this.transcript.frames?.at(-1)?.meta?.assistant === true;
596
+ if (this._activeAssistant && !tailIsAssistant) {
597
+ this._activeAssistant = false;
598
+ }
599
+
600
+ if (isStreaming) {
601
+ if (!this._activeAssistant) {
602
+ this._activeAssistant = true;
603
+ this.frame('assistant', () => this.formatAssistantMessage(content, { streaming: true }), { assistant: true, messageText: String(msg.content || '') });
604
+ } else {
605
+ this.updateTailFrame('assistant', () => this.formatAssistantMessage(content, { streaming: true }), { assistant: true, messageText: String(msg.content || '') });
597
606
  }
598
- this.write();
599
- }, { messageText: String(msg.content || '') });
607
+ return;
608
+ }
609
+
610
+ if (this._activeAssistant) {
611
+ this._activeAssistant = false;
612
+ this.updateTailFrame('assistant', () => this.formatAssistantMessage(content, { streaming: false }), { assistant: true, messageText: String(msg.content || '') });
613
+ } else {
614
+ this.frame('assistant', () => this.formatAssistantMessage(content, { streaming: false }), { assistant: true, messageText: String(msg.content || '') });
615
+ }
616
+ }
617
+
618
+ formatAssistantMessage(content, { streaming = false } = {}) {
619
+ const width = this.measure();
620
+ this.write();
621
+ this.write(`${paint('agent', GLYPHS.arrow)} ${bold(paint('agent', 'Causyne'))}${streaming ? ' ' + dim('…') : ''}`);
622
+ for (const line of renderMarkdown(content, width - 2)) {
623
+ this.write(line ? ' ' + line : '');
624
+ }
625
+ this.write();
600
626
  }
601
627
 
602
628
  /**
@@ -630,9 +656,9 @@ export class ChatRenderer {
630
656
  if (isStreaming) {
631
657
  if (!this._activeReasoning) {
632
658
  this._activeReasoning = true;
633
- this.frame('reasoning', () => this.renderReasoning(content, { streaming: true }), { reasoning: true });
659
+ this.frame('reasoning', () => this.renderReasoning(content, { streaming: true, durationText }), { reasoning: true });
634
660
  } else {
635
- this.updateTailFrame('reasoning', () => this.renderReasoning(content, { streaming: true }), { reasoning: true });
661
+ this.updateTailFrame('reasoning', () => this.renderReasoning(content, { streaming: true, durationText }), { reasoning: true });
636
662
  }
637
663
  return;
638
664
  }
@@ -659,16 +685,25 @@ export class ChatRenderer {
659
685
  this.write(`${paint('muted', GLYPHS.vLine || '│')} ${dim(`thinking${timePart}`)}`);
660
686
  }
661
687
 
662
- const displayRows = rows.slice(0, REASONING_LINES);
688
+ if (streaming && rows.length > REASONING_LINES) {
689
+ const hidden = rows.length - REASONING_LINES;
690
+ this.write(`${paint('rule', GLYPHS.vLine || '│')} ${dim(`${GLYPHS.ellipsis} ${hidden} earlier thinking line${hidden === 1 ? '' : 's'}`)}`);
691
+ }
692
+
693
+ const displayRows = streaming && rows.length > REASONING_LINES
694
+ ? rows.slice(rows.length - REASONING_LINES)
695
+ : rows.slice(0, REASONING_LINES);
696
+
663
697
  for (const row of displayRows) {
664
698
  this.write(`${paint('rule', GLYPHS.vLine || '│')} ${dim(row)}`);
665
699
  }
666
700
 
667
- if (rows.length > REASONING_LINES) {
701
+ if (!streaming && rows.length > REASONING_LINES) {
668
702
  const hidden = rows.length - REASONING_LINES;
669
703
  this.write(`${paint('rule', GLYPHS.corner || '└')} ${dim(`${GLYPHS.ellipsis} ${hidden} more line${hidden === 1 ? '' : 's'} of reasoning`)}`);
670
704
  } else if (streaming) {
671
- this.write(`${paint('rule', GLYPHS.corner || '└')} ${dim('streaming thoughts…')}`);
705
+ const timePart = durationText ? ` · ${durationText}` : '';
706
+ this.write(`${paint('rule', GLYPHS.corner || '└')} ${bold(paint('warn', 'thinking…'))} ${dim(timePart || 'streaming thoughts')}`);
672
707
  } else {
673
708
  this.write(`${paint('rule', GLYPHS.corner || '└')}`);
674
709
  }