@deksden-com/dd-flow-cli 0.9.0-beta.133 → 0.9.0-beta.135
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 +27 -0
- package/README.md +31 -0
- package/dist/build-info.json +7 -7
- 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/dd-zcode.mjs +21 -1
- 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-children.d.mts +1 -0
- package/dist/harness-runtime/lib/native-children.mjs +16 -0
- 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/controller-fanout.js +20 -3
- package/dist/services/engines.js +22 -24
- package/dist/services/eval-snapshots.js +1 -1
- package/dist/services/external-work-launch.js +1 -1
- package/dist/services/hooks.js +17 -11
- package/dist/services/lifecycle-invocations.js +66 -12
- package/dist/services/merge-server.js +1 -1
- package/dist/services/run-controller-recovery.js +2 -2
- package/dist/services/run-controller.js +2 -2
- package/dist/services/vnext-fanout.js +6 -1
- package/dist/services/work-registry.js +54 -11
- package/dist/storage/database.js +4 -0
- package/package.json +4 -1
|
@@ -117,7 +117,7 @@ export async function terminateCommandTree(child, { platform = process.platform,
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
/** Preserve the native hook protocol across the CLI process boundary. */
|
|
120
|
-
export async function runBoundedCommand({ bin, args, input = null, cwd, env = {}, timeoutMs = 15_000, timeoutCode = "native_hook_timeout", inheritDeadline = true, cleanupWithinBudget = false, maintenanceProgress = null, signal }) {
|
|
120
|
+
export async function runBoundedCommand({ bin, args, nodeBin = process.execPath, input = null, cwd, env = {}, timeoutMs = 15_000, timeoutCode = "native_hook_timeout", inheritDeadline = true, cleanupWithinBudget = false, maintenanceProgress = null, signal }) {
|
|
121
121
|
if (signal?.aborted) throw Object.assign(new Error("Bounded CLI request cancelled before launch"), { code: "process_maintenance_cancelled", details: { effect: "no_effect" } });
|
|
122
122
|
const inherited = inheritDeadline ? env.DD_FLOW_HOOK_DEADLINE_AT ?? process.env.DD_FLOW_HOOK_DEADLINE_AT : undefined;
|
|
123
123
|
if (inherited !== undefined) {
|
|
@@ -137,7 +137,7 @@ export async function runBoundedCommand({ bin, args, input = null, cwd, env = {}
|
|
|
137
137
|
const deadlineAt = Math.floor(Date.now() + Math.max(0, commandMs - Math.min(250, commandMs / 10)));
|
|
138
138
|
const script = /\.[cm]?js$/.test(bin);
|
|
139
139
|
const output = await new Promise((resolve, reject) => {
|
|
140
|
-
const child = spawn(script ?
|
|
140
|
+
const child = spawn(script ? nodeBin : bin, [...(script ? [bin] : []), ...args], {
|
|
141
141
|
cwd, env: { ...process.env, ...env, DD_FLOW_HOOK_DEADLINE_AT: String(deadlineAt) }, detached: process.platform !== "win32", stdio: ["pipe", "pipe", "pipe"]
|
|
142
142
|
});
|
|
143
143
|
let stdout = "", stderr = "", failure, cleanupTimer, settled = false, termination;
|
|
@@ -241,8 +241,8 @@ function hookDiagnostics(stderr) {
|
|
|
241
241
|
}).slice(-16);
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
-
export async function invokeNativeHook({ bin, args, payload, home, cwd, env, timeoutMs = 15_000 }) {
|
|
245
|
-
const output = await runBoundedCommand({ bin, args, input: `${JSON.stringify(payload)}\n`, cwd, env: { ...env, DD_FLOW_HOME: home }, timeoutMs });
|
|
244
|
+
export async function invokeNativeHook({ bin, args, nodeBin, payload, home, cwd, env, timeoutMs = 15_000 }) {
|
|
245
|
+
const output = await runBoundedCommand({ bin, args, nodeBin, input: `${JSON.stringify(payload)}\n`, cwd, env: { ...env, DD_FLOW_HOME: home }, timeoutMs });
|
|
246
246
|
let result;
|
|
247
247
|
try { result = JSON.parse(output); } catch { throw Object.assign(new Error("Invalid native hook JSON response"), { code: "native_hook_response_invalid" }); }
|
|
248
248
|
if (result?.ok === false && typeof result.error?.code === "string") throw Object.assign(new Error(result.error.message ?? "Native hook failed"), { code: result.error.code, details: result.error.details });
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import * as Plugin from "../vendor/opencode-plugin.mjs";
|
|
3
|
+
import { hookBudget, invokeNativeHook } from "./native-hook-command.mjs";
|
|
4
|
+
|
|
5
|
+
/** Launch-bound server plugin; never uses a process-global 'last Session'. */
|
|
6
|
+
export function makeOpenCodePlugin(binding, invoke = invokeNativeHook) {
|
|
7
|
+
return Plugin.define({ id: binding.ddFlowBin ? "dd-flow" : "dd-flow-security", async setup(ctx) {
|
|
8
|
+
const participating = new Map();
|
|
9
|
+
const key = event => JSON.stringify([binding.daemonId, event.sessionID, event.messageID, event.id]);
|
|
10
|
+
const envelope = async (phase, event, budget, outcome) => {
|
|
11
|
+
const info = await budget.run(() => ctx.session.get({ sessionID: event.sessionID }), "identity");
|
|
12
|
+
if (!info?.id || info.id !== event.sessionID || !info.location?.directory) throw new Error("OpenCode Session identity is unavailable");
|
|
13
|
+
const input = event.input;
|
|
14
|
+
if (!input || typeof input !== "object" || typeof input.command !== "string") throw new Error("OpenCode shell input is unavailable");
|
|
15
|
+
const cwd = path.resolve(info.location.directory, input.workdir ?? ".");
|
|
16
|
+
return { schema_id: "dd-flow/opencode-tool-event@1", native_protocol: 2,
|
|
17
|
+
event_id: [binding.daemonId, event.sessionID, event.messageID, event.id].join(":"), phase,
|
|
18
|
+
daemon_id: binding.daemonId, server_version: binding.version, plugin_sha256: process.env.DD_OPENCODE_PLUGIN_SHA256,
|
|
19
|
+
session: { provider_session_id: info.id, parent_provider_session_id: info.parentID ?? null,
|
|
20
|
+
agent_id: event.agent, directory: cwd, project_id: info.projectID },
|
|
21
|
+
message_id: event.messageID, tool_call_id: event.id, tool: "shell", native_tool: event.tool,
|
|
22
|
+
profile: { provider: info.model?.providerID, model: info.model?.id, variant: info.model?.variant ?? "default", agent: event.agent },
|
|
23
|
+
input: { ...input, workdir: cwd }, ...(outcome ? { outcome } : {}) };
|
|
24
|
+
};
|
|
25
|
+
const deliver = (payload, budget) => invoke({ bin: binding.ddFlowBin, nodeBin: binding.nodeBin,
|
|
26
|
+
args: ["opencode", "event", "handle", "--project-root", binding.projectRoot, "--json"],
|
|
27
|
+
payload, home: binding.ddFlowHome, timeoutMs: budget.remaining("admission", 15000) });
|
|
28
|
+
await ctx.shell.hook("create.before", event => {
|
|
29
|
+
delete event.env.OPENCODE_PASSWORD; delete event.env.OPENCODE_SERVER_PASSWORD;
|
|
30
|
+
});
|
|
31
|
+
await ctx.tool.hook("execute.before", async event => {
|
|
32
|
+
if (event.tool !== "shell" || !binding.ddFlowBin) return;
|
|
33
|
+
const budget = hookBudget(), payload = await envelope("before", event, budget);
|
|
34
|
+
event.input = { ...event.input, workdir: payload.session.directory };
|
|
35
|
+
const result = await deliver({ ...payload, input: event.input }, budget);
|
|
36
|
+
if (result?.permissionDecision === "deny" || result?.hookSpecificOutput?.permissionDecision === "deny") throw new Error("dd-flow denied native shell admission");
|
|
37
|
+
if (result?.observed) {
|
|
38
|
+
participating.set(key(event), payload);
|
|
39
|
+
await ctx.storage.set(key(event), JSON.parse(JSON.stringify(payload)));
|
|
40
|
+
// The common observer, not OpenCode's fixed 120-second cutoff, owns
|
|
41
|
+
// flow CLI inactivity. No lifecycle process is detached here.
|
|
42
|
+
event.input = { ...event.input, ...(result.hookSpecificOutput?.updatedInput ?? {}), timeout: 0, background: false };
|
|
43
|
+
} else if (event.input.timeout === undefined) event.input.timeout = 0;
|
|
44
|
+
});
|
|
45
|
+
await ctx.tool.hook("execute.after", async event => {
|
|
46
|
+
if (event.tool !== "shell") return;
|
|
47
|
+
const budget = hookBudget(), original = participating.get(key(event)) ?? await ctx.storage.get(key(event));
|
|
48
|
+
if (!original) return; // Ordinary shell tools do not create lifecycle receipts.
|
|
49
|
+
const output = event.result?.output;
|
|
50
|
+
const success = event.status === "completed" && output?.status !== "running" && output?.exit === 0 && !output?.timeout && !output?.signal;
|
|
51
|
+
const outcome = { status: success ? "completed" : output?.status === "running" ? "running" : "failed",
|
|
52
|
+
exit_code: output?.exit ?? null, signal: output?.signal ?? null, shell_id: output?.shellID ?? null };
|
|
53
|
+
const payload = await envelope("after", event, budget, outcome);
|
|
54
|
+
await deliver({ ...payload, ...(original ? { event_id: original.event_id } : {}) }, budget);
|
|
55
|
+
participating.delete(key(event));
|
|
56
|
+
await ctx.storage.remove(key(event));
|
|
57
|
+
});
|
|
58
|
+
return () => participating.clear();
|
|
59
|
+
} });
|
|
60
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isRpcError2,
|
|
3
|
+
isRpcInternalError2
|
|
4
|
+
} from "./service-probe-vt9jbch8.js";
|
|
5
|
+
|
|
6
|
+
// src/promise/rpc.ts
|
|
7
|
+
function makeRpc2(raw, events) {
|
|
8
|
+
return (definition) => {
|
|
9
|
+
const subscribe = (name, options) => {
|
|
10
|
+
if (!Object.hasOwn(definition.events, name))
|
|
11
|
+
throw new Error(`Unknown RPC event: ${definition.id}.${name}`);
|
|
12
|
+
const type = eventType(definition, name);
|
|
13
|
+
return {
|
|
14
|
+
[Symbol.asyncIterator]() {
|
|
15
|
+
const controller = new AbortController;
|
|
16
|
+
const signal = options?.signal ? AbortSignal.any([controller.signal, options.signal]) : controller.signal;
|
|
17
|
+
const iterator = async function* () {
|
|
18
|
+
try {
|
|
19
|
+
for await (const published of events.subscribe({ signal })) {
|
|
20
|
+
if (signal.aborted)
|
|
21
|
+
return;
|
|
22
|
+
if (published.type !== type)
|
|
23
|
+
continue;
|
|
24
|
+
yield published;
|
|
25
|
+
}
|
|
26
|
+
} catch (error) {
|
|
27
|
+
if (!signal.aborted)
|
|
28
|
+
throw error;
|
|
29
|
+
} finally {
|
|
30
|
+
controller.abort();
|
|
31
|
+
}
|
|
32
|
+
}();
|
|
33
|
+
return {
|
|
34
|
+
next: () => iterator.next(),
|
|
35
|
+
return: () => {
|
|
36
|
+
controller.abort();
|
|
37
|
+
return iterator.return();
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
return Object.assign(Object.fromEntries(Object.keys(definition.methods).map((name) => [
|
|
44
|
+
name,
|
|
45
|
+
async (input, options) => {
|
|
46
|
+
try {
|
|
47
|
+
const result = await raw.rpc.call({
|
|
48
|
+
rpcID: definition.id,
|
|
49
|
+
method: name,
|
|
50
|
+
input,
|
|
51
|
+
location: options?.location
|
|
52
|
+
}, { signal: options?.signal, headers: options?.headers });
|
|
53
|
+
return result.output;
|
|
54
|
+
} catch (error) {
|
|
55
|
+
if (!isRpcError2(error) && !isRpcInternalError2(error))
|
|
56
|
+
throw error;
|
|
57
|
+
throw error.data === undefined ? { type: error.type, message: error.message } : { type: error.type, message: error.message, data: error.data };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
])), {
|
|
61
|
+
events: {
|
|
62
|
+
subscribe,
|
|
63
|
+
on: (name, handler, options) => {
|
|
64
|
+
const controller = new AbortController;
|
|
65
|
+
const signal = options?.signal ? AbortSignal.any([controller.signal, options.signal]) : controller.signal;
|
|
66
|
+
const source = subscribe(name, { signal });
|
|
67
|
+
(async () => {
|
|
68
|
+
for await (const event of source)
|
|
69
|
+
await handler(event);
|
|
70
|
+
})().catch((error) => console.error(error));
|
|
71
|
+
return () => controller.abort();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function eventType(definition, name) {
|
|
78
|
+
return `rpc.${definition.id}.${name}`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export { makeRpc2 };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defaultEnsureTiming2
|
|
3
|
+
} from "./service-probe-xgnj2w4v.js";
|
|
4
|
+
import {
|
|
5
|
+
matchesVersion2
|
|
6
|
+
} from "./service-probe-sxt88q69.js";
|
|
7
|
+
|
|
8
|
+
// src/service-probe.ts
|
|
9
|
+
import { homedir } from "node:os";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
function decide2(service, options) {
|
|
12
|
+
if (!matchesVersion2(service.version, options))
|
|
13
|
+
return { _tag: "replace", pty: service.state === "ready" ? "handoff" : "clear" };
|
|
14
|
+
if (!service.compatible)
|
|
15
|
+
return fail("Background service uses an incompatible health protocol. Update this client or explicitly restart the service.");
|
|
16
|
+
if (service.state === "ready")
|
|
17
|
+
return { _tag: "reuse" };
|
|
18
|
+
if (service.state === "failed")
|
|
19
|
+
return fail("Background service failed to start");
|
|
20
|
+
return { _tag: "wait" };
|
|
21
|
+
}
|
|
22
|
+
function fail(message) {
|
|
23
|
+
return { _tag: "fail", error: new Error(message) };
|
|
24
|
+
}
|
|
25
|
+
function fallback2() {
|
|
26
|
+
return join(process.env["XDG_STATE_HOME"] ?? join(homedir(), ".local", "state"), "opencode", "service.json");
|
|
27
|
+
}
|
|
28
|
+
function same2(left, right) {
|
|
29
|
+
return left.id === right.id && left.version === right.version && left.url === right.url && left.pid === right.pid;
|
|
30
|
+
}
|
|
31
|
+
async function probeResult2(info, timeout = defaultEnsureTiming2.requestTimeout) {
|
|
32
|
+
const endpoint = {
|
|
33
|
+
url: info.url,
|
|
34
|
+
auth: info.password === undefined ? undefined : { type: "basic", username: "opencode", password: info.password }
|
|
35
|
+
};
|
|
36
|
+
const signal = AbortSignal.timeout(timeout);
|
|
37
|
+
const result = await fetch(new URL("/api/info", info.url), { headers: headers2(endpoint), signal }).then(async (response) => ({
|
|
38
|
+
response,
|
|
39
|
+
body: response.status === 404 ? undefined : await response.json()
|
|
40
|
+
})).catch(() => {
|
|
41
|
+
return;
|
|
42
|
+
});
|
|
43
|
+
if (result === undefined)
|
|
44
|
+
return { service: undefined, timedOut: signal.aborted };
|
|
45
|
+
const response = result.response;
|
|
46
|
+
if (response.status === 404)
|
|
47
|
+
return {
|
|
48
|
+
service: {
|
|
49
|
+
info,
|
|
50
|
+
endpoint,
|
|
51
|
+
version: info.version,
|
|
52
|
+
state: "ready",
|
|
53
|
+
compatible: false
|
|
54
|
+
},
|
|
55
|
+
timedOut: false
|
|
56
|
+
};
|
|
57
|
+
const serverInfo = decodeInfo(result.body);
|
|
58
|
+
if (serverInfo === undefined)
|
|
59
|
+
return { service: undefined, timedOut: false };
|
|
60
|
+
if (serverInfo.pid !== info.pid)
|
|
61
|
+
return { service: undefined, timedOut: false };
|
|
62
|
+
if (info.version !== undefined && serverInfo.version !== info.version)
|
|
63
|
+
return { service: undefined, timedOut: false };
|
|
64
|
+
return {
|
|
65
|
+
service: {
|
|
66
|
+
info,
|
|
67
|
+
endpoint,
|
|
68
|
+
version: serverInfo.version,
|
|
69
|
+
state: response.ok ? "ready" : response.status === 500 ? "failed" : "waiting",
|
|
70
|
+
compatible: true
|
|
71
|
+
},
|
|
72
|
+
timedOut: false
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function headers2(endpoint) {
|
|
76
|
+
if (endpoint.auth === undefined)
|
|
77
|
+
return;
|
|
78
|
+
return {
|
|
79
|
+
authorization: "Basic " + Buffer.from(endpoint.auth.username + ":" + endpoint.auth.password).toString("base64")
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function decodeInfo(input) {
|
|
83
|
+
if (typeof input !== "object" || input === null)
|
|
84
|
+
return;
|
|
85
|
+
if (!("version" in input) || typeof input.version !== "string")
|
|
86
|
+
return;
|
|
87
|
+
if (!("pid" in input) || typeof input.pid !== "number" || !Number.isInteger(input.pid) || input.pid < 0)
|
|
88
|
+
return;
|
|
89
|
+
return { version: input.version, pid: input.pid };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export { decide2, fallback2, same2, probeResult2, headers2 };
|
|
File without changes
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {
|
|
2
|
+
make7
|
|
3
|
+
} from "./service-probe-frbwqjmf.js";
|
|
4
|
+
import {
|
|
5
|
+
ClientError2
|
|
6
|
+
} from "./service-probe-y2etg5bs.js";
|
|
7
|
+
import {
|
|
8
|
+
make3
|
|
9
|
+
} from "./service-probe-q4g3afnw.js";
|
|
10
|
+
import {
|
|
11
|
+
make4,
|
|
12
|
+
aborted2
|
|
13
|
+
} from "./service-probe-z6qdwcsf.js";
|
|
14
|
+
import {
|
|
15
|
+
__export
|
|
16
|
+
} from "./service-probe-9rqn6x4v.js";
|
|
17
|
+
|
|
18
|
+
// src/effect/client.ts
|
|
19
|
+
var exports_client = {};
|
|
20
|
+
__export(exports_client, {
|
|
21
|
+
OpenCode: () => exports_client,
|
|
22
|
+
make: () => make2
|
|
23
|
+
});
|
|
24
|
+
import { Cause, Context, Effect, Stream } from "effect";
|
|
25
|
+
import { HttpClient, HttpClientRequest } from "effect/http";
|
|
26
|
+
var CurrentHeaders = Context.Reference("@opencode/client/effect/rpc/headers", {
|
|
27
|
+
defaultValue: () => {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
var make2 = Effect.fn("OpenCode.make")(function* (options) {
|
|
32
|
+
const httpClient = yield* HttpClient.HttpClient;
|
|
33
|
+
const raw = yield* make3(options).pipe(Effect.provideService(HttpClient.HttpClient, HttpClient.mapRequestEffect(httpClient, (request) => Effect.map(CurrentHeaders, (headers) => headers ? HttpClientRequest.setHeaders(request, new Headers(headers)) : request))));
|
|
34
|
+
const context = yield* Effect.context();
|
|
35
|
+
const native = raw.event.subscribe();
|
|
36
|
+
|
|
37
|
+
class EventFailure {
|
|
38
|
+
cause;
|
|
39
|
+
constructor(cause) {
|
|
40
|
+
this.cause = cause;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const shared = make7((signal) => Stream.toAsyncIterableWith(native.pipe(Stream.interruptWhen(aborted2(signal)), Stream.catchCause((cause) => Stream.fail(new EventFailure(cause)))), context));
|
|
44
|
+
const subscribe = () => Stream.fromAsyncIterable(shared.subscribe(), (error) => error).pipe(Stream.catch((error) => Stream.failCause(error instanceof EventFailure ? error.cause : Cause.fail(new ClientError2({ cause: error })))));
|
|
45
|
+
return {
|
|
46
|
+
...raw,
|
|
47
|
+
event: { ...raw.event, subscribe },
|
|
48
|
+
rpc: Object.assign(make4((input, options) => raw.rpc.call(input).pipe(Effect.provideService(CurrentHeaders, options?.headers)), subscribe), raw.rpc)
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export { make2, exports_client };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __returnValue = (v) => v;
|
|
3
|
+
function __exportSetter(name, newValue) {
|
|
4
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
5
|
+
}
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
set: __exportSetter.bind(all, name)
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { __export };
|