dsh-taskbridge 0.0.0-stage → 1.3.2

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.
Files changed (75) hide show
  1. package/CHANGELOG.md +763 -0
  2. package/LICENSE +21 -0
  3. package/README.md +622 -3
  4. package/bin/dsh-delegate-codex-agent.js +115 -0
  5. package/bin/dsh-delegate-control.d.ts +90 -0
  6. package/bin/dsh-delegate-control.js +450 -0
  7. package/bin/dsh-delegate-mcp.d.ts +121 -0
  8. package/bin/dsh-delegate-mcp.js +273 -0
  9. package/codex/dsh-taskbridge.toml +247 -0
  10. package/cordis.patch.yml +6 -0
  11. package/docs/INTRODUCTION.md +15 -0
  12. package/docs/INTRODUCTION.zh.md +34 -0
  13. package/docs/auth-contract.md +138 -0
  14. package/docs/claude-code.md +31 -0
  15. package/docs/codex-integration.md +937 -0
  16. package/docs/contracts-stage-b.md +443 -0
  17. package/docs/conversation-placement.md +304 -0
  18. package/docs/plugin-market.md +30 -0
  19. package/docs/redaction-contract.md +127 -0
  20. package/docs/runtime-compatibility.md +223 -0
  21. package/docs/silent-wait.md +191 -0
  22. package/docs/taskbridge-upgrade.md +28 -0
  23. package/docs/taskdispatch-upgrade.md +25 -0
  24. package/docs/worker-permissions.md +347 -0
  25. package/docs/workspace-contract.md +538 -0
  26. package/icon.svg +1 -0
  27. package/lib/client.d.ts +118 -0
  28. package/lib/client.js +3232 -0
  29. package/locale/en.json +7 -0
  30. package/locale/zh.json +7 -0
  31. package/package.json +138 -4
  32. package/src/auth/fence.js +361 -0
  33. package/src/auth/grants.js +789 -0
  34. package/src/client/api.js +2322 -0
  35. package/src/client/index.jsx +2333 -0
  36. package/src/client/styles.js +251 -0
  37. package/src/codex/installer.js +3299 -0
  38. package/src/codex/seam.js +429 -0
  39. package/src/codex/toml.js +784 -0
  40. package/src/config/defaults.js +164 -0
  41. package/src/config/redact.js +184 -0
  42. package/src/config/settings.js +629 -0
  43. package/src/config/store.js +186 -0
  44. package/src/config/validate.js +763 -0
  45. package/src/credentials/seam.js +202 -0
  46. package/src/http/execution-plane.js +456 -0
  47. package/src/http/respond.js +175 -0
  48. package/src/http/user-plane.js +1122 -0
  49. package/src/index.d.ts +332 -0
  50. package/src/index.js +657 -0
  51. package/src/jobs/activity.js +1008 -0
  52. package/src/jobs/engine.js +3614 -0
  53. package/src/jobs/history.js +1467 -0
  54. package/src/jobs/title.js +17 -0
  55. package/src/mcp/server.js +1821 -0
  56. package/src/mcp/wait.js +536 -0
  57. package/src/model/connectivity.js +371 -0
  58. package/src/model/discovery.js +582 -0
  59. package/src/model/native-catalog.js +68 -0
  60. package/src/model/openai-adapter.js +671 -0
  61. package/src/model/probe.js +264 -0
  62. package/src/model/providers.js +756 -0
  63. package/src/model/routing.js +321 -0
  64. package/src/review/preset.js +868 -0
  65. package/src/review/prompts.js +126 -0
  66. package/src/review/reviewer.js +933 -0
  67. package/src/runtime/agent-runner.js +1740 -0
  68. package/src/runtime/endpoint-discovery.js +118 -0
  69. package/src/runtime/permissions.js +1429 -0
  70. package/src/runtime/sandbox.js +358 -0
  71. package/src/runtime/session-placement.js +1121 -0
  72. package/src/workspace/audit.js +775 -0
  73. package/src/workspace/locks.js +167 -0
  74. package/src/workspace/preflight.js +424 -0
  75. package/src/workspace/worktrees.js +613 -0
@@ -0,0 +1,118 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { lstat, readFile, rm } from 'node:fs/promises';
3
+ import { homedir } from 'node:os';
4
+ import { isAbsolute, join, resolve } from 'node:path';
5
+
6
+ import { writeFileAtomic } from '../config/store.js';
7
+
8
+ export const ENDPOINT_DISCOVERY_FILE = 'runtime-endpoint.json';
9
+ export const ENDPOINT_DISCOVERY_SCHEMA = 1;
10
+ const MAX_DISCOVERY_BYTES = 4096;
11
+
12
+ export class EndpointDiscoveryError extends Error {
13
+ constructor(code, message) {
14
+ super(message);
15
+ this.name = 'EndpointDiscoveryError';
16
+ this.code = code;
17
+ }
18
+ }
19
+
20
+ export function resolveEndpointDiscoveryPath(env = process.env, homeDirectory = homedir()) {
21
+ const configuredPath = typeof env.DSH_DELEGATE_DISCOVERY_FILE === 'string'
22
+ ? env.DSH_DELEGATE_DISCOVERY_FILE.trim()
23
+ : '';
24
+ if (configuredPath !== '') {
25
+ if (!isAbsolute(configuredPath)) {
26
+ throw new EndpointDiscoveryError('MCP_CONFIG_INVALID', 'DSH_DELEGATE_DISCOVERY_FILE must be an absolute path');
27
+ }
28
+ return resolve(configuredPath);
29
+ }
30
+
31
+ return resolveDefaultEndpointDiscoveryPath(env, homeDirectory);
32
+ }
33
+
34
+ export function resolveDefaultEndpointDiscoveryPath(env = process.env, homeDirectory = homedir()) {
35
+ const configuredHome = typeof env.DSH_HOME === 'string' ? env.DSH_HOME.trim() : '';
36
+ const dshHome = configuredHome === '' ? join(homeDirectory, '.dsh') : configuredHome;
37
+ return join(resolve(dshHome), 'data', 'dsh-delegate', ENDPOINT_DISCOVERY_FILE);
38
+ }
39
+
40
+ export async function publishRuntimeEndpoint({ filePath, host, port, processId = process.pid, now = new Date() }) {
41
+ if (host !== '127.0.0.1') {
42
+ throw new EndpointDiscoveryError('MCP_ENDPOINT_BIND_UNSUPPORTED', 'the DSH endpoint must bind to 127.0.0.1');
43
+ }
44
+ if (!Number.isInteger(port) || port < 1 || port > 65_535) {
45
+ throw new EndpointDiscoveryError('MCP_ENDPOINT_INVALID', 'the DSH endpoint port is invalid');
46
+ }
47
+ if (!Number.isSafeInteger(processId) || processId < 1) {
48
+ throw new EndpointDiscoveryError('MCP_ENDPOINT_INVALID', 'the DSH process id is invalid');
49
+ }
50
+
51
+ const record = {
52
+ schemaVersion: ENDPOINT_DISCOVERY_SCHEMA,
53
+ host,
54
+ port,
55
+ processId,
56
+ instanceId: randomUUID(),
57
+ updatedAt: now.toISOString(),
58
+ };
59
+ await writeFileAtomic(filePath, `${JSON.stringify(record)}\n`);
60
+
61
+ return {
62
+ filePath,
63
+ instanceId: record.instanceId,
64
+ async dispose() {
65
+ try {
66
+ const current = await readDiscoveryRecord(filePath);
67
+ if (current.instanceId === record.instanceId) await rm(filePath, { force: true });
68
+ } catch { /* An unreadable or replaced record is not this instance's file to remove. */ }
69
+ },
70
+ };
71
+ }
72
+
73
+ export async function readRuntimeEndpoint(filePath) {
74
+ const record = await readDiscoveryRecord(filePath);
75
+ return Object.freeze({
76
+ baseUrl: `http://${record.host}:${record.port}`,
77
+ host: record.host,
78
+ port: record.port,
79
+ processId: record.processId,
80
+ instanceId: record.instanceId,
81
+ updatedAt: record.updatedAt,
82
+ });
83
+ }
84
+
85
+ async function readDiscoveryRecord(filePath) {
86
+ let metadata;
87
+ try {
88
+ metadata = await lstat(filePath);
89
+ } catch (error) {
90
+ if (error?.code === 'ENOENT') {
91
+ throw new EndpointDiscoveryError(
92
+ 'MCP_ENDPOINT_NOT_FOUND',
93
+ 'no DSH endpoint is published; start DSH with the same dsh-delegate build that published one, or set DSH_DELEGATE_BASE_URL',
94
+ );
95
+ }
96
+ throw new EndpointDiscoveryError('MCP_ENDPOINT_READ_FAILED', 'the DSH endpoint discovery file could not be read');
97
+ }
98
+ if (!metadata.isFile() || metadata.isSymbolicLink() || metadata.size > MAX_DISCOVERY_BYTES) {
99
+ throw new EndpointDiscoveryError('MCP_ENDPOINT_INVALID', 'the DSH endpoint discovery file is not a bounded regular file');
100
+ }
101
+
102
+ let record;
103
+ try {
104
+ record = JSON.parse(await readFile(filePath, 'utf8'));
105
+ } catch {
106
+ throw new EndpointDiscoveryError('MCP_ENDPOINT_INVALID', 'the DSH endpoint discovery file is malformed');
107
+ }
108
+ if (record === null || typeof record !== 'object' || Array.isArray(record)
109
+ || record.schemaVersion !== ENDPOINT_DISCOVERY_SCHEMA
110
+ || record.host !== '127.0.0.1'
111
+ || !Number.isInteger(record.port) || record.port < 1 || record.port > 65_535
112
+ || !Number.isSafeInteger(record.processId) || record.processId < 1
113
+ || typeof record.instanceId !== 'string' || record.instanceId.length < 16 || record.instanceId.length > 100
114
+ || typeof record.updatedAt !== 'string' || !Number.isFinite(Date.parse(record.updatedAt))) {
115
+ throw new EndpointDiscoveryError('MCP_ENDPOINT_INVALID', 'the DSH endpoint discovery record is invalid');
116
+ }
117
+ return record;
118
+ }