> ## Documentation Index
> Fetch the complete documentation index at: https://docs.simular.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Instance

> A running application on a machine.

Obtain via \[`App.open`] or \[`Machine.foregroundApp`].

## Constructor

```typescript
Instance(): Instance
```

### Returns

`Instance`

## Properties

<ResponseField name={"pid"} type={"null | number"} required>
  A process ID of the instance, if known. Diagnostic only.

  On macOS this is the stored launch PID (always set). On Linux it is
  the launch PID while that process is alive, else the owner of a
  window attributed to the app by `WM_CLASS` (a single-instance app
  handed the launch off to an already-running process). On Windows
  instances are app-scoped and store no PID; the value is resolved
  lazily — the owner PID of the app's first window, else a matching
  process, else `null` (e.g. while the app has no window yet). Which
  process serves a multi-process app is unspecified.
</ResponseField>

## Methods

### close()

```typescript
close(): void
```

Request the application to exit gracefully. Returns when the request has
been dispatched, not when the process has actually terminated; poll
\[`Self::is_running`] if you need to wait.

### content()

```typescript
content(): string
```

Text content of the instance's UI (aria-snapshot style).

#### Returns

`string`

### disableAccessibility()

```typescript
disableAccessibility(): void
```

Disables the accessibility tree for the instance to save resources.
No-op on Android.

Creating the accessibility tree is resource-intensive, so many
applications disable it by default. After we are done controlling the
instance, we should disable the accessibility tree again.

### enableAccessibility()

```typescript
enableAccessibility(): void
```

Enables the accessibility tree for the instance. Also works when the
application is already running. No-op on Android (uiautomator is
always available).

### focus()

```typescript
focus(): boolean
```

Brings the instance to the foreground and gives it focus.

#### Returns

`boolean`

### hide()

```typescript
hide(): boolean
```

Minimizes the instance.

#### Returns

`boolean`

### isAccessible()

```typescript
isAccessible(): boolean
```

Returns true if the instance has an accessibility tree.

#### Returns

`boolean`

### isFocused()

```typescript
isFocused(): boolean
```

Whether the instance has focus.

#### Returns

`boolean`

### isRunning()

```typescript
isRunning(): boolean
```

`true` if the underlying process is still running. Cheap, non-blocking.

#### Returns

`boolean`

### kill()

```typescript
kill(): void
```

Force-terminate immediately. The application gets no chance to save state
or run cleanup handlers.

### root()

```typescript
root(): AccessibilityNode
```

Root accessibility node of this application.

On macOS this is the application element (every window plus the app
menu bar). On Windows / Linux it is the process accessibility root.
On Android it is the current screen root — the instance must be in
the foreground.

#### Returns

`AccessibilityNode`

### scoredSearch()

```typescript
scoredSearch(order: TraversalOrder, maxNodes: number, collapseStructural: boolean, query: string, threshold: number): AccessibilityNode[]
```

Search this application's accessibility tree by *concept text*, using
bag-of-words paired-Jaccard scoring against each node's
`overallDescription`
(`simulang_rs::AXNodeSynthetic::summary_with_context`).

Mirrors `simulang_rs::Instance::scored_search` with `BowJaccard` as the
scorer and a permissive filter; returns every node whose score equals
the maximum found and exceeds `threshold`.

* `order`               – `TraversalOrder.DepthFirst` or
  `TraversalOrder.BreadthFirst`
* `max_nodes`           – upper bound on nodes visited (uses `.take()`
  over the walk)
* `collapse_structural` – hoist empty structural wrappers out of the
  walk before scoring
* `query`               – natural-language concept Jaccard-compared
  against each node's `overallDescription`
* `threshold`           – minimum score to keep a node

Returned nodes are full `AccessibilityNode` handles — call action
methods (`activate`, `setValue`, …) directly on them, walk children
with `.children()`, or render a snapshot with `.snapshot()`.

#### Parameters

<ResponseField name={"order"} type={"TraversalOrder"} required />

<ResponseField name={"maxNodes"} type={"number"} required />

<ResponseField name={"collapseStructural"} type={"boolean"} required />

<ResponseField name={"query"} type={"string"} required />

<ResponseField name={"threshold"} type={"number"} required />

#### Returns

`AccessibilityNode[]`

### show()

```typescript
show(): boolean
```

Shows the instance.

#### Returns

`boolean`

### windows()

```typescript
windows(): Window[]
```

All visible top-level windows belonging to this instance (Android:
one window per live task of the app).

#### Returns

`Window[]`
