@zds-ai/cli 0.1.8 → 0.1.10

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 (73) hide show
  1. package/README.md +387 -34
  2. package/dist/agent/context-manager.d.ts +70 -0
  3. package/dist/agent/context-manager.js +138 -0
  4. package/dist/agent/context-manager.js.map +1 -0
  5. package/dist/agent/hook-manager.d.ts +194 -0
  6. package/dist/agent/hook-manager.js +676 -0
  7. package/dist/agent/hook-manager.js.map +1 -0
  8. package/dist/agent/llm-agent.d.ts +469 -100
  9. package/dist/agent/llm-agent.js +781 -1580
  10. package/dist/agent/llm-agent.js.map +1 -1
  11. package/dist/agent/message-processor.d.ts +103 -0
  12. package/dist/agent/message-processor.js +225 -0
  13. package/dist/agent/message-processor.js.map +1 -0
  14. package/dist/agent/prompt-variables.d.ts +103 -40
  15. package/dist/agent/prompt-variables.js +250 -113
  16. package/dist/agent/prompt-variables.js.map +1 -1
  17. package/dist/agent/session-manager.d.ts +75 -0
  18. package/dist/agent/session-manager.js +194 -0
  19. package/dist/agent/session-manager.js.map +1 -0
  20. package/dist/agent/tool-executor.d.ts +111 -0
  21. package/dist/agent/tool-executor.js +397 -0
  22. package/dist/agent/tool-executor.js.map +1 -0
  23. package/dist/bin/generate_image_sd.sh +19 -12
  24. package/dist/bin/joycaption.sh +37 -0
  25. package/dist/grok/client.d.ts +52 -0
  26. package/dist/grok/client.js +127 -19
  27. package/dist/grok/client.js.map +1 -1
  28. package/dist/grok/tools.js +42 -8
  29. package/dist/grok/tools.js.map +1 -1
  30. package/dist/hooks/use-input-handler.d.ts +1 -1
  31. package/dist/hooks/use-input-handler.js +100 -13
  32. package/dist/hooks/use-input-handler.js.map +1 -1
  33. package/dist/index.js +25 -3
  34. package/dist/index.js.map +1 -1
  35. package/dist/mcp/config.d.ts +1 -0
  36. package/dist/mcp/config.js +45 -7
  37. package/dist/mcp/config.js.map +1 -1
  38. package/dist/tools/character-tool.js +13 -1
  39. package/dist/tools/character-tool.js.map +1 -1
  40. package/dist/tools/image-tool.d.ts +11 -1
  41. package/dist/tools/image-tool.js +109 -2
  42. package/dist/tools/image-tool.js.map +1 -1
  43. package/dist/tools/introspect-tool.js +131 -30
  44. package/dist/tools/introspect-tool.js.map +1 -1
  45. package/dist/tools/morph-editor.d.ts +21 -9
  46. package/dist/tools/morph-editor.js +21 -9
  47. package/dist/tools/morph-editor.js.map +1 -1
  48. package/dist/ui/components/active-task-status.d.ts +1 -1
  49. package/dist/ui/components/api-key-input.d.ts +1 -1
  50. package/dist/ui/components/backend-status.d.ts +1 -1
  51. package/dist/ui/components/chat-history.d.ts +1 -1
  52. package/dist/ui/components/chat-interface.d.ts +1 -1
  53. package/dist/ui/components/chat-interface.js +1 -1
  54. package/dist/ui/components/chat-interface.js.map +1 -1
  55. package/dist/ui/components/context-status.d.ts +1 -1
  56. package/dist/ui/components/mood-status.d.ts +1 -1
  57. package/dist/ui/components/persona-status.d.ts +1 -1
  58. package/dist/utils/chat-history-manager.d.ts +12 -4
  59. package/dist/utils/chat-history-manager.js +26 -11
  60. package/dist/utils/chat-history-manager.js.map +1 -1
  61. package/dist/utils/hook-executor.d.ts +53 -2
  62. package/dist/utils/hook-executor.js +258 -36
  63. package/dist/utils/hook-executor.js.map +1 -1
  64. package/dist/utils/rephrase-handler.d.ts +1 -1
  65. package/dist/utils/settings-manager.d.ts +41 -11
  66. package/dist/utils/settings-manager.js +172 -40
  67. package/dist/utils/settings-manager.js.map +1 -1
  68. package/dist/utils/slash-commands.d.ts +3 -3
  69. package/dist/utils/slash-commands.js +11 -5
  70. package/dist/utils/slash-commands.js.map +1 -1
  71. package/dist/utils/startup-hook.js +9 -2
  72. package/dist/utils/startup-hook.js.map +1 -1
  73. package/package.json +10 -8
@@ -0,0 +1,225 @@
1
+ import { parseImagesFromMessage, hasImageReferences } from "../utils/image-encoder.js";
2
+ import { Variable } from "./prompt-variables.js";
3
+ /**
4
+ * Handles message processing, parsing, and transformation for the LLM agent
5
+ */
6
+ export class MessageProcessor {
7
+ deps;
8
+ /** Stores prefill text from hooks */
9
+ hookPrefillText = null;
10
+ /**
11
+ * Creates a new MessageProcessor instance
12
+ * @param deps - Dependencies required for message processing
13
+ */
14
+ constructor(deps) {
15
+ this.deps = deps;
16
+ }
17
+ /**
18
+ * Processes rephrase commands and sets up rephrase state
19
+ * @param message - The input message to check for rephrase commands
20
+ * @returns Object containing rephrase information and processed message
21
+ */
22
+ async setupRephraseCommand(message) {
23
+ let isRephraseCommand = false;
24
+ let isSystemRephrase = false;
25
+ let messageToSend = message;
26
+ let messageType = "user";
27
+ let prefillText;
28
+ if (message.startsWith("/system rephrase")) {
29
+ isRephraseCommand = true;
30
+ isSystemRephrase = true;
31
+ messageToSend = message.substring(8).trim();
32
+ messageType = "system";
33
+ const prefillMatch = message.match(/^\/system rephrase\s+(.+)$/);
34
+ if (prefillMatch) {
35
+ prefillText = prefillMatch[1];
36
+ }
37
+ }
38
+ else if (message.startsWith("/rephrase")) {
39
+ isRephraseCommand = true;
40
+ messageToSend = message;
41
+ messageType = "user";
42
+ const prefillMatch = message.match(/^\/rephrase\s+(.+)$/);
43
+ if (prefillMatch) {
44
+ prefillText = prefillMatch[1];
45
+ }
46
+ }
47
+ if (isRephraseCommand) {
48
+ let lastAssistantIndex = -1;
49
+ for (let i = this.deps.chatHistory.length - 1; i >= 0; i--) {
50
+ if (this.deps.chatHistory[i].type === "assistant") {
51
+ lastAssistantIndex = i;
52
+ break;
53
+ }
54
+ }
55
+ if (lastAssistantIndex === -1) {
56
+ throw new Error("No previous assistant message to rephrase");
57
+ }
58
+ this.deps.setRephraseState(lastAssistantIndex, this.deps.chatHistory.length, -1, messageType, prefillText);
59
+ }
60
+ return { isRephraseCommand, messageType, messageToSend, prefillText };
61
+ }
62
+ /**
63
+ * Parses message content and assembles it with variables
64
+ * @param messageToSend - The message to parse and assemble
65
+ * @returns Object containing parsed content and assembled message
66
+ */
67
+ async parseAndAssembleMessage(messageToSend) {
68
+ const parsed = hasImageReferences(messageToSend)
69
+ ? parseImagesFromMessage(messageToSend)
70
+ : { text: messageToSend, images: [] };
71
+ Variable.set("USER:PROMPT", parsed.text);
72
+ const assembledMessage = Variable.renderFull("USER");
73
+ return { parsed, assembledMessage };
74
+ }
75
+ /**
76
+ * Prepares message content for LLM consumption, handling images and content types
77
+ * @param messageType - Type of message ("user" or "system")
78
+ * @param assembledMessage - The assembled message text
79
+ * @param parsed - Parsed message content including images
80
+ * @param messageToSend - Original message to send
81
+ * @param supportsVision - Whether the LLM supports vision/images
82
+ * @returns Object containing user entry and formatted message content
83
+ */
84
+ prepareMessageContent(messageType, assembledMessage, parsed, messageToSend, supportsVision) {
85
+ let messageContent = assembledMessage;
86
+ if (messageType === "user" && parsed.images.length > 0 && supportsVision) {
87
+ messageContent = [
88
+ { type: "text", text: assembledMessage },
89
+ ...parsed.images
90
+ ];
91
+ }
92
+ const userEntry = {
93
+ type: messageType,
94
+ content: messageContent,
95
+ originalContent: messageType === "user" ? (parsed.images.length > 0 && supportsVision
96
+ ? [{ type: "text", text: parsed.text }, ...parsed.images]
97
+ : parsed.text) : undefined,
98
+ timestamp: new Date(),
99
+ };
100
+ return { userEntry, messageContent };
101
+ }
102
+ /**
103
+ * Parse XML-formatted tool calls from message content (x.ai format)
104
+ * Converts <xai:function_call> elements to standard LLMToolCall format
105
+ * @param message - Message object that may contain XML tool calls
106
+ * @returns Modified message with parsed tool calls
107
+ */
108
+ parseXMLToolCalls(message) {
109
+ if (!message.content || typeof message.content !== 'string') {
110
+ return message;
111
+ }
112
+ const content = message.content;
113
+ const xmlToolCallRegex = /<xai:function_call\s+name="([^"]+)">([\s\S]*?)<\/xai:function_call>/g;
114
+ const matches = Array.from(content.matchAll(xmlToolCallRegex));
115
+ if (matches.length === 0) {
116
+ return message;
117
+ }
118
+ // Parse each XML tool call
119
+ const toolCalls = [];
120
+ let cleanedContent = content;
121
+ for (const match of matches) {
122
+ const functionName = match[1];
123
+ const paramsXML = match[2];
124
+ // Parse parameters
125
+ const paramRegex = /<parameter\s+name="([^"]+)">([^<]*)<\/parameter>/g;
126
+ const paramMatches = Array.from(paramsXML.matchAll(paramRegex));
127
+ const args = {};
128
+ for (const paramMatch of paramMatches) {
129
+ args[paramMatch[1]] = paramMatch[2];
130
+ }
131
+ // Generate a unique ID for this tool call
132
+ const toolCallId = `call_xml_${Date.now()}_${Math.random().toString(36).substring(7)}`;
133
+ toolCalls.push({
134
+ id: toolCallId,
135
+ type: "function",
136
+ function: {
137
+ name: functionName,
138
+ arguments: JSON.stringify(args)
139
+ }
140
+ });
141
+ // Remove this XML block from content
142
+ cleanedContent = cleanedContent.replace(match[0], '');
143
+ }
144
+ // Trim any extra whitespace
145
+ cleanedContent = cleanedContent.trim();
146
+ // Return modified message with tool_calls and cleaned content
147
+ return {
148
+ ...message,
149
+ content: cleanedContent || null,
150
+ tool_calls: [...(message.tool_calls || []), ...toolCalls]
151
+ };
152
+ }
153
+ /**
154
+ * Reduces streaming message chunks into a complete message object
155
+ * @param previous - Previously accumulated message data
156
+ * @param item - Current streaming chunk to process
157
+ * @returns Updated accumulated message object
158
+ */
159
+ messageReducer(previous, item) {
160
+ const reduce = (acc, delta) => {
161
+ // Ensure acc is always an object before spreading (handles null/undefined)
162
+ acc = { ...(acc || {}) };
163
+ for (const [key, value] of Object.entries(delta)) {
164
+ // Skip null values in delta (Venice sends tool_calls: null which breaks Object.entries)
165
+ if (value === null)
166
+ continue;
167
+ if (acc[key] === undefined || acc[key] === null) {
168
+ acc[key] = value;
169
+ // Clean up index properties from tool calls
170
+ if (Array.isArray(acc[key])) {
171
+ for (const arr of acc[key]) {
172
+ delete arr.index;
173
+ }
174
+ }
175
+ }
176
+ else if (typeof acc[key] === "string" && typeof value === "string") {
177
+ // Don't concatenate certain properties that should remain separate
178
+ const nonConcatenableProps = ['id', 'type', 'name'];
179
+ if (nonConcatenableProps.includes(key)) {
180
+ // For non-concatenable properties, keep the new value
181
+ acc[key] = value;
182
+ }
183
+ else {
184
+ // For content, arguments, and other text properties, concatenate
185
+ acc[key] += value;
186
+ }
187
+ }
188
+ else if (Array.isArray(acc[key]) && Array.isArray(value)) {
189
+ const accArray = acc[key];
190
+ for (let i = 0; i < value.length; i++) {
191
+ if (!accArray[i])
192
+ accArray[i] = {};
193
+ accArray[i] = reduce(accArray[i], value[i]);
194
+ }
195
+ }
196
+ else if (typeof acc[key] === "object" && typeof value === "object") {
197
+ acc[key] = reduce(acc[key], value);
198
+ }
199
+ }
200
+ return acc;
201
+ };
202
+ return reduce(previous, item.choices?.[0]?.delta || {});
203
+ }
204
+ /**
205
+ * Gets the current hook prefill text
206
+ * @returns The prefill text or null if none is set
207
+ */
208
+ getHookPrefillText() {
209
+ return this.hookPrefillText;
210
+ }
211
+ /**
212
+ * Clears the hook prefill text
213
+ */
214
+ clearHookPrefillText() {
215
+ this.hookPrefillText = null;
216
+ }
217
+ /**
218
+ * Sets the hook prefill text
219
+ * @param text - The prefill text to set
220
+ */
221
+ setHookPrefillText(text) {
222
+ this.hookPrefillText = text;
223
+ }
224
+ }
225
+ //# sourceMappingURL=message-processor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message-processor.js","sourceRoot":"","sources":["../../src/agent/message-processor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACvF,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAiCjD;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAQP;IAPpB,qCAAqC;IAC7B,eAAe,GAAkB,IAAI,CAAC;IAE9C;;;OAGG;IACH,YAAoB,IAAkC;QAAlC,SAAI,GAAJ,IAAI,CAA8B;IAAG,CAAC;IAE1D;;;;OAIG;IACH,KAAK,CAAC,oBAAoB,CAAC,OAAe;QACxC,IAAI,iBAAiB,GAAG,KAAK,CAAC;QAC9B,IAAI,gBAAgB,GAAG,KAAK,CAAC;QAC7B,IAAI,aAAa,GAAG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AQ,CAAC,CAAC,CAAC;4BAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;wBACnC,QAAQ,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;oBAC9C,CAAC;gBACH,CAAC;qBAAM,IAAI,OAAO,GAAG,CAAC,GAAG,CAAC,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;oBACrE,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;gBACrC,CAAC;YACH,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC,CAAC;QAEF,OAAO,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED;;;OAGG;IACH,kBAAkB;QAChB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,oBAAoB;QAClB,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;IAC9B,CAAC;IAED;;;OAGG;IACH,kBAAkB,CAAC,IAAY;QAC7B,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;IAC9B,CAAC;CACF"}
@@ -1,16 +1,28 @@
1
+ /**
2
+ * Variable definition class for prompt template system
3
+ * Defines structure, behavior, and relationships between variables
4
+ */
1
5
  export declare class VariableDef {
2
6
  /**
3
7
  * Map of variable names to their definitions
4
8
  * Indexed by variable name (e.g., "USER:PRE" -> VariableDef)
5
9
  */
6
10
  private static definitions;
11
+ /** Variable name (e.g., "USER:PRE", "SYSTEM") */
7
12
  name: string;
13
+ /** Rendering weight for ordering (lower = earlier) */
8
14
  weight: number;
15
+ /** Environment variable to read value from */
9
16
  env_var?: string;
17
+ /** Whether to render in full template expansion */
10
18
  renderFull: boolean;
19
+ /** Whether variable persists across clearOneShot() calls */
11
20
  persists: boolean;
21
+ /** Template string with %VAR% placeholders and %% for own content */
12
22
  template: string;
23
+ /** Variables referenced in template (%VAR% patterns) */
13
24
  adoptedChildren: string[];
25
+ /** Function to dynamically compute variable value */
14
26
  getter?: () => string;
15
27
  constructor(config: {
16
28
  name: string;
@@ -24,24 +36,56 @@ export declare class VariableDef {
24
36
  /**
25
37
  * Get or create definition by name
26
38
  * Looks in definitions map, then PROMPT_VARS, then creates default
39
+ *
27
40
  * @param name Variable name
28
41
  * @returns VariableDef instance
29
42
  */
30
43
  static getOrCreate(name: string): VariableDef;
31
44
  /**
32
45
  * Get all variable definitions
46
+ * Ensures all PROMPT_VARS are loaded into definitions map
47
+ * Later definitions override earlier ones (YAML overrides hardcoded)
48
+ *
33
49
  * @returns Array of all VariableDef instances
34
50
  */
35
51
  static getAllDefinitions(): VariableDef[];
52
+ /**
53
+ * Check if a variable is intrinsic (hardcoded in TypeScript)
54
+ *
55
+ * @param name Variable name
56
+ * @returns True if defined in INTRINSIC_VARS
57
+ */
58
+ static isIntrinsic(name: string): boolean;
59
+ /**
60
+ * Check if a variable is explicit (defined in external YAML file)
61
+ *
62
+ * @param name Variable name
63
+ * @returns True if defined in EXTERNAL_VARS
64
+ */
65
+ static isExplicit(name: string): boolean;
36
66
  }
67
+ /**
68
+ * Variable instance class for prompt template system
69
+ * Holds actual values and handles rendering logic
70
+ *
71
+ * Supports:
72
+ * - Hierarchical variable relationships (parent:child)
73
+ * - Template expansion with %VAR% placeholders
74
+ * - Dynamic value computation via getters
75
+ * - Circular dependency detection
76
+ * - Weight-based ordering
77
+ */
37
78
  export declare class Variable {
38
79
  /**
39
80
  * Map of variable names to their current values
40
81
  * Indexed by variable name (e.g., "USER:PRE" -> Variable)
41
82
  */
42
83
  private static variables;
84
+ /** Variable definition (structure and behavior) */
43
85
  def: VariableDef;
86
+ /** Array of string values for this variable */
44
87
  values: string[];
88
+ /** Whether variable has new/changed values since last render */
45
89
  isNew: boolean;
46
90
  constructor(name: string);
47
91
  get name(): string;
@@ -50,88 +94,107 @@ export declare class Variable {
50
94
  get renderFull(): boolean;
51
95
  get persists(): boolean;
52
96
  /**
53
- * Set variable value
97
+ * Set variable value (replaces existing values)
54
98
  * Creates variable if it doesn't exist
99
+ *
55
100
  * @param name Variable name
56
- * @param value Value to add
101
+ * @param value Value to set
57
102
  */
58
103
  static set(name: string, value: string): void;
104
+ /**
105
+ * Append value to variable (adds to existing values)
106
+ * Creates variable if it doesn't exist
107
+ * Use when building multi-value variables within same execution context
108
+ *
109
+ * @param name Variable name
110
+ * @param value Value to append
111
+ */
112
+ static append(name: string, value: string): void;
59
113
  /**
60
114
  * Get variable by name
115
+ *
61
116
  * @param name Variable name
62
117
  * @returns Variable instance or undefined
63
118
  */
64
119
  static get(name: string): Variable | undefined;
120
+ /**
121
+ * Get or create variable by name
122
+ *
123
+ * @param name Variable name
124
+ * @returns Variable instance
125
+ */
126
+ static getOrCreate(name: string): Variable;
65
127
  /**
66
128
  * Get all set variables
129
+ *
67
130
  * @returns Array of all Variable instances
68
131
  */
69
132
  static getAllVariables(): Variable[];
70
133
  /**
71
134
  * Clear all one-shot variables
135
+ * Removes variables where persists=false
72
136
  */
73
137
  static clearOneShot(): void;
74
138
  /**
75
- * Find birth child variables of given parent. Return sorted.
139
+ * Export persistent variables for saving to context.json
140
+ * Returns only variables with persists=true
76
141
  *
77
- * Returns birth children (prefix match) of a parent var, sorted by weight,
78
- * where renderFull == true.
142
+ * @returns Object with variable names as keys and objects containing values and isNew state
143
+ */
144
+ static exportPersistentVariables(): Record<string, {
145
+ values: string[];
146
+ isNew: boolean;
147
+ }>;
148
+ /**
149
+ * Import persistent variables from saved context.json
150
+ * Restores variables with their values and isNew state
79
151
  *
80
- * @param parent: string
81
- * Parent name (e.g., "USER" or "SYSTEM")
152
+ * @param saved Object with variable names as keys and objects containing values and isNew state
153
+ */
154
+ static importPersistentVariables(saved: Record<string, {
155
+ values: string[];
156
+ isNew: boolean;
157
+ }>): void;
158
+ /**
159
+ * Find birth child variables of given parent
160
+ * Returns variables with prefix "parent:" sorted by weight
82
161
  *
83
- * @returns variables[]
84
- * All variables with prefix "parent:", renderFull=true, sorted by weight
162
+ * @param parent Parent name (e.g., "USER" or "SYSTEM")
163
+ * @returns Variables with prefix "parent:", renderFull=true, sorted by weight
85
164
  */
86
165
  static findBirthChildren(parent: string): Variable[];
87
166
  /**
88
- * Find all full child variables of given parent. Return sorted.
89
- *
90
- * Returns all children of a parent var, sorted by weight,
91
- * where renderFull == true. Includes both birth children
92
- * (prefix match "parent:") and adopted children (from template).
167
+ * Find all child variables of given parent
168
+ * Returns both birth children (prefix match) and adopted children (template refs)
93
169
  *
94
- * @param parent: string
95
- * Parent name (e.g., "USER")
96
- *
97
- * @returns variables[]
98
- * All variables with prefix "parent:", renderFull=true, sorted by weight
170
+ * @param parent Parent name (e.g., "USER")
171
+ * @returns All child variables with renderFull=true, sorted by weight
99
172
  */
100
173
  static findFullChildrenVars(parent: string): Variable[];
101
174
  /**
102
- * Render a variable fully (recursive)
103
- * If variable exists, renders its template (which may reference children)
104
- * If variable doesn't exist but children do, renders children and joins
105
- * If variable doesn't exist but has a getter, auto-creates it
175
+ * Render a variable fully with recursive template expansion
176
+ * Handles variable creation, getter execution, and circular dependency detection
177
+ *
106
178
  * @param name Variable name (e.g., "USER" or "USER:PROMPT")
107
179
  * @param renderingStack Set of variables currently being rendered (for cycle detection)
108
180
  * @returns Rendered string
109
181
  */
110
182
  static renderFull(name: string, renderingStack?: Set<string>): string;
111
183
  /**
112
- * Render full value string using template.
184
+ * Render variable using its template with placeholder substitution
185
+ * Handles %VAR% substitution and %% replacement with own values + children
113
186
  *
114
187
  * @param renderingStack Set of variables currently being rendered (for cycle detection)
115
- * @returns string
116
- * Rendered string
188
+ * @returns Rendered template string
117
189
  */
118
190
  renderFullTemplate(renderingStack?: Set<string>): string;
119
191
  /**
120
- * Render full values as a string, from values array.
121
- *
122
- * If this variable has a getter function, computes the current value
123
- * and updates values array only if the value changed (sets isNew flag).
124
- *
125
- * After rendering, clears the isNew flag since the variable has been consumed.
126
- *
127
- * ASSUMPTION: Getter functions always return a single string value,
128
- * never an array. If this assumption changes, this logic needs revision.
129
- *
130
- * @param separator: string
131
- * The string to use as a separator. Defaults to "\n\n".
192
+ * Render variable values as string with dynamic getter support
193
+ * Updates values from getter if present and value changed
194
+ * Clears isNew flag after rendering
132
195
  *
133
- * @returns string
134
- * values joined as a string (double-nl-separated)
196
+ * @param separator String to join multiple values (default: "\n")
197
+ * @returns Joined values string
135
198
  */
136
199
  renderFullValue(separator?: string): string;
137
200
  }