script_globals library

Script Globals for VS Code Scripting API

This file provides global variable declarations for scripts. Import this file to get convenient access to VS Code API globals.

Usage

import 'package:tom_vscode_scripting_api/script_globals.dart';

void main() {
  // Now vscode, window, etc. are available
  vscode.window.showInformationMessage('Hello!');
}

Available Globals

Note

These globals require VSCode.initialize() to be called first.

Classes

AgentDefinition
A programmatic sub-agent definition. Mirrors AgentDefinition.
AgentQuery
A live Agent SDK query: a Stream<SdkMessage> plus control methods.
AgentSdkClient
Entry point mirroring the SDK's query() free function, bound to a AgentSdkTransport.
AgentSdkInputTransport
A transport that can also carry caller-owned streaming input (AgentSdkClient.streamQuery).
AgentSdkToolRegistry
Indexes the Dart ToolHandlers a query exposes and dispatches incoming agentSdk.toolCall requests to them.
AgentSdkTransport
Transport seam for streaming Agent SDK queries.
BridgeRequestDispatcher
Routes incoming server→client requests to registered handlers and writes their replies through an injected sink.
CallToolResult
The result a ToolHandler returns. Mirrors MCP CallToolResult.
CanUseToolContext
Context passed to a CanUseTool callback. Mirrors the SDK's { suggestions?, signal } argument; the payload is kept opaque (raw) until the reverse-RPC wiring (todos #4–#6) gives it structure.
ChatContext
Context for a chat request including conversation history
ChatErrorDetails
Error details for a failed chat request
ChatParticipant
A chat participant
ChatPromptReference
A reference in a chat prompt
ChatRequest
A chat request from the user
ChatResponseStream
A stream for sending responses back to the chat
ChatResult
Result of handling a chat request
ChatVariable
Chat variable value.
ChatVariableListResult
Result of listing chat variables.
ContentBlock
A content block inside an assistant or user message.
DocumentContent
Content of a document.
DocumentInfo
Metadata about a document file.
DocumentListResult
Result of listing documents.
Extension
Represents a VS Code extension
FileBatch
File batch processor
FileSystemWatcherOptions
File system watcher options
FollowUpInput
Input for adding a follow-up prompt to a queue item.
GuidelineInfo
Guideline document info.
GuidelineListResult
Result of listing guidelines.
HelperLogging
Logging control for VsCodeHelper
InputBoxOptions
Input box options
InvalidTodo
A todo in a list answer that could not be read as a TomItem.
LanguageModelChat
Represents a language model for chat requests
LanguageModelChatMessage
A message in a chat conversation
LanguageModelChatResponse
Response from a language model chat request
LanguageModelToolInformation
Information about a registered tool
LanguageModelToolResult
Tool result from language model
LazyVSCodeBridgeAdapter
A lazy-connecting adapter that auto-connects on first use.
McpHttpServerConfig
An HTTP MCP server. Mirrors McpHttpServerConfig.
McpSdkServerConfig
An in-process ("sdk") MCP server. Mirrors McpSdkServerConfigWithInstance, but carries a serializable descriptor instead of a live McpServer (proposal §7.0.4): the extension reconstructs the real instance.
McpServerConfig
An MCP server configuration referenced from Options.mcpServers. Mirrors McpServerConfig (stdio / sse / http / sdk variants).
McpServerToolPolicy
Per-tool permission policy for a remote MCP server. Mirrors McpServerToolPolicy (permission_policy is snake_case on the wire).
McpSSEServerConfig
An SSE MCP server. Mirrors McpSSEServerConfig.
McpStdioServerConfig
A stdio MCP server. Mirrors McpStdioServerConfig.
MessageOptions
Message options
Options
Options for an Agent SDK query. Mirrors the SDK's Options type.
OutputFormat
Structured output configuration. Mirrors { type:'json_schema', schema }.
PermissionAllow
Allow result (behavior: 'allow').
PermissionDeny
Deny result (behavior: 'deny').
PermissionResult
The result returned by a CanUseTool callback. Mirrors PermissionResult (an allow/deny union).
PermissionRuleValue
A single tool-permission rule. Mirrors PermissionRuleValue.
PermissionUpdate
A permission-rule mutation. Mirrors PermissionUpdate (six variants).
PermissionUpdateDirectories
addDirectories / removeDirectories updates.
PermissionUpdateRules
addRules / replaceRules / removeRules updates.
PermissionUpdateSetMode
setMode update.
PluginConfig
A local plugin configuration. Mirrors SdkPluginConfig.
Position
Position in a text document
ProjectInfo
Information about a project in the workspace.
ProjectListResult
Result of listing projects.
QuestInfo
Information about a quest.
QuestListResult
Result of listing quests.
QueuedFollowUp
A follow-up prompt attached to a queue item.
QueuedPrompt
A queued prompt item.
QueueItemInput
Input for creating a new queue item.
QueueListResult
Result of listing queue items.
QuickPickItem
Quick pick item
Range
Range in a text document
ScheduledTime
A scheduled time slot.
SdkAssistantMessage
Mirrors SDKAssistantMessage (type: 'assistant').
SdkMcpTool
An in-process tool definition. Mirrors SdkMcpToolDefinition / the object built by tool().
SdkMessage
A single message yielded by an Agent SDK query stream.
SdkPartialAssistantMessage
Mirrors SDKPartialAssistantMessage (type: 'stream_event'), emitted only when includePartialMessages is set.
SdkResultMessage
Mirrors SDKResultMessage (type: 'result', success or error subtype).
SdkSystemEvent
Carrier for the long tail of type: 'system' events that are not init (e.g. compact_boundary, status, task_progress, rate_limit, …).
SdkSystemMessage
Mirrors SDKSystemMessage (type: 'system', subtype: 'init').
SdkUnknownMessage
Forward-compatible fallback for any top-level type this mirror does not model. Preserves the full payload in raw.
SdkUserInput
One user message for AgentSdkClient.streamQuery — the SDK's SDKUserMessage input shape.
SdkUserMessage
Mirrors SDKUserMessage (type: 'user', incl. the replay variant).
Selection
Selection in a text editor
SendToChatResult
The outcome of a TomChatApi.sendToChat call.
SettingsInline
Inline settings.
SettingsPath
A path to a settings file.
SettingsRef
A settings reference. Mirrors string | Settings (a path or an inline map).
Skills
The skills selection. Mirrors string[] | 'all'.
SkillsAll
Enable all skills ('all').
SkillsList
An explicit list of skill names.
SystemPrompt
The system prompt. Mirrors string | string[] | { type:'preset', … }.
SystemPromptList
A multi-section system prompt (string array).
SystemPromptPreset
The Claude Code preset system prompt, optionally appended/trimmed.
SystemPromptText
A plain-string system prompt.
TaskBudget
A task budget. Mirrors { total }.
TerminalOptions
Terminal options
TextBlock
Mirrors a text content block.
TextDocument
Text document representation
TextEditor
Text editor representation
ThinkingAdaptive
Adaptive thinking — the model decides (type: 'adaptive').
ThinkingBlock
Mirrors a thinking content block.
ThinkingConfig
Extended-thinking configuration. Mirrors ThinkingConfig.
ThinkingDisabled
No extended thinking (type: 'disabled').
ThinkingEnabled
Fixed thinking budget (type: 'enabled').
TimedRequest
A timed request entry.
TimedRequestInput
Input for creating a new timed request.
TimedRequestListResult
Result of listing timed requests.
TodoEntry
A todo as the extension answered it: the shared TomItem plus what the bridge says about it and what the model has no field for.
TodoFileListResult
Result of listing todo files.
TodoListResult
Result of listing todos.
TodoWire
Maps the extension bridge's todo JSON onto the shared todo model and back.
TomChatApi
Scripting access to the Tom extension's "Send to Chat" transport.
TomDocumentApi
API for accessing workspace documents.
TomItem
One item: the record of D1 §3.1.
TomQueueApi
API for managing the prompt queue.
TomTimedApi
API for managing timed/scheduled requests.
TomTodoApi
API for managing TODO items across quest, workspace, and session scopes.
TomTodoDecision
One open or answered question on a todo (workspace schema decisions).
TomTodoReference
A document or resource a todo points at (workspace schema references): a workspace file, a URL, or a note — at least one of the three.
TomTodoRepeat
The day of a month a monthly or yearly rule names — exactly one of: day (1–31; a month without that day takes its last), lastDay, the nth weekday (1–5, or -1 for the last), or the first / last working day (workingDay, Monday to Friday).
TomTodoScope
Where a todo applies (workspace schema scope).
TomToolsApi
Scripting access to the Tom extension's LLM tool registry.
TomWorkspaceApi
API for accessing workspace structure and configuration.
ToolDefinitionJson
An Anthropic-shaped tool definition: {name, description, input_schema}.
ToolResultBlock
Mirrors a tool_result content block.
ToolsClaudeCodePreset
The Claude Code default tool preset.
ToolsConfig
The tool selection. Mirrors string[] | { type:'preset', preset:'claude_code' }.
ToolsList
An explicit list of tool names.
ToolUseBlock
Mirrors a tool_use content block.
TrailEntry
Trail entry (prompt/answer pair).
TrailListResult
Result of listing trail entries.
UnknownBlock
Forward-compatible fallback for any content block type this mirror does not model (redacted_thinking, server_tool_use, image, …).
VSCode
Main VS Code API wrapper class Provides unified access to all VS Code APIs through Dart
VSCodeAdapter
Abstract interface for sending requests to VS Code
VSCodeBridgeAdapter
Implementation of VSCodeAdapter using VSCodeBridgeClient.
VSCodeBridgeAgentSdkTransport
Production AgentSdkTransport backed by a VSCodeBridgeClient.
VSCodeBridgeClient
Client for communicating with VS Code VS Code Bridge.
VSCodeBridgeResult
Result of a VS Code bridge command execution.
VSCodeChat
Chat API - Create and manage chat participants
VSCodeCommands
Wrapper for vscode.commands API Provides access to VS Code command system
VSCodeCommonCommands
Common VS Code commands
VSCodeExtensions
Wrapper for vscode.extensions API Provides access to VS Code extensions management
VsCodeHelper
Helper class for VS Code API operations in scripts
VSCodeLanguageModel
Language Model API - Access to GitHub Copilot and other language models
VSCodeUri
Represents a URI in VS Code
VSCodeWindow
Wrapper for vscode.window API Provides access to window-related functionality (UI, messages, editors, etc.)
VSCodeWorkspace
Wrapper for vscode.workspace API Provides access to workspace-related functionality
VsProgress
Progress indicator helper
WorkspaceFolder
Represents a workspace folder
WorkspaceInfo
Workspace metadata.

Enums

DiagnosticSeverity
Diagnostic severity
DocumentFolder
Type of document folder.
EffortLevel
Reasoning-effort level. Mirrors EffortLevel.
PermissionBehavior
Behaviour applied by a permission rule. Mirrors PermissionBehavior.
PermissionDecisionClassification
Classification of a permission decision. Mirrors PermissionDecisionClassification (snake_case wire values).
PermissionMode
Controls how tool executions are handled. Mirrors PermissionMode (six values; default is spelled PermissionMode.default_ in Dart).
PermissionUpdateDestination
Where a permission update is persisted. Mirrors PermissionUpdateDestination.
ProjectType
Type of project detected in the workspace.
QueuedPromptStatus
Status of a queued prompt.
QueuedPromptType
Type of a queued prompt.
ScheduleMode
Schedule mode for timed requests.
SettingSource
Where the agent loads filesystem settings from. Mirrors SettingSource.
TimedRequestStatus
Status of a timed request entry.
TodoLevel
Where a todo lives, as todo.listAllVce tags it (_scope).
TomTodoPriority
Todo priority, ordered low → critical.
TomTodoRepeatRule
The kinds of rule.
TomTodoStatus
An item's status. Wire names match the workspace todo.schema.json enum exactly, in both directions: the nine values here are the nine the schema lists, which _bin/check_todo_model.py in the workspace holds.

Constants

defaultVSCodeBridgePort → const int
Default (and lowest) port for the VS Code CLI Integration Server.
maxVSCodeBridgePort → const int
Highest port in the VS Code CLI Integration Server range.

Properties

chat → VSCodeChat
VS Code chat API.
no setter
commands → VSCodeCommands
VS Code commands API.
no setter
extensions → VSCodeExtensions
VS Code extensions API.
no setter
lm → VSCodeLanguageModel
VS Code language model API.
no setter
vscode → VSCode
Main VS Code API entry point.
no setter
window → VSCodeWindow
VS Code window API.
no setter
workspace → VSCodeWorkspace
VS Code workspace API.
no setter

Functions

connectToWorkspace(String name, {String host = '127.0.0.1', int minPort = defaultVSCodeBridgePort, int maxPort = maxVSCodeBridgePort, BridgePortProbe probe = _defaultProbe, BridgeIdentityFetcher fetchIdentity = fetchBridgeWorkspaceName, bool initializeVSCode = false, BridgeAdapterFactory adapterFactory = _defaultAdapterFactory}) → Future<LazyVSCodeBridgeAdapter>
Resolves the bridge port for the workspace named name (via findBridgePortForWorkspace) and returns a connected adapter bound to it.
dispatchCanUseTool(CanUseTool callback, Map<String, dynamic> params) → Future<Map<String, dynamic>>
Invokes callback for an incoming agentSdk.canUseTool request and returns its PermissionResult as wire JSON.
fetchBridgeWorkspaceName(String host, int port) → Future<String?>
Default BridgeIdentityFetcher — connects to the bridge on host:port, issues a workspace.getInfoVce window-identity handshake, and derives the workspace name from the result. Returns null if the bridge cannot be reached or yields no identifiable workspace.
findBridgePortForWorkspace(String name, {String host = '127.0.0.1', int minPort = defaultVSCodeBridgePort, int maxPort = maxVSCodeBridgePort, BridgePortProbe probe = _defaultProbe, BridgeIdentityFetcher fetchIdentity = fetchBridgeWorkspaceName}) → Future<int>
Scans the CLI bridge port range for the window whose workspace matches name and returns its port.
findBridgePortsForWorkspace(String name, {String host = '127.0.0.1', int minPort = defaultVSCodeBridgePort, int maxPort = maxVSCodeBridgePort, BridgePortProbe probe = _defaultProbe, BridgeIdentityFetcher fetchIdentity = fetchBridgeWorkspaceName}) → Future<List<int>>
Scans the CLI bridge port range and returns every port whose window has the workspace name open, ascending; empty when none does.
normalizeWorkspaceName(String value) → String
Normalises a workspace name for comparison: trims whitespace, drops a trailing .code-workspace extension, and strips VS Code's " (Workspace)" multi-root suffix.
scanBridgePorts({String host = '127.0.0.1', int minPort = defaultVSCodeBridgePort, int maxPort = maxVSCodeBridgePort, BridgePortProbe probe = _defaultProbe, BridgeIdentityFetcher fetchIdentity = fetchBridgeWorkspaceName}) → Future<Map<int, String>>
Scans the CLI bridge port range and returns a port → workspace table for every responsive bridge.

Typedefs

BridgeAdapterFactory = LazyVSCodeBridgeAdapter Function(String host, int port)
Creates a port-bound LazyVSCodeBridgeAdapter for a resolved bridge.
BridgeIdentityFetcher = Future<String?> Function(String host, int port)
Fetches the workspace identity name reported by the bridge on host:port, or null if the bridge does not answer / has no identifiable workspace.
BridgePortProbe = Future<bool> Function(String host, int port)
Probes whether a bridge is listening on host:port.
BridgeRequestHandler = FutureOr<Object?> Function(Map<String, dynamic> params)
A handler for an incoming server→client request method. Receives the request params and returns the JSON-encodable result (sync or async).
CanUseTool = Future<PermissionResult> Function(String toolName, Map<String, dynamic> input, CanUseToolContext context)
Tool-approval callback. Mirrors CanUseTool.
ChatRequestHandler = Future<ChatResult?> Function(ChatRequest request, ChatContext context, ChatResponseStream stream)
Chat request handler callback
ToolHandler = Future<CallToolResult> Function(Map<String, dynamic> args)
A tool callback that runs in Dart. Mirrors the handler passed to tool().

Exceptions / Errors

AgentSdkQueryException
Thrown into an AgentQuery's stream when the extension reports a query failure via an error chunk.
BridgeWorkspaceNotFoundException
Thrown by findBridgePortForWorkspace when no responsive bridge in the scanned range has the requested workspace open.
LanguageModelCallException
A language-model call whose script failed in the window (the bridge answered {success: false, error}): a missing model, a refused consent, a network error inside VS Code.