@koed-labs/server 0.10.3 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/package.json +1 -1
- package/vendor/{chunk-A6WMU2GG.js → chunk-2XKSVKQA.js} +5 -4
- package/vendor/{chunk-VPC5NLZG.js → chunk-4OO6VAU3.js} +1 -1
- package/vendor/{chunk-HK2H3MVE.js → chunk-53ZFCDHP.js} +4 -0
- package/vendor/chunk-6KS67EQE.js +75 -0
- package/vendor/chunk-7EGSY3E4.js +8 -0
- package/vendor/{chunk-JKOG52PE.js → chunk-7FSHVVTZ.js} +1 -1
- package/vendor/chunk-ALJUSOF7.js +175 -0
- package/vendor/{chunk-KUIWH33N.js → chunk-AVQCUFYQ.js} +1 -1
- package/vendor/chunk-BGENSONI.js +18 -0
- package/vendor/{chunk-ZXX4ZNJY.js → chunk-BUIM2M4R.js} +3 -2
- package/vendor/{chunk-YK4F4VY2.js → chunk-C4V72GXC.js} +51 -30
- package/vendor/{chunk-JJNLH5GA.js → chunk-C5SNDPAP.js} +21 -19
- package/vendor/{chunk-J2L726BC.js → chunk-CHMH4LH5.js} +3 -3
- package/vendor/{chunk-2S3OGPUC.js → chunk-EA4QDDQA.js} +2 -2
- package/vendor/{chunk-HZJK5RWC.js → chunk-EDPNYIX5.js} +575 -215
- package/vendor/{chunk-NM5NXCVM.js → chunk-FN3HUUO2.js} +558 -988
- package/vendor/{chunk-473OA62O.js → chunk-FSNLU46W.js} +218 -12497
- package/vendor/{chunk-GELDEJJ2.js → chunk-FYYRFX4U.js} +133 -47
- package/vendor/{chunk-YOFI4PCH.js → chunk-GFASBPV2.js} +7 -1
- package/vendor/chunk-HC76426R.js +48 -0
- package/vendor/{chunk-QIIKMG3M.js → chunk-IY2HRXOZ.js} +1 -5
- package/vendor/{chunk-ZUGNCQZE.js → chunk-JYK6UL6D.js} +22 -8
- package/vendor/{chunk-2BWTLF7A.js → chunk-LRP66XEY.js} +45 -21
- package/vendor/{chunk-DXTAWHY3.js → chunk-NOU7RHYZ.js} +8 -7
- package/vendor/{chunk-C3N4N5HR.js → chunk-NVTMIAAF.js} +26 -21
- package/vendor/chunk-O7DW2VAV.js +14 -0
- package/vendor/{chunk-YJ6XUZT6.js → chunk-OCILJ737.js} +23 -16
- package/vendor/{chunk-TSRPHKAC.js → chunk-PL3LWC5C.js} +16 -42
- package/vendor/chunk-QRKHHWJJ.js +104 -0
- package/vendor/{chunk-YJWREXN6.js → chunk-RCR4XPE3.js} +1 -1
- package/vendor/{chunk-AFLKCQHF.js → chunk-SHLRINKO.js} +2 -2
- package/vendor/{chunk-NEWIOOM6.js → chunk-SNKWETM5.js} +3 -2
- package/vendor/{chunk-XNFVSVBS.js → chunk-SRKIBFOE.js} +1 -1
- package/vendor/{chunk-G4IIVVJO.js → chunk-T6UB5PNX.js} +70 -2
- package/vendor/{chunk-RVYJKKWA.js → chunk-TG26CZGQ.js} +5 -4
- package/vendor/{chunk-HFM6ROJL.js → chunk-TISYUUEJ.js} +1 -1
- package/vendor/{chunk-K2EIFEQF.js → chunk-TSAYTRX3.js} +1 -1
- package/vendor/chunk-TVYEB2GN.js +343 -0
- package/vendor/{chunk-PT3AUPGE.js → chunk-UB6JCVQ3.js} +3 -1
- package/vendor/chunk-VGIYSDNU.js +522 -0
- package/vendor/{chunk-X6M525ZJ.js → chunk-W2OJZZ6X.js} +5 -5
- package/vendor/{chunk-YCDEMYY6.js → chunk-WDFERJG3.js} +231 -99
- package/vendor/{chunk-SKVYP7NY.js → chunk-WPIEF4LY.js} +8 -8
- package/vendor/{chunk-UI5RLBKQ.js → chunk-YZLQZU5E.js} +17 -1
- package/vendor/{chunk-PY5LYLV7.js → chunk-Z5WCAUA6.js} +26 -21
- package/vendor/chunk-ZIOKV2X6.js +1589 -0
- package/vendor/chunk-ZOHNXUDY.js +12501 -0
- package/vendor/chunk-ZUDSZGVO.js +11 -0
- package/vendor/component-manifest-catalog.js +2 -1
- package/vendor/control-plane.js +11 -6
- package/vendor/chunk-2DA7EFZV.js +0 -924
- /package/vendor/{chunk-A4NKL2PK.js → chunk-V67IQB7H.js} +0 -0
|
@@ -7,7 +7,34 @@ import {
|
|
|
7
7
|
} from "./chunk-QT24SAW6.js";
|
|
8
8
|
import {
|
|
9
9
|
applyPersistedLocalPorts
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-TISYUUEJ.js";
|
|
11
|
+
import {
|
|
12
|
+
resolveKoedServerConfig,
|
|
13
|
+
writeCodexGlobalMemoryGuidancePreference
|
|
14
|
+
} from "./chunk-ALJUSOF7.js";
|
|
15
|
+
import {
|
|
16
|
+
inspectDeviceIdentityStatus
|
|
17
|
+
} from "./chunk-SRKIBFOE.js";
|
|
18
|
+
import {
|
|
19
|
+
ensureKoedHome,
|
|
20
|
+
resolveKoedServerPaths
|
|
21
|
+
} from "./chunk-TSAYTRX3.js";
|
|
22
|
+
import {
|
|
23
|
+
canUseSourceCheckoutFallback,
|
|
24
|
+
resolvePackagedKoedRuntimeRoot
|
|
25
|
+
} from "./chunk-YZLQZU5E.js";
|
|
26
|
+
import {
|
|
27
|
+
loadRepoEnv,
|
|
28
|
+
resolveApiUrl
|
|
29
|
+
} from "./chunk-W2HNI6AA.js";
|
|
30
|
+
import {
|
|
31
|
+
assertKoedAppRuntimeAvailable,
|
|
32
|
+
resolveKoedAppRuntime,
|
|
33
|
+
resolveKoedAppRuntimeExecution,
|
|
34
|
+
resolveKoedAppRuntimeForExecution,
|
|
35
|
+
resolveKoedControlPlaneVersion,
|
|
36
|
+
resolveKoedRuntimeOwner
|
|
37
|
+
} from "./chunk-V67IQB7H.js";
|
|
11
38
|
import {
|
|
12
39
|
pinDesktopBundleGenerationForStart,
|
|
13
40
|
pinGenerationForStart,
|
|
@@ -15,45 +42,23 @@ import {
|
|
|
15
42
|
readCurrentGenerationForOwner,
|
|
16
43
|
readDesktopBundleGeneration,
|
|
17
44
|
resolveDesktopRuntimeOwner,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
writeCodexGlobalMemoryGuidancePreference
|
|
21
|
-
} from "./chunk-NM5NXCVM.js";
|
|
45
|
+
validateDesktopRuntimeCapability
|
|
46
|
+
} from "./chunk-FN3HUUO2.js";
|
|
22
47
|
import {
|
|
23
48
|
applyActiveRuntimeUrls,
|
|
24
49
|
isProcessRunning,
|
|
25
50
|
readActiveRuntimeState
|
|
26
|
-
} from "./chunk-
|
|
51
|
+
} from "./chunk-T6UB5PNX.js";
|
|
27
52
|
import {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
resolveKoedAppRuntimeExecution,
|
|
31
|
-
resolveKoedAppRuntimeForExecution,
|
|
32
|
-
resolveKoedControlPlaneVersion,
|
|
33
|
-
resolveKoedRuntimeOwner
|
|
34
|
-
} from "./chunk-A4NKL2PK.js";
|
|
53
|
+
require_proper_lockfile
|
|
54
|
+
} from "./chunk-7NXKPDF3.js";
|
|
35
55
|
import {
|
|
36
56
|
collectPrivacyModelStatus,
|
|
37
57
|
resolvePrivacyModelPaths
|
|
38
|
-
} from "./chunk-
|
|
58
|
+
} from "./chunk-4OO6VAU3.js";
|
|
39
59
|
import {
|
|
40
60
|
collectUpstreamRegistryStatus
|
|
41
|
-
} from "./chunk-
|
|
42
|
-
import {
|
|
43
|
-
inspectDeviceIdentityStatus
|
|
44
|
-
} from "./chunk-XNFVSVBS.js";
|
|
45
|
-
import {
|
|
46
|
-
ensureKoedHome,
|
|
47
|
-
resolveKoedServerPaths
|
|
48
|
-
} from "./chunk-K2EIFEQF.js";
|
|
49
|
-
import {
|
|
50
|
-
canUseSourceCheckoutFallback,
|
|
51
|
-
resolvePackagedKoedRuntimeRoot
|
|
52
|
-
} from "./chunk-UI5RLBKQ.js";
|
|
53
|
-
import {
|
|
54
|
-
loadRepoEnv,
|
|
55
|
-
resolveApiUrl
|
|
56
|
-
} from "./chunk-W2HNI6AA.js";
|
|
61
|
+
} from "./chunk-RCR4XPE3.js";
|
|
57
62
|
import {
|
|
58
63
|
DESKTOP_LOCAL_CREDENTIAL_OPERATION_FAMILIES,
|
|
59
64
|
LOCAL_PERSONAL_USER_EMAIL,
|
|
@@ -67,17 +72,177 @@ import {
|
|
|
67
72
|
readDesktopLocalCredentialAuthorization,
|
|
68
73
|
resolveTeamCollaborationEnabled,
|
|
69
74
|
storeDesktopLocalCredential,
|
|
75
|
+
summarizeHistoricalIngestionState,
|
|
70
76
|
upgradeDesktopLocalCredential
|
|
71
|
-
} from "./chunk-
|
|
77
|
+
} from "./chunk-ZOHNXUDY.js";
|
|
78
|
+
import {
|
|
79
|
+
__toESM
|
|
80
|
+
} from "./chunk-BTS4ZTF3.js";
|
|
72
81
|
|
|
73
82
|
// packages/koed-server/dist/status.js
|
|
74
|
-
import { existsSync as
|
|
83
|
+
import { existsSync as existsSync11, readFileSync as readFileSync6 } from "node:fs";
|
|
75
84
|
import { homedir as homedir4 } from "node:os";
|
|
76
85
|
import { resolve as resolve12 } from "node:path";
|
|
77
86
|
import { spawnSync as nodeSpawnSync4 } from "node:child_process";
|
|
78
87
|
|
|
88
|
+
// packages/shared/src/ai-client-connections.ts
|
|
89
|
+
var import_proper_lockfile = __toESM(require_proper_lockfile(), 1);
|
|
90
|
+
import { randomUUID } from "node:crypto";
|
|
91
|
+
import {
|
|
92
|
+
existsSync,
|
|
93
|
+
mkdirSync,
|
|
94
|
+
readFileSync,
|
|
95
|
+
renameSync,
|
|
96
|
+
rmSync,
|
|
97
|
+
writeFileSync
|
|
98
|
+
} from "node:fs";
|
|
99
|
+
import path from "node:path";
|
|
100
|
+
var AI_CLIENT_CONNECTION_IDS = [
|
|
101
|
+
"codex",
|
|
102
|
+
"claude",
|
|
103
|
+
"pi"
|
|
104
|
+
];
|
|
105
|
+
var aiClientConnectionsPath = (koedHome) => path.join(koedHome, "state", "ai-client-connections.json");
|
|
106
|
+
var parseEntry = (value) => {
|
|
107
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
108
|
+
const entry = value;
|
|
109
|
+
return typeof entry.connected === "boolean" && Number.isSafeInteger(entry.revision) && entry.revision >= 0 && typeof entry.updatedAt === "string" ? {
|
|
110
|
+
connected: entry.connected,
|
|
111
|
+
revision: entry.revision,
|
|
112
|
+
updatedAt: entry.updatedAt
|
|
113
|
+
} : null;
|
|
114
|
+
};
|
|
115
|
+
var parse = (koedHome) => {
|
|
116
|
+
let text;
|
|
117
|
+
try {
|
|
118
|
+
text = readFileSync(aiClientConnectionsPath(koedHome), "utf8");
|
|
119
|
+
} catch (error) {
|
|
120
|
+
return error.code === "ENOENT" ? { kind: "missing" } : { kind: "invalid" };
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
const value = JSON.parse(text);
|
|
124
|
+
if (value.version !== 2 || typeof value.updatedAt !== "string" || !value.clients || typeof value.clients !== "object" || Array.isArray(value.clients))
|
|
125
|
+
return { kind: "invalid" };
|
|
126
|
+
const clients = {};
|
|
127
|
+
for (const id of AI_CLIENT_CONNECTION_IDS) {
|
|
128
|
+
const raw = value.clients[id];
|
|
129
|
+
if (raw === void 0) continue;
|
|
130
|
+
const entry = parseEntry(raw);
|
|
131
|
+
if (!entry) return { kind: "invalid" };
|
|
132
|
+
clients[id] = entry;
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
kind: "valid",
|
|
136
|
+
record: { version: 2, updatedAt: value.updatedAt, clients }
|
|
137
|
+
};
|
|
138
|
+
} catch {
|
|
139
|
+
return { kind: "invalid" };
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
var readAiClientConnections = (koedHome) => {
|
|
143
|
+
const parsed = parse(koedHome);
|
|
144
|
+
return parsed.kind === "valid" ? parsed.record : null;
|
|
145
|
+
};
|
|
146
|
+
var aiClientConnectionRevision = (koedHome, id) => {
|
|
147
|
+
const parsed = parse(koedHome);
|
|
148
|
+
if (parsed.kind === "invalid")
|
|
149
|
+
throw new Error(
|
|
150
|
+
"The AI Client connection record could not be read; connect the AI Client again after Koed Server repairs it."
|
|
151
|
+
);
|
|
152
|
+
return parsed.kind === "valid" ? parsed.record.clients[id]?.revision ?? 0 : 0;
|
|
153
|
+
};
|
|
154
|
+
var lockTimeoutMs = 5e3;
|
|
155
|
+
var withConnectionsLock = (koedHome, operation) => {
|
|
156
|
+
const target = aiClientConnectionsPath(koedHome);
|
|
157
|
+
mkdirSync(path.dirname(target), { recursive: true, mode: 448 });
|
|
158
|
+
const deadline = Date.now() + lockTimeoutMs;
|
|
159
|
+
let release;
|
|
160
|
+
while (true) {
|
|
161
|
+
try {
|
|
162
|
+
release = import_proper_lockfile.default.lockSync(target, { realpath: false, stale: 3e4 });
|
|
163
|
+
break;
|
|
164
|
+
} catch (error) {
|
|
165
|
+
if (error.code !== "ELOCKED" || Date.now() >= deadline)
|
|
166
|
+
throw error;
|
|
167
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
return operation();
|
|
172
|
+
} finally {
|
|
173
|
+
release();
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
var write = (koedHome, record) => {
|
|
177
|
+
const target = aiClientConnectionsPath(koedHome);
|
|
178
|
+
const temporary = `${target}.${process.pid}.${randomUUID()}.tmp`;
|
|
179
|
+
try {
|
|
180
|
+
writeFileSync(temporary, `${JSON.stringify(record)}
|
|
181
|
+
`, {
|
|
182
|
+
mode: 384,
|
|
183
|
+
flag: "wx"
|
|
184
|
+
});
|
|
185
|
+
renameSync(temporary, target);
|
|
186
|
+
} finally {
|
|
187
|
+
if (existsSync(temporary)) rmSync(temporary, { force: true });
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
var change = (koedHome, id, decide, now) => withConnectionsLock(koedHome, () => {
|
|
191
|
+
const parsed = parse(koedHome);
|
|
192
|
+
const record = parsed.kind === "valid" ? parsed.record : { version: 2, updatedAt: now.toISOString(), clients: {} };
|
|
193
|
+
const current = record.clients[id];
|
|
194
|
+
const connected = decide(current, parsed.kind !== "invalid");
|
|
195
|
+
if (connected === null) return false;
|
|
196
|
+
const updatedAt = now.toISOString();
|
|
197
|
+
write(koedHome, {
|
|
198
|
+
version: 2,
|
|
199
|
+
updatedAt,
|
|
200
|
+
clients: {
|
|
201
|
+
...record.clients,
|
|
202
|
+
[id]: {
|
|
203
|
+
connected,
|
|
204
|
+
revision: (current?.revision ?? 0) + 1,
|
|
205
|
+
updatedAt
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
return true;
|
|
210
|
+
});
|
|
211
|
+
var grantAiClientConnection = (koedHome, id, expectedRevision, now = /* @__PURE__ */ new Date()) => {
|
|
212
|
+
let granted = false;
|
|
213
|
+
change(
|
|
214
|
+
koedHome,
|
|
215
|
+
id,
|
|
216
|
+
(current, readable) => {
|
|
217
|
+
if (!readable)
|
|
218
|
+
throw new Error(
|
|
219
|
+
"The AI Client connection record could not be read; the AI Client was not connected."
|
|
220
|
+
);
|
|
221
|
+
if (current?.connected === true) {
|
|
222
|
+
granted = true;
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
if ((current?.revision ?? 0) !== expectedRevision) return null;
|
|
226
|
+
granted = true;
|
|
227
|
+
return true;
|
|
228
|
+
},
|
|
229
|
+
now
|
|
230
|
+
);
|
|
231
|
+
return granted;
|
|
232
|
+
};
|
|
233
|
+
var revokeAiClientConnection = (koedHome, id, options = {}) => change(
|
|
234
|
+
koedHome,
|
|
235
|
+
id,
|
|
236
|
+
(current) => {
|
|
237
|
+
if (options.ifRevision === void 0) return false;
|
|
238
|
+
if (current?.connected !== true) return null;
|
|
239
|
+
return (current.revision ?? 0) === options.ifRevision ? false : null;
|
|
240
|
+
},
|
|
241
|
+
options.now ?? /* @__PURE__ */ new Date()
|
|
242
|
+
);
|
|
243
|
+
|
|
79
244
|
// packages/koed-server/dist/service-runtime-selection.js
|
|
80
|
-
import { existsSync } from "node:fs";
|
|
245
|
+
import { existsSync as existsSync2 } from "node:fs";
|
|
81
246
|
var runtimeOwner = (paths, capability) => {
|
|
82
247
|
if (capability === void 0)
|
|
83
248
|
return resolveKoedRuntimeOwner();
|
|
@@ -86,7 +251,7 @@ var runtimeOwner = (paths, capability) => {
|
|
|
86
251
|
}
|
|
87
252
|
return resolveDesktopRuntimeOwner(capability, paths.koedHome);
|
|
88
253
|
};
|
|
89
|
-
async function resolveVerifiedPackagedRuntime(paths, environment, requirements, exists =
|
|
254
|
+
async function resolveVerifiedPackagedRuntime(paths, environment, requirements, exists = existsSync2, capability) {
|
|
90
255
|
let generation;
|
|
91
256
|
try {
|
|
92
257
|
if (capability) {
|
|
@@ -113,7 +278,7 @@ async function resolveVerifiedPackagedRuntime(paths, environment, requirements,
|
|
|
113
278
|
assertKoedAppRuntimeAvailable(runtime, paths);
|
|
114
279
|
return runtime;
|
|
115
280
|
}
|
|
116
|
-
async function pinAndResolvePackagedRuntime(paths, environment, requirements, exists =
|
|
281
|
+
async function pinAndResolvePackagedRuntime(paths, environment, requirements, exists = existsSync2, capability) {
|
|
117
282
|
let pin;
|
|
118
283
|
try {
|
|
119
284
|
pin = capability ? await pinDesktopBundleGenerationForStart(paths, capability) : await pinGenerationForStart(paths, runtimeOwner(paths));
|
|
@@ -202,7 +367,7 @@ var stripCodexOwnershipBlock = (content) => {
|
|
|
202
367
|
};
|
|
203
368
|
|
|
204
369
|
// packages/koed-server/dist/local-embedding-runtime.js
|
|
205
|
-
import { existsSync as
|
|
370
|
+
import { existsSync as existsSync3, statSync } from "node:fs";
|
|
206
371
|
import { spawn as nodeSpawn } from "node:child_process";
|
|
207
372
|
import { dirname, resolve } from "node:path";
|
|
208
373
|
var DOCKER_LLAMA_SERVER_BINARY = "/opt/llama.cpp/llama-server";
|
|
@@ -225,7 +390,7 @@ var nativeLlamaServerOverride = (environment) => {
|
|
|
225
390
|
}
|
|
226
391
|
return void 0;
|
|
227
392
|
};
|
|
228
|
-
var chooseRuntimePath = (candidates, defaultPath, defaultSource, exists =
|
|
393
|
+
var chooseRuntimePath = (candidates, defaultPath, defaultSource, exists = existsSync3) => {
|
|
229
394
|
for (const candidate of candidates) {
|
|
230
395
|
if (exists(candidate.path)) {
|
|
231
396
|
return candidate;
|
|
@@ -234,7 +399,7 @@ var chooseRuntimePath = (candidates, defaultPath, defaultSource, exists = exists
|
|
|
234
399
|
return { path: defaultPath, artifactSource: defaultSource };
|
|
235
400
|
};
|
|
236
401
|
var combinedArtifactSource = (sources) => sources.every((source) => source === sources[0]) ? sources[0] : "explicit-override";
|
|
237
|
-
var resolveLocalEmbeddingRuntimePaths = (paths, environment = process.env, exists =
|
|
402
|
+
var resolveLocalEmbeddingRuntimePaths = (paths, environment = process.env, exists = existsSync3, selectedRuntime) => {
|
|
238
403
|
const koedRuntimeAppDir = resolve(paths.koedHome, "runtime", "embedding-service");
|
|
239
404
|
const repoAppDir = resolve(paths.repoRoot, "apps", "embedding-service");
|
|
240
405
|
const appRuntime = selectedRuntime ?? resolveKoedAppRuntime(paths, environment, exists);
|
|
@@ -271,7 +436,7 @@ var resolveLocalEmbeddingRuntimePaths = (paths, environment = process.env, exist
|
|
|
271
436
|
const appDir = dirname(dirname(serviceEntry));
|
|
272
437
|
const host = trim(environment.KOED_EMBEDDING_HOST) ?? "127.0.0.1";
|
|
273
438
|
const port = trim(environment.KOED_EMBEDDING_PORT) ?? trim(environment.EMBEDDING_SERVICE_HOST_PORT) ?? "3800";
|
|
274
|
-
const koedRuntimeLlamaServer = resolve(paths.koedHome, "runtime", "llama.cpp", "llama-server");
|
|
439
|
+
const koedRuntimeLlamaServer = resolve(paths.nativeSelectionRoot ?? resolve(paths.koedHome, "runtime"), "llama.cpp", "llama-server");
|
|
275
440
|
const packagedLlamaServer = packagedRuntimeRoot ? resolve(packagedRuntimeRoot, "llama.cpp", "llama-server") : void 0;
|
|
276
441
|
const vendorLlamaServer = resolve(paths.repoRoot, "vendor", "llama.cpp", "llama-server");
|
|
277
442
|
const llamaOverride = nativeLlamaServerOverride(environment);
|
|
@@ -326,9 +491,9 @@ var missingRuntime = (runtime, missing) => ({
|
|
|
326
491
|
},
|
|
327
492
|
paths: runtime
|
|
328
493
|
});
|
|
329
|
-
var isExecutable = (
|
|
494
|
+
var isExecutable = (path2) => {
|
|
330
495
|
try {
|
|
331
|
-
return (statSync(
|
|
496
|
+
return (statSync(path2).mode & 73) !== 0;
|
|
332
497
|
} catch {
|
|
333
498
|
return true;
|
|
334
499
|
}
|
|
@@ -353,7 +518,7 @@ var localEmbeddingEnv = (runtime) => ({
|
|
|
353
518
|
EMBEDDING_LLAMA_SERVER_BINARY: runtime.llamaServerBin
|
|
354
519
|
});
|
|
355
520
|
var collectLocalEmbeddingRuntimeStatus = async (paths, environment = process.env, dependencies = {}) => {
|
|
356
|
-
const exists = dependencies.existsSync ??
|
|
521
|
+
const exists = dependencies.existsSync ?? existsSync3;
|
|
357
522
|
const fetcher = dependencies.fetch ?? globalThis.fetch.bind(globalThis);
|
|
358
523
|
const runtime = resolveLocalEmbeddingRuntimePaths(paths, environment, exists, dependencies.appRuntime);
|
|
359
524
|
const missing = runtimeMissing(runtime, exists);
|
|
@@ -405,7 +570,7 @@ var collectLocalEmbeddingRuntimeStatus = async (paths, environment = process.env
|
|
|
405
570
|
}
|
|
406
571
|
};
|
|
407
572
|
var startLocalEmbeddingRuntime = (paths, environment = process.env, dependencies = {}) => {
|
|
408
|
-
const exists = dependencies.existsSync ??
|
|
573
|
+
const exists = dependencies.existsSync ?? existsSync3;
|
|
409
574
|
const spawn = dependencies.spawn ?? nodeSpawn;
|
|
410
575
|
const runtime = resolveLocalEmbeddingRuntimePaths(paths, environment, exists, dependencies.appRuntime);
|
|
411
576
|
const env = {
|
|
@@ -419,6 +584,8 @@ var startLocalEmbeddingRuntime = (paths, environment = process.env, dependencies
|
|
|
419
584
|
}
|
|
420
585
|
const child = spawn(process.execPath, [runtime.serviceEntry], {
|
|
421
586
|
cwd: runtime.appDir,
|
|
587
|
+
// The release supervisor can stop its owned llama-server descendants together.
|
|
588
|
+
...paths.nativeSelectionRoot ? { detached: true } : {},
|
|
422
589
|
env,
|
|
423
590
|
stdio: "inherit"
|
|
424
591
|
});
|
|
@@ -445,12 +612,12 @@ var startLocalEmbeddingRuntime = (paths, environment = process.env, dependencies
|
|
|
445
612
|
};
|
|
446
613
|
|
|
447
614
|
// packages/koed-server/dist/local-privacy-runtime.js
|
|
448
|
-
import { existsSync as
|
|
615
|
+
import { existsSync as existsSync4 } from "node:fs";
|
|
449
616
|
import { spawn as nodeSpawn2 } from "node:child_process";
|
|
450
617
|
import { dirname as dirname2, resolve as resolve3 } from "node:path";
|
|
451
618
|
|
|
452
619
|
// packages/koed-server/dist/privacy-installation-record.js
|
|
453
|
-
import { closeSync, constants, fstatSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
620
|
+
import { closeSync, constants, fstatSync, mkdirSync as mkdirSync2, openSync, readFileSync as readFileSync2, renameSync as renameSync2, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
454
621
|
import { resolve as resolve2 } from "node:path";
|
|
455
622
|
|
|
456
623
|
// packages/koed-server/dist/privacy-inference.js
|
|
@@ -474,7 +641,7 @@ function readPrivacyInstallationRecord(paths, generationId, manifestDigest) {
|
|
|
474
641
|
const stat = fstatSync(descriptor);
|
|
475
642
|
if (!stat.isFile() || stat.size > 32768)
|
|
476
643
|
return null;
|
|
477
|
-
const value = JSON.parse(
|
|
644
|
+
const value = JSON.parse(readFileSync2(descriptor, "utf8"));
|
|
478
645
|
if (value.schemaVersion !== 1 || value.generationId !== generationId || value.manifestDigest !== manifestDigest || value.modelRevision !== PINNED_PRIVACY_MODEL_REVISION || typeof value.verifiedAt !== "string" || !Number.isFinite(Date.parse(value.verifiedAt)) || !value.compatibility || !isPrivacyInferenceVerification(value.verification))
|
|
479
646
|
return null;
|
|
480
647
|
return value;
|
|
@@ -514,13 +681,13 @@ var runtimePaths = (paths, environment, selectedRuntime) => {
|
|
|
514
681
|
};
|
|
515
682
|
};
|
|
516
683
|
var collectLocalPrivacyHealth = async (paths, environment = process.env, dependencies = {}, modelPath, includeDiagnostics = true) => {
|
|
517
|
-
const exists = dependencies.existsSync ??
|
|
684
|
+
const exists = dependencies.existsSync ?? existsSync4;
|
|
518
685
|
const env = localPrivacyEnv(paths, environment, dependencies.appRuntime);
|
|
519
686
|
const runtime = runtimePaths(paths, environment, dependencies.appRuntime);
|
|
520
687
|
const missing = [
|
|
521
688
|
...runtime.entry ? [runtime.entry] : ["authenticated privacy generation"],
|
|
522
689
|
runtime.bootstrap
|
|
523
|
-
].filter((
|
|
690
|
+
].filter((path2) => path2.startsWith("authenticated ") || !exists(path2));
|
|
524
691
|
if (missing.length > 0) {
|
|
525
692
|
return {
|
|
526
693
|
runtime: "native-privacy",
|
|
@@ -576,12 +743,12 @@ var collectLocalPrivacyHealth = async (paths, environment = process.env, depende
|
|
|
576
743
|
};
|
|
577
744
|
var collectLocalPrivacyRuntimeHealthStatus = async (paths, environment = process.env, dependencies = {}) => collectLocalPrivacyHealth(paths, environment, dependencies, void 0, false);
|
|
578
745
|
var collectLocalPrivacyRuntimeStatus = async (paths, environment = process.env, dependencies = {}) => {
|
|
579
|
-
const exists = dependencies.existsSync ??
|
|
746
|
+
const exists = dependencies.existsSync ?? existsSync4;
|
|
580
747
|
const runtime = runtimePaths(paths, environment, dependencies.appRuntime);
|
|
581
748
|
const missing = [
|
|
582
749
|
...runtime.entry ? [runtime.entry] : ["authenticated privacy generation"],
|
|
583
750
|
runtime.bootstrap
|
|
584
|
-
].filter((
|
|
751
|
+
].filter((path2) => path2.startsWith("authenticated ") || !exists(path2));
|
|
585
752
|
if (missing.length > 0) {
|
|
586
753
|
return {
|
|
587
754
|
runtime: "native-privacy",
|
|
@@ -609,7 +776,7 @@ var startLocalPrivacyRuntime = async (paths, environment = process.env, dependen
|
|
|
609
776
|
...localPrivacyEnv(paths, environment, dependencies.appRuntime)
|
|
610
777
|
};
|
|
611
778
|
const runtime = runtimePaths(paths, environment, dependencies.appRuntime);
|
|
612
|
-
const exists = dependencies.existsSync ??
|
|
779
|
+
const exists = dependencies.existsSync ?? existsSync4;
|
|
613
780
|
if (!runtime.entry || !exists(runtime.entry) || !exists(runtime.bootstrap)) {
|
|
614
781
|
const status = await collectLocalPrivacyRuntimeStatus(paths, env, {
|
|
615
782
|
existsSync: exists,
|
|
@@ -646,20 +813,25 @@ var startLocalPrivacyRuntime = async (paths, environment = process.env, dependen
|
|
|
646
813
|
};
|
|
647
814
|
|
|
648
815
|
// packages/koed-server/dist/local-postgres-runtime.js
|
|
649
|
-
import { existsSync as
|
|
816
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync3, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
650
817
|
import { dirname as dirname3, resolve as resolve4 } from "node:path";
|
|
651
818
|
import { spawnSync as nodeSpawnSync } from "node:child_process";
|
|
652
819
|
var trim3 = (value) => {
|
|
653
820
|
const trimmed = value?.trim();
|
|
654
821
|
return trimmed ? trimmed : void 0;
|
|
655
822
|
};
|
|
656
|
-
var
|
|
657
|
-
|
|
823
|
+
var hasCompletePostgresOverride = (environment) => Boolean(trim3(environment.KOED_POSTGRES_BIN_DIR) || [
|
|
824
|
+
environment.KOED_POSTGRES_INITDB_BIN,
|
|
825
|
+
environment.KOED_POSTGRES_PG_CTL_BIN,
|
|
826
|
+
environment.KOED_POSTGRES_PSQL_BIN
|
|
827
|
+
].every(trim3));
|
|
828
|
+
var hasAnyPostgresBinary = (binDir, exists = existsSync5) => ["initdb", "pg_ctl", "psql"].some((name) => exists(resolve4(binDir, name)));
|
|
829
|
+
var resolvePostgresBinDir = (paths, environment = process.env, exists = existsSync5) => {
|
|
658
830
|
const override = trim3(environment.KOED_POSTGRES_BIN_DIR);
|
|
659
831
|
if (override) {
|
|
660
832
|
return { binDir: resolve4(override), artifactSource: "explicit-override" };
|
|
661
833
|
}
|
|
662
|
-
const koedRuntimeDir = resolve4(paths.koedHome, "runtime", "postgres", "bin");
|
|
834
|
+
const koedRuntimeDir = resolve4(paths.nativeSelectionRoot ?? resolve4(paths.koedHome, "runtime"), "postgres", "bin");
|
|
663
835
|
if (hasAnyPostgresBinary(koedRuntimeDir, exists)) {
|
|
664
836
|
return { binDir: koedRuntimeDir, artifactSource: "koed-home-runtime" };
|
|
665
837
|
}
|
|
@@ -674,7 +846,7 @@ var resolvePostgresBinDir = (paths, environment = process.env, exists = existsSy
|
|
|
674
846
|
}
|
|
675
847
|
return { binDir: koedRuntimeDir, artifactSource: "koed-home-runtime" };
|
|
676
848
|
};
|
|
677
|
-
var resolveLocalPostgresRuntimePaths = (paths, environment = process.env, exists =
|
|
849
|
+
var resolveLocalPostgresRuntimePaths = (paths, environment = process.env, exists = existsSync5) => {
|
|
678
850
|
const { binDir, artifactSource } = resolvePostgresBinDir(paths, environment, exists);
|
|
679
851
|
const hasBinaryOverride = Boolean(trim3(environment.KOED_POSTGRES_INITDB_BIN) ?? trim3(environment.KOED_POSTGRES_PG_CTL_BIN) ?? trim3(environment.KOED_POSTGRES_PSQL_BIN));
|
|
680
852
|
const bin = (name, override) => resolve4(trim3(override) ?? resolve4(binDir, name));
|
|
@@ -767,7 +939,7 @@ var healthyStatus = (runtime, message) => ({
|
|
|
767
939
|
paths: safeRuntimePaths(runtime)
|
|
768
940
|
});
|
|
769
941
|
var collectLocalPostgresRuntimeStatus = (paths, environment = process.env, dependencies = {}) => {
|
|
770
|
-
const exists = dependencies.existsSync ??
|
|
942
|
+
const exists = dependencies.existsSync ?? existsSync5;
|
|
771
943
|
const spawnSync = dependencies.spawnSync ?? nodeSpawnSync;
|
|
772
944
|
const runtime = resolveLocalPostgresRuntimePaths(paths, environment, exists);
|
|
773
945
|
const missing = runtimeMissing2(runtime, exists);
|
|
@@ -796,7 +968,7 @@ var collectLocalPostgresRuntimeStatus = (paths, environment = process.env, depen
|
|
|
796
968
|
};
|
|
797
969
|
};
|
|
798
970
|
var stopLocalPostgresRuntime = (paths, environment = process.env, dependencies = {}) => {
|
|
799
|
-
const exists = dependencies.existsSync ??
|
|
971
|
+
const exists = dependencies.existsSync ?? existsSync5;
|
|
800
972
|
const spawnSync = dependencies.spawnSync ?? nodeSpawnSync;
|
|
801
973
|
const runtime = resolveLocalPostgresRuntimePaths(paths, environment, exists);
|
|
802
974
|
if (!exists(runtime.pgCtlBin)) {
|
|
@@ -838,7 +1010,7 @@ var stopLocalPostgresRuntime = (paths, environment = process.env, dependencies =
|
|
|
838
1010
|
};
|
|
839
1011
|
};
|
|
840
1012
|
var startLocalPostgresRuntime = (paths, environment = process.env, dependencies = {}) => {
|
|
841
|
-
const exists = dependencies.existsSync ??
|
|
1013
|
+
const exists = dependencies.existsSync ?? existsSync5;
|
|
842
1014
|
const spawnSync = dependencies.spawnSync ?? nodeSpawnSync;
|
|
843
1015
|
const runtime = resolveLocalPostgresRuntimePaths(paths, environment, exists);
|
|
844
1016
|
const env = {
|
|
@@ -860,12 +1032,12 @@ var startLocalPostgresRuntime = (paths, environment = process.env, dependencies
|
|
|
860
1032
|
if (versionStatus) {
|
|
861
1033
|
return { ok: false, started: false, status: versionStatus, env };
|
|
862
1034
|
}
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
1035
|
+
mkdirSync3(runtime.dataDir, { recursive: true, mode: 448 });
|
|
1036
|
+
mkdirSync3(runtime.runDir, { recursive: true, mode: 448 });
|
|
1037
|
+
mkdirSync3(dirname3(runtime.logPath), { recursive: true, mode: 448 });
|
|
866
1038
|
if (!exists(resolve4(runtime.dataDir, "PG_VERSION"))) {
|
|
867
1039
|
const pwfile = resolve4(runtime.runDir, "postgres.pw");
|
|
868
|
-
|
|
1040
|
+
writeFileSync3(pwfile, `${runtime.password}
|
|
869
1041
|
`, { mode: 384 });
|
|
870
1042
|
const init = run(runtime.initdbBin, [
|
|
871
1043
|
"-D",
|
|
@@ -876,7 +1048,7 @@ var startLocalPostgresRuntime = (paths, environment = process.env, dependencies
|
|
|
876
1048
|
"--pwfile",
|
|
877
1049
|
pwfile
|
|
878
1050
|
], env, spawnSync);
|
|
879
|
-
|
|
1051
|
+
rmSync3(pwfile, { force: true });
|
|
880
1052
|
if (init.status !== 0) {
|
|
881
1053
|
return {
|
|
882
1054
|
ok: false,
|
|
@@ -1017,24 +1189,24 @@ var startLocalPostgresRuntime = (paths, environment = process.env, dependencies
|
|
|
1017
1189
|
|
|
1018
1190
|
// packages/koed-server/dist/pi-setup.js
|
|
1019
1191
|
import { spawnSync as nodeSpawnSync2 } from "node:child_process";
|
|
1020
|
-
import { accessSync as accessSync2, constants as constants3, cpSync as cpSync2, existsSync as
|
|
1192
|
+
import { accessSync as accessSync2, constants as constants3, cpSync as cpSync2, existsSync as existsSync8, realpathSync, rmSync as rmSync5, statSync as statSync3 } from "node:fs";
|
|
1021
1193
|
import { dirname as dirname6, delimiter as delimiter2, isAbsolute as isAbsolute2, join as join2, resolve as resolve7 } from "node:path";
|
|
1022
1194
|
|
|
1023
1195
|
// packages/koed-server/dist/pi-package-transaction.mjs
|
|
1024
|
-
import { randomUUID } from "node:crypto";
|
|
1025
|
-
import { cpSync, existsSync as
|
|
1196
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
1197
|
+
import { cpSync, existsSync as existsSync6, mkdirSync as mkdirSync4, renameSync as renameSync3, rmSync as rmSync4 } from "node:fs";
|
|
1026
1198
|
import { dirname as dirname4, resolve as resolve5 } from "node:path";
|
|
1027
1199
|
var piPackageFileSystem = {
|
|
1028
1200
|
copy: (source, target) => cpSync(source, target, { recursive: true }),
|
|
1029
|
-
exists:
|
|
1030
|
-
mkdir: (target) =>
|
|
1031
|
-
rename:
|
|
1032
|
-
remove: (target) =>
|
|
1201
|
+
exists: existsSync6,
|
|
1202
|
+
mkdir: (target) => mkdirSync4(target, { recursive: true, mode: 448 }),
|
|
1203
|
+
rename: renameSync3,
|
|
1204
|
+
remove: (target) => rmSync4(target, { recursive: true, force: true })
|
|
1033
1205
|
};
|
|
1034
1206
|
var errorMessage = (error) => error instanceof Error ? error.message : String(error);
|
|
1035
1207
|
var installPiPackageTransaction = (input) => {
|
|
1036
1208
|
const fileSystem = input.fileSystem ?? piPackageFileSystem;
|
|
1037
|
-
const suffix = input.suffix ?? `${Date.now()}-${
|
|
1209
|
+
const suffix = input.suffix ?? `${Date.now()}-${randomUUID2()}`;
|
|
1038
1210
|
const staged = `${input.target}.stage-${suffix}`;
|
|
1039
1211
|
const backup = `${input.target}.backup-${suffix}`;
|
|
1040
1212
|
let previousMoved = false;
|
|
@@ -1122,8 +1294,8 @@ var installPiPackageTransaction = (input) => {
|
|
|
1122
1294
|
};
|
|
1123
1295
|
|
|
1124
1296
|
// packages/koed-server/dist/ai-client-registry.js
|
|
1125
|
-
import { accessSync, chmodSync, constants as constants2, existsSync as
|
|
1126
|
-
import { randomUUID as
|
|
1297
|
+
import { accessSync, chmodSync, constants as constants2, existsSync as existsSync7, lstatSync, mkdirSync as mkdirSync5, readFileSync as readFileSync3, renameSync as renameSync4, statSync as statSync2, unlinkSync, writeFileSync as writeFileSync4 } from "node:fs";
|
|
1298
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
1127
1299
|
import { homedir } from "node:os";
|
|
1128
1300
|
import { delimiter, dirname as dirname5, isAbsolute, join, resolve as resolve6 } from "node:path";
|
|
1129
1301
|
var platformExecutableSearchDirectories = (environment, platform = process.platform) => platform === "darwin" ? [
|
|
@@ -1153,7 +1325,7 @@ var resolveExecutablePath = (requestedPath, environment, dependencies = {}, addi
|
|
|
1153
1325
|
if (!requested)
|
|
1154
1326
|
throw new Error("AI Client executable path is empty.");
|
|
1155
1327
|
const fs = {
|
|
1156
|
-
existsSync:
|
|
1328
|
+
existsSync: existsSync7,
|
|
1157
1329
|
statSync: statSync2,
|
|
1158
1330
|
accessSync,
|
|
1159
1331
|
...dependencies
|
|
@@ -1195,7 +1367,7 @@ var captureAiClientRegistry = (environment) => {
|
|
|
1195
1367
|
}
|
|
1196
1368
|
return {
|
|
1197
1369
|
exists: true,
|
|
1198
|
-
content:
|
|
1370
|
+
content: readFileSync3(target, "utf8"),
|
|
1199
1371
|
mode: stats.mode & 511
|
|
1200
1372
|
};
|
|
1201
1373
|
} catch (error) {
|
|
@@ -1221,8 +1393,8 @@ var restoreAiClientRegistry = (environment, snapshot) => {
|
|
|
1221
1393
|
}
|
|
1222
1394
|
if (snapshot.content === null)
|
|
1223
1395
|
throw new Error("Registry snapshot is empty.");
|
|
1224
|
-
|
|
1225
|
-
|
|
1396
|
+
mkdirSync5(dirname5(target), { recursive: true, mode: 448 });
|
|
1397
|
+
writeFileSync4(target, snapshot.content, { mode: snapshot.mode ?? 384 });
|
|
1226
1398
|
chmodSync(target, snapshot.mode ?? 384);
|
|
1227
1399
|
};
|
|
1228
1400
|
var readRegistry = (target) => {
|
|
@@ -1238,7 +1410,7 @@ var readRegistry = (target) => {
|
|
|
1238
1410
|
}
|
|
1239
1411
|
let parsed;
|
|
1240
1412
|
try {
|
|
1241
|
-
parsed = JSON.parse(
|
|
1413
|
+
parsed = JSON.parse(readFileSync3(target, "utf8"));
|
|
1242
1414
|
} catch (error) {
|
|
1243
1415
|
throw new Error(`AI Client instance registry is malformed: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
1244
1416
|
}
|
|
@@ -1263,7 +1435,7 @@ var assertAiClientRegistryWritable = (environment) => {
|
|
|
1263
1435
|
readRegistry(registryPath(environment));
|
|
1264
1436
|
};
|
|
1265
1437
|
var writeRegistry = (target, root) => {
|
|
1266
|
-
|
|
1438
|
+
mkdirSync5(dirname5(target), { recursive: true, mode: 448 });
|
|
1267
1439
|
try {
|
|
1268
1440
|
if (lstatSync(target).isSymbolicLink()) {
|
|
1269
1441
|
throw new Error("AI Client instance registry must not be a symbolic link.");
|
|
@@ -1272,14 +1444,14 @@ var writeRegistry = (target, root) => {
|
|
|
1272
1444
|
if (error.code !== "ENOENT")
|
|
1273
1445
|
throw error;
|
|
1274
1446
|
}
|
|
1275
|
-
const temporary = `${target}.${process.pid}.${
|
|
1276
|
-
|
|
1447
|
+
const temporary = `${target}.${process.pid}.${randomUUID3()}.tmp`;
|
|
1448
|
+
writeFileSync4(temporary, `${JSON.stringify(root, null, 2)}
|
|
1277
1449
|
`, {
|
|
1278
1450
|
mode: 384,
|
|
1279
1451
|
flag: "wx"
|
|
1280
1452
|
});
|
|
1281
1453
|
chmodSync(temporary, 384);
|
|
1282
|
-
|
|
1454
|
+
renameSync4(temporary, target);
|
|
1283
1455
|
chmodSync(target, 384);
|
|
1284
1456
|
};
|
|
1285
1457
|
var removeExplicitAiClient = (input) => {
|
|
@@ -1303,7 +1475,7 @@ var registerExplicitAiClient = (input) => {
|
|
|
1303
1475
|
driverId: input.driverId,
|
|
1304
1476
|
displayName: input.displayName,
|
|
1305
1477
|
executablePath,
|
|
1306
|
-
...input.configHome &&
|
|
1478
|
+
...input.configHome && existsSync7(input.configHome) ? { configHome: resolve6(input.configHome) } : {}
|
|
1307
1479
|
};
|
|
1308
1480
|
writeRegistry(target, {
|
|
1309
1481
|
version: 1,
|
|
@@ -1334,9 +1506,9 @@ var migrateKoedOwnedCodexRegistration = (input) => {
|
|
|
1334
1506
|
return false;
|
|
1335
1507
|
}
|
|
1336
1508
|
const configPath = resolve6(environment.CODEX_CONFIG_PATH ?? join(environment.CODEX_HOME ?? join(homedir(), ".codex"), "config.toml"));
|
|
1337
|
-
if (!
|
|
1509
|
+
if (!existsSync7(configPath))
|
|
1338
1510
|
return false;
|
|
1339
|
-
const content = (input.readFileSync ??
|
|
1511
|
+
const content = (input.readFileSync ?? readFileSync3)(configPath, "utf8");
|
|
1340
1512
|
if (parseCodexOwnershipBlock(content).kind !== "valid")
|
|
1341
1513
|
return false;
|
|
1342
1514
|
const executablePath = resolveCodexExecutablePath(environment);
|
|
@@ -1419,7 +1591,7 @@ var resolvePiSetupNodeEntry = (candidate, platform = process.platform) => {
|
|
|
1419
1591
|
if (platform !== "win32" || !WINDOWS_PI_SHIM_EXTENSIONS.has(candidate.slice(candidate.lastIndexOf(".")).toLowerCase()))
|
|
1420
1592
|
return candidate;
|
|
1421
1593
|
const entry = join2(dirname6(candidate), "node_modules", "@earendil-works", "pi-coding-agent", "dist", "cli.js");
|
|
1422
|
-
if (
|
|
1594
|
+
if (existsSync8(entry) && statSync3(entry).isFile())
|
|
1423
1595
|
return realpathSync(entry);
|
|
1424
1596
|
throw new Error(`Pi launcher ${candidate} cannot be executed safely. Install Pi through npm with a verifiable package entry or configure a native executable.`);
|
|
1425
1597
|
};
|
|
@@ -1439,9 +1611,9 @@ var resolvePiSetupLauncher = (environment = process.env, platform = process.plat
|
|
|
1439
1611
|
for (const directory of directories) {
|
|
1440
1612
|
if (!isAbsolute2(directory))
|
|
1441
1613
|
continue;
|
|
1442
|
-
candidate = executableNames(platform).map((name) => join2(directory, name)).find((
|
|
1614
|
+
candidate = executableNames(platform).map((name) => join2(directory, name)).find((path2) => {
|
|
1443
1615
|
try {
|
|
1444
|
-
return statSync3(
|
|
1616
|
+
return statSync3(path2).isFile();
|
|
1445
1617
|
} catch {
|
|
1446
1618
|
return false;
|
|
1447
1619
|
}
|
|
@@ -1491,7 +1663,7 @@ var removePi = (environment = process.env, spawnSync = nodeSpawnSync2) => {
|
|
|
1491
1663
|
});
|
|
1492
1664
|
};
|
|
1493
1665
|
runPiForRollback = runPi;
|
|
1494
|
-
if (
|
|
1666
|
+
if (existsSync8(target)) {
|
|
1495
1667
|
backup = `${target}.remove-backup-${process.pid}-${Date.now()}`;
|
|
1496
1668
|
cpSync2(target, backup, { recursive: true });
|
|
1497
1669
|
profileRemovalAttempted = true;
|
|
@@ -1508,9 +1680,9 @@ var removePi = (environment = process.env, spawnSync = nodeSpawnSync2) => {
|
|
|
1508
1680
|
if (piPackageIsListed(listed.stdout ?? "", target)) {
|
|
1509
1681
|
throw new Error("Pi active profile still references Koed package after removal.");
|
|
1510
1682
|
}
|
|
1511
|
-
if (
|
|
1512
|
-
|
|
1513
|
-
if (
|
|
1683
|
+
if (existsSync8(target))
|
|
1684
|
+
rmSync5(target, { recursive: true, force: false });
|
|
1685
|
+
if (existsSync8(target)) {
|
|
1514
1686
|
throw new Error("Koed Pi package directory could not be removed.");
|
|
1515
1687
|
}
|
|
1516
1688
|
removeExplicitAiClient({
|
|
@@ -1518,7 +1690,7 @@ var removePi = (environment = process.env, spawnSync = nodeSpawnSync2) => {
|
|
|
1518
1690
|
driverId: "pi"
|
|
1519
1691
|
});
|
|
1520
1692
|
if (backup) {
|
|
1521
|
-
|
|
1693
|
+
rmSync5(backup, { recursive: true, force: false });
|
|
1522
1694
|
backup = null;
|
|
1523
1695
|
}
|
|
1524
1696
|
return {
|
|
@@ -1536,10 +1708,10 @@ var removePi = (environment = process.env, spawnSync = nodeSpawnSync2) => {
|
|
|
1536
1708
|
];
|
|
1537
1709
|
if (backup) {
|
|
1538
1710
|
try {
|
|
1539
|
-
if (
|
|
1540
|
-
|
|
1711
|
+
if (existsSync8(target))
|
|
1712
|
+
rmSync5(target, { recursive: true, force: true });
|
|
1541
1713
|
cpSync2(backup, target, { recursive: true });
|
|
1542
|
-
|
|
1714
|
+
rmSync5(backup, { recursive: true, force: true });
|
|
1543
1715
|
} catch (restoreError) {
|
|
1544
1716
|
failures.push(`Pi package rollback failed: ${restoreError instanceof Error ? restoreError.message : String(restoreError)}`);
|
|
1545
1717
|
}
|
|
@@ -1606,7 +1778,7 @@ var setupPi = async (environment = process.env, spawnSync = nodeSpawnSync2, opti
|
|
|
1606
1778
|
resolve7(runtime.root, "node_modules/@koed/mcp-server/integrations/pi"),
|
|
1607
1779
|
resolve7(runtime.root, "mcp-server/integrations/pi")
|
|
1608
1780
|
];
|
|
1609
|
-
const source = sourceCandidates.find(
|
|
1781
|
+
const source = sourceCandidates.find(existsSync8);
|
|
1610
1782
|
const target = resolve7(paths.koedHome, "integrations/pi");
|
|
1611
1783
|
const requestedExecutable = environment.KOED_PI_EXECUTABLE?.trim() || "pi";
|
|
1612
1784
|
const checkedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -1731,14 +1903,14 @@ var setupPi = async (environment = process.env, spawnSync = nodeSpawnSync2, opti
|
|
|
1731
1903
|
|
|
1732
1904
|
// packages/koed-server/dist/claude-setup.js
|
|
1733
1905
|
import { spawnSync as nodeSpawnSync3 } from "node:child_process";
|
|
1734
|
-
import { chmodSync as chmodSync2, existsSync as
|
|
1906
|
+
import { chmodSync as chmodSync2, existsSync as existsSync10, mkdirSync as mkdirSync7, readFileSync as readFileSync5, unlinkSync as unlinkSync3, writeFileSync as writeFileSync6 } from "node:fs";
|
|
1735
1907
|
import { homedir as homedir2 } from "node:os";
|
|
1736
1908
|
import { dirname as dirname8, resolve as resolve10 } from "node:path";
|
|
1737
1909
|
|
|
1738
1910
|
// packages/koed-server/dist/claude-background-settings.mjs
|
|
1739
|
-
import { randomUUID as
|
|
1911
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
1740
1912
|
import { Buffer } from "node:buffer";
|
|
1741
|
-
import { closeSync as closeSync2, constants as constants4, existsSync as
|
|
1913
|
+
import { closeSync as closeSync2, constants as constants4, existsSync as existsSync9, fstatSync as fstatSync2, lstatSync as lstatSync2, mkdirSync as mkdirSync6, openSync as openSync2, readFileSync as readFileSync4, renameSync as renameSync5, unlinkSync as unlinkSync2, writeFileSync as writeFileSync5 } from "node:fs";
|
|
1742
1914
|
import { basename, dirname as dirname7, join as join3, resolve as resolve8 } from "node:path";
|
|
1743
1915
|
import process2 from "node:process";
|
|
1744
1916
|
var CLAUDE_BACKGROUND_THRESHOLD = "CLAUDE_CODE_MCP_AUTO_BACKGROUND_MS";
|
|
@@ -1746,10 +1918,10 @@ var disableKey = "CLAUDE_CODE_DISABLE_BACKGROUND_TASKS";
|
|
|
1746
1918
|
var disabled = (value) => ["1", "true", "yes", "on"].includes(String(value ?? "").trim().toLowerCase());
|
|
1747
1919
|
var own = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
|
|
1748
1920
|
var object = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
1749
|
-
var assertTarget = (
|
|
1921
|
+
var assertTarget = (path2, privateFile) => {
|
|
1750
1922
|
let stat;
|
|
1751
1923
|
try {
|
|
1752
|
-
stat = lstatSync2(
|
|
1924
|
+
stat = lstatSync2(path2);
|
|
1753
1925
|
} catch (error) {
|
|
1754
1926
|
if (error.code === "ENOENT")
|
|
1755
1927
|
return;
|
|
@@ -1758,39 +1930,39 @@ var assertTarget = (path, privateFile) => {
|
|
|
1758
1930
|
if (!stat.isFile() || stat.isSymbolicLink() || typeof process2.getuid === "function" && stat.uid !== process2.getuid() || privateFile && process2.platform !== "win32" && (stat.mode & 63) !== 0)
|
|
1759
1931
|
throw new Error("Claude configuration target is not a protected owned regular file");
|
|
1760
1932
|
};
|
|
1761
|
-
var readProtectedJournal = (
|
|
1762
|
-
assertTarget(
|
|
1763
|
-
if (!
|
|
1933
|
+
var readProtectedJournal = (path2) => {
|
|
1934
|
+
assertTarget(path2, true);
|
|
1935
|
+
if (!existsSync9(path2))
|
|
1764
1936
|
return null;
|
|
1765
|
-
const fd = openSync2(
|
|
1937
|
+
const fd = openSync2(path2, constants4.O_RDONLY | (process2.platform === "win32" ? 0 : constants4.O_NOFOLLOW));
|
|
1766
1938
|
try {
|
|
1767
1939
|
const stat = fstatSync2(fd);
|
|
1768
1940
|
if (!stat.isFile() || stat.size > 65536 || typeof process2.getuid === "function" && stat.uid !== process2.getuid() || process2.platform !== "win32" && (stat.mode & 63) !== 0)
|
|
1769
1941
|
throw new Error("Claude background recall journal is not a bounded protected owned file");
|
|
1770
|
-
return
|
|
1942
|
+
return readFileSync4(fd, "utf8");
|
|
1771
1943
|
} finally {
|
|
1772
1944
|
closeSync2(fd);
|
|
1773
1945
|
}
|
|
1774
1946
|
};
|
|
1775
|
-
var writeAtomic = (
|
|
1776
|
-
assertTarget(
|
|
1777
|
-
|
|
1778
|
-
const temporary = join3(dirname7(
|
|
1947
|
+
var writeAtomic = (path2, content, privateFile) => {
|
|
1948
|
+
assertTarget(path2, privateFile);
|
|
1949
|
+
mkdirSync6(dirname7(path2), { recursive: true, mode: 448 });
|
|
1950
|
+
const temporary = join3(dirname7(path2), `.${basename(path2)}.${randomUUID4()}.tmp`);
|
|
1779
1951
|
try {
|
|
1780
|
-
|
|
1781
|
-
assertTarget(
|
|
1782
|
-
|
|
1952
|
+
writeFileSync5(temporary, content, { mode: 384, flag: "wx" });
|
|
1953
|
+
assertTarget(path2, privateFile);
|
|
1954
|
+
renameSync5(temporary, path2);
|
|
1783
1955
|
} finally {
|
|
1784
|
-
if (
|
|
1956
|
+
if (existsSync9(temporary))
|
|
1785
1957
|
unlinkSync2(temporary);
|
|
1786
1958
|
}
|
|
1787
1959
|
};
|
|
1788
|
-
function writeClaudeSettingsFileAtomic(
|
|
1789
|
-
writeAtomic(
|
|
1960
|
+
function writeClaudeSettingsFileAtomic(path2, content) {
|
|
1961
|
+
writeAtomic(path2, content, false);
|
|
1790
1962
|
}
|
|
1791
1963
|
function captureClaudeBackgroundJournal(koedHome) {
|
|
1792
|
-
const
|
|
1793
|
-
return { path, content: readProtectedJournal(
|
|
1964
|
+
const path2 = join3(koedHome, "config", "claude-background-recall.json");
|
|
1965
|
+
return { path: path2, content: readProtectedJournal(path2) };
|
|
1794
1966
|
}
|
|
1795
1967
|
function records(snapshot) {
|
|
1796
1968
|
if (snapshot.content === null)
|
|
@@ -1810,7 +1982,7 @@ function writeClaudeBackgroundJournal(snapshot, content) {
|
|
|
1810
1982
|
}
|
|
1811
1983
|
readProtectedJournal(snapshot.path);
|
|
1812
1984
|
if (content === null) {
|
|
1813
|
-
if (
|
|
1985
|
+
if (existsSync9(snapshot.path))
|
|
1814
1986
|
unlinkSync2(snapshot.path);
|
|
1815
1987
|
return;
|
|
1816
1988
|
}
|
|
@@ -1903,12 +2075,12 @@ function parseClaudeOwnedMcpEntry(output, expectedMcpCli, expectedKoedHome) {
|
|
|
1903
2075
|
}
|
|
1904
2076
|
|
|
1905
2077
|
// packages/koed-server/dist/claude-setup.js
|
|
1906
|
-
var writeClaudeSettings = (
|
|
2078
|
+
var writeClaudeSettings = (path2, content, atomic) => {
|
|
1907
2079
|
if (atomic)
|
|
1908
|
-
writeClaudeSettingsFileAtomic(
|
|
2080
|
+
writeClaudeSettingsFileAtomic(path2, content);
|
|
1909
2081
|
else {
|
|
1910
|
-
|
|
1911
|
-
chmodSync2(
|
|
2082
|
+
writeFileSync6(path2, content, { mode: 384 });
|
|
2083
|
+
chmodSync2(path2, 384);
|
|
1912
2084
|
}
|
|
1913
2085
|
};
|
|
1914
2086
|
var resolveClaudeExecutablePath = (environment, dependencies = {}, platform = process.platform) => resolveExecutablePathWithPlatformFallbacks(environment.KOED_CLAUDE_CODE_EXECUTABLE?.trim() || "claude", environment, dependencies, platform);
|
|
@@ -2030,7 +2202,7 @@ var removeClaude = (environment = process.env, spawnSync = nodeSpawnSync3) => {
|
|
|
2030
2202
|
assertAiClientRegistryWritable(environment);
|
|
2031
2203
|
executable = resolveClaudeExecutablePath(environment);
|
|
2032
2204
|
registrySnapshot = captureAiClientRegistry(environment);
|
|
2033
|
-
originalSettings =
|
|
2205
|
+
originalSettings = existsSync10(settingsPath) ? readFileSync5(settingsPath, "utf8") : null;
|
|
2034
2206
|
const settings = originalSettings ? JSON.parse(originalSettings) : {};
|
|
2035
2207
|
backgroundSnapshot = captureClaudeBackgroundJournal(paths.koedHome);
|
|
2036
2208
|
const backgroundRemoval = removeClaudeBackgroundRecall(settings, settingsPath, backgroundSnapshot);
|
|
@@ -2068,7 +2240,7 @@ var removeClaude = (environment = process.env, spawnSync = nodeSpawnSync3) => {
|
|
|
2068
2240
|
if (settings.hooks && Object.keys(settings.hooks).length === 0) {
|
|
2069
2241
|
delete settings.hooks;
|
|
2070
2242
|
}
|
|
2071
|
-
if (
|
|
2243
|
+
if (existsSync10(settingsPath)) {
|
|
2072
2244
|
writeClaudeSettings(settingsPath, `${JSON.stringify(settings, null, 2)}
|
|
2073
2245
|
`, backgroundSnapshot.content !== null);
|
|
2074
2246
|
}
|
|
@@ -2167,7 +2339,7 @@ var setupClaude = async (environment = process.env, spawnSync = nodeSpawnSync3,
|
|
|
2167
2339
|
try {
|
|
2168
2340
|
assertAiClientRegistryWritable(environment);
|
|
2169
2341
|
executable = resolveClaudeExecutablePath(environment);
|
|
2170
|
-
if (!
|
|
2342
|
+
if (!existsSync10(runtime.mcpCli) || !existsSync10(runtime.captureHook)) {
|
|
2171
2343
|
return failure("Koed's Claude Code integration artifacts are missing.", "Repair Koed, then set up Claude Code integration again.");
|
|
2172
2344
|
}
|
|
2173
2345
|
const childEnvironment = claudeProcessEnvironment(environment);
|
|
@@ -2186,7 +2358,7 @@ var setupClaude = async (environment = process.env, spawnSync = nodeSpawnSync3,
|
|
|
2186
2358
|
});
|
|
2187
2359
|
const authenticationState = claudeAuthenticationState(auth);
|
|
2188
2360
|
registrySnapshot = captureAiClientRegistry(environment);
|
|
2189
|
-
originalSettings =
|
|
2361
|
+
originalSettings = existsSync10(settingsPath) ? readFileSync5(settingsPath, "utf8") : null;
|
|
2190
2362
|
const settings = originalSettings ? JSON.parse(originalSettings) : {};
|
|
2191
2363
|
const background = options.backgroundRecall ? (() => {
|
|
2192
2364
|
backgroundSnapshot = captureClaudeBackgroundJournal(paths.koedHome);
|
|
@@ -2211,8 +2383,8 @@ var setupClaude = async (environment = process.env, spawnSync = nodeSpawnSync3,
|
|
|
2211
2383
|
if (existingMcp.status === 0) {
|
|
2212
2384
|
const configPath = environment.CLAUDE_CONFIG_DIR?.trim() ? resolve10(environment.CLAUDE_CONFIG_DIR, ".claude.json") : resolve10(environment.HOME?.trim() || homedir2(), ".claude.json");
|
|
2213
2385
|
previousMcpConfigPath = configPath;
|
|
2214
|
-
if (
|
|
2215
|
-
const config = JSON.parse(
|
|
2386
|
+
if (existsSync10(configPath)) {
|
|
2387
|
+
const config = JSON.parse(readFileSync5(configPath, "utf8"));
|
|
2216
2388
|
const entry = config.mcpServers?.[mcpName];
|
|
2217
2389
|
if (entry)
|
|
2218
2390
|
previousMcpJson = JSON.stringify(entry);
|
|
@@ -2260,7 +2432,7 @@ var setupClaude = async (environment = process.env, spawnSync = nodeSpawnSync3,
|
|
|
2260
2432
|
}
|
|
2261
2433
|
];
|
|
2262
2434
|
}
|
|
2263
|
-
|
|
2435
|
+
mkdirSync7(dirname8(settingsPath), { recursive: true, mode: 448 });
|
|
2264
2436
|
if (backgroundSnapshot && background)
|
|
2265
2437
|
writeClaudeBackgroundJournal(backgroundSnapshot, background.journal);
|
|
2266
2438
|
writeClaudeSettings(settingsPath, `${JSON.stringify(settings, null, 2)}
|
|
@@ -2304,7 +2476,7 @@ var setupClaude = async (environment = process.env, spawnSync = nodeSpawnSync3,
|
|
|
2304
2476
|
let previousMcpUnchanged = false;
|
|
2305
2477
|
if (!attemptedMcpAdd && previousMcpJson && previousMcpConfigPath) {
|
|
2306
2478
|
try {
|
|
2307
|
-
const config = JSON.parse(
|
|
2479
|
+
const config = JSON.parse(readFileSync5(previousMcpConfigPath, "utf8"));
|
|
2308
2480
|
previousMcpUnchanged = JSON.stringify(config.mcpServers?.[mcpName]) === previousMcpJson;
|
|
2309
2481
|
} catch {
|
|
2310
2482
|
}
|
|
@@ -2343,7 +2515,7 @@ var setupClaude = async (environment = process.env, spawnSync = nodeSpawnSync3,
|
|
|
2343
2515
|
} catch (restoreError) {
|
|
2344
2516
|
failures.push(`Claude settings rollback failed: ${restoreError instanceof Error ? restoreError.message : String(restoreError)}`);
|
|
2345
2517
|
}
|
|
2346
|
-
} else if (
|
|
2518
|
+
} else if (existsSync10(settingsPath)) {
|
|
2347
2519
|
try {
|
|
2348
2520
|
unlinkSync3(settingsPath);
|
|
2349
2521
|
} catch (restoreError) {
|
|
@@ -2462,15 +2634,41 @@ var defaultDependencies = () => ({
|
|
|
2462
2634
|
desktopRuntimeCapability: null,
|
|
2463
2635
|
fetch: globalThis.fetch.bind(globalThis),
|
|
2464
2636
|
spawnSync: nodeSpawnSync4,
|
|
2465
|
-
existsSync:
|
|
2466
|
-
readFileSync:
|
|
2637
|
+
existsSync: existsSync11,
|
|
2638
|
+
readFileSync: readFileSync6,
|
|
2467
2639
|
resolvePiExecutable: resolvePiSetupExecutable,
|
|
2468
2640
|
resolveClaudeExecutable: resolveClaudeExecutablePath,
|
|
2469
2641
|
resolveCodexExecutable: resolveCodexExecutablePath,
|
|
2470
2642
|
checkPid: isProcessRunning,
|
|
2471
2643
|
delay: (milliseconds) => new Promise((resolve16) => setTimeout(resolve16, milliseconds)),
|
|
2472
|
-
now: () => /* @__PURE__ */ new Date()
|
|
2644
|
+
now: () => /* @__PURE__ */ new Date(),
|
|
2645
|
+
revokeAiClientConnection
|
|
2473
2646
|
});
|
|
2647
|
+
var captureConnectionNames = {
|
|
2648
|
+
codex: "Codex",
|
|
2649
|
+
claude: "Claude Code",
|
|
2650
|
+
pi: "Pi"
|
|
2651
|
+
};
|
|
2652
|
+
var captureConnectionStatus = (id, component, connections) => {
|
|
2653
|
+
const captureConnected = connections?.clients[id]?.connected === true;
|
|
2654
|
+
const details = {
|
|
2655
|
+
...component.details ?? {},
|
|
2656
|
+
captureConnected
|
|
2657
|
+
};
|
|
2658
|
+
if (captureConnected || component.configured !== true)
|
|
2659
|
+
return { ...component, details };
|
|
2660
|
+
const state = component.state;
|
|
2661
|
+
if (state !== "healthy")
|
|
2662
|
+
return { ...component, details };
|
|
2663
|
+
const name = captureConnectionNames[id];
|
|
2664
|
+
return {
|
|
2665
|
+
...component,
|
|
2666
|
+
state: "needs_attention",
|
|
2667
|
+
message: `${name} is set up, but Koed is not reading its conversations until you connect it.`,
|
|
2668
|
+
action: `Connect ${name} again in Koed Desktop, or run \`koed setup ${id}\`.`,
|
|
2669
|
+
details
|
|
2670
|
+
};
|
|
2671
|
+
};
|
|
2474
2672
|
var runtimeSelections = /* @__PURE__ */ new WeakMap();
|
|
2475
2673
|
var withDefaults = (dependencies = {}) => {
|
|
2476
2674
|
const deps = { ...defaultDependencies(), ...dependencies };
|
|
@@ -2499,9 +2697,9 @@ var starting = (message, details) => ({
|
|
|
2499
2697
|
message,
|
|
2500
2698
|
...details ? { details } : {}
|
|
2501
2699
|
});
|
|
2502
|
-
var readJsonFile = (
|
|
2700
|
+
var readJsonFile = (path2, reader = readFileSync6) => {
|
|
2503
2701
|
try {
|
|
2504
|
-
return JSON.parse(reader(
|
|
2702
|
+
return JSON.parse(reader(path2, "utf8"));
|
|
2505
2703
|
} catch {
|
|
2506
2704
|
return null;
|
|
2507
2705
|
}
|
|
@@ -2539,7 +2737,7 @@ var inspectPi = (environment, paths, deps, refreshed) => {
|
|
|
2539
2737
|
const versionText = version.stdout?.trim() ?? "";
|
|
2540
2738
|
if (version.error || version.status !== 0) {
|
|
2541
2739
|
return {
|
|
2542
|
-
...notConfigured("Pi is not installed or could not be started.", `Install Pi ${MINIMUM_PI_VERSION} or newer, then set up Pi integration
|
|
2740
|
+
...notConfigured("Pi is not installed or could not be started.", `Install Pi ${MINIMUM_PI_VERSION} or newer, then set up Pi integration.`, { inspectionState: "unknown" }),
|
|
2543
2741
|
configured: false,
|
|
2544
2742
|
detected: detectedFromConfig
|
|
2545
2743
|
};
|
|
@@ -2694,7 +2892,7 @@ var inspectClaudeCode = async (environment, paths, deps) => {
|
|
|
2694
2892
|
const versionText = version.stdout?.trim() ?? "";
|
|
2695
2893
|
if (version.error || version.status !== 0) {
|
|
2696
2894
|
return {
|
|
2697
|
-
...notConfigured("Claude Code is not installed or could not be started.", `Install Claude Code ${MINIMUM_CLAUDE_CODE_VERSION} or newer, then set up its integration
|
|
2895
|
+
...notConfigured("Claude Code is not installed or could not be started.", `Install Claude Code ${MINIMUM_CLAUDE_CODE_VERSION} or newer, then set up its integration.`, { inspectionState: "unknown" }),
|
|
2698
2896
|
configured: false,
|
|
2699
2897
|
detected: detectedFromConfig
|
|
2700
2898
|
};
|
|
@@ -2741,6 +2939,21 @@ var inspectClaudeCode = async (environment, paths, deps) => {
|
|
|
2741
2939
|
}
|
|
2742
2940
|
const mcpConfigured = !mcp.error && mcp.status === 0;
|
|
2743
2941
|
const captureConfigured = missingHooks.length === 0;
|
|
2942
|
+
const mcpAbsent = !mcp.error && mcp.status !== 0 && /(?:not found|does not exist|no .*mcp|unknown .*server|not configured)/i.test(`${mcp.stdout ?? ""}
|
|
2943
|
+
${mcp.stderr ?? ""}`);
|
|
2944
|
+
if (!mcpConfigured && !mcpAbsent && captureConfigured) {
|
|
2945
|
+
return {
|
|
2946
|
+
...needsAttention("Claude Code's MCP configuration could not be verified.", "Check again. If this persists, run `claude mcp get` in your terminal to diagnose the configuration.", {
|
|
2947
|
+
executable,
|
|
2948
|
+
version: versionText,
|
|
2949
|
+
settingsPath,
|
|
2950
|
+
mcpName,
|
|
2951
|
+
inspectionState: "unknown"
|
|
2952
|
+
}),
|
|
2953
|
+
configured: false,
|
|
2954
|
+
detected: true
|
|
2955
|
+
};
|
|
2956
|
+
}
|
|
2744
2957
|
if (!mcpConfigured || !captureConfigured) {
|
|
2745
2958
|
return {
|
|
2746
2959
|
...notConfigured("Claude Code's Koed MCP or Capture Hook configuration is incomplete.", "Set up Claude Code integration from Koed Desktop.", {
|
|
@@ -2792,7 +3005,10 @@ var withFetchTimeout = (fetcher, timeoutMs = 5e3) => {
|
|
|
2792
3005
|
const controller = new AbortController();
|
|
2793
3006
|
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
2794
3007
|
try {
|
|
2795
|
-
return await fetcher(url, {
|
|
3008
|
+
return await fetcher(url, {
|
|
3009
|
+
...init,
|
|
3010
|
+
signal: init?.signal ? AbortSignal.any([controller.signal, init.signal]) : controller.signal
|
|
3011
|
+
});
|
|
2796
3012
|
} catch (error) {
|
|
2797
3013
|
if (error instanceof Error && error.name === "AbortError") {
|
|
2798
3014
|
throw new Error(`API request timeout after ${timeoutMs}ms. Is koed-server running?`, { cause: error });
|
|
@@ -3121,7 +3337,16 @@ var inspectCodex = async (environment, paths, deps, memoryGuidanceEnabled) => {
|
|
|
3121
3337
|
} catch {
|
|
3122
3338
|
return authenticatedRuntimeUnavailable();
|
|
3123
3339
|
}
|
|
3124
|
-
const
|
|
3340
|
+
const assignments = (key) => mcpBlock.split(/\r?\n/).filter((line) => new RegExp(`^\\s*${key}\\s*=`).test(line));
|
|
3341
|
+
const matchesAssignment = (key, value) => {
|
|
3342
|
+
const lines = assignments(key);
|
|
3343
|
+
if (lines.length !== 1)
|
|
3344
|
+
return false;
|
|
3345
|
+
const assignment = lines[0].trim();
|
|
3346
|
+
const expected = `${key} = ${value}`;
|
|
3347
|
+
return assignment.startsWith(expected) && /^(?:\s*(?:#.*)?)$/.test(assignment.slice(expected.length));
|
|
3348
|
+
};
|
|
3349
|
+
const hasExpectedAdapter = matchesAssignment("command", JSON.stringify(environment.MEMORY_NODE_COMMAND ?? "node")) && matchesAssignment("args", `[${JSON.stringify(runtime.mcpCli)}]`);
|
|
3125
3350
|
const containsRetiredCredentials = tomlStringValue(mcpEnvBlock, "MEMORY_API_URL") !== null || tomlStringValue(mcpEnvBlock, "MEMORY_API_TOKEN") !== null;
|
|
3126
3351
|
if (configuredKoedHome !== paths.koedHome || !hasExpectedAdapter) {
|
|
3127
3352
|
return {
|
|
@@ -3129,7 +3354,8 @@ var inspectCodex = async (environment, paths, deps, memoryGuidanceEnabled) => {
|
|
|
3129
3354
|
configuredKoedHome: configuredKoedHome ?? null,
|
|
3130
3355
|
expectedKoedHome: paths.koedHome,
|
|
3131
3356
|
expectedMcpAdapter: runtime.mcpCli,
|
|
3132
|
-
codexConfigPath
|
|
3357
|
+
codexConfigPath,
|
|
3358
|
+
currentHomeAuthorized: false
|
|
3133
3359
|
}),
|
|
3134
3360
|
configured: true
|
|
3135
3361
|
};
|
|
@@ -3441,6 +3667,95 @@ var localSynthesisReadiness = (snapshot, descriptor, profileAuthentication) => {
|
|
|
3441
3667
|
}
|
|
3442
3668
|
return current;
|
|
3443
3669
|
};
|
|
3670
|
+
var historicalIngestionClients = ["codex", "claude", "pi"];
|
|
3671
|
+
var inspectHistoricalIngestion = (paths, deps) => {
|
|
3672
|
+
const now = deps.now().getTime();
|
|
3673
|
+
return Object.fromEntries(historicalIngestionClients.map((client) => {
|
|
3674
|
+
const file = resolve12(paths.koedHome, "state", `${client}-historical-ingestion.json`);
|
|
3675
|
+
let value;
|
|
3676
|
+
try {
|
|
3677
|
+
if (deps.existsSync(file))
|
|
3678
|
+
value = JSON.parse(String(deps.readFileSync(file, "utf8")));
|
|
3679
|
+
} catch {
|
|
3680
|
+
value = void 0;
|
|
3681
|
+
}
|
|
3682
|
+
return [client, summarizeHistoricalIngestionState(value, now)];
|
|
3683
|
+
}));
|
|
3684
|
+
};
|
|
3685
|
+
async function fetchHistoricalActivity(input) {
|
|
3686
|
+
const controller = new AbortController();
|
|
3687
|
+
let timer;
|
|
3688
|
+
try {
|
|
3689
|
+
return await Promise.race([
|
|
3690
|
+
lookupHistoricalActivity(input, controller.signal),
|
|
3691
|
+
new Promise((resolve16) => {
|
|
3692
|
+
timer = setTimeout(() => {
|
|
3693
|
+
controller.abort();
|
|
3694
|
+
resolve16(null);
|
|
3695
|
+
}, 2e3);
|
|
3696
|
+
})
|
|
3697
|
+
]);
|
|
3698
|
+
} finally {
|
|
3699
|
+
clearTimeout(timer);
|
|
3700
|
+
}
|
|
3701
|
+
}
|
|
3702
|
+
async function lookupHistoricalActivity(input, signal) {
|
|
3703
|
+
try {
|
|
3704
|
+
const selected = /* @__PURE__ */ new Map();
|
|
3705
|
+
for (const client of historicalIngestionClients) {
|
|
3706
|
+
try {
|
|
3707
|
+
const state = JSON.parse(input.readFile(resolve12(input.koedHome, "state", `${client}-historical-ingestion.json`)));
|
|
3708
|
+
if (state.selectionFrozen === true && Array.isArray(state.selections))
|
|
3709
|
+
selected.set(client, new Set(state.selections.map((selection) => selection.candidateId).filter((id) => typeof id === "string")));
|
|
3710
|
+
} catch {
|
|
3711
|
+
}
|
|
3712
|
+
}
|
|
3713
|
+
if (!selected.size)
|
|
3714
|
+
return null;
|
|
3715
|
+
const headers = { authorization: `Bearer ${input.token}` };
|
|
3716
|
+
const listUrl = new URL("/v1/historical-imports?limit=20", input.apiUrl);
|
|
3717
|
+
const list = await input.fetcher(listUrl, { headers, signal });
|
|
3718
|
+
if (signal.aborted || !list.ok)
|
|
3719
|
+
return null;
|
|
3720
|
+
const body = await list.json();
|
|
3721
|
+
if (signal.aborted)
|
|
3722
|
+
return null;
|
|
3723
|
+
if (!Array.isArray(body.runs) || body.runs.length >= 20 || body.runs.some((run2) => typeof run2.id !== "string"))
|
|
3724
|
+
return null;
|
|
3725
|
+
const totals = {};
|
|
3726
|
+
for (const client of selected.keys())
|
|
3727
|
+
totals[client] = { recordsRead: 0, embedded: 0, eligible: 0 };
|
|
3728
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3729
|
+
for (const run2 of body.runs) {
|
|
3730
|
+
const result = await input.fetcher(new URL(`/v1/historical-imports/${encodeURIComponent(run2.id)}`, input.apiUrl), { headers, signal });
|
|
3731
|
+
if (signal.aborted || !result.ok)
|
|
3732
|
+
return null;
|
|
3733
|
+
const detail = await result.json();
|
|
3734
|
+
if (signal.aborted || !Array.isArray(detail.run?.sources))
|
|
3735
|
+
return null;
|
|
3736
|
+
for (const source of detail.run.sources) {
|
|
3737
|
+
const { aiClient, sourceSessionId, id, rawIngestedRecordCount, embeddedEventCount, embeddingEligibleEventCount } = source;
|
|
3738
|
+
if (typeof aiClient !== "string" || typeof sourceSessionId !== "string" || !selected.get(aiClient)?.has(sourceSessionId))
|
|
3739
|
+
continue;
|
|
3740
|
+
if (typeof id !== "string" || seen.has(id))
|
|
3741
|
+
continue;
|
|
3742
|
+
if (![
|
|
3743
|
+
rawIngestedRecordCount,
|
|
3744
|
+
embeddedEventCount,
|
|
3745
|
+
embeddingEligibleEventCount
|
|
3746
|
+
].every((n) => Number.isSafeInteger(n) && Number(n) >= 0))
|
|
3747
|
+
return null;
|
|
3748
|
+
seen.add(id);
|
|
3749
|
+
totals[aiClient].recordsRead += Number(rawIngestedRecordCount);
|
|
3750
|
+
totals[aiClient].embedded += Number(embeddedEventCount);
|
|
3751
|
+
totals[aiClient].eligible += Number(embeddingEligibleEventCount);
|
|
3752
|
+
}
|
|
3753
|
+
}
|
|
3754
|
+
return totals;
|
|
3755
|
+
} catch {
|
|
3756
|
+
return null;
|
|
3757
|
+
}
|
|
3758
|
+
}
|
|
3444
3759
|
var inspectAiClientReadiness = (input) => {
|
|
3445
3760
|
const clients = [
|
|
3446
3761
|
{
|
|
@@ -3952,6 +4267,7 @@ var collectKoedServerStatus = async (environment = process.env, dependencies = {
|
|
|
3952
4267
|
const capabilityReadModel = await fetchAiClientCapabilityReadModel(paths, runtimeEnvironment, repoEnv, apiUrl, fetcher);
|
|
3953
4268
|
const embeddingState = !waitingForManagedRuntime ? await fetchEmbeddingState(paths, runtimeEnvironment, repoEnv, apiUrl, fetcher) : null;
|
|
3954
4269
|
const localAiRuntime = inspectLocalAiRuntime(runtime, runtimeProcessRunning, serverConfig.runtimeMode, deps);
|
|
4270
|
+
const connectionsBefore = readAiClientConnections(paths.koedHome);
|
|
3955
4271
|
const codex = await inspectSafely("Codex", () => inspectCodex(runtimeEnvironment, paths, deps, serverConfig.codexGlobalMemoryGuidanceEnabled), { state: "needs_attention", configured: false });
|
|
3956
4272
|
const claudeCode = await inspectSafely("Claude Code", () => inspectClaudeCode(runtimeEnvironment, paths, deps), { state: "needs_attention", configured: false, detected: false });
|
|
3957
4273
|
const pi = await inspectSafely("Pi", () => inspectPi(runtimeEnvironment, paths, deps, {
|
|
@@ -3959,6 +4275,30 @@ var collectKoedServerStatus = async (environment = process.env, dependencies = {
|
|
|
3959
4275
|
refreshedSince: options.capabilitiesRefreshedSince,
|
|
3960
4276
|
now: deps.now().toISOString()
|
|
3961
4277
|
}), { state: "needs_attention", configured: false, detected: false });
|
|
4278
|
+
const observedConnection = (inspected) => {
|
|
4279
|
+
const details = inspected.details;
|
|
4280
|
+
if (details?.currentHomeAuthorized === false)
|
|
4281
|
+
return false;
|
|
4282
|
+
return details?.kind === "inspection_error" || details?.inspectionState === "unknown" ? void 0 : inspected.configured === true;
|
|
4283
|
+
};
|
|
4284
|
+
const inspectedClients = { codex, claude: claudeCode, pi };
|
|
4285
|
+
for (const id of Object.keys(inspectedClients)) {
|
|
4286
|
+
const before = connectionsBefore?.clients[id];
|
|
4287
|
+
if (before?.connected === true && observedConnection(inspectedClients[id]) === false) {
|
|
4288
|
+
try {
|
|
4289
|
+
deps.revokeAiClientConnection(paths.koedHome, id, {
|
|
4290
|
+
ifRevision: before.revision,
|
|
4291
|
+
now: deps.now()
|
|
4292
|
+
});
|
|
4293
|
+
} catch {
|
|
4294
|
+
}
|
|
4295
|
+
}
|
|
4296
|
+
}
|
|
4297
|
+
const connections = readAiClientConnections(paths.koedHome);
|
|
4298
|
+
const withCaptureConnection = (id, component) => captureConnectionStatus(id, component, connections);
|
|
4299
|
+
const codexStatus = withCaptureConnection("codex", codex);
|
|
4300
|
+
const claudeCodeStatus = withCaptureConnection("claude", claudeCode);
|
|
4301
|
+
const piStatus = withCaptureConnection("pi", pi);
|
|
3962
4302
|
const captureHook = await inspectSafely("Supported Capture Hook", () => inspectCaptureHook(runtimeEnvironment, paths, deps), { state: "needs_attention" });
|
|
3963
4303
|
const codexTranscriptWatcher = inspectCodexTranscriptWatcher(serverConfig.codexTranscriptWatcherEnabled, runtime, runtimeProcessRunning, deps);
|
|
3964
4304
|
const mcpServer = await inspectMcp(runtimeEnvironment, paths, deps).catch(() => needsAttention("MCP Server status could not be inspected.", "Repair MCP Server integration, then refresh status.", { kind: "inspection_error" }));
|
|
@@ -4031,9 +4371,9 @@ var collectKoedServerStatus = async (environment = process.env, dependencies = {
|
|
|
4031
4371
|
const readinessInput = {
|
|
4032
4372
|
localAiClientInstances,
|
|
4033
4373
|
localAiClientRegistryError,
|
|
4034
|
-
codex,
|
|
4035
|
-
claudeCode,
|
|
4036
|
-
pi,
|
|
4374
|
+
codex: codexStatus,
|
|
4375
|
+
claudeCode: claudeCodeStatus,
|
|
4376
|
+
pi: piStatus,
|
|
4037
4377
|
codexTranscriptWatcher,
|
|
4038
4378
|
claudeTranscriptWatcher,
|
|
4039
4379
|
piTranscriptWatcher,
|
|
@@ -4053,6 +4393,20 @@ var collectKoedServerStatus = async (environment = process.env, dependencies = {
|
|
|
4053
4393
|
inspectDeviceIdentity(paths, environment),
|
|
4054
4394
|
Promise.resolve(inspectUpstreamBackends(paths, deps))
|
|
4055
4395
|
]);
|
|
4396
|
+
const historicalIngestion = inspectHistoricalIngestion(paths, deps);
|
|
4397
|
+
const historicalToken = resolveActiveIntegrationApiToken(paths, runtimeEnvironment, repoEnv);
|
|
4398
|
+
const activity = historicalToken && runtimeProcessRunning ? await fetchHistoricalActivity({
|
|
4399
|
+
koedHome: paths.koedHome,
|
|
4400
|
+
apiUrl,
|
|
4401
|
+
token: historicalToken.token,
|
|
4402
|
+
fetcher,
|
|
4403
|
+
readFile: (file) => String(deps.readFileSync(file, "utf8"))
|
|
4404
|
+
}) : null;
|
|
4405
|
+
if (activity)
|
|
4406
|
+
for (const client of historicalIngestionClients) {
|
|
4407
|
+
if (activity[client])
|
|
4408
|
+
historicalIngestion[client].activity = activity[client];
|
|
4409
|
+
}
|
|
4056
4410
|
const statusWithoutState = {
|
|
4057
4411
|
ok: false,
|
|
4058
4412
|
state: "starting",
|
|
@@ -4073,13 +4427,14 @@ var collectKoedServerStatus = async (environment = process.env, dependencies = {
|
|
|
4073
4427
|
codexTranscriptWatcher,
|
|
4074
4428
|
claudeTranscriptWatcher,
|
|
4075
4429
|
piTranscriptWatcher,
|
|
4076
|
-
codex,
|
|
4077
|
-
claudeCode,
|
|
4078
|
-
pi,
|
|
4430
|
+
codex: codexStatus,
|
|
4431
|
+
claudeCode: claudeCodeStatus,
|
|
4432
|
+
pi: piStatus,
|
|
4079
4433
|
aiClients,
|
|
4080
4434
|
aiClientInstances,
|
|
4081
4435
|
aiClientFlowReadiness,
|
|
4082
4436
|
lcmSummaryService,
|
|
4437
|
+
historicalIngestion,
|
|
4083
4438
|
embeddingState,
|
|
4084
4439
|
deviceIdentity,
|
|
4085
4440
|
upstreamBackends,
|
|
@@ -4165,7 +4520,7 @@ import { dirname as dirname10, resolve as resolve15 } from "node:path";
|
|
|
4165
4520
|
|
|
4166
4521
|
// packages/koed-server/dist/local-service-secrets.js
|
|
4167
4522
|
import { randomBytes } from "node:crypto";
|
|
4168
|
-
import { existsSync as
|
|
4523
|
+
import { existsSync as existsSync12, readFileSync as readFileSync7, writeFileSync as writeFileSync7 } from "node:fs";
|
|
4169
4524
|
import { resolve as resolve13 } from "node:path";
|
|
4170
4525
|
var secretNames = [
|
|
4171
4526
|
"POSTGRES_PASSWORD",
|
|
@@ -4198,15 +4553,15 @@ var parseLocalServiceSecrets = (value) => {
|
|
|
4198
4553
|
};
|
|
4199
4554
|
var localServiceSecretsPath = (paths) => resolve13(paths.configDir, "local-service-secrets.json");
|
|
4200
4555
|
var readLocalServiceSecrets = (paths, dependencies = {}) => {
|
|
4201
|
-
const
|
|
4202
|
-
const exists = dependencies.existsSync ??
|
|
4203
|
-
if (!exists(
|
|
4204
|
-
return { state: "absent", path };
|
|
4556
|
+
const path2 = localServiceSecretsPath(paths);
|
|
4557
|
+
const exists = dependencies.existsSync ?? existsSync12;
|
|
4558
|
+
if (!exists(path2))
|
|
4559
|
+
return { state: "absent", path: path2 };
|
|
4205
4560
|
try {
|
|
4206
|
-
const parsed = parseLocalServiceSecrets(JSON.parse(String((dependencies.readFileSync ??
|
|
4207
|
-
return typeof parsed === "string" ? { state: "invalid", path, error: parsed } : { state: "valid", path, secrets: parsed };
|
|
4561
|
+
const parsed = parseLocalServiceSecrets(JSON.parse(String((dependencies.readFileSync ?? readFileSync7)(path2, "utf8"))));
|
|
4562
|
+
return typeof parsed === "string" ? { state: "invalid", path: path2, error: parsed } : { state: "valid", path: path2, secrets: parsed };
|
|
4208
4563
|
} catch {
|
|
4209
|
-
return { state: "invalid", path, error: "expected valid JSON" };
|
|
4564
|
+
return { state: "invalid", path: path2, error: "expected valid JSON" };
|
|
4210
4565
|
}
|
|
4211
4566
|
};
|
|
4212
4567
|
var generatedSecrets = (existing, random) => ({
|
|
@@ -4228,7 +4583,7 @@ var ensurePackagedLocalServiceSecrets = (paths, packaged, environment, dependenc
|
|
|
4228
4583
|
const readResult = readLocalServiceSecrets(paths, dependencies);
|
|
4229
4584
|
const existing = readResult.state === "valid" ? readResult.secrets : {};
|
|
4230
4585
|
const secrets = generatedSecrets(existing, dependencies.randomBytes ?? randomBytes);
|
|
4231
|
-
(dependencies.writeFileSync ??
|
|
4586
|
+
(dependencies.writeFileSync ?? writeFileSync7)(localServiceSecretsPath(paths), `${JSON.stringify(secrets, null, 2)}
|
|
4232
4587
|
`, { mode: 384 });
|
|
4233
4588
|
return { ...secrets, ...environment };
|
|
4234
4589
|
};
|
|
@@ -4366,25 +4721,25 @@ var provisionDesktopApiToken = async (paths, runtime, environment, repoEnv = {},
|
|
|
4366
4721
|
};
|
|
4367
4722
|
|
|
4368
4723
|
// packages/koed-server/dist/setup.js
|
|
4369
|
-
var captureManagedFile = (
|
|
4370
|
-
content: String(
|
|
4371
|
-
mode: nodeStatSync(
|
|
4724
|
+
var captureManagedFile = (path2, existsSync13, readFileSync8) => existsSync13(path2) ? {
|
|
4725
|
+
content: String(readFileSync8(path2, "utf8")),
|
|
4726
|
+
mode: nodeStatSync(path2).mode & 511
|
|
4372
4727
|
} : { content: null, mode: null };
|
|
4373
|
-
var restoreManagedFile = (
|
|
4728
|
+
var restoreManagedFile = (path2, snapshot, existsSync13, writeFileSync8, mkdirSync8) => {
|
|
4374
4729
|
if (snapshot.content === null) {
|
|
4375
|
-
if (
|
|
4376
|
-
nodeUnlinkSync(
|
|
4730
|
+
if (existsSync13(path2))
|
|
4731
|
+
nodeUnlinkSync(path2);
|
|
4377
4732
|
return;
|
|
4378
4733
|
}
|
|
4379
|
-
|
|
4380
|
-
|
|
4734
|
+
mkdirSync8(dirname10(path2), { recursive: true, mode: 448 });
|
|
4735
|
+
writeFileSync8(path2, snapshot.content, { mode: snapshot.mode ?? 384 });
|
|
4381
4736
|
if (snapshot.mode !== null)
|
|
4382
|
-
nodeChmodSync(
|
|
4737
|
+
nodeChmodSync(path2, snapshot.mode);
|
|
4383
4738
|
};
|
|
4384
4739
|
var tomlString = (value) => JSON.stringify(value);
|
|
4385
|
-
var configureCodexIntegration = ({ paths, environment, apiUrl, readFileSync:
|
|
4386
|
-
const runtime = resolveRuntime(paths, environment,
|
|
4387
|
-
const missing = [runtime.mcpCli, runtime.captureHook].filter((
|
|
4740
|
+
var configureCodexIntegration = ({ paths, environment, apiUrl, readFileSync: readFileSync8, writeFileSync: writeFileSync8, mkdirSync: mkdirSync8, existsSync: existsSync13, memoryGuidanceEnabled, resolveRuntime }) => {
|
|
4741
|
+
const runtime = resolveRuntime(paths, environment, existsSync13);
|
|
4742
|
+
const missing = [runtime.mcpCli, runtime.captureHook].filter((path2) => !existsSync13(path2));
|
|
4388
4743
|
const command = `write Codex config using ${runtime.root}`;
|
|
4389
4744
|
if (missing.length > 0) {
|
|
4390
4745
|
throw new Error(`Koed MCP Server artifacts are missing: ${missing.join(", ")}. Rebuild Koed Desktop packaging so koed-runtime contains the MCP Server and Supported Capture Hook artifacts.`);
|
|
@@ -4393,18 +4748,18 @@ var configureCodexIntegration = ({ paths, environment, apiUrl, readFileSync: rea
|
|
|
4393
4748
|
const mcpName = environment.MEMORY_MCP_NAME ?? "koed";
|
|
4394
4749
|
const codexConfigPath = resolve15(environment.CODEX_CONFIG_PATH ?? `${environment.CODEX_HOME ?? `${homedir5()}/.codex`}/config.toml`);
|
|
4395
4750
|
const codexInstructionsPath = resolveCodexGlobalInstructionsPath(environment);
|
|
4396
|
-
const existing =
|
|
4751
|
+
const existing = existsSync13(codexConfigPath) ? String(readFileSync8(codexConfigPath, "utf8")) : "";
|
|
4397
4752
|
const withoutPrevious = stripCodexOwnershipBlock(existing);
|
|
4398
4753
|
if (!/^[A-Za-z0-9_-]+$/.test(mcpName))
|
|
4399
4754
|
throw new Error("MEMORY_MCP_NAME must be a TOML bare server name.");
|
|
4400
4755
|
const guidancePath = resolveCodexGuidancePath(runtime.mcpCli);
|
|
4401
|
-
const existingInstructions =
|
|
4756
|
+
const existingInstructions = existsSync13(codexInstructionsPath) ? String(readFileSync8(codexInstructionsPath, "utf8")) : "";
|
|
4402
4757
|
let nextInstructions;
|
|
4403
4758
|
if (memoryGuidanceEnabled) {
|
|
4404
|
-
if (!
|
|
4759
|
+
if (!existsSync13(guidancePath)) {
|
|
4405
4760
|
throw new Error(`Packaged Codex memory guidance is missing: ${guidancePath}. Rebuild Koed so the MCP Server prompt assets are complete.`);
|
|
4406
4761
|
}
|
|
4407
|
-
const guidance = String(
|
|
4762
|
+
const guidance = String(readFileSync8(guidancePath, "utf8"));
|
|
4408
4763
|
nextInstructions = reconcileManagedCodexGuidance(existingInstructions, guidance);
|
|
4409
4764
|
} else {
|
|
4410
4765
|
nextInstructions = removeManagedCodexGuidance(existingInstructions);
|
|
@@ -4458,13 +4813,13 @@ KOED_HOME = ${tomlString(paths.koedHome)}
|
|
|
4458
4813
|
${hookBlocks}
|
|
4459
4814
|
${markerEnd}
|
|
4460
4815
|
`;
|
|
4461
|
-
|
|
4462
|
-
|
|
4816
|
+
mkdirSync8(dirname10(codexConfigPath), { recursive: true, mode: 448 });
|
|
4817
|
+
writeFileSync8(codexConfigPath, `${withoutPrevious.trimEnd()}
|
|
4463
4818
|
|
|
4464
4819
|
${koedBlock}`);
|
|
4465
|
-
|
|
4820
|
+
mkdirSync8(dirname10(codexInstructionsPath), { recursive: true, mode: 448 });
|
|
4466
4821
|
if (nextInstructions !== existingInstructions) {
|
|
4467
|
-
|
|
4822
|
+
writeFileSync8(codexInstructionsPath, nextInstructions, { mode: 384 });
|
|
4468
4823
|
}
|
|
4469
4824
|
return {
|
|
4470
4825
|
command,
|
|
@@ -4496,7 +4851,7 @@ var codexBlockIsExpectedKoedOwned = (block, environment, paths) => {
|
|
|
4496
4851
|
];
|
|
4497
4852
|
return block.includes(mcpHeader) && block.includes(`command = ${tomlString(nodeCommand)}`) && block.includes(`args = [${tomlString(runtime.mcpCli)}]`) && block.includes(`[mcp_servers.${mcpName}.env]`) && block.includes(`KOED_HOME = ${tomlString(paths.koedHome)}`) && requiredHooks.every((eventName) => block.includes(`[[hooks.${eventName}]]`) && block.includes(runtime.captureHook));
|
|
4498
4853
|
};
|
|
4499
|
-
var removeCodexIntegration = ({ environment = process.env, readFileSync:
|
|
4854
|
+
var removeCodexIntegration = ({ environment = process.env, readFileSync: readFileSync8 = nodeReadFileSync, writeFileSync: writeFileSync8 = nodeWriteFileSync, mkdirSync: mkdirSync8 = nodeMkdirSync, existsSync: existsSync13 = nodeExistsSync, now = () => /* @__PURE__ */ new Date() } = {}) => {
|
|
4500
4855
|
const paths = resolveKoedServerPaths(environment);
|
|
4501
4856
|
ensureKoedHome(paths);
|
|
4502
4857
|
const codexConfigPath = resolve15(environment.CODEX_CONFIG_PATH ?? `${environment.CODEX_HOME ?? `${homedir5()}/.codex`}/config.toml`);
|
|
@@ -4514,8 +4869,8 @@ var removeCodexIntegration = ({ environment = process.env, readFileSync: readFil
|
|
|
4514
4869
|
try {
|
|
4515
4870
|
assertAiClientRegistryWritable(environment);
|
|
4516
4871
|
registrySnapshot = captureAiClientRegistry(environment);
|
|
4517
|
-
configSnapshot = captureManagedFile(codexConfigPath,
|
|
4518
|
-
instructionsSnapshot = captureManagedFile(codexInstructionsPath,
|
|
4872
|
+
configSnapshot = captureManagedFile(codexConfigPath, existsSync13, readFileSync8);
|
|
4873
|
+
instructionsSnapshot = captureManagedFile(codexInstructionsPath, existsSync13, readFileSync8);
|
|
4519
4874
|
let nextConfig = configSnapshot.content;
|
|
4520
4875
|
if (configSnapshot.content !== null) {
|
|
4521
4876
|
const parsed = parseCodexOwnershipBlock(configSnapshot.content);
|
|
@@ -4531,17 +4886,17 @@ var removeCodexIntegration = ({ environment = process.env, readFileSync: readFil
|
|
|
4531
4886
|
}
|
|
4532
4887
|
const nextInstructions = instructionsSnapshot.content === null ? null : removeManagedCodexGuidance(instructionsSnapshot.content);
|
|
4533
4888
|
if (nextConfig !== configSnapshot.content && nextConfig !== null) {
|
|
4534
|
-
|
|
4535
|
-
|
|
4889
|
+
mkdirSync8(dirname10(codexConfigPath), { recursive: true, mode: 448 });
|
|
4890
|
+
writeFileSync8(codexConfigPath, nextConfig, {
|
|
4536
4891
|
mode: configSnapshot.mode ?? 384
|
|
4537
4892
|
});
|
|
4538
4893
|
}
|
|
4539
4894
|
if (nextInstructions !== instructionsSnapshot.content && nextInstructions !== null) {
|
|
4540
|
-
|
|
4895
|
+
mkdirSync8(dirname10(codexInstructionsPath), {
|
|
4541
4896
|
recursive: true,
|
|
4542
4897
|
mode: 448
|
|
4543
4898
|
});
|
|
4544
|
-
|
|
4899
|
+
writeFileSync8(codexInstructionsPath, nextInstructions, {
|
|
4545
4900
|
mode: instructionsSnapshot.mode ?? 384
|
|
4546
4901
|
});
|
|
4547
4902
|
}
|
|
@@ -4557,14 +4912,14 @@ var removeCodexIntegration = ({ environment = process.env, readFileSync: readFil
|
|
|
4557
4912
|
const failures = [error instanceof Error ? error.message : String(error)];
|
|
4558
4913
|
if (configSnapshot) {
|
|
4559
4914
|
try {
|
|
4560
|
-
restoreManagedFile(codexConfigPath, configSnapshot,
|
|
4915
|
+
restoreManagedFile(codexConfigPath, configSnapshot, existsSync13, writeFileSync8, mkdirSync8);
|
|
4561
4916
|
} catch (restoreError) {
|
|
4562
4917
|
failures.push(`Codex configuration rollback failed: ${restoreError instanceof Error ? restoreError.message : String(restoreError)}`);
|
|
4563
4918
|
}
|
|
4564
4919
|
}
|
|
4565
4920
|
if (instructionsSnapshot) {
|
|
4566
4921
|
try {
|
|
4567
|
-
restoreManagedFile(codexInstructionsPath, instructionsSnapshot,
|
|
4922
|
+
restoreManagedFile(codexInstructionsPath, instructionsSnapshot, existsSync13, writeFileSync8, mkdirSync8);
|
|
4568
4923
|
} catch (restoreError) {
|
|
4569
4924
|
failures.push(`Codex global instructions rollback failed: ${restoreError instanceof Error ? restoreError.message : String(restoreError)}`);
|
|
4570
4925
|
}
|
|
@@ -4588,12 +4943,12 @@ var removeCodexIntegration = ({ environment = process.env, readFileSync: readFil
|
|
|
4588
4943
|
var repairCodexIntegration = async (options = {}) => {
|
|
4589
4944
|
if (resolveKoedAppRuntimeExecution() !== "packaged")
|
|
4590
4945
|
return configureCodexProfile(options);
|
|
4591
|
-
const
|
|
4592
|
-
const
|
|
4946
|
+
const readFileSync8 = options.readFileSync ?? nodeReadFileSync;
|
|
4947
|
+
const existsSync13 = options.existsSync ?? nodeExistsSync;
|
|
4593
4948
|
let environment = options.environment ?? process.env;
|
|
4594
4949
|
const paths = resolveKoedServerPaths(environment);
|
|
4595
4950
|
ensureKoedHome(paths);
|
|
4596
|
-
environment = applyActiveRuntimeUrls(applyPersistedLocalPorts(paths, environment), readActiveRuntimeState(paths.runtimeStatePath,
|
|
4951
|
+
environment = applyActiveRuntimeUrls(applyPersistedLocalPorts(paths, environment), readActiveRuntimeState(paths.runtimeStatePath, readFileSync8, options.checkPid ?? isProcessRunning));
|
|
4597
4952
|
const repoEnv = loadRepoEnv(paths.repoRoot);
|
|
4598
4953
|
if (!resolveActiveIntegrationApiToken(paths, environment, repoEnv))
|
|
4599
4954
|
return configureCodexProfile({ ...options, environment });
|
|
@@ -4603,7 +4958,7 @@ var repairCodexIntegration = async (options = {}) => {
|
|
|
4603
4958
|
queue: "bullmq",
|
|
4604
4959
|
native: [],
|
|
4605
4960
|
models: []
|
|
4606
|
-
},
|
|
4961
|
+
}, existsSync13, options.desktopRuntimeCapability);
|
|
4607
4962
|
return configureCodexProfile({
|
|
4608
4963
|
...options,
|
|
4609
4964
|
environment,
|
|
@@ -4611,11 +4966,11 @@ var repairCodexIntegration = async (options = {}) => {
|
|
|
4611
4966
|
});
|
|
4612
4967
|
};
|
|
4613
4968
|
var configureCodexIntegrationForRemoteBackend = (options) => configureCodexProfile(options, options);
|
|
4614
|
-
var configureCodexProfile = ({ environment = process.env, readFileSync:
|
|
4969
|
+
var configureCodexProfile = ({ environment = process.env, readFileSync: readFileSync8 = nodeReadFileSync, writeFileSync: writeFileSync8 = nodeWriteFileSync, mkdirSync: mkdirSync8 = nodeMkdirSync, existsSync: existsSync13 = nodeExistsSync, checkPid = isProcessRunning, resolveRuntime = resolveKoedAppRuntime, registerAiClient = registerExplicitAiClient, resolveCodexExecutable = resolveCodexExecutablePath, now = () => /* @__PURE__ */ new Date() }, remote) => {
|
|
4615
4970
|
const paths = resolveKoedServerPaths(environment);
|
|
4616
4971
|
ensureKoedHome(paths);
|
|
4617
4972
|
if (!remote) {
|
|
4618
|
-
environment = applyActiveRuntimeUrls(applyPersistedLocalPorts(paths, environment), readActiveRuntimeState(paths.runtimeStatePath,
|
|
4973
|
+
environment = applyActiveRuntimeUrls(applyPersistedLocalPorts(paths, environment), readActiveRuntimeState(paths.runtimeStatePath, readFileSync8, checkPid));
|
|
4619
4974
|
}
|
|
4620
4975
|
const repoEnv = remote ? {} : loadRepoEnv(paths.repoRoot);
|
|
4621
4976
|
const apiUrl = remote?.apiUrl ?? resolveApiUrl(environment, repoEnv);
|
|
@@ -4646,18 +5001,18 @@ var configureCodexProfile = ({ environment = process.env, readFileSync: readFile
|
|
|
4646
5001
|
try {
|
|
4647
5002
|
assertAiClientRegistryWritable(integrationEnvironment);
|
|
4648
5003
|
registrySnapshot = captureAiClientRegistry(integrationEnvironment);
|
|
4649
|
-
configSnapshot = captureManagedFile(codexConfigPath,
|
|
4650
|
-
instructionsSnapshot = captureManagedFile(codexInstructionsPath,
|
|
5004
|
+
configSnapshot = captureManagedFile(codexConfigPath, existsSync13, readFileSync8);
|
|
5005
|
+
instructionsSnapshot = captureManagedFile(codexInstructionsPath, existsSync13, readFileSync8);
|
|
4651
5006
|
const codexExecutablePath = resolveCodexExecutable(integrationEnvironment);
|
|
4652
5007
|
const result = configureCodexIntegration({
|
|
4653
5008
|
paths,
|
|
4654
5009
|
environment: integrationEnvironment,
|
|
4655
5010
|
apiUrl,
|
|
4656
|
-
readFileSync:
|
|
4657
|
-
writeFileSync:
|
|
4658
|
-
mkdirSync:
|
|
4659
|
-
existsSync:
|
|
4660
|
-
memoryGuidanceEnabled: resolveKoedServerConfig(paths, { ...repoEnv, ...environment }, { existsSync:
|
|
5011
|
+
readFileSync: readFileSync8,
|
|
5012
|
+
writeFileSync: writeFileSync8,
|
|
5013
|
+
mkdirSync: mkdirSync8,
|
|
5014
|
+
existsSync: existsSync13,
|
|
5015
|
+
memoryGuidanceEnabled: resolveKoedServerConfig(paths, { ...repoEnv, ...environment }, { existsSync: existsSync13, readFileSync: readFileSync8 }).codexGlobalMemoryGuidanceEnabled,
|
|
4661
5016
|
resolveRuntime
|
|
4662
5017
|
});
|
|
4663
5018
|
const registered = registerAiClient({
|
|
@@ -4679,20 +5034,20 @@ var configureCodexProfile = ({ environment = process.env, readFileSync: readFile
|
|
|
4679
5034
|
stdout: result.stdout,
|
|
4680
5035
|
action: "Restart Codex and trust updated hooks if prompted. New sessions will be captured after Codex reloads this config."
|
|
4681
5036
|
};
|
|
4682
|
-
writeSetupVerification(paths, repaired,
|
|
5037
|
+
writeSetupVerification(paths, repaired, writeFileSync8);
|
|
4683
5038
|
return repaired;
|
|
4684
5039
|
} catch (error) {
|
|
4685
5040
|
const failures = [error instanceof Error ? error.message : String(error)];
|
|
4686
5041
|
if (configSnapshot) {
|
|
4687
5042
|
try {
|
|
4688
|
-
restoreManagedFile(codexConfigPath, configSnapshot,
|
|
5043
|
+
restoreManagedFile(codexConfigPath, configSnapshot, existsSync13, writeFileSync8, mkdirSync8);
|
|
4689
5044
|
} catch (restoreError) {
|
|
4690
5045
|
failures.push(`Codex profile rollback failed: ${restoreError instanceof Error ? restoreError.message : String(restoreError)}`);
|
|
4691
5046
|
}
|
|
4692
5047
|
}
|
|
4693
5048
|
if (instructionsSnapshot) {
|
|
4694
5049
|
try {
|
|
4695
|
-
restoreManagedFile(codexInstructionsPath, instructionsSnapshot,
|
|
5050
|
+
restoreManagedFile(codexInstructionsPath, instructionsSnapshot, existsSync13, writeFileSync8, mkdirSync8);
|
|
4696
5051
|
} catch (restoreError) {
|
|
4697
5052
|
failures.push(`Codex global instructions rollback failed: ${restoreError instanceof Error ? restoreError.message : String(restoreError)}`);
|
|
4698
5053
|
}
|
|
@@ -4714,7 +5069,7 @@ var configureCodexProfile = ({ environment = process.env, readFileSync: readFile
|
|
|
4714
5069
|
error: failures.join(" "),
|
|
4715
5070
|
action: "Review the reported failure, fix the Codex integration artifacts, then run the Codex-specific repair action again."
|
|
4716
5071
|
};
|
|
4717
|
-
writeSetupVerification(paths, failed,
|
|
5072
|
+
writeSetupVerification(paths, failed, writeFileSync8);
|
|
4718
5073
|
return failed;
|
|
4719
5074
|
}
|
|
4720
5075
|
};
|
|
@@ -4887,8 +5242,8 @@ var runSetupBootstrap = (context, spawnSync) => {
|
|
|
4887
5242
|
action: "Review stdout/stderr, fix the reported client setup failure, then rerun koed setup codex --json."
|
|
4888
5243
|
};
|
|
4889
5244
|
};
|
|
4890
|
-
var writeSetupVerification = (paths, result,
|
|
4891
|
-
|
|
5245
|
+
var writeSetupVerification = (paths, result, writeFileSync8, successMessage = "Koed core setup completed.") => {
|
|
5246
|
+
writeFileSync8(paths.lastVerificationPath, `${JSON.stringify({
|
|
4892
5247
|
ok: result.ok,
|
|
4893
5248
|
checkedAt: result.checkedAt,
|
|
4894
5249
|
message: result.ok ? successMessage : result.error
|
|
@@ -4945,10 +5300,10 @@ var setupCore = async (options = {}) => {
|
|
|
4945
5300
|
};
|
|
4946
5301
|
var setupCodex = async (options = {}) => {
|
|
4947
5302
|
const core = await setupCore(options);
|
|
4948
|
-
const
|
|
5303
|
+
const writeFileSync8 = options.writeFileSync ?? nodeWriteFileSync;
|
|
4949
5304
|
if (!core.ok) {
|
|
4950
5305
|
const paths2 = resolveKoedServerPaths(options.environment ?? process.env);
|
|
4951
|
-
writeSetupVerification(paths2, core,
|
|
5306
|
+
writeSetupVerification(paths2, core, writeFileSync8, "Codex setup completed.");
|
|
4952
5307
|
return core;
|
|
4953
5308
|
}
|
|
4954
5309
|
const environment = options.environment ?? process.env;
|
|
@@ -4961,7 +5316,7 @@ var setupCodex = async (options = {}) => {
|
|
|
4961
5316
|
writeCodexGlobalMemoryGuidancePreference(paths, config.codexGlobalMemoryGuidanceEnabled, {
|
|
4962
5317
|
existsSync: options.existsSync,
|
|
4963
5318
|
readFileSync: options.readFileSync,
|
|
4964
|
-
writeFileSync:
|
|
5319
|
+
writeFileSync: writeFileSync8
|
|
4965
5320
|
});
|
|
4966
5321
|
}
|
|
4967
5322
|
const runtime = options.resolveRuntime ? options.resolveRuntime(paths, environment, options.existsSync ?? nodeExistsSync) : resolveKoedAppRuntimeExecution() === "packaged" ? await resolveVerifiedPackagedRuntime(paths, environment, {
|
|
@@ -4988,7 +5343,7 @@ var setupCodex = async (options = {}) => {
|
|
|
4988
5343
|
}
|
|
4989
5344
|
const prepared = prepareSetupCodex(environment, options);
|
|
4990
5345
|
if (!prepared.ok) {
|
|
4991
|
-
writeSetupVerification(prepared.paths, prepared.result,
|
|
5346
|
+
writeSetupVerification(prepared.paths, prepared.result, writeFileSync8);
|
|
4992
5347
|
return prepared.result;
|
|
4993
5348
|
}
|
|
4994
5349
|
const { context } = prepared;
|
|
@@ -5005,7 +5360,7 @@ var setupCodex = async (options = {}) => {
|
|
|
5005
5360
|
error: error instanceof Error ? error.message : String(error),
|
|
5006
5361
|
action: "Fix malformed AI Client registry, then rerun Codex setup."
|
|
5007
5362
|
};
|
|
5008
|
-
writeSetupVerification(context.paths, failed,
|
|
5363
|
+
writeSetupVerification(context.paths, failed, writeFileSync8, "Codex setup completed.");
|
|
5009
5364
|
return failed;
|
|
5010
5365
|
}
|
|
5011
5366
|
let codexExecutablePath;
|
|
@@ -5022,7 +5377,7 @@ var setupCodex = async (options = {}) => {
|
|
|
5022
5377
|
error: error instanceof Error ? error.message : String(error),
|
|
5023
5378
|
action: "Install Codex or set MEMORY_CODEX_APP_SERVER_BINARY, then rerun Codex setup."
|
|
5024
5379
|
};
|
|
5025
|
-
writeSetupVerification(context.paths, failed,
|
|
5380
|
+
writeSetupVerification(context.paths, failed, writeFileSync8, "Codex setup completed.");
|
|
5026
5381
|
return failed;
|
|
5027
5382
|
}
|
|
5028
5383
|
persistSetupApiToken(context);
|
|
@@ -5047,15 +5402,16 @@ var setupCodex = async (options = {}) => {
|
|
|
5047
5402
|
error: error instanceof Error ? error.message : String(error),
|
|
5048
5403
|
action: "Fix the Codex-specific registration, then rerun koed setup codex --json."
|
|
5049
5404
|
};
|
|
5050
|
-
writeSetupVerification(context.paths, failed,
|
|
5405
|
+
writeSetupVerification(context.paths, failed, writeFileSync8, "Codex setup completed.");
|
|
5051
5406
|
return failed;
|
|
5052
5407
|
}
|
|
5053
5408
|
}
|
|
5054
|
-
writeSetupVerification(context.paths, result,
|
|
5409
|
+
writeSetupVerification(context.paths, result, writeFileSync8, "Codex setup completed.");
|
|
5055
5410
|
return result;
|
|
5056
5411
|
};
|
|
5057
5412
|
|
|
5058
5413
|
export {
|
|
5414
|
+
hasCompletePostgresOverride,
|
|
5059
5415
|
stopLocalPostgresRuntime,
|
|
5060
5416
|
startLocalPostgresRuntime,
|
|
5061
5417
|
ensurePackagedLocalServiceSecrets,
|
|
@@ -5075,6 +5431,10 @@ export {
|
|
|
5075
5431
|
resolveClaudeExecutablePath,
|
|
5076
5432
|
removeClaude,
|
|
5077
5433
|
setupClaude,
|
|
5434
|
+
aiClientConnectionRevision,
|
|
5435
|
+
grantAiClientConnection,
|
|
5436
|
+
revokeAiClientConnection,
|
|
5437
|
+
nativeLlamaServerOverride,
|
|
5078
5438
|
startLocalEmbeddingRuntime,
|
|
5079
5439
|
startLocalPrivacyRuntime,
|
|
5080
5440
|
inspectPi,
|