dsh-taskbridge 1.4.2 → 1.5.1
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 +34 -2
- package/README.md +10 -8
- package/bin/dsh-delegate-mcp.d.ts +20 -3
- package/bin/dsh-delegate-mcp.js +15 -0
- package/codex/dsh-taskbridge.toml +180 -16
- package/docs/INTRODUCTION.md +2 -2
- package/docs/INTRODUCTION.zh.md +2 -2
- package/docs/codex-integration.md +11 -13
- package/docs/conversation-placement.md +44 -7
- package/docs/plugin-market.md +1 -1
- package/docs/redaction-contract.md +47 -4
- package/docs/releases/1.5.0-token-benchmark.zh.md +73 -0
- package/docs/releases/1.5.0.zh.md +51 -0
- package/docs/releases/1.5.1.zh.md +70 -0
- package/docs/runtime-compatibility.md +4 -4
- package/docs/silent-wait.md +157 -3
- package/docs/taskbridge-upgrade.md +1 -1
- package/docs/worker-permissions.md +154 -17
- package/lib/client.js +298 -103
- package/package.json +9 -3
- package/src/client/api.js +315 -34
- package/src/client/index.jsx +151 -67
- package/src/codex/installer.js +251 -11
- package/src/config/redact.js +72 -11
- package/src/http/execution-plane.js +124 -10
- package/src/index.d.ts +347 -0
- package/src/index.js +88 -5
- package/src/jobs/activity.js +102 -9
- package/src/jobs/continuation-identity.js +283 -0
- package/src/jobs/engine.js +491 -55
- package/src/jobs/history.js +96 -0
- package/src/mcp/continuation.js +317 -0
- package/src/mcp/metrics.js +366 -0
- package/src/mcp/server.js +1203 -53
- package/src/mcp/wait.js +338 -73
- package/src/review/prompts.js +145 -126
- package/src/runtime/agent-runner.js +330 -0
- package/src/runtime/permissions.js +192 -2
- package/src/runtime/question-call.js +162 -0
- package/src/runtime/questions.js +909 -0
- package/src/runtime/sandbox.js +363 -358
- package/src/runtime/session-placement.js +1207 -1121
- package/src/version.js +121 -0
- package/src/workspace/worktrees.js +70 -4
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// Which native `ask_user_question` call a pending question belongs to.
|
|
2
|
+
//
|
|
3
|
+
// An answer is delivered by RESUMING the paused tool call, so the bridge must know exactly
|
|
4
|
+
// which call that is. The rule is deliberately narrow, and it never searches for "some"
|
|
5
|
+
// call:
|
|
6
|
+
//
|
|
7
|
+
// 1. the request's own `wait.callId` is the declared identity (the native tool sets it);
|
|
8
|
+
// 2. that id must be found in the Session log as a `tool/call` whose name is
|
|
9
|
+
// `ask_user_question`;
|
|
10
|
+
// 3. it must be the NEWEST such call: a repeated id is the live one, an older duplicate
|
|
11
|
+
// is a finished turn;
|
|
12
|
+
// 4. it must have NO `tool/result` after it — a call that already returned is history, and
|
|
13
|
+
// an answer delivered to it would resume nothing;
|
|
14
|
+
// 5. its turn must still be the OPEN turn. A call whose turn closed can only arrive as a
|
|
15
|
+
// new turn, so an answer cannot be replayed onto it.
|
|
16
|
+
//
|
|
17
|
+
// A legacy request that carries no `wait` at all is bound only when the open turn holds
|
|
18
|
+
// exactly ONE live `ask_user_question` call: with one candidate the identity is proven, and
|
|
19
|
+
// with two it is ambiguous, which is a refusal rather than a guess.
|
|
20
|
+
|
|
21
|
+
/** The tool whose calls a question may bind to. */
|
|
22
|
+
export const QUESTION_TOOL_NAME = 'ask_user_question';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Find one `tool/call` record by id, newest first.
|
|
26
|
+
* @param {object} session - Session with `seq` and `eventAt`.
|
|
27
|
+
* @param {string} callId - the id to find.
|
|
28
|
+
* @returns {{ event: object, index: number } | null} the newest match.
|
|
29
|
+
*/
|
|
30
|
+
function findCall(session, callId) {
|
|
31
|
+
for (let index = session.seq - 1; index >= 0; index -= 1) {
|
|
32
|
+
const event = session.eventAt(index);
|
|
33
|
+
if (event === null || typeof event !== 'object' || event.type !== 'tool/call') continue;
|
|
34
|
+
if (event.data?.callId === callId) return { event, index };
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The index of the last `turn/start` with no `turn/end` after it, or `null`.
|
|
41
|
+
* @param {object} session - Session with `seq` and `eventAt`.
|
|
42
|
+
* @returns {number | null} the open turn's start offset.
|
|
43
|
+
*/
|
|
44
|
+
function openTurnStart(session) {
|
|
45
|
+
for (let index = session.seq - 1; index >= 0; index -= 1) {
|
|
46
|
+
const event = session.eventAt(index);
|
|
47
|
+
if (event === null || typeof event !== 'object') continue;
|
|
48
|
+
if (event.type === 'turn/end') return null;
|
|
49
|
+
if (event.type === 'turn/start') return index;
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The tool-call id one `tool/result` event answers.
|
|
56
|
+
*
|
|
57
|
+
* DSH records the id under `data.message.toolCallId` (the result message carries the call it
|
|
58
|
+
* belongs to); older/synthetic logs put it directly on `data.callId`. BOTH are read, because a
|
|
59
|
+
* matcher that only knew one shape would report "no result yet" for a call that already
|
|
60
|
+
* returned — and an answer would then be delivered to a finished call.
|
|
61
|
+
* @param {object} event - a `tool/result` event.
|
|
62
|
+
* @returns {string | null} the call id, or null when the event names none.
|
|
63
|
+
*/
|
|
64
|
+
function resultCallId(event) {
|
|
65
|
+
const nested = event?.data?.message?.toolCallId;
|
|
66
|
+
if (typeof nested === 'string' && nested !== '') return nested;
|
|
67
|
+
const flat = event?.data?.callId;
|
|
68
|
+
if (typeof flat === 'string' && flat !== '') return flat;
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Whether a call at one offset has already produced a `tool/result`.
|
|
74
|
+
* @param {object} session - Session with `seq` and `eventAt`.
|
|
75
|
+
* @param {string} callId - the call id.
|
|
76
|
+
* @param {number} fromIndex - the call's own offset.
|
|
77
|
+
* @returns {boolean} true when a result was recorded after it.
|
|
78
|
+
*/
|
|
79
|
+
function hasResult(session, callId, fromIndex) {
|
|
80
|
+
for (let index = fromIndex + 1; index < session.seq; index += 1) {
|
|
81
|
+
const event = session.eventAt(index);
|
|
82
|
+
if (event === null || typeof event !== 'object' || event.type !== 'tool/result') continue;
|
|
83
|
+
if (resultCallId(event) === callId) return true;
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The live `ask_user_question` calls of the OPEN turn, oldest first.
|
|
90
|
+
* @param {object} session - Session with `seq` and `eventAt`.
|
|
91
|
+
* @param {number} turnStart - the open turn's start offset.
|
|
92
|
+
* @returns {{ callId: string, seq: number, turn: number | null }[]} live calls.
|
|
93
|
+
*/
|
|
94
|
+
function liveCallsOfTurn(session, turnStart) {
|
|
95
|
+
const calls = [];
|
|
96
|
+
for (let index = turnStart; index < session.seq; index += 1) {
|
|
97
|
+
const event = session.eventAt(index);
|
|
98
|
+
if (event === null || typeof event !== 'object' || event.type !== 'tool/call') continue;
|
|
99
|
+
const name = event.data?.name;
|
|
100
|
+
const callId = event.data?.callId;
|
|
101
|
+
if (name !== QUESTION_TOOL_NAME || typeof callId !== 'string' || callId === '') continue;
|
|
102
|
+
if (hasResult(session, callId, index)) continue;
|
|
103
|
+
calls.push({
|
|
104
|
+
callId,
|
|
105
|
+
seq: index,
|
|
106
|
+
turn: typeof event.data?.turn === 'number' ? event.data.turn : null,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return calls;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Resolve the ONE native call a question belongs to.
|
|
114
|
+
* @param {object} request - `session`, `declaredCallId` (from `request.wait.callId`), `toolName`.
|
|
115
|
+
* @returns {{ ok: true, callId: string, seq: number, turn: number | null }
|
|
116
|
+
* | { ok: false, detail: string }} the binding, or why it is impossible.
|
|
117
|
+
*/
|
|
118
|
+
export function QUESTION_CALL_BINDING(request) {
|
|
119
|
+
const session = request?.session ?? null;
|
|
120
|
+
if (session === null || typeof session !== 'object'
|
|
121
|
+
|| typeof session.eventAt !== 'function' || !Number.isInteger(session.seq)) {
|
|
122
|
+
return { ok: false, detail: 'the asking session keeps no readable log' };
|
|
123
|
+
}
|
|
124
|
+
const turnStart = openTurnStart(session);
|
|
125
|
+
if (turnStart === null) {
|
|
126
|
+
return { ok: false, detail: 'no turn is open, so the question belongs to no live call' };
|
|
127
|
+
}
|
|
128
|
+
const declared = typeof request?.declaredCallId === 'string' && request.declaredCallId !== ''
|
|
129
|
+
? request.declaredCallId
|
|
130
|
+
: null;
|
|
131
|
+
if (declared !== null) {
|
|
132
|
+
const found = findCall(session, declared);
|
|
133
|
+
if (found === null) return { ok: false, detail: 'the declared call id is not in the session log' };
|
|
134
|
+
const name = found.event.data?.name;
|
|
135
|
+
if (name !== QUESTION_TOOL_NAME) {
|
|
136
|
+
return { ok: false, detail: `the declared call is a ${String(name)} call, not a question` };
|
|
137
|
+
}
|
|
138
|
+
if (found.index < turnStart) {
|
|
139
|
+
return { ok: false, detail: 'the declared call belongs to an earlier turn' };
|
|
140
|
+
}
|
|
141
|
+
if (hasResult(session, declared, found.index)) {
|
|
142
|
+
return { ok: false, detail: 'the declared call already produced a result' };
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
ok: true,
|
|
146
|
+
callId: declared,
|
|
147
|
+
seq: found.index,
|
|
148
|
+
turn: typeof found.event.data?.turn === 'number' ? found.event.data.turn : null,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
// A legacy request names no call. It is bound only when the open turn holds exactly ONE
|
|
152
|
+
// live question call: two candidates make the identity ambiguous, and a guess could
|
|
153
|
+
// resume the wrong operation.
|
|
154
|
+
const candidates = liveCallsOfTurn(session, turnStart);
|
|
155
|
+
if (candidates.length === 0) {
|
|
156
|
+
return { ok: false, detail: 'the open turn holds no live question call' };
|
|
157
|
+
}
|
|
158
|
+
if (candidates.length > 1) {
|
|
159
|
+
return { ok: false, detail: `the open turn holds ${candidates.length} live question calls, so the binding is ambiguous` };
|
|
160
|
+
}
|
|
161
|
+
return { ok: true, ...candidates[0] };
|
|
162
|
+
}
|