@deksden-com/dd-flow-cli 0.9.0-beta.134 → 0.9.0-beta.136
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 +12 -0
- package/README.md +33 -0
- package/dist/build-info.json +7 -7
- package/dist/cli/command-inputs.js +1 -0
- package/dist/cli/command-metadata.js +144 -0
- package/dist/cli/command-option-descriptions.js +186 -0
- package/dist/cli/completion-cli.js +70 -0
- package/dist/cli/completion.js +57 -0
- package/dist/cli/error-output.js +52 -0
- package/dist/cli/executor-onboarding.js +71 -0
- package/dist/cli/harnesses.js +84 -0
- package/dist/cli/models.js +39 -0
- package/dist/cli/operator-profiles.js +61 -0
- package/dist/cli/output-options.js +35 -0
- package/dist/cli/response-file.js +69 -0
- package/dist/cli/run-cli.js +5 -0
- package/dist/cli/setup.js +147 -0
- package/dist/harness-runtime/OPENCODE-LICENSE.txt +24 -0
- package/dist/harness-runtime/bin/dd-opencode.mjs +1 -1
- package/dist/harness-runtime/lib/codex-capacity-policy.mjs +13 -0
- package/dist/harness-runtime/lib/dd-opencode-daemon.mjs +193 -39
- package/dist/harness-runtime/lib/dd-opencode.mjs +295 -100
- package/dist/harness-runtime/lib/delegation-instructions.mjs +3 -3
- package/dist/harness-runtime/lib/managed-daemon.mjs +1 -1
- package/dist/harness-runtime/lib/native-hook-command.d.mts +2 -2
- package/dist/harness-runtime/lib/native-hook-command.mjs +4 -4
- package/dist/harness-runtime/lib/opencode-plugin.mjs +60 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-1y4a697q.js +81 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-2ny4vxct.js +92 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-6mptkzbc.js +0 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-7x67cf1q.js +52 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-9rqn6x4v.js +16 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-9vdz0zwn.js +1661 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-ecs5ftka.js +1466 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-frbwqjmf.js +145 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-gne7h7mq.js +50 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-gx9wnkzr.js +105 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-m2eywc8w.js +0 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-nwcpakzx.js +12 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-q4g3afnw.js +623 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-qav6mfdz.js +0 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-sxt88q69.js +12 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-t1xa31vm.js +39 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-ve4aws36.js +103 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-vmytr4q8.js +4 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-vt9jbch8.js +36 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-vyas3vgt.js +0 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-wjyeq25y.js +30 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-xgnj2w4v.js +20 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-y2etg5bs.js +9 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-ydhz1zrh.js +238 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-z6qdwcsf.js +62 -0
- package/dist/harness-runtime/vendor/opencode-client/contract.d.ts +1 -0
- package/dist/harness-runtime/vendor/opencode-client/contract.js +12 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/api/api.d.ts +2806 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/api/api.js +0 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/api.d.ts +4 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/api.js +0 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/client.d.ts +2530 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/client.js +15 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/generated/client-error.d.ts +7 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/generated/client-error.js +6 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/generated/client.d.ts +2529 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/generated/client.js +8 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/generated/index.d.ts +2 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/generated/index.js +12 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/index.d.ts +35 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/index.js +75 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/rpc.d.ts +20 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/rpc.js +11 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/service.d.ts +90 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/service.js +187 -0
- package/dist/harness-runtime/vendor/opencode-client/package.json +84 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/api.d.ts +21 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/api.js +0 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/client.d.ts +252 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/client.js +14 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/generated/client-error.d.ts +8 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/generated/client-error.js +6 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/generated/client.d.ts +259 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/generated/client.js +7 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/generated/index.d.ts +3 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/generated/index.js +79 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/generated/types.d.ts +8932 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/generated/types.js +70 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/index.d.ts +6 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/index.js +83 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/rpc.d.ts +32 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/rpc.js +7 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/service.d.ts +24 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/service.js +187 -0
- package/dist/harness-runtime/vendor/opencode-client/pty-handoff.d.ts +12 -0
- package/dist/harness-runtime/vendor/opencode-client/pty-handoff.js +14 -0
- package/dist/harness-runtime/vendor/opencode-client/rpc-runtime.d.ts +20 -0
- package/dist/harness-runtime/vendor/opencode-client/rpc-runtime.js +14 -0
- package/dist/harness-runtime/vendor/opencode-client/service-contender.d.ts +37 -0
- package/dist/harness-runtime/vendor/opencode-client/service-contender.js +10 -0
- package/dist/harness-runtime/vendor/opencode-client/service-probe.d.ts +70 -0
- package/dist/harness-runtime/vendor/opencode-client/service-probe.js +16 -0
- package/dist/harness-runtime/vendor/opencode-client/service-timing.d.ts +12 -0
- package/dist/harness-runtime/vendor/opencode-client/service-timing.js +10 -0
- package/dist/harness-runtime/vendor/opencode-client/service-version.d.ts +2 -0
- package/dist/harness-runtime/vendor/opencode-client/service-version.js +6 -0
- package/dist/harness-runtime/vendor/opencode-client/service.d.ts +52 -0
- package/dist/harness-runtime/vendor/opencode-client/service.js +1 -0
- package/dist/harness-runtime/vendor/opencode-client/shared-events.d.ts +11 -0
- package/dist/harness-runtime/vendor/opencode-client/shared-events.js +8 -0
- package/dist/harness-runtime/vendor/opencode-client/solid/connection.d.ts +37 -0
- package/dist/harness-runtime/vendor/opencode-client/solid/connection.js +10 -0
- package/dist/harness-runtime/vendor/opencode-client/solid/data.d.ts +211 -0
- package/dist/harness-runtime/vendor/opencode-client/solid/data.js +18 -0
- package/dist/harness-runtime/vendor/opencode-client/solid/index.d.ts +3 -0
- package/dist/harness-runtime/vendor/opencode-client/solid/index.js +32 -0
- package/dist/harness-runtime/vendor/opencode-client/solid/pty.d.ts +22 -0
- package/dist/harness-runtime/vendor/opencode-client/solid/pty.js +8 -0
- package/dist/harness-runtime/vendor/opencode-plugin.mjs +3 -0
- package/dist/services/cli-operation-classifier.js +4 -0
- package/dist/services/cli-upgrade-allowlist.js +27 -0
- package/dist/services/discovery/agy-discovery.js +2 -0
- package/dist/services/discovery/codex-discovery.js +2 -0
- package/dist/services/discovery/droid-discovery.js +2 -0
- package/dist/services/discovery/grok-discovery.js +2 -0
- package/dist/services/discovery/opencode-discovery.js +2 -0
- package/dist/services/discovery/static.js +31 -0
- package/dist/services/discovery/zcode-discovery.js +2 -0
- package/dist/services/engines.js +23 -25
- package/dist/services/eval-snapshots.js +1 -1
- package/dist/services/executor-onboarding.js +56 -0
- package/dist/services/external-work-launch.js +1 -1
- package/dist/services/harness-discovery.js +29 -0
- package/dist/services/harness-doctor.js +75 -0
- package/dist/services/harness-probe-effects.js +51 -0
- package/dist/services/harness-version-probe.js +100 -0
- package/dist/services/hooks.js +1 -1
- package/dist/services/hybrid-contracts.js +455 -0
- package/dist/services/installation-lock.js +92 -0
- package/dist/services/managed-processes.js +30 -0
- package/dist/services/merge-server.js +1 -1
- package/dist/services/model-catalog.js +109 -0
- package/dist/services/model-discovery.js +46 -0
- package/dist/services/operator-profiles.js +236 -0
- package/dist/services/release-archive-producer.js +52 -0
- package/dist/services/release-archive.js +143 -0
- package/dist/services/release-cache.js +142 -0
- package/dist/services/release-compatibility.js +18 -0
- package/dist/services/release-download.js +67 -0
- package/dist/services/release-envelope.js +104 -0
- package/dist/services/release-manifest.js +45 -0
- package/dist/services/release-payload.js +114 -0
- package/dist/services/release-producer.js +63 -0
- package/dist/services/release-provenance.js +160 -0
- package/dist/services/release-registry.js +66 -0
- package/dist/services/release-source.js +194 -0
- package/dist/services/run-controller-recovery.js +2 -2
- package/dist/services/run-controller.js +3 -2
- package/dist/services/run-health.js +149 -0
- package/dist/services/runs.js +61 -13
- package/dist/services/setup.js +377 -0
- package/dist/storage/database.js +18 -3
- package/dist/storage/writer-contract.js +8 -0
- package/package.json +4 -1
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./service-probe-9rqn6x4v.js";
|
|
4
|
+
|
|
5
|
+
// src/shared-events.ts
|
|
6
|
+
var exports_shared_events = {};
|
|
7
|
+
__export(exports_shared_events, {
|
|
8
|
+
SharedEvents: () => exports_shared_events,
|
|
9
|
+
make: () => make7
|
|
10
|
+
});
|
|
11
|
+
function make7(connect) {
|
|
12
|
+
let current;
|
|
13
|
+
const capacity = 4096;
|
|
14
|
+
function stop(connection) {
|
|
15
|
+
connection.connected = undefined;
|
|
16
|
+
connection.controller.abort();
|
|
17
|
+
if (current === connection)
|
|
18
|
+
current = undefined;
|
|
19
|
+
}
|
|
20
|
+
async function run(connection) {
|
|
21
|
+
let iterator;
|
|
22
|
+
let completion = {};
|
|
23
|
+
try {
|
|
24
|
+
if (connection.controller.signal.aborted)
|
|
25
|
+
return;
|
|
26
|
+
iterator = connect(connection.controller.signal, () => {
|
|
27
|
+
connection.subscribers.forEach((subscriber) => subscriber.activity?.());
|
|
28
|
+
})[Symbol.asyncIterator]();
|
|
29
|
+
while (!connection.controller.signal.aborted) {
|
|
30
|
+
const item = await iterator.next();
|
|
31
|
+
if (item.done || connection.controller.signal.aborted)
|
|
32
|
+
break;
|
|
33
|
+
if (item.value.type === "server.connected")
|
|
34
|
+
connection.connected = item.value;
|
|
35
|
+
connection.subscribers.forEach((subscriber) => subscriber.push(item.value));
|
|
36
|
+
}
|
|
37
|
+
} catch (error) {
|
|
38
|
+
completion = { error };
|
|
39
|
+
} finally {
|
|
40
|
+
stop(connection);
|
|
41
|
+
try {
|
|
42
|
+
await iterator?.return?.();
|
|
43
|
+
} catch (error) {
|
|
44
|
+
if (!("error" in completion))
|
|
45
|
+
completion = { error };
|
|
46
|
+
}
|
|
47
|
+
connection.subscribers.forEach((subscriber) => subscriber.finish(completion));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
subscribe(options) {
|
|
52
|
+
return {
|
|
53
|
+
[Symbol.asyncIterator]() {
|
|
54
|
+
const pending = [];
|
|
55
|
+
const queued = [];
|
|
56
|
+
let started = false;
|
|
57
|
+
let completion;
|
|
58
|
+
let connection;
|
|
59
|
+
function finish(result, discard = true) {
|
|
60
|
+
completion = result;
|
|
61
|
+
if (discard)
|
|
62
|
+
queued.length = 0;
|
|
63
|
+
options?.signal?.removeEventListener("abort", abort);
|
|
64
|
+
if (connection?.subscribers.delete(subscriber) && !connection.subscribers.size)
|
|
65
|
+
stop(connection);
|
|
66
|
+
pending.splice(0).forEach((request) => {
|
|
67
|
+
if ("error" in result)
|
|
68
|
+
request.reject(result.error);
|
|
69
|
+
else
|
|
70
|
+
request.resolve({ done: true, value: undefined });
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function abort() {
|
|
74
|
+
finish({});
|
|
75
|
+
}
|
|
76
|
+
const subscriber = {
|
|
77
|
+
activity: options?.onActivity,
|
|
78
|
+
finish(result) {
|
|
79
|
+
finish(result, false);
|
|
80
|
+
},
|
|
81
|
+
push(value) {
|
|
82
|
+
if (completion)
|
|
83
|
+
return;
|
|
84
|
+
const request = pending.shift();
|
|
85
|
+
if (request) {
|
|
86
|
+
request.resolve({ done: false, value });
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (queued.length === capacity) {
|
|
90
|
+
finish({ error: new Error(`Event subscriber exceeded its ${capacity}-event capacity`) });
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
queued.push(value);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
function start() {
|
|
97
|
+
if (completion)
|
|
98
|
+
return;
|
|
99
|
+
const fresh = !current;
|
|
100
|
+
connection = current ?? {
|
|
101
|
+
controller: new AbortController,
|
|
102
|
+
subscribers: new Set
|
|
103
|
+
};
|
|
104
|
+
current = connection;
|
|
105
|
+
connection.subscribers.add(subscriber);
|
|
106
|
+
if (connection.connected)
|
|
107
|
+
subscriber.push(connection.connected);
|
|
108
|
+
if (fresh)
|
|
109
|
+
run(connection);
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
next() {
|
|
113
|
+
const value = queued.shift();
|
|
114
|
+
if (value)
|
|
115
|
+
return Promise.resolve({ done: false, value });
|
|
116
|
+
if (completion) {
|
|
117
|
+
if ("error" in completion)
|
|
118
|
+
return Promise.reject(completion.error);
|
|
119
|
+
return Promise.resolve({ done: true, value: undefined });
|
|
120
|
+
}
|
|
121
|
+
if (options?.signal?.aborted) {
|
|
122
|
+
abort();
|
|
123
|
+
return Promise.resolve({ done: true, value: undefined });
|
|
124
|
+
}
|
|
125
|
+
const request = Promise.withResolvers();
|
|
126
|
+
pending.push(request);
|
|
127
|
+
if (!started) {
|
|
128
|
+
started = true;
|
|
129
|
+
options?.signal?.addEventListener("abort", abort, { once: true });
|
|
130
|
+
start();
|
|
131
|
+
}
|
|
132
|
+
return request.promise;
|
|
133
|
+
},
|
|
134
|
+
return() {
|
|
135
|
+
finish({});
|
|
136
|
+
return Promise.resolve({ done: true, value: undefined });
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export { make7, exports_shared_events };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// src/solid/pty.ts
|
|
2
|
+
function createPtyClient2(api, options) {
|
|
3
|
+
return {
|
|
4
|
+
async connect(input) {
|
|
5
|
+
const result = await api.pty.connect.token({
|
|
6
|
+
ptyID: input.ptyID,
|
|
7
|
+
location: input.location,
|
|
8
|
+
"x-opencode-ticket": "1"
|
|
9
|
+
});
|
|
10
|
+
const baseUrl = new URL(options.url);
|
|
11
|
+
if (!baseUrl.pathname.endsWith("/"))
|
|
12
|
+
baseUrl.pathname += "/";
|
|
13
|
+
const url = new URL(`api/pty/${encodeURIComponent(input.ptyID)}/connect`, baseUrl);
|
|
14
|
+
if (input.location?.directory)
|
|
15
|
+
url.searchParams.set("location[directory]", input.location.directory);
|
|
16
|
+
if (input.cursor !== undefined)
|
|
17
|
+
url.searchParams.set("cursor", String(input.cursor));
|
|
18
|
+
url.searchParams.set("ticket", result.data.ticket);
|
|
19
|
+
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
20
|
+
const socket = options.openSocket?.(url) ?? new WebSocket(url);
|
|
21
|
+
socket.binaryType = "arraybuffer";
|
|
22
|
+
return socket;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function createPersistentPtyClient2(api, options) {
|
|
27
|
+
return {
|
|
28
|
+
async connect(input) {
|
|
29
|
+
const token = await api.experimental.persistentPty.connectToken({
|
|
30
|
+
ptyID: input.ptyID,
|
|
31
|
+
"x-opencode-ticket": "1"
|
|
32
|
+
});
|
|
33
|
+
const baseUrl = new URL(options.url);
|
|
34
|
+
if (!baseUrl.pathname.endsWith("/"))
|
|
35
|
+
baseUrl.pathname += "/";
|
|
36
|
+
const url = new URL(`api/experimental/persistent-pty/${encodeURIComponent(input.ptyID)}/connect`, baseUrl);
|
|
37
|
+
url.searchParams.set("ticket", token.ticket);
|
|
38
|
+
url.searchParams.set("cursor", String(input.cursor));
|
|
39
|
+
url.searchParams.set("attachment_id", input.attachmentID);
|
|
40
|
+
url.searchParams.set("takeover", String(input.takeover ?? false));
|
|
41
|
+
url.searchParams.set("input_protocol", "1");
|
|
42
|
+
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
43
|
+
const socket = options.openSocket?.(url) ?? new WebSocket(url);
|
|
44
|
+
socket.binaryType = "arraybuffer";
|
|
45
|
+
return socket;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { createPtyClient2, createPersistentPtyClient2 };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./service-probe-9rqn6x4v.js";
|
|
4
|
+
|
|
5
|
+
// src/pty-handoff.ts
|
|
6
|
+
var exports_pty_handoff = {};
|
|
7
|
+
__export(exports_pty_handoff, {
|
|
8
|
+
PtyHandoff: () => exports_pty_handoff,
|
|
9
|
+
clear: () => clear2,
|
|
10
|
+
complete: () => complete2,
|
|
11
|
+
environment: () => environment2,
|
|
12
|
+
prepare: () => prepare2
|
|
13
|
+
});
|
|
14
|
+
import { readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
15
|
+
async function prepare2(file, info, timeout) {
|
|
16
|
+
const existing = await read(file);
|
|
17
|
+
if (existing !== undefined && existing.expiresAt > Date.now() && same(existing.source, info))
|
|
18
|
+
return;
|
|
19
|
+
const { OpenCode } = await import("../promise/index.js");
|
|
20
|
+
const client = OpenCode.make({
|
|
21
|
+
baseUrl: info.url,
|
|
22
|
+
headers: info.password === undefined ? undefined : { authorization: "Basic " + Buffer.from(`opencode:${info.password}`).toString("base64") }
|
|
23
|
+
});
|
|
24
|
+
const handoff = await client.experimental.persistentPty.handoff({ signal: AbortSignal.timeout(timeout) }).then(parse).catch(async (cause) => {
|
|
25
|
+
const concurrent = await read(file);
|
|
26
|
+
if (concurrent !== undefined && concurrent.expiresAt > Date.now() && same(concurrent.source, info))
|
|
27
|
+
return;
|
|
28
|
+
console.warn("Background service cannot hand off persistent terminals; shutting them down before replacement", cause);
|
|
29
|
+
await client.experimental.persistentPty.shutdown({ signal: AbortSignal.timeout(timeout) }).catch(() => {});
|
|
30
|
+
return null;
|
|
31
|
+
});
|
|
32
|
+
if (handoff === undefined)
|
|
33
|
+
return;
|
|
34
|
+
await publish(file, info, handoff).catch((cause) => console.warn("Failed to publish persistent terminal handoff", cause));
|
|
35
|
+
}
|
|
36
|
+
function parse(body) {
|
|
37
|
+
if (typeof body !== "object" || body === null || !("handoff" in body))
|
|
38
|
+
throw new Error("Invalid persistent terminal handoff response");
|
|
39
|
+
if (body.handoff === null)
|
|
40
|
+
return null;
|
|
41
|
+
if (!isHandoff(body.handoff) || body.handoff.expiresAt <= Date.now())
|
|
42
|
+
throw new Error("Invalid or expired persistent terminal handoff");
|
|
43
|
+
return body.handoff;
|
|
44
|
+
}
|
|
45
|
+
async function publish(file, info, handoff) {
|
|
46
|
+
const temporary = `${file}.pty-handoff.${crypto.randomUUID()}.tmp`;
|
|
47
|
+
await writeFile(temporary, JSON.stringify({
|
|
48
|
+
source: { id: info.id, pid: info.pid, url: info.url },
|
|
49
|
+
handoff,
|
|
50
|
+
expiresAt: handoff?.expiresAt ?? Date.now() + 30000
|
|
51
|
+
}), { mode: 384, flag: "wx" });
|
|
52
|
+
await rename(temporary, file + ".pty-handoff").finally(() => rm(temporary, { force: true }));
|
|
53
|
+
}
|
|
54
|
+
async function environment2(file, env) {
|
|
55
|
+
const record = await read(file);
|
|
56
|
+
const current = await readFile(file, "utf8").then((text) => JSON.parse(text)).catch(() => {
|
|
57
|
+
return;
|
|
58
|
+
});
|
|
59
|
+
const handoff = record !== undefined && record.expiresAt > Date.now() && (current === undefined || same(record.source, current)) ? record.handoff : undefined;
|
|
60
|
+
return { ...env, OPENCODE_PTY_HANDOFF: handoff == null ? undefined : JSON.stringify(handoff) };
|
|
61
|
+
}
|
|
62
|
+
async function complete2(file, info) {
|
|
63
|
+
const record = await read(file);
|
|
64
|
+
if (record !== undefined && !same(record.source, info))
|
|
65
|
+
await clear2(file);
|
|
66
|
+
}
|
|
67
|
+
async function clear2(file) {
|
|
68
|
+
await rm(file + ".pty-handoff", { force: true });
|
|
69
|
+
}
|
|
70
|
+
async function read(file) {
|
|
71
|
+
const value = await readFile(file + ".pty-handoff", "utf8").then((text) => JSON.parse(text)).catch(() => {
|
|
72
|
+
return;
|
|
73
|
+
});
|
|
74
|
+
if (typeof value !== "object" || value === null || !("source" in value) || !("handoff" in value))
|
|
75
|
+
return;
|
|
76
|
+
if (typeof value.source !== "object" || value.source === null)
|
|
77
|
+
return;
|
|
78
|
+
if (!("pid" in value.source) || typeof value.source.pid !== "number")
|
|
79
|
+
return;
|
|
80
|
+
if (!("url" in value.source) || typeof value.source.url !== "string")
|
|
81
|
+
return;
|
|
82
|
+
if ("id" in value.source && typeof value.source.id !== "string")
|
|
83
|
+
return;
|
|
84
|
+
if (value.handoff !== null && !isHandoff(value.handoff))
|
|
85
|
+
return;
|
|
86
|
+
if (!("expiresAt" in value) || typeof value.expiresAt !== "number" || !Number.isFinite(value.expiresAt))
|
|
87
|
+
return;
|
|
88
|
+
return {
|
|
89
|
+
source: {
|
|
90
|
+
id: "id" in value.source && typeof value.source.id === "string" ? value.source.id : undefined,
|
|
91
|
+
pid: value.source.pid,
|
|
92
|
+
url: value.source.url
|
|
93
|
+
},
|
|
94
|
+
handoff: value.handoff,
|
|
95
|
+
expiresAt: value.expiresAt
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function same(left, right) {
|
|
99
|
+
return left.id === right.id && left.pid === right.pid && left.url === right.url;
|
|
100
|
+
}
|
|
101
|
+
function isHandoff(value) {
|
|
102
|
+
return typeof value === "object" && value !== null && "directory" in value && typeof value.directory === "string" && "instanceID" in value && typeof value.instanceID === "string" && "ticket" in value && typeof value.ticket === "string" && "expiresAt" in value && typeof value.expiresAt === "number" && Number.isFinite(value.expiresAt);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export { prepare2, environment2, complete2, clear2, exports_pty_handoff };
|
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/promise/generated/client-error.ts
|
|
2
|
+
class ClientError3 extends Error {
|
|
3
|
+
reason;
|
|
4
|
+
name = "ClientError";
|
|
5
|
+
constructor(reason, options) {
|
|
6
|
+
const detail = options?.detail ?? (options?.cause instanceof Error ? options.cause.message : undefined);
|
|
7
|
+
super(detail ? `${reason}: ${detail}` : reason, options);
|
|
8
|
+
this.reason = reason;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { ClientError3 };
|