TaskUtils
Core extension functions for task lifecycle management, safe completion, model resolution, and the "Triple Log Rule".
Category: Utility
Side-Effect Safe
Internal API
⚙️ Kotlin Implementation
// Truncate large logs for UI
val displayLog = rawOutput.truncateForDisplay(10000)
// Safe completion with logging
task.safeComplete("Operation finished", logger)
// Triple Log Rule: UI, SLF4J, and Transcript
task.tripleLog(exception, logger, transcript, "Failed to process file")
// Resolve API credentials
val apiModel = chatModel.toApiChatModel() // Resolves keys
→
👁️ Runtime Behavior
// truncateForDisplay output:
[2023-10-27 10:00:00] INFO: Starting...
... (truncated for display, 4200 characters omitted)
... (truncated for display, 4200 characters omitted)
// tripleLog Transcript Entry:
## Error: Failed to process file
Message:
Message:
Connection resetStack Trace
...// toApiChatModel result:
ApiChatModel(model=GPT-4, provider=OpenAI, key="sk-...", baseUrl="https://api.openai.com/v1")
Test Workspace Browser
Explore the artifacts and logs generated during TaskUtils unit testing.
Extension Functions
| Function | Receiver | Description |
|---|---|---|
truncateForDisplay(maxLength) |
String |
Truncates text and appends a count of omitted characters. Default 10,000. |
safeComplete(message, log) |
SessionTask |
Attempts to complete the task with Markdown rendering; catches and logs exceptions to prevent crash loops. |
tripleLog(e, log, transcript, context) |
SessionTask |
Logs to UI (error), SLF4J (error), and Transcript (Markdown with stack trace). |
toApiChatModel() |
ChatModel |
Resolves API keys and base URLs from UserSettings. Throws IllegalArgumentException if key is missing. |