@te-river/opencode-team-mode 1.5.11 → 1.5.13
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 +154 -57
- package/README.zh-CN.md +126 -47
- package/dist/agents.d.ts +5 -1
- package/dist/agents.d.ts.map +1 -1
- package/dist/agents.js +37 -11
- package/dist/agents.js.map +1 -1
- package/dist/approval-gate.d.ts +54 -16
- package/dist/approval-gate.d.ts.map +1 -1
- package/dist/approval-gate.js +163 -42
- package/dist/approval-gate.js.map +1 -1
- package/dist/host-hooks.d.ts +115 -0
- package/dist/host-hooks.d.ts.map +1 -0
- package/dist/host-hooks.js +270 -0
- package/dist/host-hooks.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +68 -4
- package/dist/index.js.map +1 -1
- package/dist/prompts/lead.d.ts +1 -1
- package/dist/prompts/lead.d.ts.map +1 -1
- package/dist/prompts/lead.js +88 -6
- package/dist/prompts/lead.js.map +1 -1
- package/dist/prompts/shared.d.ts +1 -1
- package/dist/prompts/shared.d.ts.map +1 -1
- package/dist/prompts/shared.js +203 -119
- package/dist/prompts/shared.js.map +1 -1
- package/dist/prompts/specialists.d.ts +2 -2
- package/dist/prompts/specialists.d.ts.map +1 -1
- package/dist/prompts/specialists.js +73 -23
- package/dist/prompts/specialists.js.map +1 -1
- package/dist/tm/args-schema.d.ts +31 -1
- package/dist/tm/args-schema.d.ts.map +1 -1
- package/dist/tm/args-schema.js +155 -39
- package/dist/tm/args-schema.js.map +1 -1
- package/dist/tm/bash-timeout.d.ts +72 -0
- package/dist/tm/bash-timeout.d.ts.map +1 -0
- package/dist/tm/bash-timeout.js +100 -0
- package/dist/tm/bash-timeout.js.map +1 -0
- package/dist/tm/browser.d.ts +250 -20
- package/dist/tm/browser.d.ts.map +1 -1
- package/dist/tm/browser.js +1200 -143
- package/dist/tm/browser.js.map +1 -1
- package/dist/tm/config.d.ts +129 -0
- package/dist/tm/config.d.ts.map +1 -1
- package/dist/tm/config.js +117 -1
- package/dist/tm/config.js.map +1 -1
- package/dist/tm/dispatch.d.ts +95 -0
- package/dist/tm/dispatch.d.ts.map +1 -0
- package/dist/tm/dispatch.js +369 -0
- package/dist/tm/dispatch.js.map +1 -0
- package/dist/tm/index.d.ts +32 -7
- package/dist/tm/index.d.ts.map +1 -1
- package/dist/tm/index.js +74 -5
- package/dist/tm/index.js.map +1 -1
- package/dist/tm/memory.d.ts +88 -10
- package/dist/tm/memory.d.ts.map +1 -1
- package/dist/tm/memory.js +881 -99
- package/dist/tm/memory.js.map +1 -1
- package/dist/tm/pipelines.d.ts +26 -3
- package/dist/tm/pipelines.d.ts.map +1 -1
- package/dist/tm/pipelines.js +167 -11
- package/dist/tm/pipelines.js.map +1 -1
- package/dist/tm/ptc/budgets.d.ts +22 -1
- package/dist/tm/ptc/budgets.d.ts.map +1 -1
- package/dist/tm/ptc/budgets.js +87 -8
- package/dist/tm/ptc/budgets.js.map +1 -1
- package/dist/tm/ptc/contract.d.ts +49 -9
- package/dist/tm/ptc/contract.d.ts.map +1 -1
- package/dist/tm/ptc/contract.js +41 -3
- package/dist/tm/ptc/contract.js.map +1 -1
- package/dist/tm/ptc/driver.d.ts +5 -2
- package/dist/tm/ptc/driver.d.ts.map +1 -1
- package/dist/tm/ptc/driver.js +47 -15
- package/dist/tm/ptc/driver.js.map +1 -1
- package/dist/tm/ptc/engines.d.ts +15 -4
- package/dist/tm/ptc/engines.d.ts.map +1 -1
- package/dist/tm/ptc/engines.js +281 -28
- package/dist/tm/ptc/engines.js.map +1 -1
- package/dist/tm/ptc/index.d.ts +4 -4
- package/dist/tm/ptc/index.d.ts.map +1 -1
- package/dist/tm/ptc/index.js +2 -2
- package/dist/tm/ptc/index.js.map +1 -1
- package/dist/tm/ptc/pscan.d.ts +20 -1
- package/dist/tm/ptc/pscan.d.ts.map +1 -1
- package/dist/tm/ptc/pscan.js +328 -14
- package/dist/tm/ptc/pscan.js.map +1 -1
- package/dist/tm/ptc/summary.d.ts.map +1 -1
- package/dist/tm/ptc/summary.js +23 -1
- package/dist/tm/ptc/summary.js.map +1 -1
- package/dist/tm/ptc/tool.d.ts +34 -3
- package/dist/tm/ptc/tool.d.ts.map +1 -1
- package/dist/tm/ptc/tool.js +117 -20
- package/dist/tm/ptc/tool.js.map +1 -1
- package/dist/tm/pty.d.ts +70 -0
- package/dist/tm/pty.d.ts.map +1 -0
- package/dist/tm/pty.js +242 -0
- package/dist/tm/pty.js.map +1 -0
- package/dist/tm/search.d.ts +128 -15
- package/dist/tm/search.d.ts.map +1 -1
- package/dist/tm/search.js +556 -47
- package/dist/tm/search.js.map +1 -1
- package/dist/tm/shell-bridge.d.ts +14 -1
- package/dist/tm/shell-bridge.d.ts.map +1 -1
- package/dist/tm/shell-bridge.js +57 -10
- package/dist/tm/shell-bridge.js.map +1 -1
- package/dist/tm/webfetch.d.ts +29 -7
- package/dist/tm/webfetch.d.ts.map +1 -1
- package/dist/tm/webfetch.js +117 -15
- package/dist/tm/webfetch.js.map +1 -1
- package/dist/types.d.ts +16 -0
- package/dist/types.d.ts.map +1 -1
- package/docs/installation.md +216 -17
- package/package.json +5 -2
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tm_dispatch / tm_join — ASYNC sub-agent dispatch (issue #7 of 2026-09-18).
|
|
3
|
+
*
|
|
4
|
+
* Why this exists: the host's built-in `task` tool blocks the CALLING
|
|
5
|
+
* session until the child agent returns, so "the team runs in parallel" was
|
|
6
|
+
* only half true — the lead stood still for the sum of every dispatch, and
|
|
7
|
+
* each child's full reply landed in the lead's context whether it needed it
|
|
8
|
+
* there or not. OpenCode hands plugins its own client (`input.client`), and
|
|
9
|
+
* the official session API has `create` + `promptAsync` — "start if needed
|
|
10
|
+
* and return IMMEDIATELY" — so a plugin-owned dispatcher gets real overlap
|
|
11
|
+
* without touching a line of host code. If a future host ever removes that
|
|
12
|
+
* surface, both tools degrade with an explicit instruction to fall back to
|
|
13
|
+
* `task`, rather than failing the round.
|
|
14
|
+
*
|
|
15
|
+
* Contract kept from T3 (no sub-agent spawns a sub-agent):
|
|
16
|
+
* - `tm_dispatch` executes ONLY for the team lead (ctx.agent check here,
|
|
17
|
+
* plus an explicit deny for the five specialists in agents.ts — the
|
|
18
|
+
* tm_* wildcard would otherwise hand it to everyone);
|
|
19
|
+
* - children are the five named specialists, never "team";
|
|
20
|
+
* - the child session is parented to the lead session (parentID), so the
|
|
21
|
+
* host's own session tree, cancellation and UI still make sense.
|
|
22
|
+
*
|
|
23
|
+
* Context economy (design goal #4): tm_join renders each child's reply
|
|
24
|
+
* through the SAME governance pipeline as every other tm_* tool, so five
|
|
25
|
+
* long sub-agent reports become five handles + 80-token previews that the
|
|
26
|
+
* lead can page through with tm_fetch — not 5×N kilotokens dumped inline.
|
|
27
|
+
*/
|
|
28
|
+
import { tmError, toToolResult } from "./result.js";
|
|
29
|
+
import { unwrapClientResult } from "./client-unwrap.js";
|
|
30
|
+
import { detectContentType } from "./preview.js";
|
|
31
|
+
import { shorten } from "./config.js";
|
|
32
|
+
/** The five dispatchable specialists — "team" is deliberately NOT in the
|
|
33
|
+
* list: a lead spawning a lead is the nesting T3 closed. */
|
|
34
|
+
export const DISPATCH_TARGETS = ["architect", "implementer", "reviewer", "tester", "researcher"];
|
|
35
|
+
/** Resolve the host session API defensively — a missing namespace means the
|
|
36
|
+
* host does not speak this protocol, and the caller must degrade. */
|
|
37
|
+
export function sessionApiOf(client) {
|
|
38
|
+
const session = client?.session;
|
|
39
|
+
if (!session || typeof session !== "object")
|
|
40
|
+
return null;
|
|
41
|
+
const api = session;
|
|
42
|
+
if (typeof api.create !== "function" || typeof api.promptAsync !== "function")
|
|
43
|
+
return null;
|
|
44
|
+
return api;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Pull the assistant reply text out of a `session.messages` payload.
|
|
48
|
+
* Shapes accepted (host has renamed things before): {info,parts} pairs or a
|
|
49
|
+
* bare Part[] — the LAST assistant message is the answer, everything earlier
|
|
50
|
+
* is that agent's own working transcript.
|
|
51
|
+
*/
|
|
52
|
+
export function lastAssistantText(messages) {
|
|
53
|
+
const list = Array.isArray(messages) ? messages : [];
|
|
54
|
+
for (let i = list.length - 1; i >= 0; i--) {
|
|
55
|
+
const entry = list[i];
|
|
56
|
+
const info = entry?.info;
|
|
57
|
+
const role = typeof info?.role === "string" ? String(info.role).toLowerCase() : "";
|
|
58
|
+
if (role && role !== "assistant")
|
|
59
|
+
continue;
|
|
60
|
+
const parts = entry?.parts;
|
|
61
|
+
if (!Array.isArray(parts)) {
|
|
62
|
+
// a bare message list (no {info,parts} envelope) — take any text part
|
|
63
|
+
const one = entry ?? {};
|
|
64
|
+
if (one.type === "text" && typeof one.text === "string")
|
|
65
|
+
return one.text;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const texts = parts
|
|
69
|
+
.filter((p) => {
|
|
70
|
+
const pp = p;
|
|
71
|
+
return pp && pp.type === "text" && typeof pp.text === "string" && pp.text.trim() !== "";
|
|
72
|
+
})
|
|
73
|
+
.map((p) => String(p.text));
|
|
74
|
+
if (texts.length)
|
|
75
|
+
return texts.join("\n");
|
|
76
|
+
}
|
|
77
|
+
return "";
|
|
78
|
+
}
|
|
79
|
+
/** One child's status line — the lead reads these, so keep them terse. */
|
|
80
|
+
export function renderChildLine(c, elapsedMs) {
|
|
81
|
+
const secs = Math.round(elapsedMs / 1000);
|
|
82
|
+
const tag = c.state === "running" ? `运行中 ${secs}s` : c.state === "error" ? `失败:${shorten(c.error ?? "", 80)}` : `已完成 ${secs}s`;
|
|
83
|
+
return `${c.sessionID} · ${c.agent} · "${c.label}" · ${tag}`;
|
|
84
|
+
}
|
|
85
|
+
/** Verdicts tm_join can actually observe (issue #7's "leader keeps control"). */
|
|
86
|
+
export function summarizeStates(children) {
|
|
87
|
+
let running = 0;
|
|
88
|
+
let idle = 0;
|
|
89
|
+
let error = 0;
|
|
90
|
+
for (const c of children) {
|
|
91
|
+
if (c.state === "running")
|
|
92
|
+
running++;
|
|
93
|
+
else if (c.state === "error")
|
|
94
|
+
error++;
|
|
95
|
+
else
|
|
96
|
+
idle++;
|
|
97
|
+
}
|
|
98
|
+
return { running, idle, error };
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Sleep used only by tm_join's bounded wait. Deliberately a plain timer:
|
|
102
|
+
* it never holds the event loop (the wait is awaited, not spun) and it is
|
|
103
|
+
* capped by `maxWaitMs` so a hung child cannot hang the lead.
|
|
104
|
+
*/
|
|
105
|
+
function sleep(ms) {
|
|
106
|
+
return new Promise((res) => {
|
|
107
|
+
const t = setTimeout(res, ms);
|
|
108
|
+
t.unref?.();
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
export function buildDispatchTools(deps) {
|
|
112
|
+
const leadAgent = deps.leadAgent ?? "team";
|
|
113
|
+
const targets = deps.targets ?? DISPATCH_TARGETS;
|
|
114
|
+
const maxWaitMs = deps.maxWaitMs ?? 300_000;
|
|
115
|
+
const now = deps.now ?? (() => Date.now());
|
|
116
|
+
const store = deps.pipelines.store;
|
|
117
|
+
const log = (e) => store.appendTrajectory({ tool: "tm_dispatch", ...e });
|
|
118
|
+
const children = new Map();
|
|
119
|
+
const api = sessionApiOf(deps.client);
|
|
120
|
+
/** Refresh a child's state from the host's own status map (the event bus
|
|
121
|
+
* is the fast path; this is the belt when an event was missed — a child
|
|
122
|
+
* dispatched before a plugin restart, or a session.idle that never
|
|
123
|
+
* arrived). */
|
|
124
|
+
async function refreshFromStatus(directory) {
|
|
125
|
+
const statusApi = api?.status;
|
|
126
|
+
if (typeof statusApi !== "function")
|
|
127
|
+
return;
|
|
128
|
+
let un;
|
|
129
|
+
try {
|
|
130
|
+
un = unwrapClientResult(await statusApi(directory ? { query: { directory } } : {}));
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (!un.ok || !un.data || typeof un.data !== "object")
|
|
136
|
+
return;
|
|
137
|
+
const map = un.data;
|
|
138
|
+
for (const [sid, st] of Object.entries(map)) {
|
|
139
|
+
const rec = children.get(sid);
|
|
140
|
+
if (!rec || rec.state !== "running")
|
|
141
|
+
continue;
|
|
142
|
+
const type = String(st?.type ?? "").toLowerCase();
|
|
143
|
+
if (type === "idle") {
|
|
144
|
+
rec.state = "idle";
|
|
145
|
+
rec.finishedAt = now();
|
|
146
|
+
}
|
|
147
|
+
else if (type === "busy" || type === "retry") {
|
|
148
|
+
rec.state = "running";
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function fetchReply(sid, directory) {
|
|
153
|
+
return (async () => {
|
|
154
|
+
const messages = api?.messages;
|
|
155
|
+
if (typeof messages !== "function")
|
|
156
|
+
return "";
|
|
157
|
+
try {
|
|
158
|
+
const un = unwrapClientResult(await messages({ path: { id: sid }, ...(directory ? { query: { directory } } : {}) }));
|
|
159
|
+
return un.ok ? lastAssistantText(un.data) : "";
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
return "";
|
|
163
|
+
}
|
|
164
|
+
})();
|
|
165
|
+
}
|
|
166
|
+
const dispatch = {
|
|
167
|
+
description: `Fire-and-continue sub-agent dispatch — the lead's parallelism lever (the built-in task tool BLOCKS you until the child finishes; this one does not).
|
|
168
|
+
- { agent: ${targets.join("|")} , task: "<self-contained brief>", label: "<short slug>" } → starts the specialist in its OWN child session (parented to yours) and returns the child session id IMMEDIATELY. You keep working the same round: plan the next step, do a cheap read of your own, or fire more dispatches — independent work runs concurrently instead of serially.
|
|
169
|
+
- The brief must stand alone: the child has not seen this conversation, does not know what you tried, and cannot ask you mid-run. Say what to do, WHY it matters, which files/paths are its territory, what "done" looks like, and how much thoroughness you expect — the child still answers the mandatory STATUS/CHANGES/FINDINGS/EVIDENCE/HANDOFF skeleton.
|
|
170
|
+
- Collect with tm_join (no wait = status snapshot, waitMs = bounded wait). Collected replies ride the offload pipeline: a long report arrives as a handle + preview, not a context flood.
|
|
171
|
+
- Division of labour: bulk reading / searching / aggregation burns the CHILD's context and comes back as a skeleton; your own context is the scarce resource — keep it for routing, decisions and the final merge.
|
|
172
|
+
- Only the team lead may call this; a child never dispatches (no nested teams). If the host exposes no async session API the call fails with an explicit "use the built-in task tool" directive.`,
|
|
173
|
+
args: {
|
|
174
|
+
agent: { descriptor: `agent: ${targets.join("|")} (required)` },
|
|
175
|
+
task: { descriptor: "task: string (required — the full self-contained brief the child works from)" },
|
|
176
|
+
label: { descriptor: "label: string (optional short slug for this dispatch, ≤40 chars)" },
|
|
177
|
+
},
|
|
178
|
+
execute: async (rawArgs, ctx) => {
|
|
179
|
+
const tool = "tm_dispatch";
|
|
180
|
+
try {
|
|
181
|
+
const args = (rawArgs ?? {});
|
|
182
|
+
const c = (ctx ?? {});
|
|
183
|
+
const caller = String(c.agent ?? "").trim();
|
|
184
|
+
if (caller && caller !== leadAgent) {
|
|
185
|
+
return toToolResult(tmError(tool, "governance", `只有 ${leadAgent} 可以派发子代理(当前 agent="${shorten(caller, 24)}")。T3 规则:子代理不再派子代理——把需要并行的工作交给 lead 编排。`));
|
|
186
|
+
}
|
|
187
|
+
const agent = String(args.agent ?? "").trim().toLowerCase();
|
|
188
|
+
if (!targets.includes(agent)) {
|
|
189
|
+
return toToolResult(tmError(tool, "args", `未知派发目标 "${shorten(agent, 30)}"——可用: ${targets.join(", ")}`));
|
|
190
|
+
}
|
|
191
|
+
const task = typeof args.task === "string" ? args.task.trim() : "";
|
|
192
|
+
if (task.length < 20) {
|
|
193
|
+
return toToolResult(tmError(tool, "args", "task 太短:子代理看不到本会话,派发说明必须自包含(目标、涉及文件、完成判据、期望深度)。"));
|
|
194
|
+
}
|
|
195
|
+
const parent = String(c.sessionID ?? "").trim();
|
|
196
|
+
if (!parent) {
|
|
197
|
+
return toToolResult(tmError(tool, "client", "缺少 sessionID(宿主未把会话上下文传给插件),无法建立父子会话。"));
|
|
198
|
+
}
|
|
199
|
+
if (!api) {
|
|
200
|
+
return toToolResult(tmError(tool, "client", `此宿主未暴露异步会话 API(client.session.create/promptAsync),tm_dispatch 不可用——改用内置 task 工具(会阻塞你,但功能等价)。`));
|
|
201
|
+
}
|
|
202
|
+
const label = (typeof args.label === "string" && args.label.trim() ? args.label.trim() : task.split(/\s+/).slice(0, 4).join(" ")).slice(0, 40);
|
|
203
|
+
const createApi = api?.create;
|
|
204
|
+
const promptApi = api?.promptAsync;
|
|
205
|
+
if (typeof createApi !== "function" || typeof promptApi !== "function") {
|
|
206
|
+
return toToolResult(tmError(tool, "client", "此宿主的 client.session 缺少 create/promptAsync——改用内置 task 工具。"));
|
|
207
|
+
}
|
|
208
|
+
const created = unwrapClientResult(await createApi({ body: { parentID: parent, title: `tm:${agent}:${label}` } }));
|
|
209
|
+
if (!created.ok)
|
|
210
|
+
return toToolResult(tmError(tool, "client", `创建子会话失败:${shorten(created.message ?? "", 120)}`));
|
|
211
|
+
const sid = String(created.data?.id ?? "").trim();
|
|
212
|
+
if (!sid)
|
|
213
|
+
return toToolResult(tmError(tool, "client", "子会话创建后未返回 id"));
|
|
214
|
+
const promptBody = {
|
|
215
|
+
agent,
|
|
216
|
+
noReply: false,
|
|
217
|
+
parts: [{ type: "text", text: task }],
|
|
218
|
+
};
|
|
219
|
+
const directory = typeof c.directory === "string" && c.directory ? c.directory : undefined;
|
|
220
|
+
const sent = unwrapClientResult(await promptApi({ path: { id: sid }, ...(directory ? { query: { directory } } : {}), body: promptBody }));
|
|
221
|
+
if (!sent.ok) {
|
|
222
|
+
return toToolResult(tmError(tool, "client", `子会话 ${sid} 已创建但提示未能启动:${shorten(sent.message ?? "", 120)}——可对该 id 直接用内置 task,或本次改用 task 工具。`));
|
|
223
|
+
}
|
|
224
|
+
const rec = { sessionID: sid, agent, label, parentSessionID: parent, startedAt: now(), state: "running" };
|
|
225
|
+
children.set(sid, rec);
|
|
226
|
+
deps.onChildSession?.(sid, agent);
|
|
227
|
+
log({ step_id: "dispatch", event: "start", child: sid, parent: parent, agent, label });
|
|
228
|
+
return toToolResult([
|
|
229
|
+
`已派发(非阻塞):${agent} · "${label}" · 子会话 ${sid}`,
|
|
230
|
+
`你现在可以继续:编排下一步、做廉价检查、或继续派发其它独立任务。`,
|
|
231
|
+
`收集结果:tm_join(立即看状态)或 tm_join { waitMs: 60000 }。所有派发完成前不要提交结论。`,
|
|
232
|
+
].join("\n"));
|
|
233
|
+
}
|
|
234
|
+
catch (err) {
|
|
235
|
+
const e = err;
|
|
236
|
+
return toToolResult(tmError(tool, "execute", `tm_dispatch 失败:${shorten(e?.message ?? err, 160)}`));
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
const join = {
|
|
241
|
+
description: `Collect what the async dispatches (tm_dispatch) have produced.
|
|
242
|
+
- No args: status snapshot of every open child of THIS session — running / idle(done) / error, with elapsed seconds. Cheap and non-blocking: use it to decide whether to keep working or start merging.
|
|
243
|
+
- { waitMs: 30000 }: bounded wait (capped at ${Math.round(maxWaitMs / 1000)}s) until every child settles, then returns each one's reply skeleton. Never wait for a child whose result you do not need — abort it instead ({ cancel: true }).
|
|
244
|
+
- { ids: [...] }: restrict to those child sessions; { cancel: true }: abort still-running ones (a runaway child is yours to stop, not the user's problem).
|
|
245
|
+
- Replies come back through the offload pipeline: a long sub-agent report arrives as a handle + ≤80-token preview (page it with tm_fetch), so five parallel dispatches do not multiply your context. STATUS: blocked/failed children are surfaced first, always.`,
|
|
246
|
+
args: {
|
|
247
|
+
ids: { descriptor: "ids: string[] (optional — only these child sessions)" },
|
|
248
|
+
waitMs: { descriptor: "waitMs: number (optional 0..300000 — bounded wait before collecting)" },
|
|
249
|
+
cancel: { descriptor: "cancel: true (abort the still-running children in this set)" },
|
|
250
|
+
includeText: { descriptor: "includeText: false to get only the status table (default true)" },
|
|
251
|
+
},
|
|
252
|
+
execute: async (rawArgs, ctx) => {
|
|
253
|
+
const tool = "tm_join";
|
|
254
|
+
try {
|
|
255
|
+
const args = (rawArgs ?? {});
|
|
256
|
+
const c = (ctx ?? {});
|
|
257
|
+
const caller = String(c.agent ?? "").trim();
|
|
258
|
+
if (caller && caller !== leadAgent) {
|
|
259
|
+
return toToolResult(tmError(tool, "governance", `只有 ${leadAgent} 能收集派发结果。`));
|
|
260
|
+
}
|
|
261
|
+
const parent = String(c.sessionID ?? "").trim();
|
|
262
|
+
const directory = typeof c.directory === "string" && c.directory ? c.directory : undefined;
|
|
263
|
+
const idFilter = Array.isArray(args.ids)
|
|
264
|
+
? new Set(args.ids.map((x) => String(x ?? "").trim()).filter(Boolean))
|
|
265
|
+
: null;
|
|
266
|
+
const mine = [...children.values()].filter((r) => (!parent || r.parentSessionID === parent) && (!idFilter || idFilter.has(r.sessionID)));
|
|
267
|
+
if (!mine.length) {
|
|
268
|
+
return toToolResult(`没有待收集的派发${idFilter ? "(ids 未匹配到本会话的子代理)" : ""}。刚派发过却看不到?说明那次派发没成功——回到 tm_dispatch 的返回值检查。`);
|
|
269
|
+
}
|
|
270
|
+
const waitMs = Math.max(0, Math.min(maxWaitMs, Number(args.waitMs) || 0));
|
|
271
|
+
const deadline = now() + waitMs;
|
|
272
|
+
let settled = false;
|
|
273
|
+
for (;;) {
|
|
274
|
+
await refreshFromStatus(directory);
|
|
275
|
+
const open = mine.filter((r) => r.state === "running");
|
|
276
|
+
if (!open.length || now() >= deadline) {
|
|
277
|
+
settled = !open.length;
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
await sleep(Math.min(1000, Math.max(100, deadline - now())));
|
|
281
|
+
}
|
|
282
|
+
const stillRunning = mine.filter((r) => r.state === "running");
|
|
283
|
+
const abortApi = api?.abort;
|
|
284
|
+
if (args.cancel === true || args.cancel === "true") {
|
|
285
|
+
for (const r of stillRunning) {
|
|
286
|
+
if (typeof abortApi === "function") {
|
|
287
|
+
const un = unwrapClientResult(await abortApi({ path: { id: r.sessionID } }));
|
|
288
|
+
r.error = un.ok ? "aborted on request" : `abort failed: ${shorten(un.message ?? "", 60)}`;
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
r.error = "宿主无 abort 接口,未取消";
|
|
292
|
+
}
|
|
293
|
+
r.state = "error";
|
|
294
|
+
r.finishedAt = now();
|
|
295
|
+
log({ step_id: "join", event: "cancel", child: r.sessionID, agent: r.agent, ok: r.error.startsWith("aborted") });
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
const sums = summarizeStates(mine);
|
|
299
|
+
const header = [
|
|
300
|
+
`派发汇总:${sums.idle} 完成 / ${sums.running} 运行中 / ${sums.error} 失败${settled ? "(全部已结算)" : "(未等到全部结算,可再次 tm_join)"}`,
|
|
301
|
+
...mine.map((r) => renderChildLine(r, (r.finishedAt ?? now()) - r.startedAt)),
|
|
302
|
+
];
|
|
303
|
+
const wantText = !(args.includeText === false || args.includeText === "false");
|
|
304
|
+
const collectible = mine.filter((r) => r.state !== "running");
|
|
305
|
+
const blocks = [];
|
|
306
|
+
if (wantText) {
|
|
307
|
+
for (const r of collectible) {
|
|
308
|
+
const text = await fetchReply(r.sessionID, directory);
|
|
309
|
+
blocks.push(`--- ${r.agent} "${r.label}" (${r.sessionID}) ---\n${text.trim() || "(该子会话没有可读的助手回复——用内置 read/tm_read 检查其会话,或重新派发)"}`);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
const body = [...header, ...(blocks.length ? ["", blocks.join("\n")] : [])].join("\n");
|
|
313
|
+
const stepId = deps.pipelines.nextStepId();
|
|
314
|
+
return toToolResult(await deps.pipelines.govern(stepId, tool, body, {
|
|
315
|
+
contentType: detectContentType(body),
|
|
316
|
+
clue: `join parent=${shorten(parent, 24)} idle=${sums.idle} running=${sums.running} error=${sums.error}`,
|
|
317
|
+
}));
|
|
318
|
+
}
|
|
319
|
+
catch (err) {
|
|
320
|
+
const e = err;
|
|
321
|
+
return toToolResult(tmError(tool, "execute", `tm_join 失败:${shorten(e?.message ?? err, 160)}`));
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
};
|
|
325
|
+
const observeEvent = (event) => {
|
|
326
|
+
const type = String(event?.type ?? "");
|
|
327
|
+
if (!type.startsWith("session."))
|
|
328
|
+
return;
|
|
329
|
+
const props = event?.properties;
|
|
330
|
+
const sid = String(props?.sessionID ?? "").trim();
|
|
331
|
+
if (!sid)
|
|
332
|
+
return;
|
|
333
|
+
const rec = children.get(sid);
|
|
334
|
+
if (!rec)
|
|
335
|
+
return;
|
|
336
|
+
if (type === "session.idle") {
|
|
337
|
+
if (rec.state === "running") {
|
|
338
|
+
rec.state = "idle";
|
|
339
|
+
rec.finishedAt = now();
|
|
340
|
+
log({ step_id: "events", event: "idle", child: sid, agent: rec.agent, ms: (rec.finishedAt ?? 0) - rec.startedAt });
|
|
341
|
+
}
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
if (type === "session.error") {
|
|
345
|
+
rec.state = "error";
|
|
346
|
+
rec.finishedAt = now();
|
|
347
|
+
rec.error = shorten(props?.error?.message ?? props?.error ?? "session.error", 120);
|
|
348
|
+
log({ step_id: "events", event: "error", child: sid, agent: rec.agent, reason: rec.error });
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
if (type === "session.status") {
|
|
352
|
+
const st = String(props?.status?.type ?? "").toLowerCase();
|
|
353
|
+
if (st === "idle" && rec.state === "running") {
|
|
354
|
+
rec.state = "idle";
|
|
355
|
+
rec.finishedAt = now();
|
|
356
|
+
}
|
|
357
|
+
else if (st === "busy") {
|
|
358
|
+
rec.state = "running";
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
return {
|
|
363
|
+
tm_dispatch: dispatch,
|
|
364
|
+
tm_join: join,
|
|
365
|
+
observeEvent,
|
|
366
|
+
children: () => [...children.values()],
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
//# sourceMappingURL=dispatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatch.js","sourceRoot":"","sources":["../../src/tm/dispatch.ts"],"names":[],"mappings":"AAAA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C"}
|
package/dist/tm/index.d.ts
CHANGED
|
@@ -14,13 +14,17 @@
|
|
|
14
14
|
* T0.4-verified shape: `{ tool: { tm_read: { description, args,
|
|
15
15
|
* execute(args, ctx) } } }`).
|
|
16
16
|
*/
|
|
17
|
-
import type { PluginInput, ToolDefinition } from "../types.js";
|
|
17
|
+
import type { HostEvent, PluginInput, ToolDefinition } from "../types.js";
|
|
18
18
|
import { type EnvProtectMode } from "../envprotect.js";
|
|
19
19
|
import { type TmConfig } from "./config.js";
|
|
20
20
|
import { RunStore } from "./store.js";
|
|
21
21
|
export { rmForceSafe } from "../fs-safe.js";
|
|
22
22
|
export { buildTmMemoryTool, MEMORY_CATEGORIES, MEMORY_CONTENT_MAX, MEMORY_TITLE_MAX, projectSlug, scoreMemory, parseMemoryMarkdown, renderMemoryMarkdown, } from "./memory.js";
|
|
23
|
-
export { buildTmBrowserTool, defaultBrowserExecutable, findBrowserExecutable, isChromiumFamily, parseDesktopExec, parseProgId, parseRegCommand, resolveHeadless, } from "./browser.js";
|
|
23
|
+
export { buildTmBrowserTool, defaultBrowserExecutable, findBrowserExecutable, isChromiumFamily, isPassiveResource, normalizeResourceType, parseDesktopExec, parseProgId, parseRegCommand, playwrightLaunchTarget, rememberSite, resolveHeadless, siteOf, subresourcePass, } from "./browser.js";
|
|
24
|
+
export { ptyCommandLine, ptyCommandBlocked, ptyVerdictLine } from "./pty.js";
|
|
25
|
+
export type { PtyRecord, PtyDeps } from "./pty.js";
|
|
26
|
+
export { buildDispatchTools, DISPATCH_TARGETS, lastAssistantText, renderChildLine, sessionApiOf, summarizeStates, } from "./dispatch.js";
|
|
27
|
+
export type { ChildRecord, DispatchDeps } from "./dispatch.js";
|
|
24
28
|
export interface TmRuntime {
|
|
25
29
|
runId: string;
|
|
26
30
|
config: TmConfig;
|
|
@@ -28,14 +32,33 @@ export interface TmRuntime {
|
|
|
28
32
|
/** The ONE main pipeline instance (exposed for tests + tool builders). */
|
|
29
33
|
pipelines: ReturnType<typeof import("./pipelines.js").buildPipelines>;
|
|
30
34
|
tools: Record<string, ToolDefinition>;
|
|
31
|
-
/** Kill any long-lived session the tools own (tm_browser child process).
|
|
32
|
-
|
|
35
|
+
/** Kill any long-lived session the tools own (tm_browser child process).
|
|
36
|
+
* ASYNC because the host's dispose hook awaits it — a fire-and-forget
|
|
37
|
+
* browser close could lose the window. */
|
|
38
|
+
dispose: () => Promise<void>;
|
|
39
|
+
/** Host event bus slice the async dispatcher needs (session.idle /
|
|
40
|
+
* .error / .status settle the lead's children). */
|
|
41
|
+
observeDispatchEvent: (event: HostEvent) => void;
|
|
42
|
+
/** Open async dispatches this plugin started (tests + observability). */
|
|
43
|
+
dispatches: () => Array<{
|
|
44
|
+
sessionID: string;
|
|
45
|
+
agent: string;
|
|
46
|
+
label: string;
|
|
47
|
+
state: string;
|
|
48
|
+
}>;
|
|
33
49
|
}
|
|
34
50
|
export interface CreateTmToolsOptions {
|
|
35
51
|
/** R6 mode — pass the plugin-level resolved value to keep ONE source. */
|
|
36
52
|
mode?: EnvProtectMode;
|
|
37
53
|
/** R6 extra deny rules — same single-source rule. */
|
|
38
54
|
extra?: RegExp[];
|
|
55
|
+
/** Best-effort user notification (the host toast) — tm_browser's idle
|
|
56
|
+
* reaper uses it so an auto-closed window is announced, not silent. */
|
|
57
|
+
notify?: (message: string) => void;
|
|
58
|
+
/** A tm_dispatch child session was created — let the approval gate
|
|
59
|
+
* register it so the sub-agent's own protected read opens the official
|
|
60
|
+
* dialog instead of hard-throwing in an unregistered session. */
|
|
61
|
+
onChildSession?: (sessionID: string, agent: string) => void;
|
|
39
62
|
}
|
|
40
63
|
export declare function createTmTools(input: PluginInput, opts?: CreateTmToolsOptions): Promise<TmRuntime>;
|
|
41
64
|
export { DEFAULT_BASH_READONLY_ALLOWED, DEFAULT_WEBFETCH_DOMAINS, estimateTokens, parseAllowlistEnv, parseWebfetchAllowlistEnv, resolveTmConfig, shouldOffload, shorten, TM_CONFIG_DEFAULTS, } from "./config.js";
|
|
@@ -49,10 +72,12 @@ export type { TmDeps, TmPipelines } from "./pipelines.js";
|
|
|
49
72
|
export { buildPtcArgsSchema, buildWebfetchArgsSchema, buildSearchArgsSchema } from "./args-schema.js";
|
|
50
73
|
export { toToolResult, HANDLE_INVALID_MESSAGE, tmError } from "./result.js";
|
|
51
74
|
export type { TmPhase } from "./result.js";
|
|
52
|
-
export { runShellCommand, cleanShellError } from "./shell-bridge.js";
|
|
75
|
+
export { runShellCommand, spawnShellFallback, cleanShellError } from "./shell-bridge.js";
|
|
53
76
|
export { buildTmWebfetchTool, checkWebUrl, extractWebResponse, extractSearchHits, renderSearchHits, fetchWebText, hitDomainBlacklist, HIT_DOMAIN_BLACKLIST_DEFAULT, hostAllowed, htmlToText, } from "./webfetch.js";
|
|
54
77
|
export type { SearchHit } from "./webfetch.js";
|
|
55
78
|
export { buildTmSearchTool, SEARCH_ENGINES, SEARCH_ENGINE_NAMES, renderNpmResults, renderGithubResults, renderWikiResults, } from "./search.js";
|
|
56
|
-
export { BRIDGE_ALLOW, InlineSequentialEngine, InlineVmEngine, WorkerEngine, PTC_LABEL_MAX, PTC_STATUS_VALUES, RETRYABLE_PHASES, PTC_SUMMARY_HEADER, PTC_OK_SECTION, PTC_OK_HEADER, PTC_ERR_SECTION, PTC_ERR_HEADER, PTC_RETURN_PREFIX, PTC_ERRORFULL_PREFIX, buildPtcRunTool, createGateBridge, parsePtcArgs, pipelineBridge, renderPtcSummary, resolvePtcBudgets, runPtc, selectEngine, staticPscan, } from "./ptc/index.js";
|
|
57
|
-
export
|
|
79
|
+
export { BRIDGE_ALLOW, InlineSequentialEngine, InlineVmEngine, WorkerEngine, PTC_LABEL_MAX, PTC_STATUS_VALUES, PtcProgramError, PtcStopSignal, RETRYABLE_PHASES, PTC_SUMMARY_HEADER, PTC_OK_SECTION, PTC_OK_HEADER, PTC_ERR_SECTION, PTC_ERR_HEADER, PTC_RETURN_PREFIX, PTC_ERRORFULL_PREFIX, buildPtcRunTool, createGateBridge, parsePtcArgs, pipelineBridge, renderPtcSummary, resolvePtcBudgets, resolvePtcBudgetsDetailed, runPtc, selectEngine, staticPscan, } from "./ptc/index.js";
|
|
80
|
+
export { stripNonExecutable } from "./ptc/pscan.js";
|
|
81
|
+
export { WEB_BRIDGE_TOOLS } from "./ptc/contract.js";
|
|
82
|
+
export type { PtcStatus, PtcEngine, PtcEngineName, PtcEngineRunOpts, PtcBridge, PtcCallResult, PtcErrorBody, PtcRunRequest, PtcRpcRequest, PtcRpcResponse, PtcRpcAbort, PtcEngineMessage, PtcBudgets, PtcBudgetResolution, PtcStepRecord, PtcRunOutcome, RunPtcOptions, } from "./ptc/index.js";
|
|
58
83
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/tm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tm/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAMH,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tm/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAMH,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEzE,OAAO,EAGL,KAAK,cAAc,EACpB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAmB,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAA;AAE5D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAOrC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,WAAW,EACX,WAAW,EACX,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,kBAAkB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kBAAkB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACxF,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,EAClB,4BAA4B,EAC5B,WAAW,EACX,UAAU,GACX,MAAM,eAAe,CAAA;AACtB,YAAY,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,aAAa,CAAA;AAOpB,OAAO,EACL,YAAY,EACZ,sBAAsB,EACtB,cAAc,EACd,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,aAAa,EACb,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,yBAAyB,EACzB,MAAM,EACN,YAAY,EACZ,WAAW,GACZ,MAAM,gBAAgB,CAAA;AAIvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACpD,YAAY,EACV,SAAS,EACT,SAAS,EACT,aAAa,EACb,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,YAAY,EACZ,aAAa,EACb,aAAa,EACb,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,UAAU,EACV,mBAAmB,EACnB,aAAa,EACb,aAAa,EACb,aAAa,GACd,MAAM,gBAAgB,CAAA"}
|
package/dist/tm/index.js
CHANGED
|
@@ -31,9 +31,13 @@ import { buildTmWebfetchTool } from "./webfetch.js";
|
|
|
31
31
|
import { buildTmSearchTool } from "./search.js";
|
|
32
32
|
export { rmForceSafe } from "../fs-safe.js";
|
|
33
33
|
export { buildTmMemoryTool, MEMORY_CATEGORIES, MEMORY_CONTENT_MAX, MEMORY_TITLE_MAX, projectSlug, scoreMemory, parseMemoryMarkdown, renderMemoryMarkdown, } from "./memory.js";
|
|
34
|
-
export { buildTmBrowserTool, defaultBrowserExecutable, findBrowserExecutable, isChromiumFamily, parseDesktopExec, parseProgId, parseRegCommand, resolveHeadless, } from "./browser.js";
|
|
34
|
+
export { buildTmBrowserTool, defaultBrowserExecutable, findBrowserExecutable, isChromiumFamily, isPassiveResource, normalizeResourceType, parseDesktopExec, parseProgId, parseRegCommand, playwrightLaunchTarget, rememberSite, resolveHeadless, siteOf, subresourcePass, } from "./browser.js";
|
|
35
35
|
import { buildTmMemoryTool } from "./memory.js";
|
|
36
36
|
import { buildTmBrowserTool } from "./browser.js";
|
|
37
|
+
import { buildDispatchTools } from "./dispatch.js";
|
|
38
|
+
import { buildTmPtyTool } from "./pty.js";
|
|
39
|
+
export { ptyCommandLine, ptyCommandBlocked, ptyVerdictLine } from "./pty.js";
|
|
40
|
+
export { buildDispatchTools, DISPATCH_TARGETS, lastAssistantText, renderChildLine, sessionApiOf, summarizeStates, } from "./dispatch.js";
|
|
37
41
|
export async function createTmTools(input, opts = {}) {
|
|
38
42
|
const cfg = resolveTmConfig(process.env);
|
|
39
43
|
const directory = typeof input?.directory === "string" && input.directory.length > 0
|
|
@@ -98,6 +102,9 @@ export async function createTmTools(input, opts = {}) {
|
|
|
98
102
|
expireAt,
|
|
99
103
|
mode,
|
|
100
104
|
extra,
|
|
105
|
+
// fix batch T3: the ctxDir fallback — the host process cwd is the user
|
|
106
|
+
// HOME on the desktop sidecar, never a valid workspace root.
|
|
107
|
+
workspaceDir: directory,
|
|
101
108
|
};
|
|
102
109
|
// ONE main pipeline instance shared by the four tools AND tm_webfetch —
|
|
103
110
|
// a shared step counter keeps their refs unambiguous (a second instance
|
|
@@ -131,7 +138,12 @@ export async function createTmTools(input, opts = {}) {
|
|
|
131
138
|
// Network role tool: team + researcher carry the allow; the other four
|
|
132
139
|
// hold an explicit deny (overrides the tm_* wildcard). dispose() kills
|
|
133
140
|
// the browser child when the host tears the plugin down.
|
|
134
|
-
const browserTool = buildTmBrowserTool({
|
|
141
|
+
const browserTool = buildTmBrowserTool({
|
|
142
|
+
pipelines,
|
|
143
|
+
cfg,
|
|
144
|
+
args: await buildBrowserArgsSchema(),
|
|
145
|
+
notify: opts.notify,
|
|
146
|
+
});
|
|
135
147
|
tools.tm_browser = browserTool;
|
|
136
148
|
// M3: build tm_ptc_run using a separate pipeline instance (governance
|
|
137
149
|
// reused verbatim). Its step counter starts at s0001 again — the
|
|
@@ -150,19 +162,71 @@ export async function createTmTools(input, opts = {}) {
|
|
|
150
162
|
mode,
|
|
151
163
|
extra,
|
|
152
164
|
stepPrefix: "ptc-",
|
|
165
|
+
workspaceDir: directory,
|
|
153
166
|
};
|
|
154
167
|
const ptcPipelines = buildPipelines(ptcDeps);
|
|
168
|
+
// T6 web bridge: when TM_PTC_WEB_BRIDGE=on, PTC's tm.search / tm.webfetch
|
|
169
|
+
// run SECONDARY tm_search / tm_webfetch instances over the SAME "ptc-"
|
|
170
|
+
// pipeline, so their step ids stay namespaced. They are NOT registered on
|
|
171
|
+
// the host tool surface here (the main `tools.tm_search` / `tools.tm_webfetch`
|
|
172
|
+
// already are) — they exist only as the bridge's call targets. Role gating
|
|
173
|
+
// is automatic: each bridged call is executed with the CALLER's per-execute
|
|
174
|
+
// ctx (see buildPtcRunTool.makeBridge), so the host's permission.asked runs
|
|
175
|
+
// against the calling agent's own ruleset and a non-web role is denied.
|
|
176
|
+
const ptcWebTools = cfg.ptcWebBridge === "on"
|
|
177
|
+
? {
|
|
178
|
+
tm_search: buildTmSearchTool({
|
|
179
|
+
pipelines: ptcPipelines,
|
|
180
|
+
cfg,
|
|
181
|
+
args: await buildSearchArgsSchema(),
|
|
182
|
+
}),
|
|
183
|
+
tm_webfetch: buildTmWebfetchTool({
|
|
184
|
+
pipelines: ptcPipelines,
|
|
185
|
+
cfg,
|
|
186
|
+
args: await buildWebfetchArgsSchema(),
|
|
187
|
+
}),
|
|
188
|
+
}
|
|
189
|
+
: undefined;
|
|
155
190
|
const ptcTool = buildPtcRunTool({
|
|
156
191
|
cfg,
|
|
157
192
|
store,
|
|
158
193
|
nextStepId: ptcPipelines.nextStepId,
|
|
194
|
+
// assembly-time ctx is only the directory fallback; the bridge re-binds
|
|
195
|
+
// to the real per-execute ctx inside execute(rawArgs, callCtx).
|
|
159
196
|
ctx: { directory },
|
|
160
197
|
accessToken,
|
|
161
198
|
args: await buildPtcArgsSchema(),
|
|
162
199
|
pipelines: ptcPipelines,
|
|
200
|
+
webTools: ptcWebTools,
|
|
163
201
|
});
|
|
164
202
|
tools.tm_ptc_run = ptcTool;
|
|
165
|
-
|
|
203
|
+
// tm_dispatch / tm_join — ASYNC sub-agent dispatch for the lead (issue #7:
|
|
204
|
+
// the host's `task` tool blocks the calling session, so "parallel team"
|
|
205
|
+
// really meant "serial with extra steps"). Built on the official client
|
|
206
|
+
// session API; both tools self-gate to the lead agent, and the five
|
|
207
|
+
// specialists carry an explicit deny in agents.ts.
|
|
208
|
+
const dispatch = buildDispatchTools({
|
|
209
|
+
client: input?.client,
|
|
210
|
+
pipelines,
|
|
211
|
+
onChildSession: opts.onChildSession,
|
|
212
|
+
});
|
|
213
|
+
tools.tm_dispatch = dispatch.tm_dispatch;
|
|
214
|
+
tools.tm_join = dispatch.tm_join;
|
|
215
|
+
// tm_pty — non-blocking command execution on the host's own terminal
|
|
216
|
+
// sessions (issue #6: three serial 120 s test suites are minutes of dead
|
|
217
|
+
// air inside one bash call). Every start passes the R6 classifier AND the
|
|
218
|
+
// official dialog, so this is an async lever, not a bypass channel.
|
|
219
|
+
tools.tm_pty = buildTmPtyTool({ client: input?.client, pipelines, mode, max: cfg.ptyMax });
|
|
220
|
+
return {
|
|
221
|
+
runId,
|
|
222
|
+
config: cfg,
|
|
223
|
+
store,
|
|
224
|
+
pipelines,
|
|
225
|
+
tools,
|
|
226
|
+
dispose: () => browserTool.dispose(),
|
|
227
|
+
observeDispatchEvent: dispatch.observeEvent,
|
|
228
|
+
dispatches: () => dispatch.children().map((c) => ({ sessionID: c.sessionID, agent: c.agent, label: c.label, state: c.state })),
|
|
229
|
+
};
|
|
166
230
|
}
|
|
167
231
|
// ---------- re-exports (stable import surface for tests + plugin entry) ----------
|
|
168
232
|
export { DEFAULT_BASH_READONLY_ALLOWED, DEFAULT_WEBFETCH_DOMAINS, estimateTokens, parseAllowlistEnv, parseWebfetchAllowlistEnv, resolveTmConfig, shouldOffload, shorten, TM_CONFIG_DEFAULTS, } from "./config.js";
|
|
@@ -174,7 +238,7 @@ export { buildTmTools } from "./tools.js";
|
|
|
174
238
|
export { buildPipelines } from "./pipelines.js";
|
|
175
239
|
export { buildPtcArgsSchema, buildWebfetchArgsSchema, buildSearchArgsSchema } from "./args-schema.js";
|
|
176
240
|
export { toToolResult, HANDLE_INVALID_MESSAGE, tmError } from "./result.js";
|
|
177
|
-
export { runShellCommand, cleanShellError } from "./shell-bridge.js";
|
|
241
|
+
export { runShellCommand, spawnShellFallback, cleanShellError } from "./shell-bridge.js";
|
|
178
242
|
export { buildTmWebfetchTool, checkWebUrl, extractWebResponse, extractSearchHits, renderSearchHits, fetchWebText, hitDomainBlacklist, HIT_DOMAIN_BLACKLIST_DEFAULT, hostAllowed, htmlToText, } from "./webfetch.js";
|
|
179
243
|
export { buildTmSearchTool, SEARCH_ENGINES, SEARCH_ENGINE_NAMES, renderNpmResults, renderGithubResults, renderWikiResults, } from "./search.js";
|
|
180
244
|
// ---------- tm_ptc_run ----------
|
|
@@ -182,5 +246,10 @@ export { buildTmSearchTool, SEARCH_ENGINES, SEARCH_ENGINE_NAMES, renderNpmResult
|
|
|
182
246
|
// step counter is independent — store handles any step-id overlap via
|
|
183
247
|
// tool-name-prefixed files) and MERGED into the registered `tools` map
|
|
184
248
|
// below, so all five tools ship in the `tool` segment.
|
|
185
|
-
export { BRIDGE_ALLOW, InlineSequentialEngine, InlineVmEngine, WorkerEngine, PTC_LABEL_MAX, PTC_STATUS_VALUES, RETRYABLE_PHASES, PTC_SUMMARY_HEADER, PTC_OK_SECTION, PTC_OK_HEADER, PTC_ERR_SECTION, PTC_ERR_HEADER, PTC_RETURN_PREFIX, PTC_ERRORFULL_PREFIX, buildPtcRunTool, createGateBridge, parsePtcArgs, pipelineBridge, renderPtcSummary, resolvePtcBudgets, runPtc, selectEngine, staticPscan, } from "./ptc/index.js";
|
|
249
|
+
export { BRIDGE_ALLOW, InlineSequentialEngine, InlineVmEngine, WorkerEngine, PTC_LABEL_MAX, PTC_STATUS_VALUES, PtcProgramError, PtcStopSignal, RETRYABLE_PHASES, PTC_SUMMARY_HEADER, PTC_OK_SECTION, PTC_OK_HEADER, PTC_ERR_SECTION, PTC_ERR_HEADER, PTC_RETURN_PREFIX, PTC_ERRORFULL_PREFIX, buildPtcRunTool, createGateBridge, parsePtcArgs, pipelineBridge, renderPtcSummary, resolvePtcBudgets, resolvePtcBudgetsDetailed, runPtc, selectEngine, staticPscan, } from "./ptc/index.js";
|
|
250
|
+
// T6 additions pulled straight from their submodules so ptc/index.ts (a
|
|
251
|
+
// frozen re-export facade, owned by the PTC split) is not edited: the
|
|
252
|
+
// literal-strip helper the pre-scan uses + the web-bridge tool subset.
|
|
253
|
+
export { stripNonExecutable } from "./ptc/pscan.js";
|
|
254
|
+
export { WEB_BRIDGE_TOOLS } from "./ptc/contract.js";
|
|
186
255
|
//# sourceMappingURL=index.js.map
|