@howaboua/pi-shepherdr 0.2.12 → 0.2.14
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/CHANGELOG.md +14 -0
- package/README.md +18 -10
- package/package.json +6 -6
- package/src/agents-answer.ts +22 -0
- package/src/agents-discovery.ts +3 -3
- package/src/agents-tool.ts +2 -1
- package/src/ask-answer.ts +32 -18
- package/src/attachment-notes.ts +49 -0
- package/src/attachment-protocol.ts +14 -1
- package/src/attachment-routing.ts +27 -10
- package/src/attachment-target.ts +70 -20
- package/src/attachment.ts +48 -20
- package/src/board/awareness.ts +115 -0
- package/src/board/host.ts +46 -6
- package/src/board/tool.ts +0 -3
- package/src/context-briefing.ts +226 -0
- package/src/controller.ts +81 -14
- package/src/delivery.ts +33 -0
- package/src/messages.ts +86 -15
- package/src/monitor-questions.ts +249 -0
- package/src/monitor-record.ts +6 -0
- package/src/monitor-state.ts +10 -4
- package/src/monitor.ts +40 -2
- package/src/remote/shepherdr-session-watch.mjs +72 -0
- package/src/remote/shepherdr-session.mjs +32 -2
- package/src/remote/shepherdr.mjs +21 -1
- package/src/remote-client.ts +66 -24
- package/src/session-reader.ts +49 -3
- package/src/shared-context.ts +46 -8
- package/src/types.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @howaboua/pi-shepherdr
|
|
2
2
|
|
|
3
|
+
## 0.2.14
|
|
4
|
+
|
|
5
|
+
- Delegated agents keep reporting after task completion, including follow-up work.
|
|
6
|
+
|
|
7
|
+
- Added shared-board awareness across native, Code and Notebook modes.
|
|
8
|
+
- Preserves orchestration guidance across compaction and context rollover.
|
|
9
|
+
- Restores running workers' targets and full tasks after compaction or context rollover to prevent duplicate delegation.
|
|
10
|
+
- Parents receive and answer asynchronous Ask questions while workers continue.
|
|
11
|
+
- Updated agent guidance to close finished workers without sending extra messages.
|
|
12
|
+
|
|
13
|
+
## 0.2.13
|
|
14
|
+
|
|
15
|
+
- Added Remote notes and history to existing-agent attachment, including mixed Local, Tree and Remote storage.
|
|
16
|
+
|
|
3
17
|
## 0.2.12
|
|
4
18
|
|
|
5
19
|
- Manage orchestration, board defaults and SSH connections in `/herdr`, and attach existing agents without replacing their context.
|
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ The agent tool is always available in Pi, Code Mode and Notebook Mode. Run Pi in
|
|
|
34
34
|
|
|
35
35
|
**Settings** contains orchestration and board preferences. **Status** shows machine connections and reconnect actions. **Connections** adds SSH machines through Herdr's setup flow. Agents handle discovery, attachment and detachment through the `agents` tool, not this panel.
|
|
36
36
|
|
|
37
|
-
`/herdr` is the only entry point; board, connect and orchestration subcommands are replaced by panel controls. Outside the TUI, it reports status without changing it. An orchestration change records one visible guidance message without triggering a turn. Resumed sessions restore their last mode; new sessions start with normal guidance. Tool availability and monitoring do not depend on this mode.
|
|
37
|
+
`/herdr` is the only entry point; board, connect and orchestration subcommands are replaced by panel controls. Outside the TUI, it reports status without changing it. An orchestration change records one visible guidance message without triggering a turn. Resumed sessions restore their last mode; new sessions start with normal guidance. The current guidance returns when a new model context no longer contains it, including turns started by worker messages. Tool availability and monitoring do not depend on this mode.
|
|
38
38
|
|
|
39
39
|
To add a machine, enter an SSH target or alias, a label and an optional remote session under **Connections**. Herdr performs setup in the terminal and asks before installing or replacing its remote server. OpenSSH owns authentication; Shepherdr does not store credentials. Profiles remain in Herdr's existing catalog, where they can also be renamed, disabled or removed.
|
|
40
40
|
|
|
@@ -63,22 +63,26 @@ Call the `agents` tool with `action: "help"` before first use, then send flat re
|
|
|
63
63
|
| `attach` | Share context or join a board with an existing idle agent |
|
|
64
64
|
| `detach` | Leave selected membership and retain read-only counterpart checkpoints |
|
|
65
65
|
| `read` | Read the latest assistant reply or bounded terminal output |
|
|
66
|
-
| `answer` | Answer a worker
|
|
66
|
+
| `answer` | Answer a worker's blocking or asynchronous Pi Ask |
|
|
67
67
|
| `watch` | Push future settlement from an existing Pi agent |
|
|
68
68
|
| `unwatch` | Stop reporting an agent |
|
|
69
69
|
|
|
70
70
|
`spawn` and `assign` block by default. Set `blocking: false` when the controller should continue other work immediately. A profile's `blocking` setting overrides the call for `spawn`. Task completion and blockage are then delivered automatically.
|
|
71
71
|
|
|
72
|
-
`answer` requires the pending `ask_id` from `read` or a
|
|
72
|
+
`answer` requires the pending `ask_id` from `read` or a question report. It handles both blocking and asynchronous Ask prompts. It returns `accepted` only when that exact Ask persisted the supplied responses; an accepted retry sends no input. Answering an asynchronous question does not wait for the worker's task to finish.
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
Asynchronous Ask prompts notify the controller while the worker keeps working. Session-file events drive local and remote notifications without marking the worker blocked or settling its task. Duplicate notifications are suppressed across controller restoration. Update Pi Ask on workers together with Shepherdr on controllers.
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
Needed input and work changes use `send`. It returns after submission, does not accept `blocking`, and never creates or changes a watch or task. Use `assign` only to delegate work whose result you need, not to exchange coordination messages. Close finished workers silently instead of waking them with completion acknowledgements or shutdown notices.
|
|
77
|
+
|
|
78
|
+
Delegation and explicit `watch` keep reporting subsequent work until `unwatch` or the agent's pane closes. Finishing or failing a task clears that task, not its watch. Follow-up messages through `send` retain completion reporting without replacing the task.
|
|
77
79
|
|
|
78
80
|
Every `spawn` needs an `agent_type` and a concise two- or three-word `label`. The label names both the Herdr tab and Pi session; the routing `name` remains optional and is derived from it when omitted.
|
|
79
81
|
|
|
80
82
|
Cancelling a blocking call does not kill its worker. The waiter detaches and the eventual result returns through normal asynchronous delivery.
|
|
81
83
|
|
|
84
|
+
After Pi compaction or Pi Codex context rollover, the controller receives its active agents' exact machine and target, full delegated task and last observed status. Existing work stays assigned instead of being delegated again. This reminder does not start a turn or bypass normal turn preparation.
|
|
85
|
+
|
|
82
86
|
Prompts sent through `agents` identify peer messages versus delegated tasks and include the sender's host, session, workspace, tab and pane identity, with current names. Reports include source workspace and tab names too. Raw `herdr agent prompt` calls bypass this attribution. These are runtime locations, not the desktop window showing a pane.
|
|
83
87
|
|
|
84
88
|
Messages sent through `agents` bypass the receiving Pi editor, preserving unsent drafts. Update and reload Shepherdr on receiving agents as well as controllers. If a receiver is unavailable, delivery fails without pasting into its terminal. Raw `herdr agent prompt` still uses terminal input and does not provide this protection.
|
|
@@ -99,17 +103,19 @@ await tools.agents({ action: "attach", target: "<target from find>", context: tr
|
|
|
99
103
|
|
|
100
104
|
Supply both booleans and enable at least one. `context` shares notes and history through aliases without changing either session's original context identity or moving its notes. `contextAgent` addresses the target from the controller; `controllerContextAgent` addresses the controller from the target. Use these paths as `history`'s `agent_name` or as `<agent>/notes/<path>` for notes. Each agent's relative note paths remain its own. The target receives its controller alias without starting a turn.
|
|
101
105
|
|
|
102
|
-
Context attachment requires updated Codex Conversion
|
|
106
|
+
Context attachment requires updated Codex Conversion with Local, Tree or Remote storage. Each owner keeps its original context identity and storage, including when the two agents use different stores. Remote access uses the reader's active Codex transport and requires the original account and backend, regardless of provider name. The explicit `context: true` choice does not depend on the controller's spawn-sharing setting. Use Code or Notebook with ordinary query and text for mixed-storage search and writes. Direct sensitive calls cannot cross between encrypted Remote arguments and ordinary Local or Tree arguments. If attachment changes context access during an exec cell, start a new cell before using notes or history.
|
|
107
|
+
|
|
108
|
+
An account mismatch rejects context sharing. Each agent keeps its own notes and history. If the account changes after attachment, pinned Remote notes become unavailable, including native Remote notes. Notes do not move to a new account or another store. Use messages to exchange the context the other agent needs.
|
|
103
109
|
|
|
104
110
|
`board: true` joins the controller's enabled board and returns `boardAgent` for subscriptions and notifications. The target's previous board archive stays untouched. If the folders differ, that archive remains in its original folder rather than becoming part of the controller's archive. Board-only attachment works without Codex Conversion and with Remote context storage.
|
|
105
111
|
|
|
106
112
|
The target must be idle and both Pi sessions must be saved. Existing shared-context members and controllers with context children cannot be context targets. Existing board members and roots with board children cannot switch boards. A target supports one controller and one fixed set of attachment choices. Attachment starts no task or watch; `assign` and `send` never attach implicitly.
|
|
107
113
|
|
|
108
|
-
Attachments survive resume, not forks.
|
|
114
|
+
Attachments survive resume, not forks. Local and Tree live access needs the owning Pi processes and machine connections. Remote access uses authenticated backend references rather than the owner's running process. After an interrupted attachment, resume the original sessions and retry the same target and choices. The target may already have joined even when the controller reports failure; retries reuse the original aliases and membership rather than creating duplicates.
|
|
109
115
|
|
|
110
|
-
To detach, call `agents` with `action: "detach"`, the same target, and both booleans. Enable each membership you want to leave. Context detach
|
|
116
|
+
To detach, call `agents` with `action: "detach"`, the same target, and both booleans. Enable each membership you want to leave. Context detach retains counterpart notes under the existing aliases read-only. Local and Tree notes use captured checkpoints. Remote notes retain an authenticated reference to the original owner's saved backend notes, not a frozen plaintext snapshot. Counterpart history and writes stop at detach. Native notes and history keep their original identities. Board detach restores the target's previous board and stops its shared-board notifications without deleting either archive. Board members with children cannot detach. Reattachment is unsupported.
|
|
111
117
|
|
|
112
|
-
If an attached owner closes or dies, notes reads first use its latest saved
|
|
118
|
+
If an attached owner closes or dies, Local and Tree notes reads first use its latest saved checkpoints when the source machine and session file remain reachable. This needs no running owner process and never writes to its session file. If the source is unavailable, reads return the timestamped snapshot captured at attachment, explicitly marked stale with the access failure. No latest-checkpoint guarantee is possible for a disconnected source machine or unsaved notes. Local and Tree counterpart history still requires its live owner. Remote notes and history remain reachable through the backend with the original account and backend. Backend failures stay visible without a local fallback. An incomplete detach fails with a retry instruction rather than claiming success.
|
|
113
119
|
|
|
114
120
|
## Message board
|
|
115
121
|
|
|
@@ -135,6 +141,8 @@ If the global agent directory is the launch folder's `.pi` directory, that file
|
|
|
135
141
|
|
|
136
142
|
Agents call `board` with `action: "help"` to discover channels, posts, replies, search, subscriptions and bounded reads. Code and Notebook Mode use `tools.board`. Agents choose when discussions are useful. Enabling the board, starting sessions, reading history and spawning children do not create an empty board. The first successful channel creation or post to a new channel creates it.
|
|
137
143
|
|
|
144
|
+
Agents receive a board briefing once per context window, including after compaction. It distinguishes an empty board from existing posts, leaves setup to the main agent, and points members to relevant discussion. Joining or re-enabling a board adds a briefing at the next model request. Resuming the same window does not repeat it. Post text stays behind the board tool.
|
|
145
|
+
|
|
138
146
|
Results fit 8,000 serialized UTF-8 bytes, including JSON escaping and metadata. Reads may return smaller pages or text slices than requested. Continue with the returned cursor or `next_offset_chars`. A search with `after_message_id` requires a post in the selected board, even before an archive exists.
|
|
139
147
|
|
|
140
148
|
One archive at `<owning-folder>/.pi/agent-message-board.sqlite` retains all boards for that folder. Each root Pi session has an isolated board; resume keeps it and new root sessions get separate boards. Children spawned while the board is enabled inherit its location and board ID even with another working directory. The spawn result's `boardAgent` is their address for subscriptions and explicit notifications, distinct from a pane or shared-notes identity. Independently started agents, existing `assign` targets and children spawned while it is off do not join automatically; use explicit `attach` to join an existing agent. Board identity is independent of shared notes and `share_context`.
|
|
@@ -155,7 +163,7 @@ Pi creates each worker session normally. The worker records its shared identity
|
|
|
155
163
|
|
|
156
164
|
Remote sharing requires Remote storage and the same Codex account on both ends. Local and Tree route through the owning Pi sessions and existing SSH connections. Those owners and intermediate controllers must be running; unavailable routes fail explicitly. Resume the owner and reconnect under `/herdr` → **Status** after a connection loss. No note store is copied or silently substituted.
|
|
157
165
|
|
|
158
|
-
Both extensions work independently. A target without active context support still starts, with a warning that its context is not shared. A conflicting storage mode or account rejects the shared spawn before task delivery. Profiles that select or resume an existing session cannot participate in shared `spawn`; use `attach` for
|
|
166
|
+
Both extensions work independently. A target without active context support still starts, with a warning that its context is not shared. A conflicting storage mode or account rejects the shared spawn before task delivery. Profiles that select or resume an existing session cannot participate in shared `spawn`; use `attach` for context access, then `assign`.
|
|
159
167
|
|
|
160
168
|
## Profiles
|
|
161
169
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@howaboua/pi-shepherdr",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.14",
|
|
4
4
|
"description": "Persistent blocking and asynchronous Pi agents through Herdr.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"pack:dry": "npm pack --dry-run"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"@howaboua/pi-codex-conversion": ">=3.0.
|
|
46
|
+
"@howaboua/pi-codex-conversion": ">=3.0.46",
|
|
47
47
|
"@earendil-works/pi-ai": ">=1.0.0",
|
|
48
48
|
"@earendil-works/pi-coding-agent": ">=1.0.0",
|
|
49
49
|
"@earendil-works/pi-tui": ">=1.0.0",
|
|
@@ -58,11 +58,11 @@
|
|
|
58
58
|
"unicode-case-folding": "1.1.2"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@howaboua/pi-codex-conversion": "3.0.
|
|
61
|
+
"@howaboua/pi-codex-conversion": "3.0.46",
|
|
62
62
|
"@biomejs/biome": "^2.5.10",
|
|
63
|
-
"@earendil-works/pi-ai": "1.0.
|
|
64
|
-
"@earendil-works/pi-coding-agent": "1.0.
|
|
65
|
-
"@earendil-works/pi-tui": "1.0.
|
|
63
|
+
"@earendil-works/pi-ai": "1.0.4",
|
|
64
|
+
"@earendil-works/pi-coding-agent": "1.0.4",
|
|
65
|
+
"@earendil-works/pi-tui": "1.0.4",
|
|
66
66
|
"@types/node": "^26.2.0",
|
|
67
67
|
"typebox": "1.3.18",
|
|
68
68
|
"typescript": "^7.0.2"
|
package/src/agents-answer.ts
CHANGED
|
@@ -59,6 +59,28 @@ export async function answerAgent(
|
|
|
59
59
|
signal,
|
|
60
60
|
askId,
|
|
61
61
|
);
|
|
62
|
+
if (prepared.ask.delivery === "steer") {
|
|
63
|
+
const result = await runtime.monitor.submitAskAnswer(
|
|
64
|
+
panel,
|
|
65
|
+
askId,
|
|
66
|
+
prepared.submit,
|
|
67
|
+
signal,
|
|
68
|
+
);
|
|
69
|
+
const accepted =
|
|
70
|
+
result?.status === "accepted" && answersMatch(answers, result.responses);
|
|
71
|
+
return toolResult({
|
|
72
|
+
answered: accepted,
|
|
73
|
+
ask_id: askId,
|
|
74
|
+
machine: runtime.machine,
|
|
75
|
+
status:
|
|
76
|
+
result?.status === "rejected"
|
|
77
|
+
? "rejected"
|
|
78
|
+
: accepted
|
|
79
|
+
? "accepted"
|
|
80
|
+
: "unknown",
|
|
81
|
+
target: panel.pane_id,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
62
84
|
const task = `Answer: ${prepared.ask.prompts
|
|
63
85
|
.map((prompt) => prompt.title)
|
|
64
86
|
.join(", ")}`;
|
package/src/agents-discovery.ts
CHANGED
|
@@ -48,10 +48,10 @@ export async function agentsHelp(): Promise<Record<string, unknown>> {
|
|
|
48
48
|
label: "2-3 words; tab/session",
|
|
49
49
|
answers: "[{selections?:string[],other?:string,comment?:string}]",
|
|
50
50
|
ask_id: "Exact pending Ask ID",
|
|
51
|
-
send: "Only
|
|
51
|
+
send: "Only needed input or work changes; wakes idle agents, no wait/watch. Never wake finished workers to acknowledge completion or announce closure; close finished panes silently with host controls",
|
|
52
52
|
assign: "Delegate a task to an existing agent",
|
|
53
53
|
attach:
|
|
54
|
-
"Idle target; context/board booleans choose shared access and board membership independently
|
|
54
|
+
"Idle target; context/board booleans choose shared access and board membership independently; no task/watch",
|
|
55
55
|
detach:
|
|
56
56
|
"Stop selected membership; retain counterpart checkpoints read-only; idle target",
|
|
57
57
|
blocking:
|
|
@@ -59,7 +59,7 @@ export async function agentsHelp(): Promise<Record<string, unknown>> {
|
|
|
59
59
|
share_context:
|
|
60
60
|
"Profile false isolates notes/history; otherwise follows controller sharing setting",
|
|
61
61
|
watch:
|
|
62
|
-
"
|
|
62
|
+
"Delegation and watch keep reporting subsequent work until unwatch or close",
|
|
63
63
|
prompt:
|
|
64
64
|
"Only task + inaccessible context; no method/evidence/reporting boilerplate",
|
|
65
65
|
slash:
|
package/src/agents-tool.ts
CHANGED
|
@@ -125,7 +125,8 @@ export function createAgentsTool(
|
|
|
125
125
|
...(view.assistant
|
|
126
126
|
? { reply: view.assistant.text }
|
|
127
127
|
: { reply: null }),
|
|
128
|
-
...(
|
|
128
|
+
...(view.ask &&
|
|
129
|
+
(panel.agent_status === "blocked" || view.ask.delivery === "steer")
|
|
129
130
|
? {
|
|
130
131
|
ask: modelAsk(view.ask),
|
|
131
132
|
}
|
package/src/ask-answer.ts
CHANGED
|
@@ -255,6 +255,7 @@ async function sendInput(
|
|
|
255
255
|
signal.throwIfAborted();
|
|
256
256
|
if (step.text !== undefined) {
|
|
257
257
|
await requireSameAgent(client, panel);
|
|
258
|
+
signal.throwIfAborted();
|
|
258
259
|
await client.request("pane.send_input", {
|
|
259
260
|
pane_id: panel.pane_id,
|
|
260
261
|
text: step.text,
|
|
@@ -262,6 +263,7 @@ async function sendInput(
|
|
|
262
263
|
}
|
|
263
264
|
if (step.keys) {
|
|
264
265
|
await requireSameAgent(client, panel);
|
|
266
|
+
signal.throwIfAborted();
|
|
265
267
|
await client.request("agent.send_keys", {
|
|
266
268
|
target: panel.pane_id,
|
|
267
269
|
keys: step.keys,
|
|
@@ -302,22 +304,28 @@ export async function prepareAskAnswer(
|
|
|
302
304
|
answers: AskAnswer[],
|
|
303
305
|
signal: AbortSignal,
|
|
304
306
|
expectedAskId: string,
|
|
305
|
-
): Promise<{ ask: PendingAsk; submit(): Promise<void> }> {
|
|
306
|
-
if (panel.agent_status !== "blocked") {
|
|
307
|
-
throw new Error(
|
|
308
|
-
`${panel.pane_id} is ${panel.agent_status}, not blocked on ask`,
|
|
309
|
-
);
|
|
310
|
-
}
|
|
307
|
+
): Promise<{ ask: PendingAsk; submit(signal?: AbortSignal): Promise<void> }> {
|
|
311
308
|
const view = await monitor.view(panel);
|
|
312
309
|
if (!view.ask) {
|
|
313
|
-
throw new Error(
|
|
314
|
-
`${panel.pane_id} has no pending pi-ask call on its active branch`,
|
|
315
|
-
);
|
|
310
|
+
throw new Error(`${panel.pane_id} has no live Ask on its active branch`);
|
|
316
311
|
}
|
|
317
312
|
const ask = view.ask;
|
|
313
|
+
if (panel.agent_status !== "blocked" && ask.delivery !== "steer") {
|
|
314
|
+
throw new Error(`${panel.pane_id} is not waiting on Ask`);
|
|
315
|
+
}
|
|
318
316
|
if (ask.toolCallId !== expectedAskId) {
|
|
319
|
-
throw new Error(`${panel.pane_id}
|
|
317
|
+
throw new Error(`${panel.pane_id} has a different Ask call`);
|
|
320
318
|
}
|
|
319
|
+
const requireLiveAsk = async () => {
|
|
320
|
+
const current = await getAgent(client, panel.pane_id);
|
|
321
|
+
if (
|
|
322
|
+
!sameAgentIdentity(panel, current) ||
|
|
323
|
+
(ask.delivery !== "steer" && current.agent_status !== "blocked") ||
|
|
324
|
+
(await monitor.view(current)).ask?.toolCallId !== ask.toolCallId
|
|
325
|
+
) {
|
|
326
|
+
throw new Error("ask closed before all requested answers were entered");
|
|
327
|
+
}
|
|
328
|
+
};
|
|
321
329
|
const initial = inspectAskScreen(await screen(client, panel.pane_id), ask);
|
|
322
330
|
const first = ask.prompts[0];
|
|
323
331
|
const expectedSelection = first?.choices[0]?.label ?? "Other/rephrase";
|
|
@@ -339,15 +347,10 @@ export async function prepareAskAnswer(
|
|
|
339
347
|
const final = plan.pop();
|
|
340
348
|
if (!final?.final) throw new Error("ask answer plan has no final submission");
|
|
341
349
|
for (const step of plan) {
|
|
350
|
+
await requireLiveAsk();
|
|
342
351
|
await sendInput(client, panel, step, signal);
|
|
343
352
|
await new Promise((resolve) => setTimeout(resolve, 35));
|
|
344
|
-
|
|
345
|
-
if (
|
|
346
|
-
!sameAgentIdentity(panel, current) ||
|
|
347
|
-
current.agent_status !== "blocked"
|
|
348
|
-
) {
|
|
349
|
-
throw new Error("ask closed before all requested answers were entered");
|
|
350
|
-
}
|
|
353
|
+
await requireLiveAsk();
|
|
351
354
|
if (
|
|
352
355
|
!inspectAskScreen(await screen(client, panel.pane_id), ask).recognized
|
|
353
356
|
) {
|
|
@@ -358,6 +361,17 @@ export async function prepareAskAnswer(
|
|
|
358
361
|
}
|
|
359
362
|
return {
|
|
360
363
|
ask,
|
|
361
|
-
submit:
|
|
364
|
+
submit: async (submitSignal = signal) => {
|
|
365
|
+
await requireLiveAsk();
|
|
366
|
+
if (
|
|
367
|
+
inspectAskScreen(await screen(client, panel.pane_id), ask)
|
|
368
|
+
.currentPrompt !== "Review"
|
|
369
|
+
) {
|
|
370
|
+
throw new Error(
|
|
371
|
+
"ask UI is not ready to submit; stopped without retrying input",
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
await sendInput(client, panel, final, submitSignal);
|
|
375
|
+
},
|
|
362
376
|
};
|
|
363
377
|
}
|
package/src/attachment-notes.ts
CHANGED
|
@@ -24,17 +24,66 @@ export class AttachmentNotes {
|
|
|
24
24
|
export: service.exportAttachmentNotes,
|
|
25
25
|
parse: service.parseAttachmentNotes,
|
|
26
26
|
read: service.readAttachmentNotes,
|
|
27
|
+
validate: service.validateAttachmentNotes,
|
|
28
|
+
verify: service.verifyAttachmentAccess,
|
|
29
|
+
remote: service.executeRemoteAttachment,
|
|
27
30
|
};
|
|
28
31
|
}
|
|
29
32
|
export(ctx: ExtensionContext) {
|
|
30
33
|
return this.service().export(ctx);
|
|
31
34
|
}
|
|
32
35
|
validate(snapshot: unknown, identity: ContextAgentIdentity) {
|
|
36
|
+
const service = this.service();
|
|
37
|
+
if (service.validate) return service.validate(snapshot, identity);
|
|
38
|
+
if (identity.storage === "remote")
|
|
39
|
+
throw new Error("Update Codex Conversion to retain Remote checkpoints");
|
|
33
40
|
this.service().read(snapshot, {
|
|
34
41
|
action: "list_files_by_prefix",
|
|
35
42
|
prefix: `${identity.agentName}/notes`,
|
|
36
43
|
});
|
|
37
44
|
}
|
|
45
|
+
async verify(
|
|
46
|
+
ctx: ExtensionContext,
|
|
47
|
+
snapshot: unknown,
|
|
48
|
+
identity: ContextAgentIdentity,
|
|
49
|
+
alreadyShared = false,
|
|
50
|
+
) {
|
|
51
|
+
this.validate(snapshot, identity);
|
|
52
|
+
if (identity.storage === "remote") {
|
|
53
|
+
const verify = this.service().verify;
|
|
54
|
+
if (!verify)
|
|
55
|
+
throw new Error(
|
|
56
|
+
"Update Codex Conversion to authenticate Remote attachments",
|
|
57
|
+
);
|
|
58
|
+
try {
|
|
59
|
+
await verify(ctx, snapshot);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
if (
|
|
62
|
+
!alreadyShared &&
|
|
63
|
+
error instanceof Error &&
|
|
64
|
+
error.message.startsWith("Account mismatch.")
|
|
65
|
+
)
|
|
66
|
+
throw new Error(
|
|
67
|
+
"Account mismatch. Context was not shared. Each agent keeps its own notes and history. Use messages to exchange the context you need.",
|
|
68
|
+
{ cause: error },
|
|
69
|
+
);
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async remote(
|
|
75
|
+
ctx: ExtensionContext,
|
|
76
|
+
reference: unknown,
|
|
77
|
+
request: SharedContextRequest,
|
|
78
|
+
signal?: AbortSignal,
|
|
79
|
+
) {
|
|
80
|
+
const execute = this.service().remote;
|
|
81
|
+
if (!execute)
|
|
82
|
+
throw new Error(
|
|
83
|
+
"Update Codex Conversion to read attached Remote context",
|
|
84
|
+
);
|
|
85
|
+
return execute(ctx, reference, request, signal);
|
|
86
|
+
}
|
|
38
87
|
checkTransport(value: unknown) {
|
|
39
88
|
if (Buffer.byteLength(JSON.stringify(value), "utf8") > 7 * 1024 * 1024)
|
|
40
89
|
throw new Error(
|
|
@@ -12,7 +12,9 @@ export const Identity = Type.Object({
|
|
|
12
12
|
sessionId: Type.String({ minLength: 1 }),
|
|
13
13
|
threadId: Type.String({ minLength: 1 }),
|
|
14
14
|
agentName: AgentPath,
|
|
15
|
-
storage: Type.Literal("session"),
|
|
15
|
+
storage: Type.Union([Type.Literal("session"), Type.Literal("remote")]),
|
|
16
|
+
accountScope: Type.Optional(Type.String({ pattern: "^[a-f0-9]{64}$" })),
|
|
17
|
+
backendUrl: Type.Optional(Type.String({ minLength: 1 })),
|
|
16
18
|
routing: Type.Optional(Type.Unknown()),
|
|
17
19
|
});
|
|
18
20
|
const ContextLink = Type.Object({
|
|
@@ -109,6 +111,17 @@ export function remapResult(
|
|
|
109
111
|
from: string,
|
|
110
112
|
to: string,
|
|
111
113
|
): SharedContextResult {
|
|
114
|
+
if (
|
|
115
|
+
typeof result.details.codexHistoryNotes["encrypted_output"] === "string"
|
|
116
|
+
) {
|
|
117
|
+
const hint = `Source ${from}, access through ${to}. Use ${to}/notes for note paths and ${to} for history agent_name`;
|
|
118
|
+
// Ciphertext paths cannot be remapped. Preserve host-only provenance on the original details.
|
|
119
|
+
result.details.codexHistoryNotes["attachment_hint"] = hint;
|
|
120
|
+
return {
|
|
121
|
+
...result,
|
|
122
|
+
content: [{ type: "text", text: hint }, ...result.content],
|
|
123
|
+
};
|
|
124
|
+
}
|
|
112
125
|
const details = JSON.parse(
|
|
113
126
|
JSON.stringify(result.details.codexHistoryNotes),
|
|
114
127
|
(key, value: unknown) =>
|
|
@@ -40,12 +40,7 @@ export class AttachmentRouting {
|
|
|
40
40
|
signal?: AbortSignal,
|
|
41
41
|
): Promise<SharedContextResult | undefined> {
|
|
42
42
|
const native = this.getService()?.describe(ctx);
|
|
43
|
-
if (
|
|
44
|
-
!native ||
|
|
45
|
-
native.storage !== "session" ||
|
|
46
|
-
request.sessionId !== native.sessionId
|
|
47
|
-
)
|
|
48
|
-
return undefined;
|
|
43
|
+
if (!native || request.sessionId !== native.sessionId) return undefined;
|
|
49
44
|
const child = attachmentRoutes(ctx).find(
|
|
50
45
|
(route) =>
|
|
51
46
|
route.phase === "ready" &&
|
|
@@ -56,7 +51,7 @@ export class AttachmentRouting {
|
|
|
56
51
|
const link = child.plan.context;
|
|
57
52
|
if (!isDeepStrictEqual(native, link.controller))
|
|
58
53
|
throw new Error(
|
|
59
|
-
"
|
|
54
|
+
"Shared notes are unavailable. Use messages to exchange the context you need.",
|
|
60
55
|
);
|
|
61
56
|
const next = {
|
|
62
57
|
...request,
|
|
@@ -65,7 +60,18 @@ export class AttachmentRouting {
|
|
|
65
60
|
params: remapParams(request.params, link.alias, link.target.agentName),
|
|
66
61
|
};
|
|
67
62
|
let result: SharedContextResult;
|
|
68
|
-
if (
|
|
63
|
+
if (link.target.storage === "remote") {
|
|
64
|
+
if (child.detached?.context && !this.notes.canRead(next))
|
|
65
|
+
throw new Error(
|
|
66
|
+
"Detached counterpart checkpoints are read-only; native history is unchanged",
|
|
67
|
+
);
|
|
68
|
+
result = await this.notes.remote(
|
|
69
|
+
ctx,
|
|
70
|
+
child.detached?.context ?? link.targetNotes,
|
|
71
|
+
next,
|
|
72
|
+
signal,
|
|
73
|
+
);
|
|
74
|
+
} else if (!child.detached?.context) {
|
|
69
75
|
try {
|
|
70
76
|
result = (await send(child, {
|
|
71
77
|
operation: "context",
|
|
@@ -104,7 +110,7 @@ export class AttachmentRouting {
|
|
|
104
110
|
if (owner && link && inside(request.agentName, link.controllerAlias)) {
|
|
105
111
|
if (!isDeepStrictEqual(native, link.target))
|
|
106
112
|
throw new Error(
|
|
107
|
-
"
|
|
113
|
+
"Shared notes are unavailable. Use messages to exchange the context you need.",
|
|
108
114
|
);
|
|
109
115
|
const next = {
|
|
110
116
|
...request,
|
|
@@ -122,7 +128,18 @@ export class AttachmentRouting {
|
|
|
122
128
|
};
|
|
123
129
|
const detached = detachment(ctx, owner)?.context;
|
|
124
130
|
let result: SharedContextResult;
|
|
125
|
-
if (
|
|
131
|
+
if (link.controller.storage === "remote") {
|
|
132
|
+
if (detached && !this.notes.canRead(next))
|
|
133
|
+
throw new Error(
|
|
134
|
+
"Detached counterpart checkpoints are read-only; native history is unchanged",
|
|
135
|
+
);
|
|
136
|
+
result = await this.notes.remote(
|
|
137
|
+
ctx,
|
|
138
|
+
detached ?? link.controllerNotes,
|
|
139
|
+
next,
|
|
140
|
+
signal,
|
|
141
|
+
);
|
|
142
|
+
} else if (!detached) {
|
|
126
143
|
try {
|
|
127
144
|
result = (await requestContext(
|
|
128
145
|
owner.upstream,
|
package/src/attachment-target.ts
CHANGED
|
@@ -40,16 +40,14 @@ export class AttachmentTarget {
|
|
|
40
40
|
this.getService = getService;
|
|
41
41
|
this.notes = notes;
|
|
42
42
|
}
|
|
43
|
-
context(ctx: ExtensionContext, target: boolean) {
|
|
43
|
+
async context(ctx: ExtensionContext, target: boolean) {
|
|
44
44
|
const service = this.getService();
|
|
45
45
|
if (!service?.inspectAttachment || !service.retainAttachmentIdentity)
|
|
46
46
|
throw new Error("Update Codex Conversion to attach existing context");
|
|
47
|
-
const identity = target
|
|
48
|
-
? service.inspectAttachment(ctx)
|
|
49
|
-
: service.describe(ctx);
|
|
47
|
+
const identity = await service.inspectAttachment(ctx, target);
|
|
50
48
|
if (!identity || !Check(Identity, identity))
|
|
51
49
|
throw new Error(
|
|
52
|
-
"Context attachment requires
|
|
50
|
+
"Context attachment requires notes-based continuity on both agents",
|
|
53
51
|
);
|
|
54
52
|
return identity as Static<typeof Identity>;
|
|
55
53
|
}
|
|
@@ -59,9 +57,9 @@ export class AttachmentTarget {
|
|
|
59
57
|
throw new Error(
|
|
60
58
|
"Context attachment support became unavailable; reload and retry",
|
|
61
59
|
);
|
|
62
|
-
service.retainAttachmentIdentity(ctx);
|
|
60
|
+
return service.retainAttachmentIdentity(ctx);
|
|
63
61
|
}
|
|
64
|
-
private inspect(ctx: ExtensionContext) {
|
|
62
|
+
private async inspect(ctx: ExtensionContext) {
|
|
65
63
|
if (!ctx.isIdle()) throw new Error("Attach only after the target settles");
|
|
66
64
|
if (!ctx.sessionManager.getSessionFile())
|
|
67
65
|
throw new Error("Attachment requires a saved target session");
|
|
@@ -69,7 +67,7 @@ export class AttachmentTarget {
|
|
|
69
67
|
let contextError: string | undefined;
|
|
70
68
|
let boardError: string | undefined;
|
|
71
69
|
try {
|
|
72
|
-
context = this.context(ctx, true);
|
|
70
|
+
context = await this.context(ctx, true);
|
|
73
71
|
if (
|
|
74
72
|
attachmentRoutes(ctx).some((route) => route.plan.context) ||
|
|
75
73
|
ctx.sessionManager
|
|
@@ -95,12 +93,17 @@ export class AttachmentTarget {
|
|
|
95
93
|
return {
|
|
96
94
|
sessionId: ctx.sessionManager.getSessionId(),
|
|
97
95
|
board: binding(ctx),
|
|
98
|
-
...(context ? { context, notes: this.notes.export(ctx) } : {}),
|
|
96
|
+
...(context ? { context, notes: await this.notes.export(ctx) } : {}),
|
|
99
97
|
...(contextError ? { contextError } : {}),
|
|
100
98
|
...(boardError ? { boardError } : {}),
|
|
101
99
|
};
|
|
102
100
|
}
|
|
103
|
-
async handle(
|
|
101
|
+
async handle(
|
|
102
|
+
ctx: ExtensionContext,
|
|
103
|
+
input: unknown,
|
|
104
|
+
signal?: AbortSignal,
|
|
105
|
+
): Promise<unknown> {
|
|
106
|
+
signal?.throwIfAborted();
|
|
104
107
|
if (!input || typeof input !== "object" || !("operation" in input))
|
|
105
108
|
throw new Error("Invalid attachment request");
|
|
106
109
|
if (input.operation === "attach-inspect") return this.inspect(ctx);
|
|
@@ -114,7 +117,7 @@ export class AttachmentTarget {
|
|
|
114
117
|
return this.notes.export(ctx);
|
|
115
118
|
}
|
|
116
119
|
if (input.operation === "detach-commit")
|
|
117
|
-
return this.commitDetach(ctx, input);
|
|
120
|
+
return this.commitDetach(ctx, input, signal);
|
|
118
121
|
if (
|
|
119
122
|
input.operation !== "attach-commit" ||
|
|
120
123
|
!("plan" in input) ||
|
|
@@ -162,7 +165,7 @@ export class AttachmentTarget {
|
|
|
162
165
|
"Target is already attached; another controller or different attachment choices are unsupported",
|
|
163
166
|
);
|
|
164
167
|
if (!owner) {
|
|
165
|
-
const current = this.inspect(ctx);
|
|
168
|
+
const current = await this.inspect(ctx);
|
|
166
169
|
if (
|
|
167
170
|
plan.context &&
|
|
168
171
|
(!current.context ||
|
|
@@ -174,15 +177,37 @@ export class AttachmentTarget {
|
|
|
174
177
|
if (plan.board && current.boardError) throw new Error(current.boardError);
|
|
175
178
|
if (plan.board && !isDeepStrictEqual(current.board, plan.board.previous))
|
|
176
179
|
throw new Error("Target board changed during attachment");
|
|
177
|
-
//
|
|
180
|
+
// Authentication completes before either membership mutation.
|
|
178
181
|
if (plan.context) {
|
|
179
|
-
this.notes.
|
|
182
|
+
await this.notes.verify(
|
|
183
|
+
ctx,
|
|
180
184
|
plan.context.controllerNotes,
|
|
181
185
|
plan.context.controller,
|
|
182
186
|
);
|
|
183
187
|
this.notes.validate(plan.context.targetNotes, plan.context.target);
|
|
184
188
|
}
|
|
185
|
-
if (plan.context)
|
|
189
|
+
if (plan.context) {
|
|
190
|
+
const identity = await this.context(ctx, true);
|
|
191
|
+
signal?.throwIfAborted();
|
|
192
|
+
if (
|
|
193
|
+
!ctx.isIdle() ||
|
|
194
|
+
ctx.sessionManager.getSessionId() !== plan.targetSessionId ||
|
|
195
|
+
!isDeepStrictEqual(identity, plan.context.target) ||
|
|
196
|
+
(plan.board && !isDeepStrictEqual(binding(ctx), plan.board.previous))
|
|
197
|
+
)
|
|
198
|
+
throw new Error(
|
|
199
|
+
"Target changed during attachment authentication; retry after it settles",
|
|
200
|
+
);
|
|
201
|
+
this.retainIdentity(ctx);
|
|
202
|
+
}
|
|
203
|
+
signal?.throwIfAborted();
|
|
204
|
+
if (
|
|
205
|
+
!ctx.isIdle() ||
|
|
206
|
+
ctx.sessionManager.getSessionId() !== plan.targetSessionId
|
|
207
|
+
)
|
|
208
|
+
throw new Error(
|
|
209
|
+
"Target changed during attachment; retry after it settles",
|
|
210
|
+
);
|
|
186
211
|
if (plan.board)
|
|
187
212
|
this.board.membership.commitAttachment(
|
|
188
213
|
ctx,
|
|
@@ -201,9 +226,11 @@ export class AttachmentTarget {
|
|
|
201
226
|
} else {
|
|
202
227
|
if (
|
|
203
228
|
plan.context &&
|
|
204
|
-
!isDeepStrictEqual(this.context(ctx, false), plan.context.target)
|
|
229
|
+
!isDeepStrictEqual(await this.context(ctx, false), plan.context.target)
|
|
205
230
|
)
|
|
206
|
-
throw new Error(
|
|
231
|
+
throw new Error(
|
|
232
|
+
"Shared notes are unavailable. Use messages to exchange the context you need.",
|
|
233
|
+
);
|
|
207
234
|
if (
|
|
208
235
|
plan.board &&
|
|
209
236
|
!isDeepStrictEqual(binding(ctx), {
|
|
@@ -220,7 +247,11 @@ export class AttachmentTarget {
|
|
|
220
247
|
);
|
|
221
248
|
return plan;
|
|
222
249
|
}
|
|
223
|
-
private async commitDetach(
|
|
250
|
+
private async commitDetach(
|
|
251
|
+
ctx: ExtensionContext,
|
|
252
|
+
input: unknown,
|
|
253
|
+
signal?: AbortSignal,
|
|
254
|
+
) {
|
|
224
255
|
if (!Check(Detachment, input)) throw new Error("Invalid detach request");
|
|
225
256
|
const requested = input as Static<typeof Detachment>;
|
|
226
257
|
const { plan } = requested;
|
|
@@ -238,12 +269,31 @@ export class AttachmentTarget {
|
|
|
238
269
|
throw new Error("Invalid detach choices");
|
|
239
270
|
const previous = detachment(ctx, plan);
|
|
240
271
|
if (requested.context && plan.context) {
|
|
241
|
-
if (
|
|
272
|
+
if (
|
|
273
|
+
!isDeepStrictEqual(await this.context(ctx, false), plan.context.target)
|
|
274
|
+
)
|
|
242
275
|
throw new Error("Target context changed before detach");
|
|
243
276
|
this.notes.validate(requested.context, plan.context.controller);
|
|
277
|
+
await this.notes.verify(
|
|
278
|
+
ctx,
|
|
279
|
+
requested.context,
|
|
280
|
+
plan.context.controller,
|
|
281
|
+
true,
|
|
282
|
+
);
|
|
244
283
|
}
|
|
245
|
-
const ownNotes = requested.context
|
|
284
|
+
const ownNotes = requested.context
|
|
285
|
+
? await this.notes.export(ctx)
|
|
286
|
+
: undefined;
|
|
246
287
|
if (ownNotes) this.notes.checkTransport(ownNotes);
|
|
288
|
+
signal?.throwIfAborted();
|
|
289
|
+
if (
|
|
290
|
+
!ctx.isIdle() ||
|
|
291
|
+
ctx.sessionManager.getSessionId() !== plan.targetSessionId ||
|
|
292
|
+
!isDeepStrictEqual(attachmentOwner(ctx), plan)
|
|
293
|
+
)
|
|
294
|
+
throw new Error(
|
|
295
|
+
"Target changed during detach authentication; retry after it settles",
|
|
296
|
+
);
|
|
247
297
|
if (requested.board && plan.board && !previous?.board)
|
|
248
298
|
this.board.membership.detachTarget(
|
|
249
299
|
ctx,
|