paseo-plugin-zcode-provider 0.0.0-stage → 0.2.0
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/LICENSE +21 -0
- package/NOTICE.md +29 -0
- package/README.md +112 -2
- package/client/account.tsx +827 -0
- package/client/diagnostics.tsx +379 -0
- package/client/runtime.tsx +296 -0
- package/client/settings.tsx +84 -0
- package/client/value.tsx +20 -0
- package/icon.svg +1 -0
- package/index.client.tsx +22 -0
- package/index.server.ts +39 -0
- package/package.json +77 -4
- package/paseo-plugin.json +6 -0
- package/server/account.ts +781 -0
- package/server/attachments.ts +150 -0
- package/server/build-info.ts +2 -0
- package/server/conversation.ts +319 -0
- package/server/diagnostics.ts +252 -0
- package/server/discovery/discover.ts +225 -0
- package/server/discovery/manifest.ts +36 -0
- package/server/discovery/types.ts +30 -0
- package/server/errors.ts +36 -0
- package/server/host/bridge.ts +490 -0
- package/server/host/schemas.ts +119 -0
- package/server/logger.ts +19 -0
- package/server/mapping.ts +270 -0
- package/server/models.ts +68 -0
- package/server/persistence.ts +146 -0
- package/server/presentation.ts +470 -0
- package/server/provider-status.ts +81 -0
- package/server/provider.ts +838 -0
- package/server/runtime/managed.ts +501 -0
- package/server/runtime/pins.ts +72 -0
- package/server/runtime-setup.ts +77 -0
- package/server/session-types.ts +49 -0
- package/server/session.ts +866 -0
- package/server/status.ts +89 -0
- package/server/timeline.ts +18 -0
- package/server/usage.ts +362 -0
- package/server/vendor/zcode/LICENSE +202 -0
- package/server/vendor/zcode/NOTICE.md +70 -0
- package/server/vendor/zcode/THIRD-PARTY-NOTICES.md +37 -0
- package/server/vendor/zcode/packages/model-option-map/src/compiler.ts +92 -0
- package/server/vendor/zcode/packages/model-option-map/src/evaluator.ts +214 -0
- package/server/vendor/zcode/packages/model-option-map/src/index.ts +5 -0
- package/server/vendor/zcode/packages/model-option-map/src/merge-patch.ts +97 -0
- package/server/vendor/zcode/packages/model-option-map/src/option-maps.ts +42 -0
- package/server/vendor/zcode/packages/model-option-map/src/parser.ts +240 -0
- package/server/vendor/zcode/packages/model-option-map/src/tokenizer.ts +141 -0
- package/server/vendor/zcode/packages/model-option-map/src/types.ts +36 -0
- package/server/vendor/zcode/packages/rpc/src/buffer.ts +88 -0
- package/server/vendor/zcode/packages/rpc/src/channelClient.ts +275 -0
- package/server/vendor/zcode/packages/rpc/src/channelServer.ts +283 -0
- package/server/vendor/zcode/packages/rpc/src/channels.shared.ts +66 -0
- package/server/vendor/zcode/packages/rpc/src/channels.ts +4 -0
- package/server/vendor/zcode/packages/rpc/src/delayedChannel.ts +17 -0
- package/server/vendor/zcode/packages/rpc/src/foundation.ts +260 -0
- package/server/vendor/zcode/packages/rpc/src/protocol.ts +397 -0
- package/server/vendor/zcode/packages/rpc/src/proxy-channel.ts +213 -0
- package/server/vendor/zcode/packages/rpc/src/serialization.ts +291 -0
- package/server/vendor/zcode/packages/shared/src/account-provider-state.ts +13 -0
- package/server/vendor/zcode/packages/shared/src/background-bash-output.ts +24 -0
- package/server/vendor/zcode/packages/shared/src/background-task-controls.ts +404 -0
- package/server/vendor/zcode/packages/shared/src/bash-output-display.ts +11 -0
- package/server/vendor/zcode/packages/shared/src/bots.ts +558 -0
- package/server/vendor/zcode/packages/shared/src/browser-use/backend.ts +80 -0
- package/server/vendor/zcode/packages/shared/src/browser-use/command-metadata.ts +170 -0
- package/server/vendor/zcode/packages/shared/src/browser-use/commands.ts +588 -0
- package/server/vendor/zcode/packages/shared/src/browser-use/result.ts +130 -0
- package/server/vendor/zcode/packages/shared/src/browser-use/snapshot.ts +77 -0
- package/server/vendor/zcode/packages/shared/src/command-types.ts +96 -0
- package/server/vendor/zcode/packages/shared/src/config-schema.ts +8 -0
- package/server/vendor/zcode/packages/shared/src/cuaAccessibilitySettings.ts +41 -0
- package/server/vendor/zcode/packages/shared/src/database-startup.ts +178 -0
- package/server/vendor/zcode/packages/shared/src/env.ts +63 -0
- package/server/vendor/zcode/packages/shared/src/execution-output-preview.ts +14 -0
- package/server/vendor/zcode/packages/shared/src/localTtft.ts +192 -0
- package/server/vendor/zcode/packages/shared/src/model-config.ts +123 -0
- package/server/vendor/zcode/packages/shared/src/model-execution.ts +23 -0
- package/server/vendor/zcode/packages/shared/src/model-provider-family.ts +171 -0
- package/server/vendor/zcode/packages/shared/src/model-provider-types.ts +81 -0
- package/server/vendor/zcode/packages/shared/src/model-selection.ts +60 -0
- package/server/vendor/zcode/packages/shared/src/oauth.ts +203 -0
- package/server/vendor/zcode/packages/shared/src/official-mcp-auth.ts +272 -0
- package/server/vendor/zcode/packages/shared/src/official-mcp-tool-error.ts +68 -0
- package/server/vendor/zcode/packages/shared/src/process-diagnostic.ts +42 -0
- package/server/vendor/zcode/packages/shared/src/protocol.ts +369 -0
- package/server/vendor/zcode/packages/shared/src/provider-family-connection-selection.ts +32 -0
- package/server/vendor/zcode/packages/shared/src/remoteAssetInstallMode.ts +11 -0
- package/server/vendor/zcode/packages/shared/src/remoteResourcePackages.ts +91 -0
- package/server/vendor/zcode/packages/shared/src/runtimeEnv.ts +315 -0
- package/server/vendor/zcode/packages/shared/src/settings-source.ts +10 -0
- package/server/vendor/zcode/packages/shared/src/usage-quota.ts +74 -0
- package/server/vendor/zcode/packages/shared/src/usage-stats.ts +462 -0
- package/server/vendor/zcode/packages/shared/src/validationAppSettings.ts +562 -0
- package/server/vendor/zcode/packages/shared/src/workspacePurpose.ts +2 -0
- package/server/vendor/zcode/packages/shared/src/wslUserValidation.ts +33 -0
- package/server/vendor/zcode/packages/shared/src/zcode-agent-policy.ts +25 -0
- package/server/vendor/zcode/packages/shared/src/zcode-media-policy.ts +10 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol/index.ts +3720 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-legacy-types.ts +529 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/apply.ts +218 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/attachment-ref.ts +14 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/command.ts +482 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/core.ts +100 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/create-workflow-display.ts +156 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/cuaPermission.ts +41 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/delta.ts +147 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/input-intent.ts +69 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/rows.ts +432 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/session-config.ts +43 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/sessions-index-workflow-activity.ts +195 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/sessions-index.ts +85 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/shared-context-import.ts +38 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/shared-context-ref.ts +10 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/snapshot.ts +509 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/submission.ts +5 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/toolDisplay.ts +264 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/transport.ts +1152 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/wire-assembler.ts +574 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/wire-binary.ts +65 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/wire-codec.ts +240 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/wire-fault.ts +39 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/wire.ts +159 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workflow-artifacts.ts +291 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workflow-observation-display.ts +281 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workflow-row-meta.ts +163 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workflow-run-settings-command.ts +62 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workflow-runs-delta.ts +517 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workflow-runs.ts +512 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workspace-config.ts +81 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workspace-hook-review.ts +210 -0
- package/server/vendor/zcode/packages/shared/src/zcode-task-mode-schema.ts +6 -0
- package/server/vendor/zcode/packages/shared/src/zcode-task-types-core.ts +1187 -0
- package/server/vendor/zcode/packages/shared/src/zcodeEndpoint.ts +296 -0
- package/server/vendor/zcode/provenance.json +405 -0
- package/shared/account.ts +201 -0
- package/shared/diagnostics.ts +52 -0
- package/shared/runtime-setup.ts +73 -0
- package/vendor/acp-registry/LICENSE +176 -0
- package/vendor/paseo/LICENSE +211 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { valid } from "semver";
|
|
3
|
+
import { PROVIDER_VERSION as providerVersion } from "./build-info.js";
|
|
4
|
+
import { AdapterError, type ZCodeErrorCode } from "./errors.js";
|
|
5
|
+
import type { DiscoveredRuntime } from "./discovery/types.js";
|
|
6
|
+
|
|
7
|
+
const stages = [
|
|
8
|
+
"discovery",
|
|
9
|
+
"version",
|
|
10
|
+
"host-inspection",
|
|
11
|
+
"smoke",
|
|
12
|
+
"host-start",
|
|
13
|
+
"request",
|
|
14
|
+
"response",
|
|
15
|
+
"notification",
|
|
16
|
+
"transport",
|
|
17
|
+
"session",
|
|
18
|
+
] as const;
|
|
19
|
+
const checks = [
|
|
20
|
+
"bundle-metadata",
|
|
21
|
+
"minimum-version",
|
|
22
|
+
"host-entry",
|
|
23
|
+
"host-imports",
|
|
24
|
+
"host-path",
|
|
25
|
+
"rpc-module-load",
|
|
26
|
+
"rpc-missing",
|
|
27
|
+
"rpc-ambiguous",
|
|
28
|
+
"host-inspection-result",
|
|
29
|
+
"cli-smoke",
|
|
30
|
+
"native-envelope",
|
|
31
|
+
"native-result",
|
|
32
|
+
"native-event",
|
|
33
|
+
"native-error",
|
|
34
|
+
"native-exit",
|
|
35
|
+
"request-timeout",
|
|
36
|
+
"request-write",
|
|
37
|
+
] as const;
|
|
38
|
+
const operations = new Set([
|
|
39
|
+
"initialize",
|
|
40
|
+
"readWorkspacePresentation",
|
|
41
|
+
"readModelSelection",
|
|
42
|
+
"createSession",
|
|
43
|
+
"resumeSession",
|
|
44
|
+
"listSessions",
|
|
45
|
+
"readSession",
|
|
46
|
+
"closeSession",
|
|
47
|
+
"disposeWorkspace",
|
|
48
|
+
"cancelGeneration",
|
|
49
|
+
"respondStructuredInput",
|
|
50
|
+
"respondPermission",
|
|
51
|
+
"getEntitlementSnapshot",
|
|
52
|
+
"getCodingPlanResetStatus",
|
|
53
|
+
"helloConversationV4",
|
|
54
|
+
"initializeConversationV4",
|
|
55
|
+
"syncAppRuntimePreferences",
|
|
56
|
+
"sendConversationCommandV4",
|
|
57
|
+
"subscribeConversationV4",
|
|
58
|
+
"unsubscribeConversationV4",
|
|
59
|
+
"resyncConversationV4",
|
|
60
|
+
"conversationRowsRangeV4",
|
|
61
|
+
"attachmentBeginV4",
|
|
62
|
+
"attachmentChunkV4",
|
|
63
|
+
"attachmentCommitV4",
|
|
64
|
+
"attachmentAbortV4",
|
|
65
|
+
"oauth.restoreCachedSessionState",
|
|
66
|
+
"oauth.getActiveProvider",
|
|
67
|
+
"oauth.startOAuthWithPolling",
|
|
68
|
+
"oauth.pollPendingOAuth",
|
|
69
|
+
"oauth.cancelPending",
|
|
70
|
+
"oauth.logout",
|
|
71
|
+
"setting.get",
|
|
72
|
+
"setting.update",
|
|
73
|
+
"provider-settings.getView",
|
|
74
|
+
"provider-settings.refresh",
|
|
75
|
+
"provider-settings.createPersonalProvider",
|
|
76
|
+
"provider-settings.savePersonalProviderOverlay",
|
|
77
|
+
"provider-settings.deletePersonalProvider",
|
|
78
|
+
"provider-settings.addPersonalModel",
|
|
79
|
+
"provider-settings.deletePersonalModel",
|
|
80
|
+
"provider-settings.setPersonalModelEnabled",
|
|
81
|
+
"usage-stats.getEntitlementSnapshot",
|
|
82
|
+
"event",
|
|
83
|
+
"catalog",
|
|
84
|
+
"session.create",
|
|
85
|
+
"session.resume",
|
|
86
|
+
"session.list",
|
|
87
|
+
"session.prompt",
|
|
88
|
+
"session.configure",
|
|
89
|
+
"session.close",
|
|
90
|
+
"session.cancel",
|
|
91
|
+
"session.permission.respond",
|
|
92
|
+
"session.open",
|
|
93
|
+
"session.interrupt",
|
|
94
|
+
"session.permission",
|
|
95
|
+
]);
|
|
96
|
+
// Paths from record/map keys can contain user data. Only fixed schema field names are reportable.
|
|
97
|
+
const schemaFields = new Set([
|
|
98
|
+
"id",
|
|
99
|
+
"type",
|
|
100
|
+
"method",
|
|
101
|
+
"params",
|
|
102
|
+
"result",
|
|
103
|
+
"error",
|
|
104
|
+
"code",
|
|
105
|
+
"message",
|
|
106
|
+
"subscriptionId",
|
|
107
|
+
"event",
|
|
108
|
+
"sessionId",
|
|
109
|
+
"turnId",
|
|
110
|
+
"seq",
|
|
111
|
+
"payload",
|
|
112
|
+
"kind",
|
|
113
|
+
"delta",
|
|
114
|
+
"status",
|
|
115
|
+
"models",
|
|
116
|
+
"settings",
|
|
117
|
+
"mode",
|
|
118
|
+
"current",
|
|
119
|
+
"thoughtLevel",
|
|
120
|
+
"model",
|
|
121
|
+
"provider",
|
|
122
|
+
"providers",
|
|
123
|
+
"options",
|
|
124
|
+
"request",
|
|
125
|
+
"workspacePath",
|
|
126
|
+
"sessions",
|
|
127
|
+
"items",
|
|
128
|
+
"usage",
|
|
129
|
+
"data",
|
|
130
|
+
"name",
|
|
131
|
+
"role",
|
|
132
|
+
"content",
|
|
133
|
+
"requestId",
|
|
134
|
+
"toolCallId",
|
|
135
|
+
]);
|
|
136
|
+
|
|
137
|
+
export interface RuntimeDiagnostic {
|
|
138
|
+
readonly appVersion?: string;
|
|
139
|
+
readonly cliVersion?: string;
|
|
140
|
+
readonly platform?: string;
|
|
141
|
+
readonly stage?: (typeof stages)[number];
|
|
142
|
+
readonly operation?: string;
|
|
143
|
+
readonly check?: (typeof checks)[number];
|
|
144
|
+
readonly serverSha256?: string;
|
|
145
|
+
readonly cliSha256?: string;
|
|
146
|
+
readonly nativeCode?: number;
|
|
147
|
+
readonly exitCode?: number;
|
|
148
|
+
readonly validation?: readonly { path: string; code: string }[];
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function runtimeDiagnostic(
|
|
152
|
+
runtime: DiscoveredRuntime,
|
|
153
|
+
): RuntimeDiagnostic {
|
|
154
|
+
return {
|
|
155
|
+
appVersion: runtime.identity.appVersion,
|
|
156
|
+
cliVersion: runtime.identity.cliVersion,
|
|
157
|
+
platform: runtime.identity.platform,
|
|
158
|
+
serverSha256: runtime.identity.serverSha256,
|
|
159
|
+
cliSha256: runtime.identity.cliSha256,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function diagnosticError(
|
|
164
|
+
error: unknown,
|
|
165
|
+
context: RuntimeDiagnostic,
|
|
166
|
+
defaultCode: ZCodeErrorCode = "NATIVE_PROTOCOL_ERROR",
|
|
167
|
+
): AdapterError {
|
|
168
|
+
const diagnostic = {
|
|
169
|
+
...context,
|
|
170
|
+
...(error instanceof AdapterError ? error.diagnostic : {}),
|
|
171
|
+
};
|
|
172
|
+
const cause = error instanceof AdapterError ? error.cause : error;
|
|
173
|
+
if (cause instanceof z.ZodError) {
|
|
174
|
+
diagnostic.validation = cause.issues.slice(0, 10).map((issue) => ({
|
|
175
|
+
path: issue.path
|
|
176
|
+
.map((part) =>
|
|
177
|
+
typeof part === "number"
|
|
178
|
+
? "[]"
|
|
179
|
+
: schemaFields.has(String(part))
|
|
180
|
+
? String(part)
|
|
181
|
+
: "*",
|
|
182
|
+
)
|
|
183
|
+
.join("."),
|
|
184
|
+
code: issue.code,
|
|
185
|
+
}));
|
|
186
|
+
}
|
|
187
|
+
return new AdapterError(
|
|
188
|
+
error instanceof AdapterError ? error.code : defaultCode,
|
|
189
|
+
error instanceof AdapterError ? error.message : "ZCode operation failed",
|
|
190
|
+
error instanceof AdapterError ? error.details : {},
|
|
191
|
+
{ cause: error },
|
|
192
|
+
diagnostic,
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export function formatDiagnostic(error: unknown): string {
|
|
197
|
+
const context = error instanceof AdapterError ? error.diagnostic : undefined;
|
|
198
|
+
const result: Record<string, unknown> = {
|
|
199
|
+
providerVersion,
|
|
200
|
+
code: error instanceof AdapterError ? error.code : "NATIVE_PROTOCOL_ERROR",
|
|
201
|
+
};
|
|
202
|
+
if (context) {
|
|
203
|
+
for (const key of ["appVersion", "cliVersion"] as const) {
|
|
204
|
+
const value = context[key];
|
|
205
|
+
if (value && valid(value)) result[key] = valid(value);
|
|
206
|
+
}
|
|
207
|
+
if (
|
|
208
|
+
context.platform &&
|
|
209
|
+
/^(darwin|linux|win32)-(arm64|x64|ia32)$/u.test(context.platform)
|
|
210
|
+
)
|
|
211
|
+
result.platform = context.platform;
|
|
212
|
+
if (context.stage && stages.includes(context.stage))
|
|
213
|
+
result.stage = context.stage;
|
|
214
|
+
if (context.check && checks.includes(context.check))
|
|
215
|
+
result.check = context.check;
|
|
216
|
+
if (context.operation && operations.has(context.operation))
|
|
217
|
+
result.operation = context.operation;
|
|
218
|
+
for (const key of ["serverSha256", "cliSha256"] as const) {
|
|
219
|
+
if (/^[a-f0-9]{64}$/u.test(context[key] ?? ""))
|
|
220
|
+
result[key] = context[key];
|
|
221
|
+
}
|
|
222
|
+
for (const key of ["nativeCode", "exitCode"] as const) {
|
|
223
|
+
if (Number.isSafeInteger(context[key])) result[key] = context[key];
|
|
224
|
+
}
|
|
225
|
+
if (context.validation)
|
|
226
|
+
result.validation = context.validation.slice(0, 10).map((issue) => ({
|
|
227
|
+
path: issue.path
|
|
228
|
+
.split(".")
|
|
229
|
+
.slice(0, 20)
|
|
230
|
+
.map((part) =>
|
|
231
|
+
schemaFields.has(part) || part === "[]" || part === "" ? part : "*",
|
|
232
|
+
)
|
|
233
|
+
.join("."),
|
|
234
|
+
code: [
|
|
235
|
+
"invalid_type",
|
|
236
|
+
"too_big",
|
|
237
|
+
"too_small",
|
|
238
|
+
"invalid_format",
|
|
239
|
+
"not_multiple_of",
|
|
240
|
+
"unrecognized_keys",
|
|
241
|
+
"invalid_union",
|
|
242
|
+
"invalid_key",
|
|
243
|
+
"invalid_element",
|
|
244
|
+
"invalid_value",
|
|
245
|
+
"custom",
|
|
246
|
+
].includes(issue.code)
|
|
247
|
+
? issue.code
|
|
248
|
+
: "custom",
|
|
249
|
+
}));
|
|
250
|
+
}
|
|
251
|
+
return JSON.stringify(result, null, 2);
|
|
252
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { access, constants, readFile, realpath, stat } from "node:fs/promises";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { isAbsolute, join } from "node:path";
|
|
5
|
+
import { gte, valid } from "semver";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { AdapterError } from "../errors.js";
|
|
8
|
+
import { resolveManagedRuntime } from "../runtime/managed.js";
|
|
9
|
+
import { assessCompatibility, MINIMUM_NODE_VERSION } from "./manifest.js";
|
|
10
|
+
import type { DiscoveredRuntime, RuntimeSmokeResult } from "./types.js";
|
|
11
|
+
|
|
12
|
+
export interface DiscoveryOptions {
|
|
13
|
+
readonly environment?: NodeJS.ProcessEnv;
|
|
14
|
+
readonly signal?: AbortSignal;
|
|
15
|
+
}
|
|
16
|
+
export function runtimeEnvironment(
|
|
17
|
+
environment: NodeJS.ProcessEnv,
|
|
18
|
+
): NodeJS.ProcessEnv {
|
|
19
|
+
const result = { ...environment };
|
|
20
|
+
delete result.ELECTRON_RUN_AS_NODE;
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
async function run(
|
|
24
|
+
executable: string,
|
|
25
|
+
args: string[],
|
|
26
|
+
environment: NodeJS.ProcessEnv,
|
|
27
|
+
signal?: AbortSignal,
|
|
28
|
+
): Promise<string> {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
execFile(
|
|
31
|
+
executable,
|
|
32
|
+
args,
|
|
33
|
+
{
|
|
34
|
+
env: environment,
|
|
35
|
+
signal,
|
|
36
|
+
timeout: 15_000,
|
|
37
|
+
maxBuffer: 64 * 1024,
|
|
38
|
+
windowsHide: true,
|
|
39
|
+
},
|
|
40
|
+
(error, stdout) => {
|
|
41
|
+
if (error)
|
|
42
|
+
reject(
|
|
43
|
+
new AdapterError(
|
|
44
|
+
"RUNTIME_SMOKE_FAILED",
|
|
45
|
+
"Configured ZCode executable failed its runtime check",
|
|
46
|
+
),
|
|
47
|
+
);
|
|
48
|
+
else resolve(stdout.trim());
|
|
49
|
+
},
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
// Both variables override the managed runtime (ADR 15); setting only one is a
|
|
54
|
+
// configuration error rather than a silent fallback.
|
|
55
|
+
async function configuredPaths(environment: NodeJS.ProcessEnv): Promise<{
|
|
56
|
+
installRoot: string;
|
|
57
|
+
executable: string;
|
|
58
|
+
source: DiscoveredRuntime["source"];
|
|
59
|
+
}> {
|
|
60
|
+
const names = ["PASEO_ZCODE_RUNTIME", "PASEO_ZCODE_NODE"] as const;
|
|
61
|
+
if (names.some((name) => environment[name])) {
|
|
62
|
+
for (const name of names)
|
|
63
|
+
if (!environment[name] || !isAbsolute(environment[name]!))
|
|
64
|
+
throw new AdapterError(
|
|
65
|
+
"RUNTIME_DISCOVERY_FAILED",
|
|
66
|
+
`${name} must be an absolute path; set both variables or neither`,
|
|
67
|
+
);
|
|
68
|
+
return {
|
|
69
|
+
installRoot: environment.PASEO_ZCODE_RUNTIME!,
|
|
70
|
+
executable: environment.PASEO_ZCODE_NODE!,
|
|
71
|
+
source: "environment",
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const managed = await resolveManagedRuntime(environment);
|
|
75
|
+
if (managed === undefined)
|
|
76
|
+
throw new AdapterError(
|
|
77
|
+
"RUNTIME_SETUP_REQUIRED",
|
|
78
|
+
"ZCode runtime is not set up. Install it in Settings → Plugins → zcode-provider → Settings → Runtime.",
|
|
79
|
+
);
|
|
80
|
+
return { ...managed, source: "managed" };
|
|
81
|
+
}
|
|
82
|
+
export async function discoverRuntime({
|
|
83
|
+
environment = process.env,
|
|
84
|
+
signal,
|
|
85
|
+
}: DiscoveryOptions = {}): Promise<DiscoveredRuntime> {
|
|
86
|
+
const configured = await configuredPaths(environment);
|
|
87
|
+
try {
|
|
88
|
+
const installRoot = await realpath(configured.installRoot);
|
|
89
|
+
const executable = await realpath(configured.executable);
|
|
90
|
+
if (
|
|
91
|
+
!(await stat(installRoot)).isDirectory() ||
|
|
92
|
+
!(await stat(executable)).isFile()
|
|
93
|
+
)
|
|
94
|
+
throw new Error("Invalid runtime path");
|
|
95
|
+
await access(executable, constants.X_OK);
|
|
96
|
+
const paths = {
|
|
97
|
+
installRoot,
|
|
98
|
+
executable,
|
|
99
|
+
serverEntry: join(installRoot, "server/remote/zcode-server.cjs"),
|
|
100
|
+
cliEntry: join(installRoot, "agent/zcode.cjs"),
|
|
101
|
+
appPackage: join(installRoot, "package.json"),
|
|
102
|
+
builtinProviderConfig: join(
|
|
103
|
+
installRoot,
|
|
104
|
+
"agent/provider/zcode-builtin.json",
|
|
105
|
+
),
|
|
106
|
+
};
|
|
107
|
+
for (const file of [
|
|
108
|
+
paths.serverEntry,
|
|
109
|
+
paths.cliEntry,
|
|
110
|
+
paths.appPackage,
|
|
111
|
+
paths.builtinProviderConfig,
|
|
112
|
+
])
|
|
113
|
+
if (!(await stat(file)).isFile()) throw new Error("Missing runtime file");
|
|
114
|
+
// Run Electron in Node mode only during identification, so a mistaken path
|
|
115
|
+
// cannot launch its desktop UI. It is rejected before any Server starts.
|
|
116
|
+
const node = z
|
|
117
|
+
.object({
|
|
118
|
+
node: z.string(),
|
|
119
|
+
electron: z.string().optional(),
|
|
120
|
+
platform: z.string(),
|
|
121
|
+
arch: z.string(),
|
|
122
|
+
})
|
|
123
|
+
.parse(
|
|
124
|
+
JSON.parse(
|
|
125
|
+
await run(
|
|
126
|
+
executable,
|
|
127
|
+
[
|
|
128
|
+
"-e",
|
|
129
|
+
"console.log(JSON.stringify({node:process.versions.node,electron:process.versions.electron,platform:process.platform,arch:process.arch}))",
|
|
130
|
+
],
|
|
131
|
+
{ ...environment, ELECTRON_RUN_AS_NODE: "1" },
|
|
132
|
+
signal,
|
|
133
|
+
),
|
|
134
|
+
),
|
|
135
|
+
);
|
|
136
|
+
if (
|
|
137
|
+
node.electron ||
|
|
138
|
+
!valid(node.node) ||
|
|
139
|
+
!gte(node.node, MINIMUM_NODE_VERSION)
|
|
140
|
+
)
|
|
141
|
+
throw new AdapterError(
|
|
142
|
+
"UNSUPPORTED_ZCODE",
|
|
143
|
+
`PASEO_ZCODE_NODE requires ordinary Node.js >=${MINIMUM_NODE_VERSION}; Electron is unsupported`,
|
|
144
|
+
);
|
|
145
|
+
const pkg = z
|
|
146
|
+
.object({ name: z.literal("zcode-runtime"), version: z.string() })
|
|
147
|
+
.parse(JSON.parse(await readFile(paths.appPackage, "utf8")));
|
|
148
|
+
const env = runtimeEnvironment(environment);
|
|
149
|
+
const [serverVersion, cliOutput, serverBytes, cliBytes] = await Promise.all(
|
|
150
|
+
[
|
|
151
|
+
run(executable, [paths.serverEntry, "--version"], env, signal),
|
|
152
|
+
run(executable, [paths.cliEntry, "--version"], env, signal),
|
|
153
|
+
readFile(paths.serverEntry),
|
|
154
|
+
readFile(paths.cliEntry),
|
|
155
|
+
],
|
|
156
|
+
);
|
|
157
|
+
if (serverVersion !== pkg.version)
|
|
158
|
+
throw new AdapterError(
|
|
159
|
+
"UNSUPPORTED_ZCODE",
|
|
160
|
+
"ZCode runtime package and Server versions differ",
|
|
161
|
+
);
|
|
162
|
+
const cliVersion = cliOutput.match(
|
|
163
|
+
/^(?:zcode\s+)?v?(\d+\.\d+\.\d+(?:-[\w.-]+)?)$/i,
|
|
164
|
+
)?.[1];
|
|
165
|
+
if (!cliVersion)
|
|
166
|
+
throw new AdapterError(
|
|
167
|
+
"UNSUPPORTED_ZCODE",
|
|
168
|
+
"ZCode Agent returned an invalid version",
|
|
169
|
+
);
|
|
170
|
+
const identity = {
|
|
171
|
+
platform: `${node.platform}-${node.arch}`,
|
|
172
|
+
appVersion: serverVersion,
|
|
173
|
+
cliVersion,
|
|
174
|
+
nodeVersion: node.node,
|
|
175
|
+
cliSha256: createHash("sha256").update(cliBytes).digest("hex"),
|
|
176
|
+
serverSha256: createHash("sha256").update(serverBytes).digest("hex"),
|
|
177
|
+
};
|
|
178
|
+
const compatibility = assessCompatibility(identity);
|
|
179
|
+
return {
|
|
180
|
+
source: configured.source,
|
|
181
|
+
paths,
|
|
182
|
+
identity,
|
|
183
|
+
compatibility: compatibility.status,
|
|
184
|
+
compatibilityReason: compatibility.reason,
|
|
185
|
+
writableInstallRoot: await access(installRoot, constants.W_OK).then(
|
|
186
|
+
() => true,
|
|
187
|
+
() => false,
|
|
188
|
+
),
|
|
189
|
+
};
|
|
190
|
+
} catch (error) {
|
|
191
|
+
if (error instanceof AdapterError || signal?.aborted) throw error;
|
|
192
|
+
throw new AdapterError(
|
|
193
|
+
"RUNTIME_DISCOVERY_FAILED",
|
|
194
|
+
"Configured ZCode runtime is missing required files or has invalid metadata",
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
export function assertRuntimeSupported(runtime: DiscoveredRuntime): void {
|
|
199
|
+
if (runtime.compatibility !== "supported")
|
|
200
|
+
throw new AdapterError("UNSUPPORTED_ZCODE", runtime.compatibilityReason);
|
|
201
|
+
}
|
|
202
|
+
export async function runRuntimeSmoke(
|
|
203
|
+
runtime: DiscoveredRuntime,
|
|
204
|
+
environment: NodeJS.ProcessEnv = process.env,
|
|
205
|
+
signal?: AbortSignal,
|
|
206
|
+
): Promise<RuntimeSmokeResult> {
|
|
207
|
+
// Discovery checks both executable versions. Protocol and V4 are checked by
|
|
208
|
+
// the real Server connection, without inspecting an embedded bundle export.
|
|
209
|
+
try {
|
|
210
|
+
assertRuntimeSupported(runtime);
|
|
211
|
+
const version = await run(
|
|
212
|
+
runtime.paths.executable,
|
|
213
|
+
[runtime.paths.serverEntry, "--version"],
|
|
214
|
+
runtimeEnvironment(environment),
|
|
215
|
+
signal,
|
|
216
|
+
);
|
|
217
|
+
return {
|
|
218
|
+
passed: version === runtime.identity.appVersion,
|
|
219
|
+
cliVersion: runtime.identity.cliVersion,
|
|
220
|
+
};
|
|
221
|
+
} catch (error) {
|
|
222
|
+
if (signal?.aborted) throw error;
|
|
223
|
+
return { passed: false, error: "ZCode runtime check failed" };
|
|
224
|
+
}
|
|
225
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { gte, parse } from "semver";
|
|
2
|
+
import type { RuntimeIdentity } from "./types.js";
|
|
3
|
+
|
|
4
|
+
export const ZCODE_SOURCE_COMMIT = "29628c9acdb81b703bbd4080c207a0e7ce5e276e";
|
|
5
|
+
export const MINIMUM_ZCODE_VERSION = { app: "3.14.0", cli: "0.16.9" } as const;
|
|
6
|
+
export const MINIMUM_NODE_VERSION = "24.14.0";
|
|
7
|
+
|
|
8
|
+
export function assessCompatibility(identity: RuntimeIdentity): {
|
|
9
|
+
status: "supported" | "unsupported";
|
|
10
|
+
reason: string;
|
|
11
|
+
} {
|
|
12
|
+
for (const [component, version, minimum] of [
|
|
13
|
+
["app", identity.appVersion, MINIMUM_ZCODE_VERSION.app],
|
|
14
|
+
["CLI", identity.cliVersion, MINIMUM_ZCODE_VERSION.cli],
|
|
15
|
+
] as const) {
|
|
16
|
+
const parsed = version === undefined ? null : parse(version);
|
|
17
|
+
if (
|
|
18
|
+
parsed === null ||
|
|
19
|
+
parsed.prerelease.length !== 0 ||
|
|
20
|
+
!gte(parsed, minimum)
|
|
21
|
+
) {
|
|
22
|
+
return {
|
|
23
|
+
status: "unsupported",
|
|
24
|
+
reason: `ZCode ${component} requires a stable version >=${minimum}`,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
status: "supported",
|
|
30
|
+
reason:
|
|
31
|
+
"ZCode Server and Agent meet the minimum stable versions; runtime compatibility is checked during use",
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Last reviewed public changelog release; source versions are not releases.
|
|
36
|
+
export const LAST_REVIEWED_ZCODE_RELEASE = "3.14.4";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface RuntimePaths {
|
|
2
|
+
readonly installRoot: string;
|
|
3
|
+
readonly executable: string;
|
|
4
|
+
readonly cliEntry: string;
|
|
5
|
+
readonly serverEntry: string;
|
|
6
|
+
readonly appPackage: string;
|
|
7
|
+
readonly builtinProviderConfig: string;
|
|
8
|
+
}
|
|
9
|
+
export interface RuntimeIdentity {
|
|
10
|
+
readonly platform: string;
|
|
11
|
+
readonly appVersion: string;
|
|
12
|
+
readonly cliVersion: string;
|
|
13
|
+
readonly nodeVersion: string;
|
|
14
|
+
readonly cliSha256: string;
|
|
15
|
+
readonly serverSha256: string;
|
|
16
|
+
}
|
|
17
|
+
export interface DiscoveredRuntime {
|
|
18
|
+
/** "managed" is the pinned plugin-installed runtime; "environment" is an override. */
|
|
19
|
+
readonly source: "managed" | "environment";
|
|
20
|
+
readonly paths: RuntimePaths;
|
|
21
|
+
readonly identity: RuntimeIdentity;
|
|
22
|
+
readonly compatibility: "supported" | "unsupported";
|
|
23
|
+
readonly compatibilityReason: string;
|
|
24
|
+
readonly writableInstallRoot: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface RuntimeSmokeResult {
|
|
27
|
+
readonly passed: boolean;
|
|
28
|
+
readonly cliVersion?: string;
|
|
29
|
+
readonly error?: string;
|
|
30
|
+
}
|
package/server/errors.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type ZCodeErrorCode =
|
|
2
|
+
| "PERSISTENCE_INVALID"
|
|
3
|
+
| "PERSISTENCE_WRITE_FAILED"
|
|
4
|
+
| "PERSISTENCE_VERSION_UNSUPPORTED"
|
|
5
|
+
| "INVALID_CONFIGURATION"
|
|
6
|
+
| "INVALID_WORKSPACE"
|
|
7
|
+
| "UNSUPPORTED_PLATFORM"
|
|
8
|
+
| "UNSUPPORTED_ZCODE"
|
|
9
|
+
| "RUNTIME_DISCOVERY_FAILED"
|
|
10
|
+
| "RUNTIME_SMOKE_FAILED"
|
|
11
|
+
| "RUNTIME_SETUP_REQUIRED"
|
|
12
|
+
| "RUNTIME_SETUP_FAILED"
|
|
13
|
+
| "NATIVE_PROTOCOL_ERROR"
|
|
14
|
+
| "NATIVE_INPUT_REJECTED"
|
|
15
|
+
| "NATIVE_TIMEOUT"
|
|
16
|
+
| "NATIVE_EXITED"
|
|
17
|
+
| "AUTH_REQUIRED"
|
|
18
|
+
| "UNSUPPORTED_CONTENT"
|
|
19
|
+
| "SESSION_NOT_FOUND"
|
|
20
|
+
| "SESSION_BUSY"
|
|
21
|
+
| "INTERACTION_UNSUPPORTED";
|
|
22
|
+
|
|
23
|
+
export class AdapterError extends Error {
|
|
24
|
+
override readonly name = "ZCodeProviderError";
|
|
25
|
+
|
|
26
|
+
constructor(
|
|
27
|
+
readonly code: ZCodeErrorCode,
|
|
28
|
+
message: string,
|
|
29
|
+
readonly details: Record<string, unknown> = {},
|
|
30
|
+
options?: ErrorOptions,
|
|
31
|
+
readonly diagnostic?: RuntimeDiagnostic,
|
|
32
|
+
) {
|
|
33
|
+
super(message, options);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
import type { RuntimeDiagnostic } from "./diagnostics.js";
|