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,186 @@
|
|
|
1
|
+
// Durable document store for plugin-owned state.
|
|
2
|
+
//
|
|
3
|
+
// Two properties matter here and nowhere else: a reader never observes a
|
|
4
|
+
// half-written document, and a document from an unknown schema version is
|
|
5
|
+
// refused instead of being reinterpreted. Delegation authorization is
|
|
6
|
+
// deliberately NOT stored here — see src/auth/grants.js.
|
|
7
|
+
//
|
|
8
|
+
// A third property is added because callers hand these documents to UI and
|
|
9
|
+
// HTTP layers: every document this module returns is deep-frozen, so a caller
|
|
10
|
+
// cannot mutate what the store believes is on disk. A writer must go through
|
|
11
|
+
// `commit`, which works on its own deep copy.
|
|
12
|
+
|
|
13
|
+
import { randomBytes } from 'node:crypto';
|
|
14
|
+
import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
15
|
+
import { dirname, join } from 'node:path';
|
|
16
|
+
|
|
17
|
+
const WINDOWS_TRANSIENT_RENAME = new Set(['EACCES', 'EBUSY', 'EPERM']);
|
|
18
|
+
|
|
19
|
+
async function renameWithRetry(temp, target) {
|
|
20
|
+
let delay = 20;
|
|
21
|
+
for (let attempt = 0; ; attempt += 1) {
|
|
22
|
+
try {
|
|
23
|
+
await rename(temp, target);
|
|
24
|
+
return;
|
|
25
|
+
} catch (error) {
|
|
26
|
+
const transient = process.platform === 'win32' && WINDOWS_TRANSIENT_RENAME.has(error?.code ?? '');
|
|
27
|
+
if (!transient || attempt >= 8) throw error;
|
|
28
|
+
}
|
|
29
|
+
await new Promise((resolve) => { setTimeout(resolve, delay); });
|
|
30
|
+
delay = Math.min(delay * 2, 200);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Replace a file atomically: write a random sibling, then rename over the
|
|
36
|
+
* target so a crash leaves either the old or the new complete document.
|
|
37
|
+
* @param {string} filename - final path.
|
|
38
|
+
* @param {string} content - complete next content.
|
|
39
|
+
* @returns {Promise<void>} resolves after the rename.
|
|
40
|
+
*/
|
|
41
|
+
export async function writeFileAtomic(filename, content) {
|
|
42
|
+
await mkdir(dirname(filename), { recursive: true, mode: 0o700 });
|
|
43
|
+
const temp = `${filename}.${randomBytes(6).toString('hex')}.tmp`;
|
|
44
|
+
try {
|
|
45
|
+
await writeFile(temp, content, { mode: 0o600, flag: 'wx' });
|
|
46
|
+
await renameWithRetry(temp, filename);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
await rm(temp, { force: true });
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Freeze a JSON-shaped value and everything below it.
|
|
55
|
+
*
|
|
56
|
+
* Used on every snapshot this module hands out, so "the caller changed the
|
|
57
|
+
* document" is impossible rather than merely discouraged: a write to a frozen
|
|
58
|
+
* object throws in the strict mode every ESM module runs in. The input is
|
|
59
|
+
* expected to be JSON data (objects, arrays, primitives); a cyclic graph is not
|
|
60
|
+
* produced by `JSON.parse` and is not supported.
|
|
61
|
+
* @template T
|
|
62
|
+
* @param {T} value - value to freeze in place.
|
|
63
|
+
* @returns {T} the same value, frozen down to its leaves.
|
|
64
|
+
*/
|
|
65
|
+
export function deepFreeze(value) {
|
|
66
|
+
if (value === null || typeof value !== 'object') return value;
|
|
67
|
+
// Already frozen (possibly by an earlier pass): nothing below can be mutable.
|
|
68
|
+
if (Object.isFrozen(value)) return value;
|
|
69
|
+
for (const key of Object.keys(value)) deepFreeze(value[key]);
|
|
70
|
+
return Object.freeze(value);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Refusal raised when a stored document cannot be trusted as-is. */
|
|
74
|
+
export class StoreError extends Error {
|
|
75
|
+
/**
|
|
76
|
+
* @param {string} code - stable machine code.
|
|
77
|
+
* @param {string} message - human-readable explanation.
|
|
78
|
+
*/
|
|
79
|
+
constructor(code, message) {
|
|
80
|
+
super(message);
|
|
81
|
+
this.name = 'StoreError';
|
|
82
|
+
this.code = code;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* One JSON document with a versioned envelope and serialized writes.
|
|
88
|
+
*
|
|
89
|
+
* Writes are queued: a read-modify-write cycle inside this process cannot lose
|
|
90
|
+
* a concurrent update, and the last committed snapshot is what a restart reads.
|
|
91
|
+
* Reads are not queued — the file is replaced atomically, and `current` only
|
|
92
|
+
* ever points at a complete document, so a concurrent read returns either the
|
|
93
|
+
* old or the new snapshot and never a partial one.
|
|
94
|
+
*/
|
|
95
|
+
export class JsonDocument {
|
|
96
|
+
/**
|
|
97
|
+
* @param {string} dataDir - plugin data directory.
|
|
98
|
+
* @param {string} fileName - document file name inside the directory.
|
|
99
|
+
* @param {object} options - `schemaVersion` and `initial` factory.
|
|
100
|
+
*/
|
|
101
|
+
constructor(dataDir, fileName, { schemaVersion, initial }) {
|
|
102
|
+
this.path = join(dataDir, fileName);
|
|
103
|
+
this.schemaVersion = schemaVersion;
|
|
104
|
+
this.initial = initial;
|
|
105
|
+
this.current = null;
|
|
106
|
+
// In-flight first read. Concurrent `load()` calls share it instead of each
|
|
107
|
+
// issuing their own read of the same file.
|
|
108
|
+
this.loading = null;
|
|
109
|
+
this.queue = Promise.resolve();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Read the document, creating the in-memory default when absent.
|
|
114
|
+
* @returns {Promise<object>} the current document, frozen.
|
|
115
|
+
*/
|
|
116
|
+
async load() {
|
|
117
|
+
if (this.current !== null) return this.current;
|
|
118
|
+
if (this.loading === null) {
|
|
119
|
+
this.loading = this.readOnce().finally(() => { this.loading = null; });
|
|
120
|
+
}
|
|
121
|
+
return await this.loading;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Perform the single physical read behind {@link JsonDocument#load}.
|
|
126
|
+
* @returns {Promise<object>} the loaded document, frozen.
|
|
127
|
+
*/
|
|
128
|
+
async readOnce() {
|
|
129
|
+
let raw;
|
|
130
|
+
try {
|
|
131
|
+
raw = await readFile(this.path, 'utf8');
|
|
132
|
+
} catch (error) {
|
|
133
|
+
if (error?.code === 'ENOENT') {
|
|
134
|
+
this.current = deepFreeze(this.initial());
|
|
135
|
+
return this.current;
|
|
136
|
+
}
|
|
137
|
+
throw new StoreError('STORE_UNREADABLE', `cannot read ${this.path}: ${error?.code ?? 'unknown error'}`);
|
|
138
|
+
}
|
|
139
|
+
let parsed;
|
|
140
|
+
try {
|
|
141
|
+
parsed = JSON.parse(raw);
|
|
142
|
+
} catch {
|
|
143
|
+
throw new StoreError('STORE_MALFORMED', 'stored document is not valid JSON');
|
|
144
|
+
}
|
|
145
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
146
|
+
throw new StoreError('STORE_MALFORMED', 'stored document is not an object');
|
|
147
|
+
}
|
|
148
|
+
if (parsed.schemaVersion !== this.schemaVersion) {
|
|
149
|
+
throw new StoreError(
|
|
150
|
+
'STORE_SCHEMA_UNSUPPORTED',
|
|
151
|
+
`stored schemaVersion ${String(parsed.schemaVersion)} is not supported by this release`,
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
this.current = deepFreeze(parsed);
|
|
155
|
+
return this.current;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Apply a synchronous mutation and commit it durably.
|
|
160
|
+
*
|
|
161
|
+
* The mutation receives a mutable deep copy, so it can edit in place. It is
|
|
162
|
+
* not allowed to reach back into this document (for example by awaiting
|
|
163
|
+
* another `commit`), which would queue behind itself and never settle.
|
|
164
|
+
* @param {(document: object) => object | void} mutate - receives a deep copy; returns the next document or mutates it.
|
|
165
|
+
* @returns {Promise<object>} the committed document, frozen.
|
|
166
|
+
*/
|
|
167
|
+
commit(mutate) {
|
|
168
|
+
const run = this.queue.then(async () => {
|
|
169
|
+
const base = await this.load();
|
|
170
|
+
const draft = structuredClone(base);
|
|
171
|
+
const returned = mutate(draft);
|
|
172
|
+
const next = returned === undefined ? draft : returned;
|
|
173
|
+
if (next === null || typeof next !== 'object' || Array.isArray(next)) {
|
|
174
|
+
throw new StoreError('STORE_INVALID', 'a committed document must be an object');
|
|
175
|
+
}
|
|
176
|
+
next.schemaVersion = this.schemaVersion;
|
|
177
|
+
await writeFileAtomic(this.path, `${JSON.stringify(next, null, 2)}\n`);
|
|
178
|
+
this.current = deepFreeze(next);
|
|
179
|
+
return this.current;
|
|
180
|
+
});
|
|
181
|
+
// The queue tail is settled either way: one failed write must not poison
|
|
182
|
+
// every later commit.
|
|
183
|
+
this.queue = run.then(() => undefined, () => undefined);
|
|
184
|
+
return run;
|
|
185
|
+
}
|
|
186
|
+
}
|