Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,70 @@ because an earlier attempt of the same post failed with nothing sent.
by a draft filed before items waited on their drafts (muster 0.218.0) is
settled the same way once its lease has lapsed.

#### Read-backs: is a post live?

An officer offered `officer_post_draft` is also offered
**`officer_post_readback`**: it asks the plugin bound to it whether a post is
live upstream, and which account the plugin's venue session is signed in to,
so the officer can settle "did draft 42 go out, and on which account?" without
asking you. **A read-back sends nothing**: it files no draft, approves,
retries or re-files nothing, and the plugin must only read.

The officer names what to look for — `draft_id` (one of ITS drafts on that
plugin: muster hands the plugin the draft's exact body, target kind and ref,
the parent a reply answers, any reference it was posted as, and when the draft
was written — the post cannot be older, so search no further back and never
take an older post with the same text for it), `post_ref`, or the exact
`text` — plus `venue`, and optionally `parent_ref` (a reply's thread),
`account` (the handle it expects; a leading `@` is dropped) and `project`.
At most 20 a day and 5 unanswered per officer. The plugin must be a live
plugin of the officer's owner bound to that officer; another owner's plugin,
or one of the owner's that is not bound to it, is refused.

##### `POST /plugin/v1/readbacks/claim`

`{"limit": 1-5}` (out-of-range values are clamped) answers at once,
`200 {"readbacks": [...]}`, empty when none is waiting. Each is leased to your
plugin for 15 minutes; one you do not answer in time is handed out again, with
`attempts` one higher:

```json
{"readback_id": 7, "venue": "example.social", "account": "example", "project": null,
"post_ref": null, "text": null, "parent_ref": null,
"draft": {"draft_id": 42, "body": "…", "target_kind": "reply", "target_ref": "123",
"parent_ref": "123", "external_ref": null, "created_at": "…"},
"attempts": 1, "lease_until": "…"}
```

Only your plugin's read-backs are handed to you. A plugin that does not know
the route keeps working: nothing else waits on it.

##### `POST /plugin/v1/readbacks/{id}/answer`

`{"status": "found"|"absent"|"unknown", "post_ref", "url", "account_seen", "detail"}`:

| field | rule |
|---|---|
| `status` | `found`: the post is live; `absent`: you read every place you check (for a post, at least two: absence in one read proves nothing) and it is not there; `unknown`: you could not tell |
| `post_ref`, `url` | only with `found`: the post's id (1-200 bytes, no spaces) and its absolute `http(s)` URL |
| `account_seen` | the handle your venue session is signed in to, when you could read it |
| `detail` | what you read, at most 1000 bytes; the officer reads it as data |

`200 {"readback_id", "status", "item_id"}`: the answer is now ONE item of kind
`plugin.readback` in the officer's queue (subject `readback:<id>`), carrying
the request as filed, the answer, and `account_matches` when both an expected
and a seen account are known. The first answer wins: a repeat answers the
stored one. `404` a read-back that is not your plugin's; `400` a bad field;
`409` one you have not claimed, or the officer is no longer defined for its
owner (nothing recorded).

Muster answers a read-back `unknown` itself (`answered_by: "muster"`), on a
timer, so the officer always hears back: once it was handed out 3 times with
no answer, or once 6 hours passed with no claim from your plugin — counted from
the later of its filing and your plugin's last claim. A claim never gives one
up for time: your plugin is handed every open read-back the timer has not
already answered. Never while your lease on it is live.

#### Outreach drafts: dm, follow, like

An outbound draft that reaches a **person** — a DM, a follow, a like, or a
Expand Down
2 changes: 1 addition & 1 deletion internal/api/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ func (s *Server) toolsFor(ctx context.Context, a agents.Agent) []agentTool {
continue
}
// officer_post_draft: also its type's outbound_drafts grant, read now
if (t.def.Name == officers.ToolPostDraft || t.def.Name == officers.ToolContentDue) && !s.officerOutboundGranted(ctx, o) {
if (t.def.Name == officers.ToolPostDraft || t.def.Name == officers.ToolContentDue || t.def.Name == officers.ToolPostReadback) && !s.officerOutboundGranted(ctx, o) {
continue
}
// the contact tools: also its type's contacts grant, read now
Expand Down
1 change: 1 addition & 0 deletions internal/api/host_stepup.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ var hostStepUpExempt = map[string]string{
officers.ToolAskPerson: "a host instance's own (hostOfficerMirrorTool)",
officers.ToolPostDraft: "a host instance's own (hostOfficerMirrorTool); the draft itself waits for the owner",
officers.ToolContentDue: "a host instance's own (hostOfficerMirrorTool); a read",
officers.ToolPostReadback: "a host instance's own (hostOfficerMirrorTool); asks its bound plugin to read a post back, which sends nothing",
officers.ToolContactGet: "a host instance's own (hostOfficerMirrorTool)",
officers.ToolContactsList: "a host instance's own (hostOfficerMirrorTool)",
officers.ToolContactNote: "a host instance's own (hostOfficerMirrorTool); it can only set a mark",
Expand Down
2 changes: 1 addition & 1 deletion internal/api/host_stepup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func TestEveryMirrorToolIsClassifiedForTheStepUp(t *testing.T) {
chiefAskTool, chiefRestartTool, "connector_request", "connector_status", "connectors_list", connectorRequestsListTool,
dispatchRequestTool, internalHTTPToolName, notifyOwnerTool, officers.ToolAskPerson, officers.ToolBrief, officers.ToolClaim,
officers.ToolComplete, officers.ToolContactGet, officers.ToolContactNote, officers.ToolContactsList, officers.ToolEngagementByPost, officers.ToolHeartbeat,
officers.ToolItems, officers.ToolPostDraft, officers.ToolContentDue, officers.ToolPagePublish, officers.ToolRelease, officers.ToolTaskCreate, officers.ToolTaskHandoff, pageAssetDeleteTool, pageAssetUploadTool, pageCreateTool, pageGetTool, pageLinkRevokeTool,
officers.ToolItems, officers.ToolPostDraft, officers.ToolContentDue, officers.ToolPostReadback, officers.ToolPagePublish, officers.ToolRelease, officers.ToolTaskCreate, officers.ToolTaskHandoff, pageAssetDeleteTool, pageAssetUploadTool, pageCreateTool, pageGetTool, pageLinkRevokeTool,
pageListTool, pageResponsesTool, pageShareRequestTool, pageUpdateTool, pluginDraftRetryTool, pluginDraftsListTool, pluginMessagesListTool,
pluginOutboundBatchGetTool, pluginRequestsListTool, postgresQueryToolName, taskCommentTool, taskGetTool,
taskSetStatusTool, tasksListTool, trackTaskTool, taskAttachTool,
Expand Down
32 changes: 24 additions & 8 deletions internal/api/isolation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,11 @@ var isolationClasses = map[string]routeClass{
// A stamped direct reply (owner_replies.go): it names A's message by id,
// which B's plugin must not settle (404, as a missing one).
"POST /plugin/v1/messages/{id}/owner-answered": classPlugin,
// An officer's read-backs (plugin_readbacks.go): the claim names nothing
// and sees only this plugin's rows; the answer names A's read-back by id,
// which B's plugin must not answer (404, as a missing one).
"POST /plugin/v1/readbacks/claim": classPlugin,
"POST /plugin/v1/readbacks/{id}/answer": classPlugin,

// The mirrored rendered view (tunnel v2) addresses its session like the
// mirrored terminal above (?host=&session=); the
Expand Down Expand Up @@ -1403,6 +1408,14 @@ func newIsoWorld(t *testing.T) *isoWorld {
must(err, "a write queued on the reference")
_, err = ns.ClaimRefWrites(ua, aPlugin1.ID, 1, time.Hour)
must(err, "the reference's write leased to A's plugin")
// A's officer's read-back for A's FIRST plugin (0210): the object POST
// /plugin/v1/readbacks/{id}/answer names (the canary in the text it asks
// for). A's own plugin answering reaches it (the walk wires no officer
// store, so 409) where a ghost's is 404; B's plugin must get the ghost's.
var aReadback int64
err = pool.QueryRow(ua, `INSERT INTO plugin_readbacks (plugin_id, officer, instance, request) VALUES ($1, 'marketing:a', 'officer-marketing-a-1', $2) RETURNING id`,
aPlugin1.ID, `{"venue":"x","text":"`+w.canary+` post"}`).Scan(&aReadback)
must(err, "a read-back")
// A's chief routed that message to a mirrored session (0021): the object
// POST /api/routes/{id}/reply names.
aRoute, err := ps.CreateRoute(ua, w.a.agent.ID, w.a.uid, aMsg.ID,
Expand Down Expand Up @@ -1545,7 +1558,7 @@ func newIsoWorld(t *testing.T) *isoWorld {
tag: w.aTag, link: w.aSessionLink, mirrorHost: w.canary + "-host", mirrorSession: "main", token: w.aToken2.ID,
pushDevice: w.objA.pushDevice, flowJob: w.aJob.ID, runnerTok: w.aRunner2.ID, flowReq: w.aFlowReq.ID,
plugin: w.aPlugin2.ID, draft: w.aDraft.ID, queued: aQueued.ID, route: aRoute.RouteID, upload: aUpload.PublicID, ask: aAsk.ID,
pluginMsg: aMsg.ID, refWrite: aRefWrite.ID, refTask: aRef.Note.ID, rule: aRuleOn, ruleOff: aRuleOff, ruleDel: aRuleDel,
pluginMsg: aMsg.ID, readback: aReadback, refWrite: aRefWrite.ID, refTask: aRef.Note.ID, rule: aRuleOn, ruleOff: aRuleOff, ruleDel: aRuleDel,
page: aPage.ID, pageLink: aPageLink.ID, pageDel: aPageDel.ID, pageResp: aPageResp.ID, team: w.aTeam,
officerType: aOffType, officer: aOffType + ":a", officerItem: aOffItem, spawn: aSpawn.ID, morningDate: isoMorningDate}
// The ghost: ids and names that exist for NOBODY. A refusal of A's object
Expand All @@ -1556,7 +1569,7 @@ func newIsoWorld(t *testing.T) *isoWorld {
mirrorHost: "ghost-host", mirrorSession: "main", ccAccount: "ghostacct", token: ghostID, pushDevice: ghostID,
flowJob: ghostID, runnerTok: ghostID, flowReq: ghostID, plugin: ghostID, draft: ghostID, passkey: "00000000-0000-4000-a000-00000000ghost",
queued: ghostID, route: "rt_000000000000000000000000", upload: "GhostGhostGhostGhost00", ask: ghostID, pluginMsg: ghostID, standing: ghostID,
device: ghostID, refWrite: ghostID, refTask: ghostID, rule: ghostID, ruleOff: ghostID, ruleDel: ghostID,
device: ghostID, readback: ghostID, refWrite: ghostID, refTask: ghostID, rule: ghostID, ruleOff: ghostID, ruleDel: ghostID,
chief: ghostID, chiefChat: ghostID, chiefName: "ghost-agent" + w.suffix,
page: ghostID, pageLink: ghostID, pageDel: ghostID, pageResp: ghostID,
officerType: "ghostofficer", officer: "ghostofficer:a", officerItem: ghostID, morningDate: "1999-01-01"}
Expand Down Expand Up @@ -1920,6 +1933,7 @@ type isoObjs struct {
upload string // a file attachment's public id (0024)
route string // a session route's id (0021)
pluginMsg int64 // a plugin message's id (its retry route)
readback int64 // an officer's read-back for A's first plugin (0210)
refWrite int64 // a write queued on a plugin task reference (0072)
refTask int64 // the reference refWrite is on (its retry/dismiss routes' {id})
ask int64 // an attention ask's id (0025)
Expand Down Expand Up @@ -2020,6 +2034,8 @@ func (w *isoWorld) fill(pattern string, o isoObjs, actor isoUser) (method, path,
id = strconv.FormatInt(o.draft, 10)
case strings.HasPrefix(path, "/plugin/v1/task-writes/{id}"):
id = strconv.FormatInt(o.refWrite, 10)
case strings.HasPrefix(path, "/plugin/v1/readbacks/{id}"):
id = strconv.FormatInt(o.readback, 10)
case strings.Contains(path, "/ref-writes/{wid}"):
// The owner's retry/dismiss: {id} is the reference the write is on
// ({wid} is replaced below). A's write is leased (then settled by A's
Expand Down Expand Up @@ -2133,9 +2149,9 @@ func (w *isoWorld) fill(pattern string, o isoObjs, actor isoUser) (method, path,
// A whole valid message: what B's plugin posts is accepted as B's own.
// The draft routes' fields ride along: a claim that does not wait, a
// result and a check verdict (so a refusal is about WHOSE draft, not a
// malformed body).
// malformed body), and a read-back's answer status.
return method, path, `{"external_id":"iso-` + w.suffix + `-` + strconv.FormatInt(actor.uid, 10) +
`","sender":"iso","subject":"iso-write","body":"iso-write","wait_seconds":0,"ok":true,"sendable":true}`
`","sender":"iso","subject":"iso-write","body":"iso-write","wait_seconds":0,"ok":true,"sendable":true,"status":"unknown"}`
}
if strings.HasPrefix(path, "/api/") || strings.HasPrefix(path, "/agent/") || path == "/mcp" || strings.HasPrefix(path, "/connect/") ||
strings.HasPrefix(path, "/runner/") {
Expand Down Expand Up @@ -2638,8 +2654,8 @@ func TestNoRouteLetsOneUserReachAnothersData(t *testing.T) {
t.Errorf("CONTROL: B's personal API token was admitted on only %d routes — the leg is not walking", tokAdmitted)
}
// The plugin-token leg too: B's plugin must have been ADMITTED on its own
// door (its message stored as B's, its two claims — the drafts' and the
// task writes' — answered "nothing for you", and GET /plugin/v1/self naming
// door (its message stored as B's, its three claims — the drafts', the
// task writes' and the read-backs' — answered "nothing for you", and GET /plugin/v1/self naming
// B's own plugin, and GET /plugin/v1/drafts/checks listing only B's own
// drafts awaiting a check), or its clean answers
// everywhere else are only the refusal of an unknown token. The result
Expand All @@ -2654,8 +2670,8 @@ func TestNoRouteLetsOneUserReachAnothersData(t *testing.T) {
}
}
}
if plugAdmitted != 5 {
t.Errorf("CONTROL: B's plugin token was admitted on %d routes; want exactly its own message, two claim routes, its drafts awaiting a check and its self", plugAdmitted)
if plugAdmitted != 6 {
t.Errorf("CONTROL: B's plugin token was admitted on %d routes; want exactly its own message, three claim routes, its drafts awaiting a check and its self", plugAdmitted)
}
// The device-credential leg: B's device must have been ADMITTED on its own
// tier (its config read, its own unpair) and nowhere else. The push PUT is
Expand Down
6 changes: 5 additions & 1 deletion internal/api/officer_builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,17 @@ func (s *Server) RunOfficerAttentionSweep(ctx context.Context, interval time.Dur
// withdraws its duplicate), and every settled escalation ask is carried back
// (settleOfficerEscalation). First, with or without the attention store,
// every HELD draft.refused item whose officer is back under the bound is
// delivered (promoteHeldRefusals).
// delivered (promoteHeldRefusals), and every read-back its plugin will not
// answer is answered unknown (sweepReadbacks).
func (s *Server) SweepOfficerAttention(ctx context.Context) {
if s.officerStore == nil {
return
}
sys := authz.System(ctx)
s.promoteHeldRefusals(sys)
// Read-backs no plugin will answer (plugin_readbacks.go): with or
// without the attention store, as the held refusals.
s.sweepReadbacks(ctx, sys)
if s.ext.Attention == nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion internal/api/officer_task_create_pg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ func TestABuiltinOfficersSessionPreAllowsItsTaskTools(t *testing.T) {
t.Fatal("no session for the officer's instance")
}
want := "officer_brief,officer_items,officer_claim,officer_heartbeat,officer_complete,officer_release,officer_ask_person," +
"officer_post_draft,officer_content_due,officer_contact_get,officer_contacts_list,officer_contact_note,officer_engagement_by_post," +
"officer_post_draft,officer_content_due,officer_post_readback,officer_contact_get,officer_contacts_list,officer_contact_note,officer_engagement_by_post," +
"officer_my_state,officer_confirm_card,officer_refusal_refile,officer_refusal_drop,officer_task_create,officer_task_handoff," +
"tasks_list,task_get,task_comment,connectors_list,connector_request,connector_status"
if got := strings.Join(sess.AllowMCPTools, ","); got != want {
Expand Down
4 changes: 3 additions & 1 deletion internal/api/officers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1740,7 +1740,7 @@ func (s *Server) protectedRefusal(a agents.Agent) string {
// officer: each acts for the caller's own (officerOf).
func officerToolDefs() []agents.ToolDef {
defs := append(append(append(queueToolDefs(), shipToolDefs()...), kubeReadToolDef(), obsRawToolDef()), taskReadToolDefs()...)
defs = append(append(append(defs, itemAskToolDefs()...), prContextToolDef(), gapTaskToolDef(), rolloutEvidenceToolDef(), postDraftToolDef(), contentDueToolDef()), contactToolDefs()...)
defs = append(append(append(defs, itemAskToolDefs()...), prContextToolDef(), gapTaskToolDef(), rolloutEvidenceToolDef(), postDraftToolDef(), contentDueToolDef(), postReadbackToolDef()), contactToolDefs()...)
return append(append(defs, ownStateToolDefs()...), officerPageToolDef(), officerTaskCreateToolDef(), officerTaskHandoffToolDef())
}

Expand Down Expand Up @@ -2124,6 +2124,8 @@ func (s *Server) dispatchOfficerTool(ctx context.Context, a agents.Agent, name,
return s.officerPostDraft(ctx, a, o, c, arguments), true // plugin_outbound.go
case officers.ToolContentDue:
return s.officerContentDue(ctx, o), true // content_sets.go
case officers.ToolPostReadback:
return s.officerPostReadback(ctx, a, o, arguments), true // plugin_readbacks.go
case officers.ToolContactGet, officers.ToolContactsList, officers.ToolContactNote, officers.ToolEngagementByPost:
return s.officerContactTool(ctx, a, o, name, arguments), true // officer_contacts.go
case officers.ToolMyState, officers.ToolConfirmCard, officers.ToolRefusalRefile, officers.ToolRefusalDrop:
Expand Down
2 changes: 2 additions & 0 deletions internal/api/plugin_capabilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ var pluginRouteCapabilities = map[string]string{
"POST /plugin/v1/drafts/claim": "messages",
"POST /plugin/v1/drafts/{id}/result": "messages",
"POST /plugin/v1/drafts/{id}/renew": "messages",
"POST /plugin/v1/readbacks/claim": "messages",
"POST /plugin/v1/readbacks/{id}/answer": "messages",
"POST /plugin/v1/tasks": "messages or tasks",
"GET /plugin/v1/tasks": "messages",
"POST /plugin/v1/task-writes/claim": "messages",
Expand Down
Loading
Loading