@ycodium-ai/agent-dsh 0.2.3196 → 0.2.3208
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 +33 -0
- package/assets/permission-sync.d.mts +3 -0
- package/assets/permission-sync.mjs +64 -0
- package/dist/index.js +213 -92
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -40,6 +40,39 @@ Facts:
|
|
|
40
40
|
- Session model switching is `unsupported` on the card: the plugin does not switch
|
|
41
41
|
models inside a running session.
|
|
42
42
|
|
|
43
|
+
## Permission sync bridge
|
|
44
|
+
|
|
45
|
+
DSH keeps the permission preset (`sandbox/mode` + `approval/policy`) as a fact of the
|
|
46
|
+
session, not of the process: `session/new` reads `DSH_PERMISSION_MODE` for its initial
|
|
47
|
+
preset, and `session/resume` preserves whatever the session recorded. The only in-place
|
|
48
|
+
switch DSH ships is its `/permission <preset>` command, a client-side remote that is not
|
|
49
|
+
exposed over ACP. A plain "reopen with a new env" therefore changes nothing for an
|
|
50
|
+
existing session: Ycodium's thread would claim Full access while DSH kept asking.
|
|
51
|
+
|
|
52
|
+
The plugin closes that gap without starting a new session, so the conversation context is
|
|
53
|
+
kept. The `--patch` overlay that already carries the session skill root also inserts
|
|
54
|
+
[`assets/permission-sync.mjs`](assets/permission-sync.mjs), a dependency-free cordis
|
|
55
|
+
plugin. On every `session/created` (resume included) it reads `DSH_PERMISSION_MODE` and,
|
|
56
|
+
when the session's current preset differs, calls `permissionPresets.set(session, preset)`
|
|
57
|
+
— the same write path DSH's own `/permission` command uses. It only touches root sessions
|
|
58
|
+
(`header.parentSession` absent); child sessions keep the preset their parent pinned.
|
|
59
|
+
|
|
60
|
+
Contract and drift policy:
|
|
61
|
+
|
|
62
|
+
- It consumes DSH internals: the `permissionPresets` cordis service (`set` / `current`),
|
|
63
|
+
`ctx.sessions.list()`, the `session/created` event, and `insert` entries in a `--patch`
|
|
64
|
+
overlay. Verified against dsh 0.2.1-rc.2.
|
|
65
|
+
- Failure is always open: `inject` keeps the plugin inactive when the service is gone; a
|
|
66
|
+
changed method shape writes one stderr line and does nothing; an overlay that does not
|
|
67
|
+
compose is dropped with a warning. No failure path throws into the session.
|
|
68
|
+
- After a DSH upgrade run
|
|
69
|
+
`pnpm --filter @ycodium-ai/agent-dsh check:permission-sync` (or set `DSH_BIN`). It boots
|
|
70
|
+
`dsh --profile acp` with the same overlay and asserts both that the entry composes and
|
|
71
|
+
that the plugin activates. It exits 0 when no dsh is installed.
|
|
72
|
+
- Exit plan: when DSH applies `DSH_PERMISSION_MODE` on resume, or exposes the permission
|
|
73
|
+
preset over ACP (session mode or config option), delete the inserted plugin, its overlay
|
|
74
|
+
entry, and this section.
|
|
75
|
+
|
|
43
76
|
Develop with `vp run --filter @ycodium-ai/agent-dsh typecheck`, `build`, and `test`.
|
|
44
77
|
|
|
45
78
|
## License
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ycodium 注入进 dsh 的权限档同步插件——这是 dsh 的 cordis 插件,不是 Ycodium 插件。
|
|
3
|
+
*
|
|
4
|
+
* 为什么需要它:权限档是 dsh 的会话级事实,`session/resume` 会保留会话里记着的那一档;
|
|
5
|
+
* `DSH_PERMISSION_MODE` 只决定**新会话**的默认值。Ycodium 的切档走「记在 thread 上、下一轮带
|
|
6
|
+
* resume cursor 重开」,重开的还是同一个会话,所以档换不动。dsh 自己的活切入口是 `/permission`
|
|
7
|
+
* 命令,那是它内部 remote,ACP 上拿不到。
|
|
8
|
+
*
|
|
9
|
+
* 这个插件补的就是那一步:进程启动时(`--patch` 插入)读 `DSH_PERMISSION_MODE`,在会话
|
|
10
|
+
* 创建 / 恢复时把会话的权限预设切到请求值。它只改权限旋钮事件,不动会话历史,所以上下文不丢。
|
|
11
|
+
*
|
|
12
|
+
* 约束(改它之前先看 README 的「权限桥」一节):
|
|
13
|
+
* - 只用 dsh 的 cordis 服务与事件,不 import 任何模块,打成单文件 `.mjs` 由覆盖层 insert 进来。
|
|
14
|
+
* - 失效只能降级、不能拖垮会话:服务缺失时靠 `inject` 不激活,方法形状不对或调用失败时只往
|
|
15
|
+
* stderr 打一行,绝不抛出。
|
|
16
|
+
* - 只处理根会话(`header.parentSession` 为空):子会话各有自己的档,不能跟着顶层的档走。
|
|
17
|
+
* - 只是桥:dsh 哪天在 resume 时认 `DSH_PERMISSION_MODE`、或把权限档接进 ACP,就删掉这一整条。
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export const name = "ycodium-permission-sync";
|
|
21
|
+
|
|
22
|
+
export const inject = ["permissionPresets", "sessions"];
|
|
23
|
+
|
|
24
|
+
const PREFIX = "[ycodium-permission-sync]";
|
|
25
|
+
|
|
26
|
+
/** stderr 是安全的诊断面;stdout 是 ACP 的协议通道,一个字节都不能碰。 */
|
|
27
|
+
function report(message) {
|
|
28
|
+
try {
|
|
29
|
+
console.error(`${PREFIX} ${message}`);
|
|
30
|
+
} catch {
|
|
31
|
+
// 诊断写不出去也不能影响会话。
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function messageOf(error) {
|
|
36
|
+
return error instanceof Error ? error.message : String(error);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function apply(ctx) {
|
|
40
|
+
const requested = (process.env.DSH_PERMISSION_MODE ?? "").trim();
|
|
41
|
+
if (requested === "") return;
|
|
42
|
+
const presets = ctx.permissionPresets;
|
|
43
|
+
if (typeof presets?.set !== "function" || typeof presets?.current !== "function") {
|
|
44
|
+
report("permissionPresets.set/current is missing; the session keeps its recorded permission");
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const sync = (session) => {
|
|
49
|
+
if (session?.header?.parentSession !== undefined) return;
|
|
50
|
+
try {
|
|
51
|
+
if (presets.current(session) !== requested) presets.set(session, requested);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
report(`cannot switch session ${session?.id ?? "?"} to ${requested}: ${messageOf(error)}`);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
ctx.on("session/created", sync);
|
|
58
|
+
try {
|
|
59
|
+
for (const session of ctx.sessions.list()) sync(session);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
report(`cannot scan existing sessions: ${messageOf(error)}`);
|
|
62
|
+
}
|
|
63
|
+
report(`active requested=${requested}`);
|
|
64
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -7657,8 +7657,8 @@ var UnboundedEventStream = class {
|
|
|
7657
7657
|
iterators.subscribers.delete(subscriber);
|
|
7658
7658
|
return { value: void 0, done: true };
|
|
7659
7659
|
}
|
|
7660
|
-
await new Promise((
|
|
7661
|
-
subscriber.wake =
|
|
7660
|
+
await new Promise((resolve3) => {
|
|
7661
|
+
subscriber.wake = resolve3;
|
|
7662
7662
|
});
|
|
7663
7663
|
}
|
|
7664
7664
|
},
|
|
@@ -13727,7 +13727,7 @@ var recursive = /* @__PURE__ */ new WeakMap();
|
|
|
13727
13727
|
var NONE = 0;
|
|
13728
13728
|
var ASSUMED = 1;
|
|
13729
13729
|
var PROVEN = 2;
|
|
13730
|
-
function isRecursive(inst, stack,
|
|
13730
|
+
function isRecursive(inst, stack, resolve3) {
|
|
13731
13731
|
const cached2 = recursive.get(inst);
|
|
13732
13732
|
if (cached2 !== void 0)
|
|
13733
13733
|
return cached2 ? PROVEN : NONE;
|
|
@@ -13737,7 +13737,7 @@ function isRecursive(inst, stack, resolve2) {
|
|
|
13737
13737
|
let result = NONE;
|
|
13738
13738
|
const check2 = (child) => {
|
|
13739
13739
|
if (result !== PROVEN && child?._zod) {
|
|
13740
|
-
const answer = isRecursive(child, stack,
|
|
13740
|
+
const answer = isRecursive(child, stack, resolve3);
|
|
13741
13741
|
if (answer > result)
|
|
13742
13742
|
result = answer;
|
|
13743
13743
|
}
|
|
@@ -13748,7 +13748,7 @@ function isRecursive(inst, stack, resolve2) {
|
|
|
13748
13748
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
13749
13749
|
if (spread && !desc.enumerable)
|
|
13750
13750
|
continue;
|
|
13751
|
-
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack,
|
|
13751
|
+
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve3) : NONE;
|
|
13752
13752
|
if (child > answer)
|
|
13753
13753
|
answer = child;
|
|
13754
13754
|
}
|
|
@@ -13812,7 +13812,7 @@ function isRecursive(inst, stack, resolve2) {
|
|
|
13812
13812
|
break;
|
|
13813
13813
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
13814
13814
|
case "lazy": {
|
|
13815
|
-
const inner = def._cachedInner ?? (
|
|
13815
|
+
const inner = def._cachedInner ?? (resolve3 ? inst._zod.innerType : void 0);
|
|
13816
13816
|
merge2(inner ? isRecursive(inner, stack, false) : ASSUMED);
|
|
13817
13817
|
break;
|
|
13818
13818
|
}
|
|
@@ -30476,11 +30476,11 @@ var Connection = class {
|
|
|
30476
30476
|
const id = this.nextRequestId++;
|
|
30477
30477
|
let cancel = () => {
|
|
30478
30478
|
};
|
|
30479
|
-
const response = new Promise((
|
|
30479
|
+
const response = new Promise((resolve3, reject) => {
|
|
30480
30480
|
const pendingResponse = {
|
|
30481
30481
|
resolve: (value) => {
|
|
30482
30482
|
try {
|
|
30483
|
-
|
|
30483
|
+
resolve3(mapResponse ? mapResponse(value) : value);
|
|
30484
30484
|
} catch (error62) {
|
|
30485
30485
|
reject(error62);
|
|
30486
30486
|
}
|
|
@@ -30537,8 +30537,8 @@ var Connection = class {
|
|
|
30537
30537
|
this.stream = stream;
|
|
30538
30538
|
this.staticHandlers = handlers;
|
|
30539
30539
|
this.allowBatches = options?.allowBatches ?? true;
|
|
30540
|
-
this.closedPromise = new Promise((
|
|
30541
|
-
this.abortController.signal.addEventListener("abort", () =>
|
|
30540
|
+
this.closedPromise = new Promise((resolve3) => {
|
|
30541
|
+
this.abortController.signal.addEventListener("abort", () => resolve3());
|
|
30542
30542
|
});
|
|
30543
30543
|
void this.receive();
|
|
30544
30544
|
}
|
|
@@ -31036,7 +31036,7 @@ function ndJsonStream(output2, input2) {
|
|
|
31036
31036
|
});
|
|
31037
31037
|
return write;
|
|
31038
31038
|
};
|
|
31039
|
-
const
|
|
31039
|
+
const readable2 = new ReadableStream({
|
|
31040
31040
|
async start(controller) {
|
|
31041
31041
|
const lines = new LineBuffer();
|
|
31042
31042
|
const enqueueLine = async (lineBytes) => {
|
|
@@ -31112,7 +31112,7 @@ function ndJsonStream(output2, input2) {
|
|
|
31112
31112
|
return writeJson(message);
|
|
31113
31113
|
}
|
|
31114
31114
|
});
|
|
31115
|
-
return { readable, writable };
|
|
31115
|
+
return { readable: readable2, writable };
|
|
31116
31116
|
}
|
|
31117
31117
|
|
|
31118
31118
|
// ../../node_modules/.pnpm/@agentclientprotocol+sdk@1.4.0_zod@4.6.5/node_modules/@agentclientprotocol/sdk/dist/schema/guards.gen.js
|
|
@@ -31432,8 +31432,8 @@ var AsyncQueue = class {
|
|
|
31432
31432
|
if (this.failed) {
|
|
31433
31433
|
return Promise.reject(this.failure);
|
|
31434
31434
|
}
|
|
31435
|
-
return new Promise((
|
|
31436
|
-
this.waiters.push({ resolve:
|
|
31435
|
+
return new Promise((resolve3, reject) => {
|
|
31436
|
+
this.waiters.push({ resolve: resolve3, reject });
|
|
31437
31437
|
});
|
|
31438
31438
|
}
|
|
31439
31439
|
};
|
|
@@ -32473,11 +32473,11 @@ function createAcpConnection(options) {
|
|
|
32473
32473
|
failIfClosed();
|
|
32474
32474
|
const id = nextRequestId;
|
|
32475
32475
|
nextRequestId += 1;
|
|
32476
|
-
const { promise: promise2, resolve:
|
|
32476
|
+
const { promise: promise2, resolve: resolve3, reject } = Promise.withResolvers();
|
|
32477
32477
|
pending.set(String(id), {
|
|
32478
32478
|
method,
|
|
32479
32479
|
...promptId === void 0 ? {} : { promptId },
|
|
32480
|
-
resolve:
|
|
32480
|
+
resolve: resolve3,
|
|
32481
32481
|
reject
|
|
32482
32482
|
});
|
|
32483
32483
|
const message = params === void 0 ? { jsonrpc: "2.0", id, method } : { jsonrpc: "2.0", id, method, params };
|
|
@@ -32506,8 +32506,8 @@ function createAcpConnection(options) {
|
|
|
32506
32506
|
if (inboundBatches === 0) {
|
|
32507
32507
|
return;
|
|
32508
32508
|
}
|
|
32509
|
-
await new Promise((
|
|
32510
|
-
idleWaiters.push(
|
|
32509
|
+
await new Promise((resolve3) => {
|
|
32510
|
+
idleWaiters.push(resolve3);
|
|
32511
32511
|
if (inboundBatches === 0) {
|
|
32512
32512
|
releaseIdleWaiters();
|
|
32513
32513
|
}
|
|
@@ -33075,12 +33075,12 @@ function createPromptResults({
|
|
|
33075
33075
|
}) {
|
|
33076
33076
|
const prompts = /* @__PURE__ */ new Map();
|
|
33077
33077
|
const add = (identity, finish) => {
|
|
33078
|
-
const { promise: done, resolve:
|
|
33078
|
+
const { promise: done, resolve: resolve3 } = Promise.withResolvers();
|
|
33079
33079
|
const record2 = {
|
|
33080
33080
|
...identity,
|
|
33081
33081
|
finish,
|
|
33082
33082
|
done,
|
|
33083
|
-
resolve:
|
|
33083
|
+
resolve: resolve3,
|
|
33084
33084
|
rejected: false,
|
|
33085
33085
|
interrupted: false,
|
|
33086
33086
|
finished: false
|
|
@@ -33128,8 +33128,8 @@ function createPromptResults({
|
|
|
33128
33128
|
try {
|
|
33129
33129
|
const drained = await Promise.race([
|
|
33130
33130
|
Promise.all(claimed.map((record2) => record2.done)).then(() => true),
|
|
33131
|
-
new Promise((
|
|
33132
|
-
timer = setTimeout(() =>
|
|
33131
|
+
new Promise((resolve3) => {
|
|
33132
|
+
timer = setTimeout(() => resolve3(false), options.resultDrainTimeoutMs ?? 2e3);
|
|
33133
33133
|
})
|
|
33134
33134
|
]);
|
|
33135
33135
|
if (drained) return;
|
|
@@ -33286,14 +33286,14 @@ function createExecutorRequests({
|
|
|
33286
33286
|
}
|
|
33287
33287
|
}
|
|
33288
33288
|
const requestId = randomId();
|
|
33289
|
-
const outcome = await new Promise((
|
|
33289
|
+
const outcome = await new Promise((resolve3) => {
|
|
33290
33290
|
const pending = {
|
|
33291
33291
|
requestId,
|
|
33292
33292
|
request: params,
|
|
33293
33293
|
permissionRequest,
|
|
33294
33294
|
turnId: shared.activeTurnId,
|
|
33295
33295
|
settled: false,
|
|
33296
|
-
resolve:
|
|
33296
|
+
resolve: resolve3
|
|
33297
33297
|
};
|
|
33298
33298
|
approvals.add(pending);
|
|
33299
33299
|
emit(
|
|
@@ -33511,14 +33511,14 @@ function createExecutorRuntime({
|
|
|
33511
33511
|
if (!promptMutex.isLocked) {
|
|
33512
33512
|
return true;
|
|
33513
33513
|
}
|
|
33514
|
-
return await new Promise((
|
|
33514
|
+
return await new Promise((resolve3) => {
|
|
33515
33515
|
const timer = setTimeout(() => {
|
|
33516
33516
|
shared.promptWaiters = shared.promptWaiters.filter((waiter) => waiter !== onSettle);
|
|
33517
|
-
|
|
33517
|
+
resolve3(false);
|
|
33518
33518
|
}, timeoutMs);
|
|
33519
33519
|
const onSettle = () => {
|
|
33520
33520
|
clearTimeout(timer);
|
|
33521
|
-
|
|
33521
|
+
resolve3(true);
|
|
33522
33522
|
};
|
|
33523
33523
|
shared.promptWaiters.push(onSettle);
|
|
33524
33524
|
});
|
|
@@ -34277,8 +34277,8 @@ var Mutex = class {
|
|
|
34277
34277
|
this.locked = true;
|
|
34278
34278
|
return Promise.resolve();
|
|
34279
34279
|
}
|
|
34280
|
-
return new Promise((
|
|
34281
|
-
this.waiters.push(
|
|
34280
|
+
return new Promise((resolve3) => {
|
|
34281
|
+
this.waiters.push(resolve3);
|
|
34282
34282
|
});
|
|
34283
34283
|
}
|
|
34284
34284
|
tryAcquire() {
|
|
@@ -34595,6 +34595,9 @@ function createAcpSessionRegistry(threads, stopBooked2) {
|
|
|
34595
34595
|
if (!booked) return Promise.resolve();
|
|
34596
34596
|
booked.closing ??= Promise.resolve().then(() => stopBooked2(booked)).then(() => {
|
|
34597
34597
|
if (threads.get(threadId) === booked) threads.delete(threadId);
|
|
34598
|
+
}).catch((cause) => {
|
|
34599
|
+
if (threads.get(threadId) === booked) delete booked.closing;
|
|
34600
|
+
throw cause;
|
|
34598
34601
|
});
|
|
34599
34602
|
return booked.closing;
|
|
34600
34603
|
};
|
|
@@ -34604,15 +34607,70 @@ function createAcpSessionRegistry(threads, stopBooked2) {
|
|
|
34604
34607
|
return { requireThread, stopSession, stopAll };
|
|
34605
34608
|
}
|
|
34606
34609
|
|
|
34610
|
+
// ../../packages/ycodium-acp-executor/src/session-cleanup.ts
|
|
34611
|
+
var reportedForwardingFailures = /* @__PURE__ */ new WeakSet();
|
|
34612
|
+
async function cleanupAcpSession(input2) {
|
|
34613
|
+
const failures = [];
|
|
34614
|
+
const forwarding = input2.forwarding.catch((cause) => {
|
|
34615
|
+
if (reportedForwardingFailures.has(input2.forwarding)) return;
|
|
34616
|
+
reportedForwardingFailures.add(input2.forwarding);
|
|
34617
|
+
failures.push(new Error(`forwarding failed: ${String(cause)}`, { cause }));
|
|
34618
|
+
});
|
|
34619
|
+
for (const [step, cleanup] of [
|
|
34620
|
+
["executor.dispose", () => input2.executor.dispose()],
|
|
34621
|
+
["stopProcess", input2.stopProcess],
|
|
34622
|
+
["forwarding", () => forwarding]
|
|
34623
|
+
]) {
|
|
34624
|
+
try {
|
|
34625
|
+
await cleanup();
|
|
34626
|
+
} catch (cause) {
|
|
34627
|
+
failures.push(new Error(`${step} failed: ${String(cause)}`, { cause }));
|
|
34628
|
+
}
|
|
34629
|
+
}
|
|
34630
|
+
if (failures.length > 0) {
|
|
34631
|
+
throw new AggregateError(failures, failures.map((error62) => error62.message).join("; "));
|
|
34632
|
+
}
|
|
34633
|
+
}
|
|
34634
|
+
async function cleanupAcpStartup(input2) {
|
|
34635
|
+
try {
|
|
34636
|
+
await cleanupAcpSession(input2);
|
|
34637
|
+
return true;
|
|
34638
|
+
} catch (cleanupError) {
|
|
34639
|
+
input2.log.warn("ACP session startup cleanup failed", {
|
|
34640
|
+
threadId: input2.threadId,
|
|
34641
|
+
error: String(cleanupError)
|
|
34642
|
+
});
|
|
34643
|
+
return false;
|
|
34644
|
+
}
|
|
34645
|
+
}
|
|
34646
|
+
function createRetryableClose(run) {
|
|
34647
|
+
let task;
|
|
34648
|
+
return () => {
|
|
34649
|
+
if (task) return task;
|
|
34650
|
+
const done = Promise.withResolvers();
|
|
34651
|
+
const current = done.promise;
|
|
34652
|
+
task = current;
|
|
34653
|
+
void current.catch(() => {
|
|
34654
|
+
if (task === current) task = void 0;
|
|
34655
|
+
});
|
|
34656
|
+
try {
|
|
34657
|
+
run().then(done.resolve, done.reject);
|
|
34658
|
+
} catch (cause) {
|
|
34659
|
+
done.reject(cause);
|
|
34660
|
+
}
|
|
34661
|
+
return current;
|
|
34662
|
+
};
|
|
34663
|
+
}
|
|
34664
|
+
|
|
34607
34665
|
// ../../packages/ycodium-acp-executor/src/prompt-dispatch.ts
|
|
34608
34666
|
var dispatchAcpPrompt = (executor, input2) => {
|
|
34609
|
-
const { promise: dispatched, resolve:
|
|
34667
|
+
const { promise: dispatched, resolve: resolve3 } = Promise.withResolvers();
|
|
34610
34668
|
let written = false;
|
|
34611
34669
|
const finished = executor.prompt({
|
|
34612
34670
|
...input2,
|
|
34613
34671
|
onDispatched: (turnId) => {
|
|
34614
34672
|
written = true;
|
|
34615
|
-
|
|
34673
|
+
resolve3(turnId);
|
|
34616
34674
|
}
|
|
34617
34675
|
});
|
|
34618
34676
|
return Promise.race([
|
|
@@ -34666,7 +34724,7 @@ function toAcpMcpServers(entries) {
|
|
|
34666
34724
|
|
|
34667
34725
|
// ../../packages/ycodium-acp-executor/src/probe.ts
|
|
34668
34726
|
function withProbeTimeout(promise2, timeoutMs, what) {
|
|
34669
|
-
return new Promise((
|
|
34727
|
+
return new Promise((resolve3, reject) => {
|
|
34670
34728
|
const timer = setTimeout(() => {
|
|
34671
34729
|
reject(new Error(`${what} timed out after ${timeoutMs}ms`));
|
|
34672
34730
|
}, timeoutMs);
|
|
@@ -34674,7 +34732,7 @@ function withProbeTimeout(promise2, timeoutMs, what) {
|
|
|
34674
34732
|
promise2.then(
|
|
34675
34733
|
(value) => {
|
|
34676
34734
|
clearTimeout(timer);
|
|
34677
|
-
|
|
34735
|
+
resolve3(value);
|
|
34678
34736
|
},
|
|
34679
34737
|
(error62) => {
|
|
34680
34738
|
clearTimeout(timer);
|
|
@@ -34919,28 +34977,45 @@ var createDshUsage = (input2) => {
|
|
|
34919
34977
|
return { readQuota };
|
|
34920
34978
|
};
|
|
34921
34979
|
|
|
34922
|
-
// src/
|
|
34980
|
+
// src/dshOverlay.ts
|
|
34923
34981
|
import * as NodeCrypto3 from "node:crypto";
|
|
34924
34982
|
import * as NodeFSP from "node:fs/promises";
|
|
34925
34983
|
import * as NodeOS2 from "node:os";
|
|
34926
34984
|
import * as NodePath3 from "node:path";
|
|
34985
|
+
import * as NodeURL2 from "node:url";
|
|
34927
34986
|
var import_yaml = __toESM(require_dist(), 1);
|
|
34928
34987
|
var OVERLAY_DIR = "ycodium-dsh-patches";
|
|
34929
34988
|
var DUMP_CONFIG_TIMEOUT_MS = 15e3;
|
|
34930
34989
|
var DUMP_CONFIG_MAX_OUTPUT_BYTES = 1024 * 1024;
|
|
34931
34990
|
var SKILL_FILESYSTEM_ID = "skill-filesystem";
|
|
34991
|
+
var PERMISSION_SYNC_ID = "ycodium-permission-sync";
|
|
34932
34992
|
var posixPath = (path) => path.replaceAll("\\", "/");
|
|
34933
|
-
function
|
|
34934
|
-
|
|
34935
|
-
|
|
34936
|
-
|
|
34937
|
-
|
|
34938
|
-
|
|
34939
|
-
|
|
34940
|
-
|
|
34941
|
-
|
|
34942
|
-
|
|
34943
|
-
|
|
34993
|
+
function permissionSyncModulePath() {
|
|
34994
|
+
const here = NodePath3.dirname(NodeURL2.fileURLToPath(import.meta.url));
|
|
34995
|
+
return NodePath3.resolve(here, "..", "assets", "permission-sync.mjs");
|
|
34996
|
+
}
|
|
34997
|
+
function dshOverlay(input2) {
|
|
34998
|
+
const lines = [];
|
|
34999
|
+
if (input2.permissionSyncModule !== void 0) {
|
|
35000
|
+
lines.push(
|
|
35001
|
+
"- insert:",
|
|
35002
|
+
` - id: ${PERMISSION_SYNC_ID}`,
|
|
35003
|
+
` name: ${JSON.stringify(posixPath(input2.permissionSyncModule))}`
|
|
35004
|
+
);
|
|
35005
|
+
}
|
|
35006
|
+
if (input2.skillsDir !== void 0) {
|
|
35007
|
+
lines.push(
|
|
35008
|
+
`- id: ${SKILL_FILESYSTEM_ID}`,
|
|
35009
|
+
" config:",
|
|
35010
|
+
" customSkillDirs:",
|
|
35011
|
+
` - ${JSON.stringify(posixPath(input2.skillsDir))}`
|
|
35012
|
+
);
|
|
35013
|
+
}
|
|
35014
|
+
return `${lines.join("\n")}
|
|
35015
|
+
`;
|
|
35016
|
+
}
|
|
35017
|
+
async function ensureDshOverlay(input2, tempRoot = NodeOS2.tmpdir()) {
|
|
35018
|
+
const contents = dshOverlay(input2);
|
|
34944
35019
|
const hash2 = NodeCrypto3.createHash("sha256").update(contents).digest("hex").slice(0, 16);
|
|
34945
35020
|
const directory = NodePath3.join(tempRoot, OVERLAY_DIR);
|
|
34946
35021
|
const file2 = NodePath3.join(directory, `${hash2}.yml`);
|
|
@@ -34958,10 +35033,10 @@ async function ensureDshSkillOverlay(skillsDir, tempRoot = NodeOS2.tmpdir()) {
|
|
|
34958
35033
|
});
|
|
34959
35034
|
return file2;
|
|
34960
35035
|
}
|
|
34961
|
-
async function spawnDsh(host, launch,
|
|
35036
|
+
async function spawnDsh(host, launch, extraArgs, suffix = []) {
|
|
34962
35037
|
const spawned = {
|
|
34963
35038
|
program: launch.program,
|
|
34964
|
-
args: [...
|
|
35039
|
+
args: [...launch.args, ...extraArgs, ...suffix],
|
|
34965
35040
|
cwd: launch.cwd
|
|
34966
35041
|
};
|
|
34967
35042
|
const handle = await host.process.spawn({
|
|
@@ -34983,42 +35058,84 @@ async function overlayTakesEffect(input2) {
|
|
|
34983
35058
|
maxOutputBytes: DUMP_CONFIG_MAX_OUTPUT_BYTES,
|
|
34984
35059
|
what: "dsh --dump-config"
|
|
34985
35060
|
});
|
|
34986
|
-
|
|
35061
|
+
if (run.exitCode !== 0) return false;
|
|
35062
|
+
const dump = run.stdout ?? "";
|
|
35063
|
+
if (input2.skillsDir !== void 0 && !dumpConfigHasSkillRoot(dump, input2.skillsDir)) return false;
|
|
35064
|
+
if (input2.expectPermissionSync && !dumpConfigHasPermissionSync(dump)) return false;
|
|
35065
|
+
return true;
|
|
34987
35066
|
}
|
|
34988
35067
|
function dumpConfigHasSkillRoot(dump, skillsDir) {
|
|
34989
|
-
let entries;
|
|
34990
|
-
try {
|
|
34991
|
-
entries = (0, import_yaml.parse)(dump);
|
|
34992
|
-
} catch {
|
|
34993
|
-
return false;
|
|
34994
|
-
}
|
|
34995
|
-
if (!Array.isArray(entries)) return false;
|
|
34996
35068
|
const target = posixPath(skillsDir);
|
|
34997
|
-
return
|
|
34998
|
-
if (typeof entry !== "object" || entry === null) return false;
|
|
35069
|
+
return dumpConfigEntries(dump).some((entry) => {
|
|
34999
35070
|
const { id, config: config2 } = entry;
|
|
35000
35071
|
const dirs = config2?.customSkillDirs;
|
|
35001
35072
|
return id === SKILL_FILESYSTEM_ID && Array.isArray(dirs) && dirs.some((dir) => typeof dir === "string" && posixPath(dir) === target);
|
|
35002
35073
|
});
|
|
35003
35074
|
}
|
|
35004
|
-
|
|
35075
|
+
function dumpConfigHasPermissionSync(dump) {
|
|
35076
|
+
return dumpConfigEntries(dump).some(
|
|
35077
|
+
(entry) => entry.id === PERMISSION_SYNC_ID
|
|
35078
|
+
);
|
|
35079
|
+
}
|
|
35080
|
+
function dumpConfigEntries(dump) {
|
|
35081
|
+
let entries;
|
|
35082
|
+
try {
|
|
35083
|
+
entries = (0, import_yaml.parse)(dump);
|
|
35084
|
+
} catch {
|
|
35085
|
+
return [];
|
|
35086
|
+
}
|
|
35087
|
+
return Array.isArray(entries) ? entries : [];
|
|
35088
|
+
}
|
|
35089
|
+
async function readable(path) {
|
|
35090
|
+
return NodeFSP.access(path).then(
|
|
35091
|
+
() => true,
|
|
35092
|
+
() => false
|
|
35093
|
+
);
|
|
35094
|
+
}
|
|
35095
|
+
async function dshOverlayPatchArgs(input2) {
|
|
35005
35096
|
const { skills, host, launch } = input2;
|
|
35006
|
-
|
|
35097
|
+
const skillsDir = skills !== void 0 && skills.names.length > 0 ? skills.skillsDir : void 0;
|
|
35098
|
+
const modulePath = permissionSyncModulePath();
|
|
35099
|
+
const expectPermissionSync = await readable(modulePath);
|
|
35100
|
+
if (!expectPermissionSync) {
|
|
35101
|
+
host.log.warn(
|
|
35102
|
+
"dsh permission sync module is missing; switching the permission mode will not reach dsh"
|
|
35103
|
+
);
|
|
35104
|
+
}
|
|
35105
|
+
if (skillsDir === void 0 && !expectPermissionSync) return [];
|
|
35007
35106
|
try {
|
|
35008
|
-
const overlay = await
|
|
35009
|
-
|
|
35107
|
+
const overlay = await ensureDshOverlay(
|
|
35108
|
+
{
|
|
35109
|
+
...skillsDir === void 0 ? {} : { skillsDir },
|
|
35110
|
+
...expectPermissionSync ? { permissionSyncModule: modulePath } : {}
|
|
35111
|
+
},
|
|
35112
|
+
input2.tempRoot
|
|
35113
|
+
);
|
|
35114
|
+
if (skillsDir === void 0) return ["--patch", overlay];
|
|
35115
|
+
const key = `${launch.cwd}\0${overlay}\0${expectPermissionSync ? "sync" : "no-sync"}`;
|
|
35010
35116
|
let check2 = input2.verified.get(key);
|
|
35011
35117
|
if (check2 === void 0) {
|
|
35012
|
-
check2 = overlayTakesEffect({
|
|
35118
|
+
check2 = overlayTakesEffect({
|
|
35119
|
+
host,
|
|
35120
|
+
launch,
|
|
35121
|
+
overlay,
|
|
35122
|
+
skillsDir,
|
|
35123
|
+
expectPermissionSync
|
|
35124
|
+
});
|
|
35013
35125
|
input2.verified.set(key, check2);
|
|
35014
35126
|
}
|
|
35015
35127
|
if (await check2) return ["--patch", overlay];
|
|
35016
|
-
host.log.warn(
|
|
35128
|
+
host.log.warn(
|
|
35129
|
+
"dsh did not take the session overlay; skills and permission switching stay on dsh's own defaults"
|
|
35130
|
+
);
|
|
35017
35131
|
} catch (error62) {
|
|
35018
35132
|
input2.verified.clear();
|
|
35019
|
-
host.log.warn(
|
|
35020
|
-
|
|
35021
|
-
|
|
35133
|
+
host.log.warn(
|
|
35134
|
+
"dsh session overlay failed; skills and permission switching stay on dsh's own defaults",
|
|
35135
|
+
{
|
|
35136
|
+
error: error62 instanceof Error ? error62.message : String(error62)
|
|
35137
|
+
}
|
|
35138
|
+
);
|
|
35022
35139
|
}
|
|
35023
35140
|
return [];
|
|
35024
35141
|
}
|
|
@@ -35288,9 +35405,9 @@ async function probeDshModels(input2) {
|
|
|
35288
35405
|
}
|
|
35289
35406
|
let handshake;
|
|
35290
35407
|
try {
|
|
35291
|
-
const { readable, writable } = nodeStreamsFromHandle(handle);
|
|
35408
|
+
const { readable: readable2, writable } = nodeStreamsFromHandle(handle);
|
|
35292
35409
|
handshake = await openAcpProbeHandshake({
|
|
35293
|
-
readable,
|
|
35410
|
+
readable: readable2,
|
|
35294
35411
|
writable,
|
|
35295
35412
|
clientInfo: DSH_CLIENT_INFO,
|
|
35296
35413
|
requestTimeoutMs: PROBE_REQUEST_TIMEOUT_MS
|
|
@@ -35428,8 +35545,8 @@ function dshOpenCommands(session) {
|
|
|
35428
35545
|
|
|
35429
35546
|
// src/dshInstance.ts
|
|
35430
35547
|
var RESUME_SCHEMA_VERSION = 1;
|
|
35431
|
-
var yieldTick = () => new Promise((
|
|
35432
|
-
setImmediate(
|
|
35548
|
+
var yieldTick = () => new Promise((resolve3) => {
|
|
35549
|
+
setImmediate(resolve3);
|
|
35433
35550
|
});
|
|
35434
35551
|
var EventBus = class {
|
|
35435
35552
|
#queued = [];
|
|
@@ -35456,8 +35573,8 @@ var EventBus = class {
|
|
|
35456
35573
|
const queued = this.#queued.shift();
|
|
35457
35574
|
if (queued !== void 0) return Promise.resolve({ done: false, value: queued });
|
|
35458
35575
|
if (this.#closed) return Promise.resolve({ done: true, value: void 0 });
|
|
35459
|
-
return new Promise((
|
|
35460
|
-
this.#waiters.push(
|
|
35576
|
+
return new Promise((resolve3) => {
|
|
35577
|
+
this.#waiters.push(resolve3);
|
|
35461
35578
|
});
|
|
35462
35579
|
}
|
|
35463
35580
|
};
|
|
@@ -35474,18 +35591,23 @@ function nowIso() {
|
|
|
35474
35591
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
35475
35592
|
}
|
|
35476
35593
|
async function stopBooked(booked) {
|
|
35477
|
-
await
|
|
35478
|
-
|
|
35479
|
-
|
|
35594
|
+
await cleanupAcpSession({
|
|
35595
|
+
executor: booked.executor,
|
|
35596
|
+
stopProcess: () => booked.handle.kill("SIGTERM"),
|
|
35597
|
+
forwarding: booked.forwarding
|
|
35598
|
+
});
|
|
35480
35599
|
}
|
|
35481
35600
|
var createDshInstance = (config2, host) => {
|
|
35482
35601
|
const recipe = parseDshInstanceConfig(config2);
|
|
35483
35602
|
const events = new EventBus();
|
|
35484
35603
|
const threads = /* @__PURE__ */ new Map();
|
|
35485
|
-
const
|
|
35604
|
+
const overlayChecks = /* @__PURE__ */ new Map();
|
|
35486
35605
|
let disposed = false;
|
|
35487
|
-
let disposeTask;
|
|
35488
35606
|
const { requireThread, stopSession, stopAll } = createAcpSessionRegistry(threads, stopBooked);
|
|
35607
|
+
const disposeOnce = createRetryableClose(async () => {
|
|
35608
|
+
await stopAll();
|
|
35609
|
+
events.close();
|
|
35610
|
+
});
|
|
35489
35611
|
const instance = {
|
|
35490
35612
|
probe: async () => {
|
|
35491
35613
|
if (recipe.binaryPath.length === 0) {
|
|
@@ -35546,15 +35668,15 @@ var createDshInstance = (config2, host) => {
|
|
|
35546
35668
|
cwd,
|
|
35547
35669
|
env
|
|
35548
35670
|
};
|
|
35549
|
-
const
|
|
35671
|
+
const overlayArgs = await dshOverlayPatchArgs({
|
|
35550
35672
|
skills: input2.skills,
|
|
35551
35673
|
host,
|
|
35552
35674
|
launch,
|
|
35553
|
-
verified:
|
|
35675
|
+
verified: overlayChecks
|
|
35554
35676
|
});
|
|
35555
35677
|
throwIfStartAborted(signal);
|
|
35556
|
-
const { handle, spawned } = await spawnDsh(host, launch,
|
|
35557
|
-
const { readable, writable, stderrTail } = nodeStreamsFromHandle2(handle);
|
|
35678
|
+
const { handle, spawned } = await spawnDsh(host, launch, overlayArgs);
|
|
35679
|
+
const { readable: readable2, writable, stderrTail } = nodeStreamsFromHandle2(handle);
|
|
35558
35680
|
const resume = input2.discardResumeCursor === true ? void 0 : parseAcpResumeCursor(input2.resumeCursor, RESUME_SCHEMA_VERSION);
|
|
35559
35681
|
const requestedModelId = modelIdFromSelection(input2.modelSelection);
|
|
35560
35682
|
const requestedEffort = modelSelectionStringOption(
|
|
@@ -35562,7 +35684,7 @@ var createDshInstance = (config2, host) => {
|
|
|
35562
35684
|
DSH_EFFORT_OPTION_ID
|
|
35563
35685
|
);
|
|
35564
35686
|
const executor = createAcpExecutor({
|
|
35565
|
-
readable,
|
|
35687
|
+
readable: readable2,
|
|
35566
35688
|
writable,
|
|
35567
35689
|
stderrTail,
|
|
35568
35690
|
cwd,
|
|
@@ -35631,9 +35753,13 @@ var createDshInstance = (config2, host) => {
|
|
|
35631
35753
|
});
|
|
35632
35754
|
return session;
|
|
35633
35755
|
} catch (error62) {
|
|
35634
|
-
await
|
|
35635
|
-
|
|
35636
|
-
|
|
35756
|
+
await cleanupAcpStartup({
|
|
35757
|
+
executor,
|
|
35758
|
+
stopProcess: () => handle.kill("SIGTERM"),
|
|
35759
|
+
forwarding,
|
|
35760
|
+
log: host.log,
|
|
35761
|
+
threadId: input2.threadId
|
|
35762
|
+
});
|
|
35637
35763
|
throw error62;
|
|
35638
35764
|
}
|
|
35639
35765
|
},
|
|
@@ -35713,13 +35839,8 @@ var createDshInstance = (config2, host) => {
|
|
|
35713
35839
|
}),
|
|
35714
35840
|
continuationKey: dshContinuationKey(recipe.homePath),
|
|
35715
35841
|
dispose: () => {
|
|
35716
|
-
if (disposeTask) return disposeTask;
|
|
35717
35842
|
disposed = true;
|
|
35718
|
-
|
|
35719
|
-
await stopAll();
|
|
35720
|
-
events.close();
|
|
35721
|
-
})();
|
|
35722
|
-
return disposeTask;
|
|
35843
|
+
return disposeOnce();
|
|
35723
35844
|
}
|
|
35724
35845
|
};
|
|
35725
35846
|
return instance;
|
|
@@ -35737,7 +35858,7 @@ var executors = [
|
|
|
35737
35858
|
];
|
|
35738
35859
|
var index_default = definePlugin({
|
|
35739
35860
|
id: "agent-dsh",
|
|
35740
|
-
apiVersion:
|
|
35861
|
+
apiVersion: 19,
|
|
35741
35862
|
executors,
|
|
35742
35863
|
activate(ctx) {
|
|
35743
35864
|
ctx.log.info("dsh executor ready");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ycodium-ai/agent-dsh",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3208",
|
|
4
4
|
"description": "DeepSeek Harness executor: dsh CLI over Agent Client Protocol stdio.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ycodium",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"esbuild": "0.28.1",
|
|
23
23
|
"vite-plus": "0.2.2",
|
|
24
24
|
"yaml": "^2.9.0",
|
|
25
|
-
"@ycodium-ai/plugin-api": "0.2.
|
|
26
|
-
"ycodium-acp-executor": "0.2.
|
|
25
|
+
"@ycodium-ai/plugin-api": "0.2.3208",
|
|
26
|
+
"ycodium-acp-executor": "0.2.3208",
|
|
27
27
|
"ycodium-executor-testing": "0.0.0"
|
|
28
28
|
},
|
|
29
29
|
"ycodium": {
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "node build.mjs",
|
|
42
|
+
"check:permission-sync": "node scripts/check-permission-sync.mjs",
|
|
42
43
|
"typecheck": "tsgo --noEmit",
|
|
43
44
|
"test": "vp test run"
|
|
44
45
|
}
|