Skip to content

Resource Watch Channel

Reference for ahp-resource-watch:/<id> channels — short-lived, per-connection filesystem watches that deliver batched change actions. See Resource Watch Channel specification for lifecycle and subscription semantics.

JSON Schema: state.schema.json

State Types

ResourceWatchState

Full state for a single resource watch, returned when a client subscribes to an ahp-resource-watch: URI.

Watches are otherwise stateless: the watcher exists to deliver {@link ResourceWatchChangedAction} events. The state carries only the descriptor of what is being watched so a re-subscribing client can recover the watch configuration after reconnecting.

FieldTypeRequiredDescription
rootURIYesThe URI being watched. For recursive watches this is the root of the subtree; for non-recursive watches this is the single file or directory.
recursivebooleanYestrue if the watcher reports changes for descendants of root; false if it only reports changes to root itself (and, when root is a directory, its direct children).
excludes
{
  items: string[]
}
NoOptional glob patterns or paths relative to root to exclude from change reporting.
includes
{
  items: string[]
}
NoOptional glob patterns or paths relative to root to restrict change reporting to. Omit to report every change under root subject to excludes.

ResourceChangeType

Discriminant for {@link ResourceChange.type}.

MemberValue
Added'added'
Updated'updated'
Deleted'deleted'

ResourceChange

A single change observed by a resource watcher.

FieldTypeDescription
uriURIThe URI of the resource that changed.
typeResourceChangeTypeThe kind of change observed.

Actions

Deliver resource changes on a watch channel. Watch state itself is immutable.

JSON Schema: actions.schema.json

resourceWatch/changed

A batch of resource changes observed by the watcher.

Watch events are coalesced into batches by the server to keep the action stream tractable; an empty changes.items list MUST NOT be dispatched. The reducer does not retain change history — these actions exist purely to deliver events to subscribers, who consume them directly off the action stream and apply their own logic.

FieldTypeDescription
typeActionType.ResourceWatchChanged
changes
{
  items: ResourceChange[]
}
The set of changes in this batch, wrapped for forward compatibility.

Commands

JSON Schema: commands.schema.json

createResourceWatch

Creates a resource watcher on the receiver's filesystem.

The receiver allocates an ahp-resource-watch:/<id> channel URI and returns it on {@link CreateResourceWatchResult.channel}. The caller then subscribes to that channel to receive resourceWatch/changed actions over the standard action envelope.

The watch lifecycle is tied to subscription: when every subscriber has unsubscribed (or the underlying connection drops), the receiver MUST release the watcher. There is no explicit dispose command — unsubscribe is the only handle the caller needs.

Like the rest of the resource* family, createResourceWatch is symmetrical and MAY be sent in either direction. Access is gated through the same permission flow as resourceRead/resourceWrite.

PropertyValue
DirectionClient ↔ Server
TypeRequest

Parameters:

FieldTypeRequiredDescription
channel'ahp-root://'Yes
uriURIYesURI to watch.
recursivebooleanNoIf true, the receiver MUST report changes for descendants of uri. If false (default), only changes to uri itself — and, when uri is a directory, its direct children — are reported.
excludes
{
  items: string[]
}
NoGlob patterns or paths relative to uri to exclude from reporting. Wrapped in { items } for forward compatibility.
includes
{
  items: string[]
}
NoGlob patterns or paths relative to uri to restrict reporting to. Omit to report every change under uri subject to excludes. Wrapped in { items } for forward compatibility.

Result:

FieldTypeDescription
channelURIReceiver-assigned watch channel URI (ahp-resource-watch:/&lt;id&gt;). The caller subscribes to this URI to start receiving change events and unsubscribes to release the watcher.

Example:

jsonc
// Client → Server
{ "jsonrpc": "2.0", "id": 30, "method": "createResourceWatch",
  "params": {
    "channel": "ahp-root://",
    "uri": "file:///workspace",
    "recursive": true,
    "excludes": { "items": ["**\u002f.git/**", "**\u002fnode_modules/**"] }
  } }

// Server → Client
{ "jsonrpc": "2.0", "id": 30, "result": {
  "channel": "ahp-resource-watch:/d3a9f1e0-…"
} }

Released under the MIT License.