@sgtbeatdown/pi-tasks 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -118
- package/package.json +3 -5
- package/skills/wolfpack-pi-task-delegation/SKILL.md +33 -21
- package/src/extension.ts +112 -28
- package/src/index.ts +1 -1
- package/src/task-core.ts +128 -38
- package/src/task-inbox.ts +58 -17
- package/src/task-protocol.ts +16 -0
- package/src/task-store.ts +28 -141
- package/src/gateway-client.ts +0 -409
- package/src/legacy-extension.ts +0 -241
- package/src/legacy-task-inbox.ts +0 -148
- package/src/metrics-cli.ts +0 -20
- package/src/metrics.ts +0 -288
- package/src/task-artifacts.ts +0 -153
- package/src/task-board.ts +0 -365
- package/src/v1-compat-extension.ts +0 -1
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# pi-tasks
|
|
2
2
|
|
|
3
|
-
`pi-tasks` is
|
|
3
|
+
`pi-tasks` is an endpoint-owned Pi extension for Wolfpack relay v2. It keeps task state in each Pi endpoint's local SQLite store and uses Wolfpack as a content-blind relay. It never writes assignments to terminals. Wolfpack's [relay v2 control-api contract](https://github.com/almogdepaz/wolfpack/blob/main/docs/control-api-schema.md#pi-tasks-relay-v2-boundary) is canonical for the transport boundary.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## endpoint-owned relay
|
|
6
6
|
|
|
7
|
-
The default extension uses the configured local Wolfpack relay
|
|
7
|
+
The default extension uses the configured local Wolfpack relay, never the in-memory conformance relay. It registers an opaque endpoint with `POST /api/task-relay/v2/connect`, stores task state at the deterministic per-session path `~/.pi/tasks/v2/sessions/<sha256(WOLFPACK_SESSION_NAME)>/tasks.sqlite`, and exchanges opaque relay envelopes through Wolfpack. The adapter requires a Wolfpack release exposing the stable [relay v2 control-api contract](https://github.com/almogdepaz/wolfpack/blob/main/docs/control-api-schema.md#pi-tasks-relay-v2-boundary).
|
|
8
8
|
|
|
9
9
|
Set `WOLFPACK_SESSION_NAME` for every Pi process. The adapter uses `WOLFPACK_PORT` when the local control port differs from `18790`; `WOLFPACK_SESSION_NAME` resolves the active Pi process to its relay endpoint. After the target extension registers, run `wolfpack session status <session> --json` and read its `taskEndpoint`. Pass that opaque `{ relay, id }` value unchanged; do not derive it from a session name, broker ID, terminal label, output, or prose.
|
|
10
10
|
|
|
@@ -20,107 +20,42 @@ Set `WOLFPACK_SESSION_NAME` for every Pi process. The adapter uses `WOLFPACK_POR
|
|
|
20
20
|
}
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
The
|
|
23
|
+
The `agent_task_send` schema is exactly `to`, `task`, and optional `timeoutMs`. Unsupported fields are rejected before persistence: a pre-persistence validation rejection creates no task. If creation status is uncertain after a transport failure, idempotency remains necessary; inspect the structured task ID rather than creating an unrelated replacement.
|
|
24
24
|
|
|
25
|
-
Wolfpack
|
|
25
|
+
Wolfpack owns durable mailbox delivery and peer forwarding; Pi owns lifecycle, logical event order, receipts, and local SQLite state. `agent_task_send` returns after relay acceptance only, not Pi insertion or model execution. The receiver inserts model-visible events as structured `pi-tasks-event` custom messages through Pi's safe `deliverAs: "followUp"` queue and records structured `{ taskId, eventId }` insertion evidence. Replay after Pi has structurally recorded an event cannot create another logical receipt. `createInMemoryTaskRelay` remains exported solely as a deterministic conformance fixture.
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
## delegation workflow
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
Configure Pi role models with `WOLFPACK_IMPLEMENTER_MODEL` and `WOLFPACK_REVIEWER_MODEL`; they default to `openai-codex/gpt-5.6-terra` and `openai-codex/gpt-5.6-sol`. Explicit user or project choices override those defaults.
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
IMPLEMENTER_MODEL="${WOLFPACK_IMPLEMENTER_MODEL:-openai-codex/gpt-5.6-terra}"
|
|
33
|
+
REVIEWER_MODEL="${WOLFPACK_REVIEWER_MODEL:-openai-codex/gpt-5.6-sol}"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
1. create or select a role session. For a disposable worker, omit an initial assignment prompt and pass the resolved role model: `wolfpack agent spawn <project> --name <task-role> --model "$IMPLEMENTER_MODEL" --json` (or `"$REVIEWER_MODEL"` for review). Put all worker instructions in `agent_task_send.task` so the new Pi process can become idle before assignment.
|
|
30
37
|
2. verify structured session readiness, wait for extension registration, and read `taskEndpoint` from `wolfpack session status <session> --json`.
|
|
31
|
-
3. call `agent_task_send` with that endpoint and the complete
|
|
38
|
+
3. call `agent_task_send` with that endpoint and the complete instructions. Keep working; use `agent_task_status` or `agent_task_inbox` for structured evidence, and call `agent_task_wait` only when explicitly asked to block.
|
|
32
39
|
4. use `agent_task_message` for durable questions, answers, and information. The receiver calls `agent_task_done` as its final action; no completion prose follows.
|
|
33
40
|
5. independently verify the result, call `agent_task_ack({ taskId })` once for that terminal task, then explicitly retain or close only the role sessions the parent spawned.
|
|
34
41
|
|
|
35
|
-
|
|
42
|
+
Coordinator-capable agents may delegate further when justified, and the spawning coordinator owns each child's lifecycle. After terminal completion and acknowledgment, deliberately retain the child or run `wolfpack kill <stable-session-id> --json`, then verify that exact ID is absent from `wolfpack list --json`. Never use `wolfpack session send`, `/exit`, or `/quit` for cleanup; terminal input is not Wolfpack teardown.
|
|
36
43
|
|
|
37
|
-
|
|
44
|
+
## worker-only execution gate
|
|
38
45
|
|
|
39
|
-
`PI_TASK_WORKER=1`
|
|
46
|
+
Set `PI_TASK_WORKER=1` only when launching a task-only worker. The exact value enables a fail-closed model `tool_call` gate; an absent value or any other value leaves ordinary interactive Pi behavior unchanged. Before assignment, only `agent_task_inbox`, `agent_task_status`, and `agent_task_wait` are allowed. Other current and future model tools are blocked with `PI_TASK_WORKER_ASSIGNMENT_REQUIRED`. Explicit user `!`/`!!` shell commands are outside Pi's model `tool_call` event and are not intercepted.
|
|
47
|
+
|
|
48
|
+
`PI_TASK_WORKER=1` sessions are leaf roles. Workers cannot call `agent_task_send`, `agent_task_cancel`, or `agent_task_ack`; those attempts are blocked with `PI_TASK_WORKER_COORDINATION_FORBIDDEN`. `agent_task_message` is limited to the eligible incorporated assignment named by its input `taskId`. Generic role-orchestration guidance applies only to non-worker coordinators.
|
|
40
49
|
|
|
41
50
|
The gate opens only when the current Pi session contains a structured `pi-tasks-event` entry for `task.created` and the same event belongs to a locally persisted active task targeted to the current endpoint. Rendered prompt text, terminal output, unknown events, foreign tasks, and stale terminal tasks do not authorize execution. On restart, durable session evidence reopens the gate only while the matching local task remains eligible.
|
|
42
51
|
|
|
43
52
|
Preflighting `agent_task_done` marks that task as closing before sibling calls are preflighted. Ordinary tools remain blocked for a closing, pending-terminal, accepted-terminal, or `delivery_blocked` task; an idempotent `agent_task_done` retry for that same assigned task remains allowed. Another independently active assignment can still authorize work.
|
|
44
53
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
A receiver task snapshot reports terminal transport separately as `terminalDelivery`: `not_submitted`, `pending`, `accepted`, or `delivery_blocked`. The blocked variant includes the stable intent/envelope identities, origin endpoint, timestamp, and structured non-retryable relay error. Canonical task `status` remains origin-owned and is never changed to `delivery_blocked`. Retryable failures keep the same pending terminal intent and envelope; permanent failures remain inspectable and are not rebound to a successor endpoint without a separate authenticated Wolfpack contract.
|
|
48
|
-
|
|
49
|
-
`agent_task_ack` is valid only for a terminal origin-owned task. Sequential, concurrent, and restart retries reuse one durable `task.parent_acknowledged` event and the same destination envelope identities while still retrying any pending physical delivery.
|
|
50
|
-
|
|
51
|
-
## v1 gateway adapter (retained)
|
|
52
|
-
|
|
53
|
-
The v1 gateway client is available only through the published `@sgtbeatdown/pi-tasks/v1-compat-extension` entry. This is an explicit opt-in: after resolving the installed package root, add `src/v1-compat-extension.ts` as an extension path in Pi settings instead of loading the package default. The package manifest loads only `src/extension.ts` (v2); v2 does not fall back to v1 when its relay is unavailable or incompatible. Its v1 behavior and operational requirements are documented below.
|
|
54
|
-
|
|
55
|
-
## requirements and trust boundary
|
|
56
|
-
|
|
57
|
-
- a reachable local Wolfpack v1 task gateway on every participating machine;
|
|
58
|
-
- this package loaded in every participating Pi process;
|
|
59
|
-
- `WOLFPACK_SESSION_NAME` set by Wolfpack so the local gateway can resolve the caller to a stable broker ID; and
|
|
60
|
-
- `WOLFPACK_PORT` when the local control port is not the default `18790`.
|
|
61
|
-
|
|
62
|
-
The boundary is trusted local processes and trusted Tailnet machines. Pi only calls its own local gateway. The gateways perform direct fetch federation; Pi never fetches a peer directly. v1 adds no task capability authentication. Normal Wolfpack global JWT behavior is not bypassed, and JWT federation is unsupported: peer delivery fails clearly when credentials would be required.
|
|
63
|
-
|
|
64
|
-
## task address and send
|
|
65
|
-
|
|
66
|
-
A target is always `{ machine, sessionId }`, where `sessionId` is the stable opaque broker ID returned by Wolfpack session control. Use `machine: "local"` for same-machine work. For a peer, use the receiver's canonical HTTPS Tailnet origin, for example `https://worker.example.ts.net`; do not supply a hostname label, path, query, fragment, credentials, unexpected port, or arbitrary HTTPS URL.
|
|
67
|
-
|
|
68
|
-
```json
|
|
69
|
-
{
|
|
70
|
-
"to": { "machine": "local", "sessionId": "receiver-broker-id" },
|
|
71
|
-
"task": "implement the narrow change and run focused tests",
|
|
72
|
-
"context": {
|
|
73
|
-
"summary": "## constraints and preferences\n- keep scope narrow\n## key decisions\n- preserve the public contract",
|
|
74
|
-
"refs": [{ "path": "src/extension.ts", "purpose": "affected tool wiring" }]
|
|
75
|
-
},
|
|
76
|
-
"metadata": { "phaseId": "phase-1", "issueId": "task-3", "verificationTier": "focused" },
|
|
77
|
-
"onCompletePrompt": "review the receiver diff before reporting completion",
|
|
78
|
-
"timeoutMs": 1800000
|
|
79
|
-
}
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
### v1 minimal valid send envelope
|
|
83
|
-
|
|
84
|
-
```json
|
|
85
|
-
{
|
|
86
|
-
"to": {
|
|
87
|
-
"machine": "local",
|
|
88
|
-
"sessionId": "receiver-broker-id"
|
|
89
|
-
},
|
|
90
|
-
"task": "implement the narrow change and run focused tests"
|
|
91
|
-
}
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
`INVALID_REQUEST.error.path` is an optional RFC 6901 JSON Pointer to the rejected send field, for example `/preflight/requiredProject`; use it rather than parsing error prose. A pre-persistence validation rejection creates no task, so correct the field and retry. If creation status is uncertain, idempotency remains necessary.
|
|
95
|
-
|
|
96
|
-
Remote addressing changes only `to.machine`:
|
|
97
|
-
|
|
98
|
-
```json
|
|
99
|
-
{ "to": { "machine": "https://worker.example.ts.net", "sessionId": "receiver-broker-id" }, "task": "review the cited diff" }
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
Context is optional, curated Markdown plus deliberately selected ref metadata. The extension renders refs but never reads or copies their contents. Relative refs resolve in the receiver project; absolute refs are same-machine only and must remain inside the authoritative parent or receiver project root. Missing refs are warnings, not copied content or transcript transfer.
|
|
103
|
-
|
|
104
|
-
Initial limits are 16 KiB UTF-8 each for task instructions and context summary, 48 KiB for the assignment envelope, and 64 KiB for an HTTP request body. The initial size limits require representative payload benchmarking before adjustment.
|
|
105
|
-
|
|
106
|
-
`agent_task_send` waits for durable gateway acceptance, not adapter insertion or task execution; delivery remains pending until `task.delivered`. A remote initial send has one initial attempt: the receiver persists a provisional receipt, then receives sender confirmation before Pi can see the assignment. Later peer confirmation, messages, terminal updates, cancellation, delivery notices, and parent acknowledgment have four total attempts: the initial attempt plus retries around 1, 2, and 4 seconds with jitter. Exhaustion is a visible local delivery failure, not a background queue or offline dispatch promise.
|
|
107
|
-
|
|
108
|
-
Normal delegation is fire-and-forget. Use `agent_task_wait` only when the user explicitly asks to block.
|
|
109
|
-
|
|
110
|
-
## tools, messages, and acknowledgment
|
|
54
|
+
## terminal delivery and acknowledgment
|
|
111
55
|
|
|
112
|
-
|
|
113
|
-
| --- | --- |
|
|
114
|
-
| `agent_task_send` | create a durable gateway assignment |
|
|
115
|
-
| `agent_task_status` | read task state, history, result, and warnings |
|
|
116
|
-
| `agent_task_wait` | explicitly poll a task until terminal or timeout |
|
|
117
|
-
| `agent_task_inbox` | read task events without acknowledgment |
|
|
118
|
-
| `agent_task_ack` | acknowledge one independently verified terminal task |
|
|
119
|
-
| `agent_task_message` | send a durable `question`, `answer`, or `information` event |
|
|
120
|
-
| `agent_task_cancel` | request cancellation |
|
|
121
|
-
| `agent_task_done` | receiver-only terminal completion; terminates the tool turn |
|
|
56
|
+
A receiver task snapshot reports terminal transport separately as `terminalDelivery`: `not_submitted`, `pending`, `accepted`, or `delivery_blocked`. The blocked variant includes stable intent/envelope identities, origin endpoint, timestamp, and structured non-retryable relay error. Canonical task `status` remains origin-owned and is never changed to `delivery_blocked`. Retryable failures keep the same pending terminal intent and envelope; permanent failures remain inspectable and are not rebound to a successor endpoint without a separate authenticated Wolfpack contract.
|
|
122
57
|
|
|
123
|
-
|
|
58
|
+
`agent_task_ack` is valid only for a terminal origin-owned task. Sequential, concurrent, and restart retries reuse one durable `task.parent_acknowledged` event and the same destination envelope identities while retrying pending physical delivery.
|
|
124
59
|
|
|
125
60
|
Report source modifications in `result.changedFiles`. Artifacts are receiver-project-relative regular files for a parent to inspect, not a changed-file list:
|
|
126
61
|
|
|
@@ -128,36 +63,6 @@ Report source modifications in `result.changedFiles`. Artifacts are receiver-pro
|
|
|
128
63
|
{ "result": { "changedFiles": ["src/extension.ts"] }, "artifacts": [{ "path": "verification/task-2.md" }] }
|
|
129
64
|
```
|
|
130
65
|
|
|
131
|
-
See the canonical Wolfpack artifact contract for provenance, containment, and warning behavior.
|
|
132
|
-
|
|
133
|
-
The sender gateway owns canonical event order, timeout, and terminal state. The first accepted terminal event wins. Sender timeout triggers best-effort remote cancellation; late terminals remain diagnostics. After independently verifying one terminal result, call `agent_task_ack({ taskId })`. Remote acknowledgment is two-phase: the receiver durably confirms pending acknowledgment before the sender records final parent acknowledgment. If that delivery fails, the task remains visible and a later explicit acknowledgment repairs it with the same event ID.
|
|
134
|
-
|
|
135
|
-
## structured delivery and replay
|
|
136
|
-
|
|
137
|
-
The extension polls the local gateway every five seconds. With no pending message, it submits each visible event as a structured custom message using Pi's safe `deliverAs: "followUp"` mode: idle Pi starts immediately, while an active turn finishes before the queued event starts the next turn. It never steers or interrupts active work. Delivery remains pending until `task.delivered`. The `{ taskId, eventId }` details let task context participate in the session without parsing prose.
|
|
138
|
-
|
|
139
|
-
On start or resume it rebuilds incorporated IDs from the full durable session entry set, not only active prompt context. A session gets only missing events; a new Pi session in the same Wolfpack PTY gets complete active history. The receiver records gateway delivery only after the structured insertion exists. A restart after insertion and before acknowledgment therefore acknowledges the existing entry without duplicate injection. Unknown model-visible events fail closed without advancing the cursor. Gateway delivery is at-least-once; this does not claim exactly-once model execution.
|
|
140
|
-
|
|
141
|
-
## parent workflow
|
|
142
|
-
|
|
143
|
-
1. create or select a Wolfpack Pi session with the canonical session-control workflow and retain its stable broker ID. Spawn a disposable worker without an initial model prompt using `wolfpack agent spawn <project> --name <task-role> --json` so it reaches idle before assignment; put worker instructions in `agent_task_send.task`.
|
|
144
|
-
2. before remote dispatch, complete Wolfpack's [Live-peer readiness checklist](https://github.com/almogdepaz/wolfpack/blob/main/docs/task-gateway.md#live-peer-readiness-checklist) and retain operator-recorded package/reload evidence; only then check the target's local requirements and send compact instructions with curated context and selected refs when they save receiver investigation.
|
|
145
|
-
3. keep working; use `agent_task_status` or `agent_task_inbox` for structured follow-up, and `agent_task_message` for questions, answers, and decisions.
|
|
146
|
-
4. verify cited files, diffs, tests, and paths-only artifact metadata independently before reporting success.
|
|
147
|
-
5. acknowledge the accepted terminal result, then clean up only sessions this parent spawned. Keep a reusable implementer alive while review or correction remains possible; never make workers close their own sessions.
|
|
148
|
-
|
|
149
|
-
Isolated coverage is the deterministic acceptance gate, but a specific live peer still requires current readiness at the time of use. If the checklist cannot pass, stop before task creation and report fixture-only verification. Do not use direct peer URLs from Pi.
|
|
150
|
-
|
|
151
|
-
See `skills/wolfpack-pi-task-delegation/SKILL.md` for the operational workflow and `skills/task-context-summary/SKILL.md` for recovery/reuse summaries.
|
|
152
|
-
|
|
153
|
-
## deferred follow-up
|
|
154
|
-
|
|
155
|
-
These are documented operational debt, not production TODOs: exact Pi runtime registration and heartbeat/capability leases; durable offline initial dispatch; JWT/authenticated peer federation; artifact byte transfer and retention; representative payload benchmarking; automated recovery summaries; and summary caching only after measured repeated-generation waste. v1 has no queue, scheduler, artifact transfer, or transcript transfer.
|
|
156
|
-
|
|
157
|
-
## legacy historical metrics
|
|
158
|
-
|
|
159
|
-
`task-metrics` and the task board remain read-only analyzers for already-existing historical `.pi/tasks` directories. They are not part of the runtime task protocol and must not create, mutate, or deliver v1 gateway tasks. Replacing or retiring that historical reporting surface requires a product decision about gateway-wide query/metrics ownership.
|
|
160
|
-
|
|
161
66
|
## development
|
|
162
67
|
|
|
163
68
|
```bash
|
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sgtbeatdown/pi-tasks",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Durable Pi agent delegation through
|
|
3
|
+
"version": "0.1.7",
|
|
4
|
+
"description": "Durable endpoint-owned Pi agent delegation through Wolfpack relay v2.",
|
|
5
5
|
"module": "src/index.ts",
|
|
6
6
|
"exports": {
|
|
7
|
-
".": "./src/index.ts"
|
|
8
|
-
"./v1-compat-extension": "./src/v1-compat-extension.ts"
|
|
7
|
+
".": "./src/index.ts"
|
|
9
8
|
},
|
|
10
9
|
"repository": {
|
|
11
10
|
"type": "git",
|
|
@@ -50,7 +49,6 @@
|
|
|
50
49
|
},
|
|
51
50
|
"scripts": {
|
|
52
51
|
"test": "bun test",
|
|
53
|
-
"task-metrics": "bun src/metrics-cli.ts",
|
|
54
52
|
"typecheck": "tsc --noEmit"
|
|
55
53
|
},
|
|
56
54
|
"type": "module"
|
|
@@ -7,27 +7,49 @@ description: Use when opening, selecting, delegating to, checking, or cleaning u
|
|
|
7
7
|
|
|
8
8
|
use `wolfpack-tailnet-control` for session control. this skill covers endpoint-owned v2 task lifecycle, structured handoffs, and parent verification. The package default is the v2 extension described by Wolfpack's [relay v2 control-api contract](https://github.com/almogdepaz/wolfpack/blob/main/docs/control-api-schema.md#pi-tasks-relay-v2-boundary).
|
|
9
9
|
|
|
10
|
+
## choose one assignment mode
|
|
11
|
+
|
|
12
|
+
choose exactly one mode for the initial assignment:
|
|
13
|
+
|
|
14
|
+
- **full-startup mode:** spawn with the complete `--plan`, `--prompt-file`, or concise `--prompt`. do not call `agent_task_send` for that same work.
|
|
15
|
+
- **endpoint mode:** spawn without a startup plan or prompt, obtain the structured `taskEndpoint`, then put the complete assignment in one `agent_task_send.task`.
|
|
16
|
+
|
|
17
|
+
never combine a plan-driven spawn with a narrower endpoint task. prefer one cohesive implementation handoff per approved PR or phase; split only at a real approval, design, isolation, or blocker boundary—not per issue, commit, finding, or verification checkpoint. the remaining v2 workflow below describes endpoint mode.
|
|
18
|
+
|
|
19
|
+
## role model selection
|
|
20
|
+
|
|
21
|
+
Pi role models are explicit and configurable at spawn time:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
IMPLEMENTER_MODEL="${WOLFPACK_IMPLEMENTER_MODEL:-openai-codex/gpt-5.6-terra}"
|
|
25
|
+
REVIEWER_MODEL="${WOLFPACK_REVIEWER_MODEL:-openai-codex/gpt-5.6-sol}"
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Pass `--model "$IMPLEMENTER_MODEL"` when spawning the editing implementer and `--model "$REVIEWER_MODEL"` when spawning the read-only reviewer. an explicit user or project model choice overrides the environment/default. never infer role or model from the session name, and never omit the resolved model because the current parent default may differ.
|
|
29
|
+
|
|
10
30
|
## v2 requirements and addressing
|
|
11
31
|
|
|
12
32
|
- load this package's default extension in every participating Pi process and set `WOLFPACK_SESSION_NAME`. Set `WOLFPACK_PORT` only when the local Wolfpack control port differs from `18790`.
|
|
13
33
|
- address `agent_task_send` targets only as `to: { relay, id }`. For the default Wolfpack adapter, the relay is `wolfpack-pi-tasks-v2` and the ID is opaque.
|
|
14
|
-
- create a disposable worker without an initial
|
|
34
|
+
- create a disposable worker without an initial assignment prompt: `wolfpack agent spawn <project> --name <task-role> --model "$IMPLEMENTER_MODEL" --json` (or `"$REVIEWER_MODEL"` for review). Do not start a disposable worker with a blocking “wait for assignments” prompt. Put the complete instructions in `agent_task_send.task`.
|
|
15
35
|
- after the target extension registers, run structured session control (`wolfpack session status <session> --json`) and read its `taskEndpoint`. Do not derive endpoint IDs from session names, broker IDs, terminal labels, output, or prose.
|
|
16
36
|
- pass the returned endpoint without translation:
|
|
17
37
|
|
|
18
38
|
```json
|
|
19
39
|
{
|
|
20
40
|
"to": { "relay": "wolfpack-pi-tasks-v2", "id": "target-opaque-endpoint-id" },
|
|
21
|
-
"task": "implement the
|
|
22
|
-
"timeoutMs":
|
|
41
|
+
"task": "implement the approved phase and run focused tests",
|
|
42
|
+
"timeoutMs": 3600000
|
|
23
43
|
}
|
|
24
44
|
```
|
|
25
45
|
|
|
26
|
-
The default `agent_task_send` schema is exactly `to`, `task`, and optional `timeoutMs`.
|
|
46
|
+
The default `agent_task_send` schema is exactly `to`, `task`, and optional `timeoutMs`. Unsupported fields are rejected rather than translated. use at least `3600000` milliseconds for coding assignments; timeout is a failure deadline, not a progress-poll interval.
|
|
27
47
|
|
|
28
48
|
## phase roles and handoffs
|
|
29
49
|
|
|
30
|
-
For a multi-step project phase, retain one persistent implementer and one persistent read-only reviewer. Reuse a healthy role session for corrections and follow-up review; a completed task finishes one assignment, not the underlying session. Do not rotate a healthy role session for routine corrections. Rotate only for phase completion, material context degradation, harness failure, or required specialist independence. Keep at most one active assignment per role unless the user explicitly approves parallel work.
|
|
50
|
+
For a multi-step project phase, retain one persistent implementer and one persistent read-only reviewer. Give the implementer the whole approved phase, including required commit ordering and focused verification, rather than opening one task per issue or checkpoint. Reuse a healthy role session for corrections and follow-up review; a completed task finishes one assignment, not the underlying session. Do not rotate a healthy role session for routine corrections. Rotate only for phase completion, material context degradation, harness failure, or required specialist independence. Keep at most one active assignment per role unless the user explicitly approves parallel work.
|
|
51
|
+
|
|
52
|
+
A coordinator-capable agent may delegate further when the quality or throughput gain justifies it. The spawning coordinator owns each child's complete lifecycle: record the stable session ID, acknowledge its terminal task once, then deliberately retain the child or close it with `wolfpack kill <stable-session-id> --json` and verify that exact ID is absent from `wolfpack list --json`.
|
|
31
53
|
|
|
32
54
|
`PI_TASK_WORKER=1` sessions are leaf roles. Workers cannot call `agent_task_send`; workers cannot call `agent_task_cancel`; workers cannot call `agent_task_ack`. These coordinator-tool attempts are blocked with the stable reason `PI_TASK_WORKER_COORDINATION_FORBIDDEN`, not the pre-assignment reason. They may use `agent_task_message` only for the eligible incorporated assignment named by its input `taskId`. Generic role-orchestration guidance applies only to non-worker coordinators. Task workers must not create, rotate, or close Wolfpack sessions through shell or session-control tools.
|
|
33
55
|
|
|
@@ -40,17 +62,17 @@ After every verified and acknowledged terminal task, explicitly retain a parent-
|
|
|
40
62
|
| assignment completion | worker | `agent_task_done` | unchanged |
|
|
41
63
|
| task acknowledgment | parent | `agent_task_ack` | unchanged |
|
|
42
64
|
| role session retention | parent | `none` | retained for reuse |
|
|
43
|
-
| role session teardown |
|
|
44
|
-
| teardown verification |
|
|
45
|
-
| Pi exit | none | `/quit` | not Wolfpack teardown |
|
|
65
|
+
| role session teardown | spawning coordinator | `wolfpack kill <stable-session-id> --json` | exact stable session id terminated |
|
|
66
|
+
| teardown verification | spawning coordinator | `wolfpack list --json` | exact stable session id absent |
|
|
67
|
+
| Pi exit | none | `/exit` or `/quit` | not Wolfpack teardown |
|
|
46
68
|
|
|
47
|
-
Assignment completion ends the assigned task, not the reusable role session. When no further reuse is likely, the
|
|
69
|
+
Assignment completion ends the assigned task, not the reusable role session. When no further reuse is likely, the coordinator that spawned the role—not the worker itself—must pass the exact stable session ID to `wolfpack kill <stable-session-id> --json`, then inspect `wolfpack list --json` and verify that ID is absent. Never use `wolfpack session send`, `/exit`, or `/quit` for cleanup: they are terminal interaction, not Wolfpack teardown. Do not guess lifecycle commands. Workers never close themselves.
|
|
48
70
|
|
|
49
71
|
## v2 workflow
|
|
50
72
|
|
|
51
73
|
1. create or select the role session, verify its structured project and terminal readiness, then obtain its registered `taskEndpoint`.
|
|
52
74
|
2. call `agent_task_send` with the opaque endpoint and concise instructions in `task`. The tool returns after relay acceptance only, not Pi insertion or model execution. If submission reports a retryable delivery error after local persistence, use the structured task ID from the error and inspect it rather than creating an unrelated replacement.
|
|
53
|
-
3. keep working. Use `agent_task_status` or `agent_task_inbox`
|
|
75
|
+
3. keep working. Use `agent_task_status` or `agent_task_inbox` only at meaningful checkpoints or when progress evidence is needed; do not turn status checks into lifecycle chatter. Call `agent_task_wait` only when the user explicitly asks to block.
|
|
54
76
|
4. use `agent_task_message` for durable `question`, `answer`, or `information` flow. Do not use rendered text, terminal output, or logs as lifecycle evidence.
|
|
55
77
|
5. assignees call `agent_task_done` as their final action with the assigned task ID, terminal status, concise summary, and optional structured result, error, and artifact declarations. Report source modifications in `result.changedFiles`; artifacts are receiver-project-relative regular files for a parent to inspect, not changed-file lists: `{ "result": { "changedFiles": ["src/extension.ts"] }, "artifacts": [{ "path": "verification/task-2.md" }] }`. No prose completion afterward.
|
|
56
78
|
6. the parent independently verifies files, diff, tests, and artifacts. Then call `agent_task_ack({ taskId })` for that one terminal task and explicitly retain or close the spawned role session.
|
|
@@ -63,21 +85,11 @@ Receiver terminal submission has one task-wide logical identity. Same-status ret
|
|
|
63
85
|
|
|
64
86
|
Set `PI_TASK_WORKER=1` only for task-only workers. Before a valid structured assignment matches a locally owned active task, the worker gate allows only inbox/status/wait inspection and blocks other model tools with `PI_TASK_WORKER_ASSIGNMENT_REQUIRED`.
|
|
65
87
|
|
|
66
|
-
## v1 compatibility
|
|
67
|
-
|
|
68
|
-
The retained v1 workflow is available only through the explicit `@sgtbeatdown/pi-tasks/v1-compat-extension` entrypoint. It does not load by default, and v2 never falls back or translates its targets.
|
|
69
|
-
|
|
70
|
-
v1 uses a reachable local Wolfpack task gateway and addresses targets as `to: { machine, sessionId }`. Use `machine: "local"` for same-machine work; remote work uses only the receiver's canonical HTTPS Tailnet origin. v1 trusts local processes and trusted Tailnet machines, has no JWT federation, and follows Wolfpack's [task gateway guide](https://github.com/almogdepaz/wolfpack/blob/main/docs/task-gateway.md).
|
|
71
|
-
|
|
72
|
-
Before v1 remote dispatch, complete the [Live-peer readiness checklist](https://github.com/almogdepaz/wolfpack/blob/main/docs/task-gateway.md#live-peer-readiness-checklist), including operator-recorded package/reload evidence. If it cannot pass, stop before task creation and report fixture-only verification. Isolated coverage is the deterministic acceptance gate, but it does not prove a specific live peer.
|
|
73
|
-
|
|
74
|
-
Only v1 supports curated `context.summary`/refs, role, metadata, preflight, idempotency keys, and completion prompts. Use `context.summary` only for constraints, decisions, and recovery state. Refs are metadata, not copied files or transcript. A v1 remote initial send gets one initial attempt; later peer events get four total attempts. Retry exhaustion is surfaced; v1 has no offline queue or background dispatch promise.
|
|
75
|
-
|
|
76
88
|
## do not
|
|
77
89
|
|
|
78
90
|
- do not use terminal output, rendered prompts, logs, or error prose as task state.
|
|
79
91
|
- do not ask workers to complete in prose or close their own sessions.
|
|
80
92
|
- do not steer or interrupt an active Pi turn with task context; use the adapter's follow-up queue.
|
|
81
93
|
- Do not copy plans, source contents, or transcripts into task context.
|
|
82
|
-
- do not
|
|
94
|
+
- do not derive or transform opaque endpoint IDs.
|
|
83
95
|
- do not promise JWT federation, artifact byte transfer, exactly-once model execution, or successor endpoint rebinding.
|
package/src/extension.ts
CHANGED
|
@@ -5,9 +5,9 @@ import { Type } from "typebox";
|
|
|
5
5
|
|
|
6
6
|
import { abortableSleep } from "./abortable-sleep";
|
|
7
7
|
import { deliverTaskInbox, incorporatedTaskEvents } from "./task-inbox";
|
|
8
|
-
import { TaskOutboxDeliveryError, TaskProtocolError } from "./task-protocol";
|
|
8
|
+
import { TaskDeliveryEvidenceState, TaskDeliveryStage, TaskOutboxDeliveryError, TaskProtocolError } from "./task-protocol";
|
|
9
9
|
import { createWolfpackTaskCore } from "./wolfpack-task-relay";
|
|
10
|
-
import type { TaskCore } from "./task-core";
|
|
10
|
+
import type { SubmitIntentInput, SubmitIntentOutcome, TaskCore } from "./task-core";
|
|
11
11
|
import type { TaskEndpoint, TaskSnapshot } from "./task-protocol";
|
|
12
12
|
|
|
13
13
|
const DEFAULT_TASK_TIMEOUT_MS = 30 * 60 * 1_000;
|
|
@@ -64,7 +64,6 @@ export function registerAgentTaskTools(pi: ExtensionAPI, core: TaskCore | undefi
|
|
|
64
64
|
let inboxContext: ExtensionContext | undefined;
|
|
65
65
|
let backgroundTimer: ReturnType<typeof setInterval> | undefined;
|
|
66
66
|
let lifecycleEpoch = 0;
|
|
67
|
-
const pendingInsertions = new Set<string>();
|
|
68
67
|
const closingTaskIds = new Set<string>();
|
|
69
68
|
const workerGateEnabled = process.env.PI_TASK_WORKER === "1";
|
|
70
69
|
const configuredCore: ConfiguredCoreFactory = core === undefined ? createConfiguredCoreLoader(createCore) : async (): Promise<TaskCore> => core;
|
|
@@ -104,9 +103,10 @@ export function registerAgentTaskTools(pi: ExtensionAPI, core: TaskCore | undefi
|
|
|
104
103
|
sendMessage(message, options) { if (isCurrent()) pi.sendMessage(message, options); },
|
|
105
104
|
appendEntry(customType, data) { if (isCurrent()) pi.appendEntry(customType, data); },
|
|
106
105
|
}, guardedCore, {
|
|
106
|
+
isIdle: (): boolean => isCurrent() && context.isIdle(),
|
|
107
107
|
hasPendingMessages: (): boolean => !isCurrent() || context.hasPendingMessages(),
|
|
108
108
|
sessionManager: context.sessionManager,
|
|
109
|
-
},
|
|
109
|
+
}, signal);
|
|
110
110
|
return outboxError;
|
|
111
111
|
});
|
|
112
112
|
const refreshLifecycle = async (context: ExtensionContext, epoch: number): Promise<void> => {
|
|
@@ -157,7 +157,6 @@ export function registerAgentTaskTools(pi: ExtensionAPI, core: TaskCore | undefi
|
|
|
157
157
|
});
|
|
158
158
|
|
|
159
159
|
pi.on("session_start", async (_event, context) => {
|
|
160
|
-
pendingInsertions.clear();
|
|
161
160
|
closingTaskIds.clear();
|
|
162
161
|
const epoch = ++lifecycleEpoch;
|
|
163
162
|
inboxContext = context;
|
|
@@ -173,8 +172,12 @@ export function registerAgentTaskTools(pi: ExtensionAPI, core: TaskCore | undefi
|
|
|
173
172
|
inboxContext = context;
|
|
174
173
|
await refreshLifecycle(context, epoch);
|
|
175
174
|
});
|
|
175
|
+
pi.on("agent_settled", async (_event, context) => {
|
|
176
|
+
const epoch = lifecycleEpoch;
|
|
177
|
+
inboxContext = context;
|
|
178
|
+
await refreshLifecycle(context, epoch);
|
|
179
|
+
});
|
|
176
180
|
pi.on("session_shutdown", () => {
|
|
177
|
-
pendingInsertions.clear();
|
|
178
181
|
closingTaskIds.clear();
|
|
179
182
|
lifecycleEpoch += 1;
|
|
180
183
|
if (backgroundTimer) clearInterval(backgroundTimer);
|
|
@@ -194,10 +197,13 @@ export function registerAgentTaskTools(pi: ExtensionAPI, core: TaskCore | undefi
|
|
|
194
197
|
});
|
|
195
198
|
pi.registerTool({
|
|
196
199
|
name: "agent_task_status", label: "Task Status", description: "Read local endpoint-owned task state; status is unavailable while its origin is offline.", parameters: TaskIdParams,
|
|
197
|
-
async execute(_id, params, signal) {
|
|
200
|
+
async execute(_id, params, signal, _onUpdate, context) {
|
|
198
201
|
try {
|
|
199
|
-
const
|
|
200
|
-
|
|
202
|
+
const activeCore = await configuredCore(signal);
|
|
203
|
+
const task = activeCore.getTask(params.taskId);
|
|
204
|
+
if (!task) return taskError(new Error("unknown local task"));
|
|
205
|
+
const deliveryEvidence = taskDeliveryEvidence(task);
|
|
206
|
+
return toolResult({ ...task, deliveryEvidence }, `## task status\n- task: \`${task.taskId}\`\n- status: ${task.status}${receiverAssignment(activeCore, task, context)}${deliveryEvidenceText(deliveryEvidence)}`);
|
|
201
207
|
} catch (error) { return taskError(error); }
|
|
202
208
|
}, renderResult(result, _options, theme) { return new Text(theme.fg("accent", text(result))); },
|
|
203
209
|
});
|
|
@@ -220,11 +226,12 @@ export function registerAgentTaskTools(pi: ExtensionAPI, core: TaskCore | undefi
|
|
|
220
226
|
});
|
|
221
227
|
pi.registerTool({
|
|
222
228
|
name: "agent_task_inbox", label: "Task Inbox", description: "Read local task records after processing relay deliveries without acknowledging task lifecycle.", parameters: Type.Object({}),
|
|
223
|
-
async execute(_id, _params, signal) {
|
|
229
|
+
async execute(_id, _params, signal, _onUpdate, context) {
|
|
224
230
|
try {
|
|
225
231
|
await refreshInbox(signal);
|
|
226
|
-
const
|
|
227
|
-
|
|
232
|
+
const activeCore = await configuredCore(signal);
|
|
233
|
+
const tasks = activeCore.listTasks();
|
|
234
|
+
return toolResult({ tasks }, `## task inbox\n${tasks.map((task) => `- \`${task.taskId}\`: ${task.status}${receiverAssignment(activeCore, task, context)}`).join("\n") || "- empty"}`);
|
|
228
235
|
} catch (error) { return taskError(error); }
|
|
229
236
|
},
|
|
230
237
|
renderResult(result, _options, theme) { return new Text(theme.fg("accent", text(result))); },
|
|
@@ -258,8 +265,32 @@ export function registerAgentTaskTools(pi: ExtensionAPI, core: TaskCore | undefi
|
|
|
258
265
|
name: "agent_task_done", label: "Complete Agent Task", description: "Persist a terminal task intent before relay submission.", parameters: DoneParams,
|
|
259
266
|
async execute(_id, params, signal) {
|
|
260
267
|
try {
|
|
261
|
-
|
|
262
|
-
|
|
268
|
+
const activeCore = await configuredCore(signal);
|
|
269
|
+
let submission: SubmitIntentOutcome | undefined;
|
|
270
|
+
try {
|
|
271
|
+
const input: SubmitIntentInput = { taskId: params.taskId, type: `task.${params.status}`, payload: { summary: params.summary, ...(params.result === undefined ? {} : { result: params.result }), ...(params.error === undefined ? {} : { error: params.error }), ...(params.artifacts === undefined ? {} : { artifacts: params.artifacts }) } };
|
|
272
|
+
if (activeCore.submitIntentWithOutcome) submission = await activeCore.submitIntentWithOutcome(input, signal);
|
|
273
|
+
else await activeCore.submitIntent(input, signal);
|
|
274
|
+
} catch (error) {
|
|
275
|
+
return blockedDoneResult(activeCore, params.taskId, params.status, error) ?? taskError(error);
|
|
276
|
+
}
|
|
277
|
+
const task = activeCore.getTask(params.taskId);
|
|
278
|
+
if (!task) return taskError(new Error("unknown local task"));
|
|
279
|
+
if (submission?.authority === "origin" && submission.canonicalEvent.type === "task.late_terminal") {
|
|
280
|
+
return {
|
|
281
|
+
...toolResult({ taskId: params.taskId, requestedStatus: params.status, observedCanonicalStatus: task.status, canonicalEvent: submission.canonicalEvent }, `## canonical late terminal recorded\n- task: \`${params.taskId}\`\n- requested status: ${params.status}\n- canonical status remains: ${task.status}\n- ${params.summary}`),
|
|
282
|
+
terminate: true,
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
if (submission?.authority === "origin" && task.status === params.status) {
|
|
286
|
+
return {
|
|
287
|
+
...toolResult({ taskId: params.taskId, requestedStatus: params.status, observedCanonicalStatus: task.status, canonicalCompletion: { state: "confirmed", status: task.status } }, `## task ${task.status}\n- task: \`${params.taskId}\`\n- canonical status: ${task.status}\n- ${params.summary}`),
|
|
288
|
+
terminate: true,
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
const deliveryOutcome = task.terminalDelivery.state === "accepted" ? "accepted" : "recorded";
|
|
292
|
+
const result = toolResult({ taskId: params.taskId, requestedStatus: params.status, observedCanonicalStatus: task.status, terminalDelivery: task.terminalDelivery }, `## terminal intent ${deliveryOutcome}\n- task: \`${params.taskId}\`\n- requested status: ${params.status}\n- observed canonical status: ${task.status}\n- ${params.summary}`);
|
|
293
|
+
return task.terminalDelivery.state === "accepted" || terminal(task.status) ? { ...result, terminate: true } : result;
|
|
263
294
|
} catch (error) { return taskError(error); }
|
|
264
295
|
}, renderResult(result, _options, theme) { return new Text(theme.fg("accent", text(result))); },
|
|
265
296
|
});
|
|
@@ -281,6 +312,37 @@ export default function piTasks(pi: ExtensionAPI): void {
|
|
|
281
312
|
registerAgentTaskTools(pi);
|
|
282
313
|
}
|
|
283
314
|
|
|
315
|
+
interface TaskDeliveryEvidence {
|
|
316
|
+
readonly receiverPersistence: "not_confirmed" | "confirmed";
|
|
317
|
+
readonly piInsertion: "not_confirmed" | "blocked" | "confirmed";
|
|
318
|
+
readonly wakeAcceptance: "not_confirmed" | "pending" | "confirmed";
|
|
319
|
+
readonly modelExecution: "not_evidenced";
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function taskDeliveryEvidence(task: TaskSnapshot): TaskDeliveryEvidence {
|
|
323
|
+
let receiverPersistence: TaskDeliveryEvidence["receiverPersistence"] = "not_confirmed";
|
|
324
|
+
let piInsertion: TaskDeliveryEvidence["piInsertion"] = "not_confirmed";
|
|
325
|
+
let wakeAcceptance: TaskDeliveryEvidence["wakeAcceptance"] = "not_confirmed";
|
|
326
|
+
const assignmentEventId = task.events.find((event) => event.type === "task.created")?.eventId;
|
|
327
|
+
for (const event of task.events) {
|
|
328
|
+
if (event.type !== "task.delivery_receipt" || event.payload.eventId !== assignmentEventId) continue;
|
|
329
|
+
if (event.payload.stage === TaskDeliveryStage.receiverPersisted) receiverPersistence = "confirmed";
|
|
330
|
+
if (event.payload.stage === TaskDeliveryStage.piInsertion && event.payload.state === TaskDeliveryEvidenceState.blocked) piInsertion = "blocked";
|
|
331
|
+
if (event.payload.stage === TaskDeliveryStage.piInserted || event.payload.stage === undefined) {
|
|
332
|
+
receiverPersistence = "confirmed";
|
|
333
|
+
piInsertion = "confirmed";
|
|
334
|
+
}
|
|
335
|
+
if (event.payload.stage === TaskDeliveryStage.wakeRequested) wakeAcceptance = "pending";
|
|
336
|
+
if (event.payload.stage === TaskDeliveryStage.wakeAccepted) wakeAcceptance = "confirmed";
|
|
337
|
+
}
|
|
338
|
+
return { receiverPersistence, piInsertion, wakeAcceptance, modelExecution: "not_evidenced" };
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function deliveryEvidenceText(evidence: TaskDeliveryEvidence): string {
|
|
342
|
+
const insertion = evidence.piInsertion === "blocked" ? "blocked; retryable" : evidence.piInsertion;
|
|
343
|
+
return `\n- receiver persistence: ${evidence.receiverPersistence}\n- Pi insertion: ${insertion}\n- wake acceptance: ${evidence.wakeAcceptance}\n- model execution: ${evidence.modelExecution}`;
|
|
344
|
+
}
|
|
345
|
+
|
|
284
346
|
function toolResult(details: unknown, markdown: string): AgentToolResult<unknown> {
|
|
285
347
|
return { content: [{ type: "text", text: markdown }], details };
|
|
286
348
|
}
|
|
@@ -294,26 +356,41 @@ function taskError(error: unknown): AgentToolResult<unknown> {
|
|
|
294
356
|
}
|
|
295
357
|
|
|
296
358
|
function blockedCancellationResult(core: TaskCore, taskId: string, error: unknown): AgentToolResult<unknown> | undefined {
|
|
297
|
-
if (!(error instanceof TaskOutboxDeliveryError) || error.
|
|
359
|
+
if (!(error instanceof TaskOutboxDeliveryError) || error.details?.taskId !== taskId) return undefined;
|
|
298
360
|
const task = core.getTask(taskId);
|
|
299
|
-
|
|
361
|
+
const warning = task === undefined ? undefined : blockedDeliveryWarning(error, task.target);
|
|
362
|
+
if (task?.status !== "cancelled" || !sameEndpoint(task.origin, core.endpoint) || warning === undefined) return undefined;
|
|
363
|
+
return toolResult({ taskId, status: "cancelled", warnings: [warning] }, `## task cancelled\n- task: \`${taskId}\`\n- canonical status: cancelled\n- target delivery: blocked; receiver incorporation not confirmed`);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function blockedDoneResult(core: TaskCore, taskId: string, requestedStatus: string, error: unknown): AgentToolResult<unknown> | undefined {
|
|
367
|
+
if (!(error instanceof TaskOutboxDeliveryError)) return undefined;
|
|
368
|
+
const task = core.getTask(taskId);
|
|
369
|
+
if (task === undefined) return undefined;
|
|
370
|
+
if (!sameEndpoint(task.origin, core.endpoint) && task.terminalDelivery.state === "delivery_blocked" && task.terminalDelivery.intentType === `task.${requestedStatus}`) {
|
|
371
|
+
return toolResult({
|
|
372
|
+
taskId,
|
|
373
|
+
status: task.status,
|
|
374
|
+
terminalDelivery: task.terminalDelivery,
|
|
375
|
+
error: { code: error.code, message: error.message, retryable: error.retryable },
|
|
376
|
+
}, `## terminal intent delivery blocked\n- task: \`${taskId}\`\n- canonical status: ${task.status}\n- canonical completion not confirmed; retry remains allowed`);
|
|
377
|
+
}
|
|
378
|
+
const warning = blockedDeliveryWarning(error, task.target);
|
|
379
|
+
if (!sameEndpoint(task.origin, core.endpoint) || task.status !== requestedStatus || warning === undefined) return undefined;
|
|
380
|
+
return {
|
|
381
|
+
...toolResult({ taskId, status: task.status, warnings: [warning] }, `## task ${task.status}\n- task: \`${taskId}\`\n- canonical status: ${task.status}\n- target delivery: blocked; receiver incorporation not confirmed`),
|
|
382
|
+
terminate: true,
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function blockedDeliveryWarning(error: TaskOutboxDeliveryError, target: TaskEndpoint): Readonly<Record<string, unknown>> | undefined {
|
|
387
|
+
if (error.code !== TARGET_NOT_REGISTERED_CODE || error.retryable) return undefined;
|
|
300
388
|
const details = { ...error.details };
|
|
301
389
|
delete details.taskId;
|
|
302
390
|
delete details.envelopeId;
|
|
303
391
|
delete details.target;
|
|
304
392
|
delete details.blockedAt;
|
|
305
|
-
return
|
|
306
|
-
taskId,
|
|
307
|
-
status: "cancelled",
|
|
308
|
-
warnings: [{
|
|
309
|
-
code: error.code,
|
|
310
|
-
message: error.message,
|
|
311
|
-
retryable: false,
|
|
312
|
-
delivery: "blocked",
|
|
313
|
-
target: task.target,
|
|
314
|
-
details,
|
|
315
|
-
}],
|
|
316
|
-
}, `## task cancelled\n- task: \`${taskId}\`\n- canonical status: cancelled\n- target delivery: blocked; receiver incorporation not confirmed`);
|
|
393
|
+
return { code: error.code, message: error.message, retryable: false, delivery: "blocked", target, details };
|
|
317
394
|
}
|
|
318
395
|
|
|
319
396
|
function outboxFailureStatus(error: unknown): "tasks: relay unavailable" | "tasks: outbox degraded" {
|
|
@@ -324,6 +401,13 @@ function terminal(status: string): boolean {
|
|
|
324
401
|
return ["completed", "failed", "cancelled", "timed_out"].includes(status);
|
|
325
402
|
}
|
|
326
403
|
|
|
404
|
+
function receiverAssignment(core: TaskCore, task: TaskSnapshot, context: Pick<ExtensionContext, "sessionManager">): string {
|
|
405
|
+
if (task.status !== "active" || sameEndpoint(task.origin, core.endpoint) || !sameEndpoint(task.target, core.endpoint)) return "";
|
|
406
|
+
const created = task.events.find((event) => event.type === "task.created");
|
|
407
|
+
if (!created || !incorporatedTaskEvents(context.sessionManager.getEntries()).some((evidence) => evidence.taskId === task.taskId && evidence.eventId === created.eventId)) return "";
|
|
408
|
+
return `\n\n## task assignment\n${task.task}`;
|
|
409
|
+
}
|
|
410
|
+
|
|
327
411
|
function assignedWorkerTasks(core: TaskCore, entries: readonly unknown[]): readonly TaskSnapshot[] {
|
|
328
412
|
const assignments = new Map<string, TaskSnapshot>();
|
|
329
413
|
for (const evidence of incorporatedTaskEvents(entries)) {
|
package/src/index.ts
CHANGED
|
@@ -31,5 +31,5 @@ export type {
|
|
|
31
31
|
TaskRecord,
|
|
32
32
|
TaskRelay,
|
|
33
33
|
} from "./task-protocol";
|
|
34
|
-
export type { TaskCore, TaskCoreOptions } from "./task-core";
|
|
34
|
+
export type { SubmitIntentOutcome, TaskCore, TaskCoreOptions } from "./task-core";
|
|
35
35
|
export type { TaskStore, TaskStoreOptions } from "./task-store";
|