dsh-taskbridge 0.0.0-stage → 1.3.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 +754 -0
- package/LICENSE +21 -0
- package/README.md +624 -3
- package/bin/dsh-delegate-codex-agent.js +115 -0
- package/bin/dsh-delegate-control.d.ts +90 -0
- package/bin/dsh-delegate-control.js +450 -0
- package/bin/dsh-delegate-mcp.d.ts +121 -0
- package/bin/dsh-delegate-mcp.js +273 -0
- package/codex/dsh-delegate.toml +245 -0
- package/cordis.patch.yml +6 -0
- package/docs/INTRODUCTION.md +15 -0
- package/docs/INTRODUCTION.zh.md +32 -0
- package/docs/auth-contract.md +138 -0
- package/docs/claude-code.md +31 -0
- package/docs/codex-integration.md +922 -0
- package/docs/contracts-stage-b.md +443 -0
- package/docs/conversation-placement.md +293 -0
- package/docs/plugin-market.md +30 -0
- package/docs/redaction-contract.md +127 -0
- package/docs/runtime-compatibility.md +220 -0
- package/docs/silent-wait.md +191 -0
- package/docs/taskbridge-upgrade.md +28 -0
- package/docs/taskdispatch-upgrade.md +25 -0
- package/docs/worker-permissions.md +347 -0
- package/docs/workspace-contract.md +538 -0
- package/icon.svg +1 -0
- package/lib/client.d.ts +118 -0
- package/lib/client.js +3232 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +135 -4
- package/src/auth/fence.js +361 -0
- package/src/auth/grants.js +789 -0
- package/src/client/api.js +2322 -0
- package/src/client/index.jsx +2333 -0
- package/src/client/styles.js +251 -0
- package/src/codex/installer.js +3260 -0
- package/src/codex/seam.js +429 -0
- package/src/codex/toml.js +784 -0
- package/src/config/defaults.js +164 -0
- package/src/config/redact.js +184 -0
- package/src/config/settings.js +629 -0
- package/src/config/store.js +186 -0
- package/src/config/validate.js +763 -0
- package/src/credentials/seam.js +202 -0
- package/src/http/execution-plane.js +454 -0
- package/src/http/respond.js +175 -0
- package/src/http/user-plane.js +1122 -0
- package/src/index.d.ts +332 -0
- package/src/index.js +657 -0
- package/src/jobs/activity.js +1008 -0
- package/src/jobs/engine.js +3609 -0
- package/src/jobs/history.js +1467 -0
- package/src/mcp/server.js +1820 -0
- package/src/mcp/wait.js +536 -0
- package/src/model/connectivity.js +371 -0
- package/src/model/discovery.js +582 -0
- package/src/model/native-catalog.js +68 -0
- package/src/model/openai-adapter.js +671 -0
- package/src/model/probe.js +264 -0
- package/src/model/providers.js +756 -0
- package/src/model/routing.js +321 -0
- package/src/review/preset.js +868 -0
- package/src/review/prompts.js +126 -0
- package/src/review/reviewer.js +933 -0
- package/src/runtime/agent-runner.js +1738 -0
- package/src/runtime/endpoint-discovery.js +118 -0
- package/src/runtime/permissions.js +1429 -0
- package/src/runtime/sandbox.js +358 -0
- package/src/runtime/session-placement.js +1103 -0
- package/src/workspace/audit.js +775 -0
- package/src/workspace/locks.js +167 -0
- package/src/workspace/preflight.js +424 -0
- package/src/workspace/worktrees.js +613 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// Shared HTTP plumbing for both delegation planes.
|
|
2
|
+
//
|
|
3
|
+
// The helpers here are deliberately dumb: they parse a bounded JSON body, emit
|
|
4
|
+
// a JSON response, and translate refusals into status codes. Every decision
|
|
5
|
+
// about *whether* a request may proceed lives in the plane that owns the route.
|
|
6
|
+
|
|
7
|
+
/** Bound on a request body. A control request is small by nature. */
|
|
8
|
+
export const MAX_BODY_BYTES = 512 * 1024;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Read a bounded JSON body from a node request stream.
|
|
12
|
+
* @param {import('node:http').IncomingMessage} req - request.
|
|
13
|
+
* @param {number} [limit] - byte bound.
|
|
14
|
+
* @returns {Promise<object>} parsed body, or an empty object when absent.
|
|
15
|
+
*/
|
|
16
|
+
export async function readJsonBody(req, limit = MAX_BODY_BYTES) {
|
|
17
|
+
const chunks = [];
|
|
18
|
+
let size = 0;
|
|
19
|
+
for await (const chunk of req) {
|
|
20
|
+
size += chunk.length;
|
|
21
|
+
if (size > limit) {
|
|
22
|
+
throw new HttpError(413, 'BODY_TOO_LARGE', `request body exceeds ${limit} bytes`);
|
|
23
|
+
}
|
|
24
|
+
chunks.push(chunk);
|
|
25
|
+
}
|
|
26
|
+
if (chunks.length === 0) return {};
|
|
27
|
+
const text = Buffer.concat(chunks).toString('utf8').trim();
|
|
28
|
+
if (text === '') return {};
|
|
29
|
+
try {
|
|
30
|
+
const parsed = JSON.parse(text);
|
|
31
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
32
|
+
throw new HttpError(400, 'BODY_NOT_OBJECT', 'request body must be a JSON object');
|
|
33
|
+
}
|
|
34
|
+
return parsed;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (error instanceof HttpError) throw error;
|
|
37
|
+
throw new HttpError(400, 'BODY_INVALID_JSON', 'request body is not valid JSON');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Read a bounded JSON body from a WHATWG Request.
|
|
43
|
+
* @param {Request} request - fetch-style request.
|
|
44
|
+
* @param {number} [limit] - byte bound.
|
|
45
|
+
* @returns {Promise<object>} parsed body, or an empty object when absent.
|
|
46
|
+
*/
|
|
47
|
+
export async function readJsonRequest(request, limit = MAX_BODY_BYTES) {
|
|
48
|
+
const text = await request.text();
|
|
49
|
+
if (Buffer.byteLength(text, 'utf8') > limit) {
|
|
50
|
+
throw new HttpError(413, 'BODY_TOO_LARGE', `request body exceeds ${limit} bytes`);
|
|
51
|
+
}
|
|
52
|
+
if (text.trim() === '') return {};
|
|
53
|
+
try {
|
|
54
|
+
const parsed = JSON.parse(text);
|
|
55
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
56
|
+
throw new HttpError(400, 'BODY_NOT_OBJECT', 'request body must be a JSON object');
|
|
57
|
+
}
|
|
58
|
+
return parsed;
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (error instanceof HttpError) throw error;
|
|
61
|
+
throw new HttpError(400, 'BODY_INVALID_JSON', 'request body is not valid JSON');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** An HTTP-level refusal with a stable code. */
|
|
66
|
+
export class HttpError extends Error {
|
|
67
|
+
/**
|
|
68
|
+
* @param {number} status - HTTP status.
|
|
69
|
+
* @param {string} code - stable machine code.
|
|
70
|
+
* @param {string} message - explanation.
|
|
71
|
+
* @param {object} [details] - bounded details.
|
|
72
|
+
*/
|
|
73
|
+
constructor(status, code, message, details = {}) {
|
|
74
|
+
super(message);
|
|
75
|
+
this.name = 'HttpError';
|
|
76
|
+
this.status = status;
|
|
77
|
+
this.code = code;
|
|
78
|
+
this.details = details;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Emit a JSON response on a node response object.
|
|
84
|
+
* @param {import('node:http').ServerResponse} res - response.
|
|
85
|
+
* @param {number} status - status code.
|
|
86
|
+
* @param {unknown} payload - JSON payload.
|
|
87
|
+
* @param {Record<string, string>} [headers] - extra headers.
|
|
88
|
+
* @returns {void}
|
|
89
|
+
*/
|
|
90
|
+
export function sendJson(res, status, payload, headers = {}) {
|
|
91
|
+
const body = Buffer.from(`${JSON.stringify(payload)}\n`, 'utf8');
|
|
92
|
+
res.writeHead(status, {
|
|
93
|
+
'content-type': 'application/json; charset=utf-8',
|
|
94
|
+
'content-length': String(body.byteLength),
|
|
95
|
+
// These responses carry authorization state; they must never be cached or
|
|
96
|
+
// sniffed into another context.
|
|
97
|
+
'cache-control': 'no-store',
|
|
98
|
+
'x-content-type-options': 'nosniff',
|
|
99
|
+
...headers,
|
|
100
|
+
});
|
|
101
|
+
res.end(body);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Build a WHATWG JSON response for a fetch-style route.
|
|
106
|
+
* @param {number} status - status code.
|
|
107
|
+
* @param {unknown} payload - JSON payload.
|
|
108
|
+
* @param {Record<string, string>} [headers] - extra headers.
|
|
109
|
+
* @returns {Response} response.
|
|
110
|
+
*/
|
|
111
|
+
export function jsonResponse(status, payload, headers = {}) {
|
|
112
|
+
return new Response(`${JSON.stringify(payload)}\n`, {
|
|
113
|
+
status,
|
|
114
|
+
headers: {
|
|
115
|
+
'content-type': 'application/json; charset=utf-8',
|
|
116
|
+
'cache-control': 'no-store',
|
|
117
|
+
'x-content-type-options': 'nosniff',
|
|
118
|
+
...headers,
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Map a thrown value onto a status/code pair without leaking internals.
|
|
125
|
+
*
|
|
126
|
+
* Known refusals keep their own code so a caller can act on it; anything
|
|
127
|
+
* unrecognized becomes a generic 500 with no message from the original error.
|
|
128
|
+
* @param {unknown} error - thrown value.
|
|
129
|
+
* @returns {{ status: number, code: string, message: string, details: object }} mapping.
|
|
130
|
+
*/
|
|
131
|
+
export function classifyError(error) {
|
|
132
|
+
if (error instanceof HttpError) {
|
|
133
|
+
return { status: error.status, code: error.code, message: error.message, details: error.details ?? {} };
|
|
134
|
+
}
|
|
135
|
+
const code = typeof error?.code === 'string' ? error.code : null;
|
|
136
|
+
const details = error?.details !== null && typeof error?.details === 'object' ? error.details : {};
|
|
137
|
+
const message = typeof error?.message === 'string' ? error.message : 'the request could not be completed';
|
|
138
|
+
if (code === null) {
|
|
139
|
+
return { status: 500, code: 'INTERNAL_ERROR', message: 'the request could not be completed', details: {} };
|
|
140
|
+
}
|
|
141
|
+
return { status: statusForCode(code), code, message, details };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function statusForCode(code) {
|
|
145
|
+
if (code === AUTH_UNAUTHENTICATED) return 401;
|
|
146
|
+
if (code.startsWith('USER_PLANE_') || code.startsWith('CONNECTION_')) return 403;
|
|
147
|
+
if (code.endsWith('_NOT_FOUND') || code === 'GRANT_UNKNOWN' || code === 'CONNECTION_UNKNOWN') return 404;
|
|
148
|
+
if (code.startsWith('SETTINGS_') || code.startsWith('PROVIDER_') || code.startsWith('MODEL_')) return 400;
|
|
149
|
+
if (code.startsWith('SELECTION_')) return 409;
|
|
150
|
+
if (code.startsWith('GRANT_')) return 409;
|
|
151
|
+
if (code === 'WORKSPACE_BUSY') return 409;
|
|
152
|
+
if (code.startsWith('ROUTING_')) return 409;
|
|
153
|
+
if (code.startsWith('AUDIT_')) return 409;
|
|
154
|
+
// An archived task is not a request error: the task exists, but only as a
|
|
155
|
+
// durable record, so the action conflicts with the task's real state.
|
|
156
|
+
if (code === 'JOB_ARCHIVED_TASK') return 409;
|
|
157
|
+
if (code.startsWith('JOB_')) return 409;
|
|
158
|
+
// The credential seam is a separate service. "It is not installed here" is a
|
|
159
|
+
// capability gap (503), "the backend refused the write" is an upstream failure
|
|
160
|
+
// (502), and "the caller sent no usable value" is the caller's mistake (400).
|
|
161
|
+
if (code === 'CREDENTIAL_SEAM_UNAVAILABLE') return 503;
|
|
162
|
+
if (code === 'CREDENTIAL_OPERATION_FAILED' || code === 'CREDENTIAL_READ_ONLY') return 502;
|
|
163
|
+
if (code === 'CREDENTIAL_VALUE_REQUIRED' || code === 'CREDENTIAL_VALUE_TOO_LARGE' || code === 'CREDENTIAL_REF_INVALID') return 400;
|
|
164
|
+
if (code.startsWith('CREDENTIAL_')) return 409;
|
|
165
|
+
// Codex integration: the operator's own Codex home/config is the subject, so a
|
|
166
|
+
// refusal to touch it is a state conflict, and a malformed request a 400.
|
|
167
|
+
if (code === 'CODEX_INTEGRATION_UNAVAILABLE') return 503;
|
|
168
|
+
if (code === 'CODEX_HOME_INVALID' || code === 'CODEX_ACTION_INVALID') return 400;
|
|
169
|
+
if (code.startsWith('CODEX_') || code.startsWith('MCP_') || code.startsWith('AGENT_')) return 409;
|
|
170
|
+
if (code === 'BODY_TOO_LARGE') return 413;
|
|
171
|
+
if (code === 'BODY_INVALID_JSON' || code === 'BODY_NOT_OBJECT') return 400;
|
|
172
|
+
return 400;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const AUTH_UNAUTHENTICATED = 'USER_PLANE_UNAUTHENTICATED';
|