OpenTalon / app · opentalon.ai / native / runtime / contracts.cjs
| 1 | const string = (maxLength = 500) => ({ type: 'string', minLength: 1, maxLength }) |
| 2 | const id = string(150) |
| 3 | const revision = { type: 'integer', minimum: 1 } |
| 4 | const { agentModels, agentIds } = require('./agent-models.cjs') |
| 5 | const agentSelection = { |
| 6 | agent: { enum: agentIds }, |
| 7 | model: string(100), |
| 8 | } |
| 9 | const dispatchComment = { |
| 10 | ...string(10000), |
| 11 | description: 'Optional task comment saved with the dispatch before the agent starts.', |
| 12 | } |
| 13 | const status = { enum: ['To do', 'Sent to agent', 'In progress', 'Done'] } |
| 14 | const priority = { enum: ['Urgent', 'High', 'Medium', 'Low', 'None'] } |
| 15 | const sort = { enum: ['manual', 'priority-desc', 'priority-asc'] } |
| 16 | const dueDate = { |
| 17 | anyOf: [{ type: 'string', minLength: 10, maxLength: 10 }, { type: 'null' }], |
| 18 | description: 'Due date as a local calendar date YYYY-MM-DD. Null clears it.', |
| 19 | } |
| 20 | const theme = { enum: ['graphite', 'warm-paper', 'native-light', 'system'] } |
| 21 | const boardIcons = [ |
| 22 | 'activity', |
| 23 | 'bird', |
| 24 | 'book-open', |
| 25 | 'bot', |
| 26 | 'briefcase', |
| 27 | 'brush', |
| 28 | 'building', |
| 29 | 'calendar', |
| 30 | 'camera', |
| 31 | 'car', |
| 32 | 'chart-column', |
| 33 | 'chart-line', |
| 34 | 'cloud', |
| 35 | 'code', |
| 36 | 'coffee', |
| 37 | 'compass', |
| 38 | 'cpu', |
| 39 | 'database', |
| 40 | 'dollar-sign', |
| 41 | 'dumbbell', |
| 42 | 'feather', |
| 43 | 'flag', |
| 44 | 'flask', |
| 45 | 'gamepad', |
| 46 | 'gift', |
| 47 | 'globe', |
| 48 | 'graduation-cap', |
| 49 | 'hammer', |
| 50 | 'heart', |
| 51 | 'house', |
| 52 | 'image', |
| 53 | 'inbox', |
| 54 | 'leaf', |
| 55 | 'lightbulb', |
| 56 | 'lock', |
| 57 | 'mail', |
| 58 | 'map', |
| 59 | 'megaphone', |
| 60 | 'mic', |
| 61 | 'moon', |
| 62 | 'music', |
| 63 | 'newspaper', |
| 64 | 'notebook-pen', |
| 65 | 'package', |
| 66 | 'palette', |
| 67 | 'pen-tool', |
| 68 | 'plane', |
| 69 | 'plug', |
| 70 | 'rocket', |
| 71 | 'server', |
| 72 | 'shield', |
| 73 | 'shopping-cart', |
| 74 | 'smartphone', |
| 75 | 'sparkles', |
| 76 | 'star', |
| 77 | 'sun', |
| 78 | 'target', |
| 79 | 'terminal', |
| 80 | 'trophy', |
| 81 | 'user', |
| 82 | 'users', |
| 83 | 'utensils', |
| 84 | 'video', |
| 85 | 'wallet', |
| 86 | 'workflow', |
| 87 | 'wrench', |
| 88 | 'zap', |
| 89 | ] |
| 90 | const boardIcon = { |
| 91 | anyOf: [{ enum: boardIcons }, { type: 'null' }], |
| 92 | description: |
| 93 | 'Sidebar icon for the board, chosen to suit its subject. Null uses the default board icon.', |
| 94 | } |
| 95 | const write = { requestKey: string(200) } |
| 96 | const taskWrite = { ...write, id, expectedRevision: revision } |
| 97 | function tool(name, description, properties = {}, required = [], mutates = false) { |
| 98 | return { |
| 99 | name, |
| 100 | description, |
| 101 | inputSchema: { type: 'object', properties, required, additionalProperties: false }, |
| 102 | mutates, |
| 103 | } |
| 104 | } |
| 105 | const tools = [ |
| 106 | tool('get_project_folder', 'Read a project’s agent folder override and effective folder. An empty override uses the global OpenTalon working folder.', { id }, ['id']), |
| 107 | tool('set_project_folder', 'Set one project’s agent working folder using its last-read revision. Use an existing absolute folder, or an empty string to use the global folder. Affects new conversations only; existing runs retain their original folder.', |
| 108 | { ...write, id, expectedRevision: revision, workingFolder: { type: 'string', maxLength: 4000 } }, ['requestKey', 'id', 'expectedRevision', 'workingFolder'], true), |
| 109 | tool('get_agent_models', 'Read the Mac-owned effective model catalog, shipped defaults and user overrides. Mobile syncs this catalog automatically.'), |
| 110 | tool('set_agent_models', |
| 111 | 'Replace model overrides using the last-read catalogRevision. New app defaults still merge in on updates. Custom labels/models and hidden choices persist. An empty overrides array restores shipped defaults. This does not dispatch work or change running tasks.', |
| 112 | { |
| 113 | ...write, |
| 114 | expectedCatalogRevision: revision, |
| 115 | overrides: { type: 'array', maxItems: 100, items: { |
| 116 | type: 'object', additionalProperties: false, |
| 117 | properties: { agent: agentSelection.agent, id: string(100), title: string(80), hidden: { type: 'boolean' } }, |
| 118 | required: ['agent', 'id', 'title'], |
| 119 | } }, |
| 120 | }, ['requestKey', 'expectedCatalogRevision', 'overrides'], true), |
| 121 | tool( |
| 122 | 'list_task_comments', |
| 123 | 'Read comments and screenshot IDs for a task in chronological order.', |
| 124 | { taskId: id }, |
| 125 | ['taskId'] |
| 126 | ), |
| 127 | tool('read_comment_image', 'Read one comment screenshot as an MCP image.', { imageId: id }, [ |
| 128 | 'imageId', |
| 129 | ]), |
| 130 | tool( |
| 131 | 'add_task_comment', |
| 132 | 'Legacy alias for add_task_activity. Records an agent update in Activity, NEVER a user comment. notifyAgent is ignored. Prefer add_task_activity. Up to three PNG/JPEG screenshots under 2 MB each.', |
| 133 | { |
| 134 | ...write, |
| 135 | taskId: id, |
| 136 | text: { type: 'string', maxLength: 10000 }, |
| 137 | notifyAgent: { type: 'boolean' }, |
| 138 | images: { |
| 139 | type: 'array', |
| 140 | maxItems: 3, |
| 141 | items: { |
| 142 | type: 'object', |
| 143 | properties: { |
| 144 | name: string(200), |
| 145 | mimeType: { enum: ['image/png', 'image/jpeg'] }, |
| 146 | data: string(2800000), |
| 147 | }, |
| 148 | required: ['name', 'mimeType', 'data'], |
| 149 | additionalProperties: false, |
| 150 | }, |
| 151 | }, |
| 152 | }, |
| 153 | ['taskId', 'text', 'requestKey'], |
| 154 | true |
| 155 | ), |
| 156 | tool( |
| 157 | 'get_task_agent_run', |
| 158 | 'Read the current assignment, prior provider run, and available recovery actions. Call this before continuing a dispatched task from its saved conversation.', |
| 159 | { taskId: id }, |
| 160 | ['taskId'] |
| 161 | ), |
| 162 | tool( |
| 163 | 'recover_agent_run', |
| 164 | 'After the owner explicitly asks to continue, recover the last run using the current task revision and prior run ID. Use attach only from the exact saved conversation with its verified thread ID. Use queue only after the provider turn has ended and include the owner’s continuation message. Reopening a closed or archived task also requires explicit owner approval. Reuse requestKey for identical retries.', |
| 165 | { |
| 166 | ...write, |
| 167 | taskId: id, |
| 168 | expectedRunId: id, |
| 169 | expectedRevision: revision, |
| 170 | mode: { enum: ['attach', 'queue'] }, |
| 171 | threadId: id, |
| 172 | message: string(10000), |
| 173 | reopenClosed: { type: 'boolean' }, |
| 174 | }, |
| 175 | ['taskId', 'expectedRunId', 'expectedRevision', 'mode', 'requestKey'], |
| 176 | true |
| 177 | ), |
| 178 | tool( |
| 179 | 'report_agent_progress', |
| 180 | 'Update the task attached to an active dispatched run. Done requires proof and definitionOfDoneMet true. Include actedOnCommentIds for the revision requests this proof verifies. The completion report and receipt for each listed request save atomically before Done.', |
| 181 | { |
| 182 | ...write, |
| 183 | runId: id, |
| 184 | state: { enum: ['working', 'needs-input', 'done', 'failed'] }, |
| 185 | summary: string(10000), |
| 186 | proof: string(10000), |
| 187 | definitionOfDoneMet: { type: 'boolean' }, |
| 188 | actedOnCommentIds: { type: 'array', items: id, minItems: 1, maxItems: 50, uniqueItems: true }, |
| 189 | }, |
| 190 | ['runId', 'state', 'summary', 'requestKey'], |
| 191 | true |
| 192 | ), |
| 193 | tool( |
| 194 | 'get_app_status', |
| 195 | 'Read local app availability, version, fixed statuses, data location and data revision. No connection credentials.' |
| 196 | ), |
| 197 | tool( |
| 198 | 'list_boards', |
| 199 | 'List all boards in sidebar order, each with its icon (null is the default).' |
| 200 | ), |
| 201 | tool( |
| 202 | 'create_board', |
| 203 | 'Create a named board. Pass an icon that suits the board; when omitted, one is chosen from the name where an obvious match exists. Reuse requestKey only for an identical retry.', |
| 204 | { ...write, name: string(100), icon: boardIcon }, |
| 205 | ['name', 'requestKey'], |
| 206 | true |
| 207 | ), |
| 208 | tool( |
| 209 | 'set_board_icon', |
| 210 | 'Set or clear a board icon using the board last-read revision. Choose the icon that best suits the board subject.', |
| 211 | { ...taskWrite, icon: boardIcon }, |
| 212 | ['id', 'icon', 'expectedRevision', 'requestKey'], |
| 213 | true |
| 214 | ), |
| 215 | tool( |
| 216 | 'rename_board', |
| 217 | 'Rename a board using its last-read revision.', |
| 218 | { ...taskWrite, name: string(100) }, |
| 219 | ['id', 'name', 'expectedRevision', 'requestKey'], |
| 220 | true |
| 221 | ), |
| 222 | tool( |
| 223 | 'delete_board', |
| 224 | 'Delete an empty board. Live and trashed tasks prevent deletion. Keep at least one board.', |
| 225 | taskWrite, |
| 226 | ['id', 'expectedRevision', 'requestKey'], |
| 227 | true |
| 228 | ), |
| 229 | tool( |
| 230 | 'list_tasks', |
| 231 | 'Read tasks with priority and metadata. Optional priority filter and priority-desc (urgent first) or priority-asc (low first) sort within board/status; None stays last. Search titles and notes across boards by omitting boardId. Follow nextCursor until null.', |
| 232 | { |
| 233 | boardId: id, |
| 234 | status, |
| 235 | priority, |
| 236 | issueType: { enum: ['Issue', 'Bug'] }, |
| 237 | sort, |
| 238 | query: { type: 'string', maxLength: 500 }, |
| 239 | limit: { type: 'integer', minimum: 1, maximum: 200 }, |
| 240 | cursor: string(2000), |
| 241 | } |
| 242 | ), |
| 243 | tool('get_task_history', 'Read saved task revisions, newest first. Follow nextBefore with beforeVersion for older revisions.', |
| 244 | { id, beforeVersion: { type: 'integer', minimum: 1 }, limit: { type: 'integer', minimum: 1, maximum: 50 } }, ['id']), |
| 245 | tool('restore_task_revision', 'Restore saved fields, plan, project and status as a new revision. Retains newer history and comments. Stops agent work; Sent to agent restores as To do. Requires an explicit user request and current task revision.', |
| 246 | { ...taskWrite, historyID: id }, ['id', 'historyID', 'expectedRevision', 'requestKey'], true), |
| 247 | tool('get_task', 'Read one task and its revision by UUID or project task ID (e.g. VOX-001), including a trashed task. Use the returned UUID for edits.', { id }, ['id']), |
| 248 | tool( |
| 249 | 'create_task', |
| 250 | 'Create a task, normally in To do. Save an attached Markdown plan in planMarkdown, never buried in notes. Returns the committed task and revision.', |
| 251 | { |
| 252 | ...write, |
| 253 | ...agentSelection, |
| 254 | dispatchComment, |
| 255 | boardId: id, |
| 256 | title: string(), |
| 257 | notes: { type: 'string', maxLength: 100000 }, |
| 258 | planMarkdown: { type: 'string', maxLength: 100000 }, |
| 259 | status, |
| 260 | priority, |
| 261 | issueType: { enum: ['Issue', 'Bug'] }, |
| 262 | definitionOfDone: { type: 'string', maxLength: 10000 }, |
| 263 | dueDate, |
| 264 | }, |
| 265 | ['boardId', 'title', 'requestKey'], |
| 266 | true |
| 267 | ), |
| 268 | tool( |
| 269 | 'update_task', |
| 270 | 'Patch supplied issueType (Issue or Bug), title, notes, planMarkdown, priority, dueDate, definitionOfDone or status. Save plans in planMarkdown instead of notes. Use last-read expectedRevision; conflicts return the current task. Dispatched agent runs must complete through report_agent_progress with proof, not by changing status.', |
| 271 | { |
| 272 | ...taskWrite, |
| 273 | title: string(), |
| 274 | notes: { type: 'string', maxLength: 100000 }, |
| 275 | planMarkdown: { type: 'string', maxLength: 100000 }, |
| 276 | status, |
| 277 | priority, |
| 278 | issueType: { enum: ['Issue', 'Bug'] }, |
| 279 | definitionOfDone: { type: 'string', maxLength: 10000 }, |
| 280 | dueDate, |
| 281 | }, |
| 282 | ['id', 'expectedRevision', 'requestKey'], |
| 283 | true |
| 284 | ), |
| 285 | tool('set_task_plan', 'Save the task’s Markdown plan against the exact previous Markdown. Preserve a conflicting draft for review.', |
| 286 | { ...write, id, markdown: { type: 'string', maxLength: 100000 }, |
| 287 | expectedMarkdown: { type: 'string', maxLength: 100000 } }, |
| 288 | ['id', 'markdown', 'expectedMarkdown', 'requestKey'], true), |
| 289 | tool( |
| 290 | 'move_task', |
| 291 | 'Move a task to a board/status, optionally beforeId OR afterId in that destination. Omit both to append. Last-read revision required.', |
| 292 | { ...taskWrite, ...agentSelection, dispatchComment, boardId: id, status, beforeId: id, afterId: id }, |
| 293 | ['id', 'expectedRevision', 'requestKey'], |
| 294 | true |
| 295 | ), |
| 296 | tool( |
| 297 | 'trash_task', |
| 298 | 'Recoverably delete a task. No automatic purge.', |
| 299 | taskWrite, |
| 300 | ['id', 'expectedRevision', 'requestKey'], |
| 301 | true |
| 302 | ), |
| 303 | tool('list_trash', 'Read deleted tasks with pagination, optional board and text search.', { |
| 304 | boardId: id, |
| 305 | query: { type: 'string', maxLength: 500 }, |
| 306 | limit: { type: 'integer', minimum: 1, maximum: 200 }, |
| 307 | cursor: string(2000), |
| 308 | }), |
| 309 | tool( |
| 310 | 'restore_task', |
| 311 | 'Restore a trashed task to its board/status, using its former position when available, otherwise appending.', |
| 312 | taskWrite, |
| 313 | ['id', 'expectedRevision', 'requestKey'], |
| 314 | true |
| 315 | ), |
| 316 | tool('get_preferences', 'Read appearance and selected board with the preference revision.'), |
| 317 | tool( |
| 318 | 'set_preferences', |
| 319 | 'Update appearance and/or selected board. Cannot change connection enablement or credentials.', |
| 320 | { ...write, expectedRevision: revision, theme, selectedBoard: id }, |
| 321 | ['expectedRevision', 'requestKey'], |
| 322 | true |
| 323 | ), |
| 324 | tool( |
| 325 | 'create_backup', |
| 326 | 'Export all boards, tasks, Trash, ordering and appearance. Choose format json for a readable portable backup; sqlite is the backward-compatible default. Never overwrites files. Excludes credentials and replay receipts.', |
| 327 | { ...write, destination: string(4000), format: { enum: ['json', 'sqlite'] } }, |
| 328 | ['requestKey'], |
| 329 | true |
| 330 | ), |
| 331 | tool( |
| 332 | 'inspect_backup', |
| 333 | 'Validate a selected absolute backup path and report format, board/task/Trash counts and SHA-256. Does not replace data.', |
| 334 | { path: string(4000) }, |
| 335 | ['path'] |
| 336 | ), |
| 337 | tool( |
| 338 | 'preview_destructive_action', |
| 339 | 'Preview purge_tasks, purge_archived_tasks, empty_trash or restore_backup. Show this exact preview to the person and obtain explicit confirmation before confirm_destructive_action. Token expires in 5 minutes and binds current revision and backup hash.', |
| 340 | { |
| 341 | action: { enum: ['purge_tasks', 'purge_archived_tasks', 'empty_trash', 'restore_backup'] }, |
| 342 | taskIds: { type: 'array', items: id, minItems: 1, maxItems: 10000, uniqueItems: true }, |
| 343 | path: string(4000), |
| 344 | }, |
| 345 | ['action'] |
| 346 | ), |
| 347 | tool( |
| 348 | 'confirm_destructive_action', |
| 349 | 'Execute an explicitly approved preview token once. Stale previews are rejected. Reuse the same requestKey to recover an uncertain response.', |
| 350 | { ...write, token: string(200) }, |
| 351 | ['token', 'requestKey'], |
| 352 | true |
| 353 | ), |
| 354 | ] |
| 355 | tools.push( |
| 356 | tool('list_task_files', 'List the files attached to a task, including filenames, sizes and file IDs.', |
| 357 | { taskId: id }, ['taskId']), |
| 358 | tool('attach_task_file', 'Attach a regular file to a task using base64. Accepts up to 10 MB per file. Video files are excluded. Reuse requestKey for identical retries.', |
| 359 | { ...write, taskId: id, name: string(240), contentType: string(150), |
| 360 | base64: { type: 'string', maxLength: Math.ceil(10 * 1024 * 1024 / 3) * 4 } }, |
| 361 | ['taskId', 'name', 'contentType', 'base64', 'requestKey'], true), |
| 362 | tool('list_task_activity','Read task activity, including moves, edits, agent reports and earlier messages. Newest first; follow nextBefore with beforeSequence.', |
| 363 | {taskId:id,commentId:id,beforeSequence:{type:'integer',minimum:1},limit:{type:'integer',minimum:1,maximum:50}},['taskId']), |
| 364 | tool('add_task_activity','Record an agent update in Activity. Pass commentIds to link one verified response to all revision requests it addresses, or commentId for an older single-request client. Only include requests actually acted on.', |
| 365 | {...tools.find(({name})=>name==='add_task_comment').inputSchema.properties,commentId:id, |
| 366 | commentIds:{type:'array',items:id,minItems:1,maxItems:50,uniqueItems:true}},['taskId','text','requestKey'],true) |
| 367 | ) |
| 368 | // A revision request keeps the ID its device gave it, so a withdrawal can name it before it arrives. |
| 369 | const revisionId = { type: 'string', minLength: 1, maxLength: 150 } |
| 370 | const local = [ |
| 371 | tool('read_task_file', 'Read attached file bytes for native open or sync.', |
| 372 | { taskId: id, fileId: id }, ['taskId', 'fileId']), |
| 373 | tool('add_user_comment','Save a comment explicitly entered in the native application. Private user interface action.', |
| 374 | {...tools.find(({name})=>name==='add_task_comment').inputSchema.properties, clientId: revisionId},['taskId','text','requestKey'],true), |
| 375 | tool('withdraw_revision_request', 'Withdraw one of the user’s own revision requests before an agent receives it. Private user interface action.', |
| 376 | { ...write, taskId: id, id: revisionId }, ['taskId', 'id', 'requestKey'], true), |
| 377 | tool('companion_organize_task', 'Apply an explicit companion Archive, Trash or restore action.', |
| 378 | { ...write, id, destination: { enum: ['archive', 'trash', 'active'] } }, |
| 379 | ['id', 'destination', 'requestKey'], true), |
| 380 | tool('force_complete_task', 'Apply an explicit user override to mark a task Done.', { ...write, id }, |
| 381 | ['id', 'requestKey'], true), |
| 382 | tool('companion_set_task_field', 'Apply a companion field edit against its last seen value.', |
| 383 | { ...write, ...agentSelection, dispatchComment, id, |
| 384 | field: { enum: ['project', 'status', 'priority', 'dueDate', 'title', 'notes', 'definitionOfDone', 'issueType'] }, |
| 385 | value: { anyOf: [{ type: 'string', maxLength: 100000 }, { type: 'null' }] }, |
| 386 | expectedValue: { anyOf: [{ type: 'string', maxLength: 100000 }, { type: 'null' }] }, |
| 387 | }, ['id', 'field', 'value', 'expectedValue', 'requestKey'], true), |
| 388 | tool('companion_delete_archived_task', 'Apply a confirmed companion Archive deletion.', |
| 389 | taskWrite, ['id', 'expectedRevision', 'requestKey'], true), |
| 390 | tool('companion_empty_trash', 'Apply a confirmed companion Trash deletion at the reviewed workspace revision.', |
| 391 | { ...write, expectedRevision: revision }, ['expectedRevision', 'requestKey'], true), |
| 392 | tool('companion_reorder_task', 'Place a task next to another task in the same project and status.', |
| 393 | { ...write, id, boardId: id, status, anchorId: id, before: { type: 'boolean' } }, |
| 394 | ['id', 'boardId', 'status', 'anchorId', 'before', 'requestKey'], true), |
| 395 | tool('manage_archived_tasks', 'Apply an explicitly confirmed bulk Archive action.', |
| 396 | { ...write, expectedRevision: revision, permanently: { type: 'boolean' }, |
| 397 | taskIds: { type: 'array', items: id, minItems: 1, maxItems: 10000, uniqueItems: true } }, |
| 398 | ['expectedRevision', 'permanently', 'taskIds', 'requestKey'], true), |
| 399 | tool('capture_task', 'Create a to-do in an existing or newly named project.', { |
| 400 | ...tools.find(({ name }) => name === 'create_task').inputSchema.properties, |
| 401 | newProjectName: string(100), |
| 402 | }, ['boardId', 'title', 'requestKey'], true), |
| 403 | tool( |
| 404 | 'reorder_tasks', |
| 405 | 'Save the full visible ordering of one column locally without changing task statuses or agent assignment.', |
| 406 | { |
| 407 | ...write, |
| 408 | boardId: id, |
| 409 | status, |
| 410 | expectedRevision: revision, |
| 411 | taskIds: { type: 'array', items: id, minItems: 1, maxItems: 10000, uniqueItems: true }, |
| 412 | }, |
| 413 | ['boardId', 'status', 'expectedRevision', 'taskIds', 'requestKey'], |
| 414 | true |
| 415 | ), |
| 416 | tool( |
| 417 | 'reorder_all_tasks', |
| 418 | 'Save the full visible ordering of one All tasks column locally. One task may arrive from another column; each project keeps the same relative order.', |
| 419 | { |
| 420 | ...write, |
| 421 | ...agentSelection, |
| 422 | status, |
| 423 | expectedRevision: revision, |
| 424 | taskIds: { type: 'array', items: id, minItems: 1, maxItems: 10000, uniqueItems: true }, |
| 425 | }, |
| 426 | ['status', 'expectedRevision', 'taskIds', 'requestKey'], |
| 427 | true |
| 428 | ), |
| 429 | tool( |
| 430 | 'retry_task_comment', |
| 431 | 'Requeue a comment after reviewing its conversation', |
| 432 | { ...write, id }, |
| 433 | ['id', 'requestKey'], |
| 434 | true |
| 435 | ), |
| 436 | tool('choose_comment_images', 'Attach up to three screenshot image files'), |
| 437 | tool('paste_comment_image', 'Attach a screenshot from the clipboard'), |
| 438 | tool('check_task_comments', 'Check pending comments now'), |
| 439 | tool('get_agent_settings', 'Read the default task agent, working folder and permission mode'), |
| 440 | tool( |
| 441 | 'set_agent_settings', |
| 442 | 'Save the default task agent and working folder, and optionally change the permission mode', |
| 443 | { |
| 444 | ...write, |
| 445 | defaultAgent: { enum: agentIds }, |
| 446 | workingFolder: { type: 'string', maxLength: 4000 }, |
| 447 | permissionMode: { enum: ['auto', 'manual', 'full-access'] }, |
| 448 | }, |
| 449 | ['defaultAgent', 'workingFolder', 'requestKey'], |
| 450 | true |
| 451 | ), |
| 452 | tool('choose_agent_folder', 'Choose a folder for dispatched tasks'), |
| 453 | tool('agent_runtime_status', 'Check installed agent launchers'), |
| 454 | tool( |
| 455 | 'open_agent_install_guide', |
| 456 | 'Open official agent installation instructions', |
| 457 | { agent: { enum: agentIds } }, |
| 458 | ['agent'] |
| 459 | ), |
| 460 | tool('stop_agent_run', 'Stop one dispatched run', { runId: id }, ['runId']), |
| 461 | tool('open_agent_thread', 'Open an existing agent conversation', { runId: id }, ['runId']), |
| 462 | tool( |
| 463 | 'answer_agent_approval', |
| 464 | 'Answer one pending agent permission request once', |
| 465 | { runId: id, approvalId: id, allow: { type: 'boolean' } }, |
| 466 | ['runId', 'approvalId', 'allow'] |
| 467 | ), |
| 468 | tool('snapshot', 'Local renderer state'), |
| 469 | tool( |
| 470 | 'set_editor_dirty', |
| 471 | 'Protect unsaved editor text when closing the window', |
| 472 | { dirty: { type: 'boolean' } }, |
| 473 | ['dirty'] |
| 474 | ), |
| 475 | tool('connection_status', 'Local connection setup'), |
| 476 | tool( |
| 477 | 'set_connection', |
| 478 | 'Enable or disable the embedded connector locally', |
| 479 | { enabled: { type: 'boolean' } }, |
| 480 | ['enabled'] |
| 481 | ), |
| 482 | tool('reset_connection_key', 'Reset the local connection key'), |
| 483 | tool( |
| 484 | 'client_configuration', |
| 485 | 'Read private client setup locally', |
| 486 | { transport: { enum: ['stdio', 'http'] } }, |
| 487 | ['transport'] |
| 488 | ), |
| 489 | tool('show_data_folder', 'Open the local data folder'), |
| 490 | tool('agent_setup_fields', 'Read desktop setup fields locally'), |
| 491 | tool('copy_setup_field', 'Copy one desktop setup field', { id: string(100) }, ['id']), |
| 492 | tool('save_claude_extension', 'Save a local Claude Desktop extension'), |
| 493 | tool('save_project_connection', 'Save Claude setup in a selected working folder'), |
| 494 | tool( |
| 495 | 'open_setup_app', |
| 496 | 'Open a supported desktop app', |
| 497 | { app: { enum: ['codex', 'claude', 'terminal'] } }, |
| 498 | ['app'] |
| 499 | ), |
| 500 | tool( |
| 501 | 'copy_terminal_setup', |
| 502 | 'Copy an optional registration command', |
| 503 | { client: { enum: ['codex', 'claude-code', 'gemini'] } }, |
| 504 | ['client'] |
| 505 | ), |
| 506 | tool('open_company_website', 'Visit the project website'), |
| 507 | tool('open_newsletter', 'Open the product updates link in your browser'), |
| 508 | tool( |
| 509 | 'open_support_link', |
| 510 | 'Open an app support page', |
| 511 | { kind: { enum: ['coffee', 'setup'] } }, |
| 512 | ['kind'] |
| 513 | ), |
| 514 | tool( |
| 515 | 'open_setup_guide', |
| 516 | 'Open an official setup guide', |
| 517 | { client: { enum: ['claude-code', 'codex', 'claude'] } }, |
| 518 | ['client'] |
| 519 | ), |
| 520 | tool('choose_backup', 'Save through a native dialog'), |
| 521 | tool('choose_restore', 'Inspect a backup through a native dialog'), |
| 522 | tool( |
| 523 | 'import_prototype', |
| 524 | 'Preserve an earlier local prototype once', |
| 525 | { workspace: { type: 'object' } }, |
| 526 | ['workspace'] |
| 527 | ), |
| 528 | ] |
| 529 | class AppError extends Error { |
| 530 | constructor(code, message, details) { |
| 531 | super(message) |
| 532 | this.code = code |
| 533 | this.details = details |
| 534 | } |
| 535 | } |
| 536 | function validate(schema, value, field = 'arguments') { |
| 537 | if (schema.anyOf) { |
| 538 | for (const rule of schema.anyOf) { |
| 539 | try { |
| 540 | validate(rule, value, field) |
| 541 | return |
| 542 | } catch (error) { |
| 543 | if (!(error instanceof AppError)) throw error |
| 544 | } |
| 545 | } |
| 546 | throw new AppError( |
| 547 | 'INVALID_ARGUMENT', |
| 548 | schema.anyOf[0].enum |
| 549 | ? `${field} must be null or one of: ${schema.anyOf[0].enum.join(', ')}.` |
| 550 | : `${field} must be a date string or null.` |
| 551 | ) |
| 552 | } |
| 553 | if (schema.type === 'null' && value !== null) |
| 554 | throw new AppError('INVALID_ARGUMENT', `${field} must be null.`) |
| 555 | if (schema.enum && !schema.enum.includes(value)) |
| 556 | throw new AppError('INVALID_ARGUMENT', `${field} must be one of: ${schema.enum.join(', ')}.`) |
| 557 | if (schema.type === 'object') { |
| 558 | if (!value || typeof value !== 'object' || Array.isArray(value)) |
| 559 | throw new AppError('INVALID_ARGUMENT', `${field} must be an object.`) |
| 560 | for (const key of schema.required || []) |
| 561 | if (value[key] === undefined) |
| 562 | throw new AppError('INVALID_ARGUMENT', `${field}.${key} is required.`) |
| 563 | if (schema.additionalProperties === false) |
| 564 | for (const key of Object.keys(value)) |
| 565 | if (!Object.hasOwn(schema.properties, key)) |
| 566 | throw new AppError('INVALID_ARGUMENT', `Unknown argument: ${key}.`) |
| 567 | for (const [key, rule] of Object.entries(schema.properties || {})) |
| 568 | if (value[key] !== undefined) validate(rule, value[key], `${field}.${key}`) |
| 569 | } |
| 570 | if ( |
| 571 | schema.type === 'string' && |
| 572 | (typeof value !== 'string' || |
| 573 | value.length < (schema.minLength || 0) || |
| 574 | value.length > (schema.maxLength || Infinity)) |
| 575 | ) |
| 576 | throw new AppError('INVALID_ARGUMENT', `${field} has an invalid length or type.`) |
| 577 | if ( |
| 578 | schema.type === 'integer' && |
| 579 | (!Number.isSafeInteger(value) || |
| 580 | value < (schema.minimum ?? -Infinity) || |
| 581 | value > (schema.maximum ?? Infinity)) |
| 582 | ) |
| 583 | throw new AppError('INVALID_ARGUMENT', `${field} must be an integer in range.`) |
| 584 | if (schema.type === 'boolean' && typeof value !== 'boolean') |
| 585 | throw new AppError('INVALID_ARGUMENT', `${field} must be true or false.`) |
| 586 | if (schema.type === 'array') { |
| 587 | if ( |
| 588 | !Array.isArray(value) || |
| 589 | value.length < (schema.minItems || 0) || |
| 590 | value.length > (schema.maxItems || Infinity) || |
| 591 | (schema.uniqueItems && new Set(value).size !== value.length) |
| 592 | ) |
| 593 | throw new AppError('INVALID_ARGUMENT', `${field} must be a bounded array of unique values.`) |
| 594 | value.forEach((item, index) => validate(schema.items, item, `${field}[${index}]`)) |
| 595 | } |
| 596 | } |
| 597 | function validateAction(name, input, allowLocal = false) { |
| 598 | const contract = [...tools, ...(allowLocal ? local : [])].find((item) => item.name === name) |
| 599 | if (!contract) throw new AppError('UNKNOWN_ACTION', 'This action is not available.') |
| 600 | validate(contract.inputSchema, input) |
| 601 | return contract |
| 602 | } |
| 603 | module.exports = { tools, AppError, validateAction, boardIcons, agentModels } |