@jingyi0605/codingns 0.6.1 → 0.6.5
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/bin/codingns.mjs +225 -0
- package/dist/public/assets/AdaptiveButlerPage-CfsUVZKl.js +3 -0
- package/dist/public/assets/{App-Dsf3ooXU.js → App-B9HcTkMT.js} +3 -3
- package/dist/public/assets/{BootstrapPage-CE0m1qSR.js → BootstrapPage-BgLdZEKQ.js} +1 -1
- package/dist/public/assets/ConversationPage-Cj8go7L0.js +4 -0
- package/dist/public/assets/{DesktopDetachPreviewPage-Dxarr_Wf.js → DesktopDetachPreviewPage-YCBnyC58.js} +1 -1
- package/dist/public/assets/{DesktopWindowPage-VytPwJ4c.js → DesktopWindowPage-CrvndE23.js} +1 -1
- package/dist/public/assets/{FileContextPanel-DwFzLsOp.js → FileContextPanel-CdC7GGw5.js} +1 -1
- package/dist/public/assets/{GitSidebar-CH6WqTrM.js → GitSidebar-z2SBinQh.js} +1 -1
- package/dist/public/assets/{MobileCreateSessionSheet-DcxKM00P.js → MobileCreateSessionSheet-Cb2HM-y3.js} +1 -1
- package/dist/public/assets/{MobileTopHeaderFrame-C5rIKQT6.js → MobileTopHeaderFrame-etF2HKlm.js} +1 -1
- package/dist/public/assets/{MobileWorkspaceSwitcherHeader-CfUnHgv_.js → MobileWorkspaceSwitcherHeader-CuGJ31kb.js} +1 -1
- package/dist/public/assets/{RelayConnectEntryPage-CgMvVZwa.js → RelayConnectEntryPage-BB6DbGtP.js} +1 -1
- package/dist/public/assets/{ServerSettingsModal-CFul__z1.js → ServerSettingsModal-Bl1sacZg.js} +1 -1
- package/dist/public/assets/{SessionIndexPage-B-tRhBXC.js → SessionIndexPage-NbF9gJnp.js} +1 -1
- package/dist/public/assets/SettingsPage-DGsmQpLv.js +1 -0
- package/dist/public/assets/{TerminalManagerPanel-BbORd-ee.js → TerminalManagerPanel-BOm8Hi_v.js} +1 -1
- package/dist/public/assets/{TerminalPage-DWHv6mlu.js → TerminalPage-B5JNFU6w.js} +19 -19
- package/dist/public/assets/{TerminalRuntimeFallbackModal-B29YxbQe.js → TerminalRuntimeFallbackModal-CM3LRKOJ.js} +1 -1
- package/dist/public/assets/{ToolFilesPage-Dx9cv9hu.js → ToolFilesPage-GSqKQsj_.js} +1 -1
- package/dist/public/assets/{ToolGitPage-D7H3vAia.js → ToolGitPage-BVFWMMQp.js} +1 -1
- package/dist/public/assets/{ToolProcessesPage-PqQWxsy-.js → ToolProcessesPage-DZ456fYz.js} +1 -1
- package/dist/public/assets/{ToolsHomePage-CX05Pe_4.js → ToolsHomePage-DsJp0y8A.js} +1 -1
- package/dist/public/assets/{WorkbenchLandingPage-CchkAC75.js → WorkbenchLandingPage-DyPei0e-.js} +1 -1
- package/dist/public/assets/WorkbenchLayout-DlbgBT3n.js +4 -0
- package/dist/public/assets/WorkbenchModal-LNfB69qx.js +1 -0
- package/dist/public/assets/WorkbenchShellRoute-BsxumYx5.js +1 -0
- package/dist/public/assets/{WorkbenchShellRoute-RGZpA0_J.css → WorkbenchShellRoute-DhQo_0vu.css} +1 -1
- package/dist/public/assets/{WorkspaceDebugDetailPage-Deqy2_pO.js → WorkspaceDebugDetailPage-CaXj5zVI.js} +1 -1
- package/dist/public/assets/{WorkspaceDetailPage-Cvf-ZdlB.js → WorkspaceDetailPage-DOexuuaw.js} +1 -1
- package/dist/public/assets/{WorkspaceHomePage-Dsyvqyk1.js → WorkspaceHomePage-DkCHNjKD.js} +1 -1
- package/dist/public/assets/{client-runtime-manager-DROQJ9v3.js → client-runtime-manager-6OoYHXGd.js} +1 -1
- package/dist/public/assets/{file-tree-icon-Bp3Ntt7u.js → file-tree-icon-9pt1OStn.js} +1 -1
- package/dist/public/assets/index-BwlbvwaA.css +1 -0
- package/dist/public/assets/index-DSw-TkQL.js +42 -0
- package/dist/public/assets/{login-direct-candidate-resolver-DotM530R.js → login-direct-candidate-resolver-CLlYtBRq.js} +1 -1
- package/dist/public/assets/model-switch-api-C-l8-E1S.js +1 -0
- package/dist/public/assets/{preferences-service-BG6GKG29.js → preferences-service-BCcfYP_d.js} +1 -1
- package/dist/public/assets/{relay-entry-pmr-c42O.js → relay-entry-BmLkMKuq.js} +1 -1
- package/dist/public/assets/session-runtime-machine-DgtvREca.js +21 -0
- package/dist/public/assets/{terminal-runtime-meta-8_uRZf7h.js → terminal-runtime-meta-0h-75uRy.js} +1 -1
- package/dist/public/assets/{useRegisteredDebugTemplates-DWX7LXQu.js → useRegisteredDebugTemplates-rBVmAqh3.js} +1 -1
- package/dist/public/index.html +2 -2
- package/dist/server/modules/assistant-capability/assistant-capability-service.d.ts +4 -1
- package/dist/server/modules/assistant-capability/assistant-capability-service.js +12 -1
- package/dist/server/modules/assistant-capability/assistant-capability-service.js.map +1 -1
- package/dist/server/modules/butler/butler-control-session-service.d.ts +4 -1
- package/dist/server/modules/butler/butler-control-session-service.js +17 -1
- package/dist/server/modules/butler/butler-control-session-service.js.map +1 -1
- package/dist/server/modules/butler/butler-profile-service.d.ts +3 -1
- package/dist/server/modules/butler/butler-profile-service.js +16 -4
- package/dist/server/modules/butler/butler-profile-service.js.map +1 -1
- package/dist/server/modules/opencli/opencli-bridge-skill-service.d.ts +12 -0
- package/dist/server/modules/opencli/opencli-bridge-skill-service.js +124 -0
- package/dist/server/modules/opencli/opencli-bridge-skill-service.js.map +1 -0
- package/dist/server/modules/opencli/opencli-catalog-service.d.ts +50 -0
- package/dist/server/modules/opencli/opencli-catalog-service.js +345 -0
- package/dist/server/modules/opencli/opencli-catalog-service.js.map +1 -0
- package/dist/server/modules/opencli/opencli-controller.d.ts +13 -0
- package/dist/server/modules/opencli/opencli-controller.js +30 -0
- package/dist/server/modules/opencli/opencli-controller.js.map +1 -0
- package/dist/server/modules/opencli/opencli-health-service.d.ts +28 -0
- package/dist/server/modules/opencli/opencli-health-service.js +106 -0
- package/dist/server/modules/opencli/opencli-health-service.js.map +1 -0
- package/dist/server/modules/opencli/opencli-install-discovery.d.ts +23 -0
- package/dist/server/modules/opencli/opencli-install-discovery.js +130 -0
- package/dist/server/modules/opencli/opencli-install-discovery.js.map +1 -0
- package/dist/server/modules/opencli/opencli-management-service.d.ts +59 -0
- package/dist/server/modules/opencli/opencli-management-service.js +152 -0
- package/dist/server/modules/opencli/opencli-management-service.js.map +1 -0
- package/dist/server/modules/opencli/opencli-runtime-builder.d.ts +11 -0
- package/dist/server/modules/opencli/opencli-runtime-builder.js +214 -0
- package/dist/server/modules/opencli/opencli-runtime-builder.js.map +1 -0
- package/dist/server/modules/opencli/opencli-runtime-layout.d.ts +3 -0
- package/dist/server/modules/opencli/opencli-runtime-layout.js +11 -0
- package/dist/server/modules/opencli/opencli-runtime-layout.js.map +1 -0
- package/dist/server/modules/opencli/opencli-runtime-profile-service.d.ts +29 -0
- package/dist/server/modules/opencli/opencli-runtime-profile-service.js +104 -0
- package/dist/server/modules/opencli/opencli-runtime-profile-service.js.map +1 -0
- package/dist/server/modules/opencli/opencli-runtime-resolver.d.ts +29 -0
- package/dist/server/modules/opencli/opencli-runtime-resolver.js +110 -0
- package/dist/server/modules/opencli/opencli-runtime-resolver.js.map +1 -0
- package/dist/server/modules/opencli/opencli-session-prompt-service.d.ts +11 -0
- package/dist/server/modules/opencli/opencli-session-prompt-service.js +66 -0
- package/dist/server/modules/opencli/opencli-session-prompt-service.js.map +1 -0
- package/dist/server/modules/provider/provider-catalog-service.d.ts +46 -0
- package/dist/server/modules/provider/provider-catalog-service.js +249 -0
- package/dist/server/modules/provider/provider-catalog-service.js.map +1 -0
- package/dist/server/modules/provider/provider-controller.d.ts +15 -2
- package/dist/server/modules/provider/provider-controller.js +44 -6
- package/dist/server/modules/provider/provider-controller.js.map +1 -1
- package/dist/server/modules/provider/provider-disabled.d.ts +8 -0
- package/dist/server/modules/provider/provider-disabled.js +45 -0
- package/dist/server/modules/provider/provider-disabled.js.map +1 -0
- package/dist/server/modules/provider/provider-discovery-helper-client.d.ts +1 -0
- package/dist/server/modules/provider/provider-discovery-helper-client.js.map +1 -1
- package/dist/server/modules/provider/provider-discovery-helper-process.js +3 -3
- package/dist/server/modules/provider/provider-discovery-helper-process.js.map +1 -1
- package/dist/server/modules/provider/provider-discovery-runtime.d.ts +1 -1
- package/dist/server/modules/provider/provider-discovery-runtime.js +12 -8
- package/dist/server/modules/provider/provider-discovery-runtime.js.map +1 -1
- package/dist/server/modules/sessions/claude-compatible-provider-registry.d.ts +16 -0
- package/dist/server/modules/sessions/claude-compatible-provider-registry.js +91 -0
- package/dist/server/modules/sessions/claude-compatible-provider-registry.js.map +1 -0
- package/dist/server/modules/sessions/session-history-service.d.ts +7 -1
- package/dist/server/modules/sessions/session-history-service.js +49 -16
- package/dist/server/modules/sessions/session-history-service.js.map +1 -1
- package/dist/server/modules/sessions/session-live-runtime-router-service.js +9 -4
- package/dist/server/modules/sessions/session-live-runtime-router-service.js.map +1 -1
- package/dist/server/modules/sessions/session-live-runtime-service.d.ts +8 -4
- package/dist/server/modules/sessions/session-live-runtime-service.js +100 -87
- package/dist/server/modules/sessions/session-live-runtime-service.js.map +1 -1
- package/dist/server/modules/sessions/session-permission-request-service.d.ts +5 -2
- package/dist/server/modules/sessions/session-permission-request-service.js +26 -27
- package/dist/server/modules/sessions/session-permission-request-service.js.map +1 -1
- package/dist/server/modules/sessions/session-provider-config-service.d.ts +17 -1
- package/dist/server/modules/sessions/session-provider-config-service.js +121 -17
- package/dist/server/modules/sessions/session-provider-config-service.js.map +1 -1
- package/dist/server/modules/skills/skill-manager-service.d.ts +5 -0
- package/dist/server/modules/skills/skill-manager-service.js +26 -0
- package/dist/server/modules/skills/skill-manager-service.js.map +1 -1
- package/dist/server/modules/tasks/task-helper-process-handlers.d.ts +1 -0
- package/dist/server/modules/tasks/task-helper-process-handlers.js +1 -1
- package/dist/server/modules/tasks/task-helper-process-handlers.js.map +1 -1
- package/dist/server/routes/opencli.d.ts +3 -0
- package/dist/server/routes/opencli.js +7 -0
- package/dist/server/routes/opencli.js.map +1 -0
- package/dist/server/routes/providers.js +4 -2
- package/dist/server/routes/providers.js.map +1 -1
- package/dist/server/server/create-server.d.ts +8 -0
- package/dist/server/server/create-server.js +44 -11
- package/dist/server/server/create-server.js.map +1 -1
- package/dist/server/storage/repositories/opencli-catalog-entry-repository.d.ts +9 -0
- package/dist/server/storage/repositories/opencli-catalog-entry-repository.js +85 -0
- package/dist/server/storage/repositories/opencli-catalog-entry-repository.js.map +1 -0
- package/dist/server/storage/repositories/opencli-provider-repository.d.ts +8 -0
- package/dist/server/storage/repositories/opencli-provider-repository.js +88 -0
- package/dist/server/storage/repositories/opencli-provider-repository.js.map +1 -0
- package/dist/server/storage/repositories/opencli-runtime-profile-repository.d.ts +11 -0
- package/dist/server/storage/repositories/opencli-runtime-profile-repository.js +127 -0
- package/dist/server/storage/repositories/opencli-runtime-profile-repository.js.map +1 -0
- package/dist/server/storage/repositories/provider-control-repository.d.ts +9 -0
- package/dist/server/storage/repositories/provider-control-repository.js +51 -0
- package/dist/server/storage/repositories/provider-control-repository.js.map +1 -0
- package/dist/server/storage/sqlite/client.js +53 -0
- package/dist/server/storage/sqlite/client.js.map +1 -1
- package/dist/server/storage/sqlite/schema.sql +66 -0
- package/dist/server/types/domain.d.ts +50 -0
- package/node_modules/@codingns/session-sync-core/dist/runtime/legna-runtime.d.ts +5 -0
- package/node_modules/@codingns/session-sync-core/dist/runtime/legna-runtime.js +1 -1
- package/node_modules/@codingns/session-sync-core/dist/runtime/legna-runtime.js.map +1 -1
- package/package.json +1 -1
- package/dist/public/assets/AdaptiveButlerPage-Dw72U3hG.js +0 -3
- package/dist/public/assets/ConversationPage-8wOY7SX-.js +0 -4
- package/dist/public/assets/SettingsPage-C9LGxSQZ.js +0 -1
- package/dist/public/assets/WorkbenchLayout-pOZvEqp7.js +0 -3
- package/dist/public/assets/WorkbenchModal-ColqvV6a.js +0 -1
- package/dist/public/assets/WorkbenchShellRoute-C0_h4lP6.js +0 -1
- package/dist/public/assets/index-B84Po2NA.css +0 -1
- package/dist/public/assets/index-C-0oeG_5.js +0 -42
- package/dist/public/assets/model-switch-api-Bh9nYslz.js +0 -1
- package/dist/public/assets/session-runtime-machine-YN84QBlr.js +0 -21
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { nowIso } from "../../shared/utils/time.js";
|
|
4
|
+
import { createOpenCliRuntimeStagingRoot } from "./opencli-runtime-layout.js";
|
|
5
|
+
export class OpenCliRuntimeBuilder {
|
|
6
|
+
runtimeProfileRepository;
|
|
7
|
+
now;
|
|
8
|
+
constructor(runtimeProfileRepository, options = {}) {
|
|
9
|
+
this.runtimeProfileRepository = runtimeProfileRepository;
|
|
10
|
+
this.now = options.now ?? nowIso;
|
|
11
|
+
}
|
|
12
|
+
buildProfile(profileOrId) {
|
|
13
|
+
const profile = resolveProfile(this.runtimeProfileRepository, profileOrId);
|
|
14
|
+
if (profile.status === "ready" && runtimeRootLooksUsable(profile.runtimeRootPath)) {
|
|
15
|
+
return profile;
|
|
16
|
+
}
|
|
17
|
+
const stagingRootPath = createOpenCliRuntimeStagingRoot(profile.runtimeRootPath);
|
|
18
|
+
try {
|
|
19
|
+
const enabledCommandIds = parseEnabledCommandIds(profile.enabledCommandIdsJson);
|
|
20
|
+
const sourceLayout = readOpenCliSourceLayout(profile.sourceInstallPath);
|
|
21
|
+
const filteredManifest = filterManifestEntries(sourceLayout.manifestEntries, enabledCommandIds);
|
|
22
|
+
const enabledSites = new Set(filteredManifest.map((entry) => normalizeManifestCommandId(entry).site));
|
|
23
|
+
fs.rmSync(stagingRootPath, { recursive: true, force: true });
|
|
24
|
+
fs.mkdirSync(stagingRootPath, { recursive: true });
|
|
25
|
+
copyPackageJson(sourceLayout.packageJsonPath, path.join(stagingRootPath, "package.json"));
|
|
26
|
+
writeManifest(path.join(stagingRootPath, "cli-manifest.json"), filteredManifest);
|
|
27
|
+
linkDirectory(sourceLayout.distPath, path.join(stagingRootPath, "dist"));
|
|
28
|
+
if (sourceLayout.nodeModulesPath) {
|
|
29
|
+
linkDirectory(sourceLayout.nodeModulesPath, path.join(stagingRootPath, "node_modules"));
|
|
30
|
+
}
|
|
31
|
+
copyPrunedClis({
|
|
32
|
+
sourceClisRoot: sourceLayout.clisPath,
|
|
33
|
+
targetClisRoot: path.join(stagingRootPath, "clis"),
|
|
34
|
+
enabledSites
|
|
35
|
+
});
|
|
36
|
+
writeOpenCliShim(stagingRootPath);
|
|
37
|
+
fs.mkdirSync(path.dirname(profile.runtimeRootPath), { recursive: true });
|
|
38
|
+
fs.rmSync(profile.runtimeRootPath, { recursive: true, force: true });
|
|
39
|
+
fs.renameSync(stagingRootPath, profile.runtimeRootPath);
|
|
40
|
+
return this.runtimeProfileRepository.upsert({
|
|
41
|
+
...profile,
|
|
42
|
+
status: "ready",
|
|
43
|
+
updatedAt: this.now(),
|
|
44
|
+
lastErrorCode: null,
|
|
45
|
+
lastErrorDetail: null
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
fs.rmSync(stagingRootPath, { recursive: true, force: true });
|
|
50
|
+
return this.runtimeProfileRepository.upsert({
|
|
51
|
+
...profile,
|
|
52
|
+
status: "failed",
|
|
53
|
+
updatedAt: this.now(),
|
|
54
|
+
lastErrorCode: "OPENCLI_RUNTIME_BUILD_FAILED",
|
|
55
|
+
lastErrorDetail: error instanceof Error ? error.message : String(error)
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function resolveProfile(repository, profileOrId) {
|
|
61
|
+
if (typeof profileOrId !== "string") {
|
|
62
|
+
return profileOrId;
|
|
63
|
+
}
|
|
64
|
+
const profile = repository.findById(profileOrId);
|
|
65
|
+
if (!profile) {
|
|
66
|
+
throw new Error(`OPENCLI_RUNTIME_PROFILE_NOT_FOUND:${profileOrId}`);
|
|
67
|
+
}
|
|
68
|
+
return profile;
|
|
69
|
+
}
|
|
70
|
+
function runtimeRootLooksUsable(runtimeRootPath) {
|
|
71
|
+
return [
|
|
72
|
+
path.join(runtimeRootPath, "package.json"),
|
|
73
|
+
path.join(runtimeRootPath, "cli-manifest.json"),
|
|
74
|
+
path.join(runtimeRootPath, "clis"),
|
|
75
|
+
path.join(runtimeRootPath, "bin", "opencli")
|
|
76
|
+
].every((entryPath) => fs.existsSync(entryPath));
|
|
77
|
+
}
|
|
78
|
+
function parseEnabledCommandIds(value) {
|
|
79
|
+
const parsed = JSON.parse(value);
|
|
80
|
+
if (!Array.isArray(parsed) || parsed.some((entry) => typeof entry !== "string")) {
|
|
81
|
+
throw new Error("OPENCLI_RUNTIME_ENABLED_COMMAND_IDS_INVALID");
|
|
82
|
+
}
|
|
83
|
+
return new Set(parsed);
|
|
84
|
+
}
|
|
85
|
+
function readOpenCliSourceLayout(sourceInstallPath) {
|
|
86
|
+
const packageJsonPath = path.join(sourceInstallPath, "package.json");
|
|
87
|
+
const distPath = path.join(sourceInstallPath, "dist");
|
|
88
|
+
const clisPath = path.join(sourceInstallPath, "clis");
|
|
89
|
+
const nodeModulesPath = path.join(sourceInstallPath, "node_modules");
|
|
90
|
+
const manifestPath = path.join(sourceInstallPath, "cli-manifest.json");
|
|
91
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
92
|
+
throw new Error("OPENCLI_RUNTIME_SOURCE_PACKAGE_JSON_MISSING");
|
|
93
|
+
}
|
|
94
|
+
if (!fs.existsSync(distPath)) {
|
|
95
|
+
throw new Error("OPENCLI_RUNTIME_SOURCE_DIST_MISSING");
|
|
96
|
+
}
|
|
97
|
+
if (!fs.existsSync(clisPath)) {
|
|
98
|
+
throw new Error("OPENCLI_RUNTIME_SOURCE_CLIS_MISSING");
|
|
99
|
+
}
|
|
100
|
+
if (!fs.existsSync(manifestPath)) {
|
|
101
|
+
throw new Error("OPENCLI_RUNTIME_SOURCE_MANIFEST_MISSING");
|
|
102
|
+
}
|
|
103
|
+
const rawManifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
|
104
|
+
if (!Array.isArray(rawManifest)) {
|
|
105
|
+
throw new Error("OPENCLI_RUNTIME_SOURCE_MANIFEST_INVALID");
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
packageJsonPath,
|
|
109
|
+
distPath,
|
|
110
|
+
clisPath,
|
|
111
|
+
nodeModulesPath: fs.existsSync(nodeModulesPath) ? nodeModulesPath : null,
|
|
112
|
+
manifestEntries: rawManifest
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function filterManifestEntries(manifestEntries, enabledCommandIds) {
|
|
116
|
+
const filteredEntries = manifestEntries.filter((entry) => {
|
|
117
|
+
const { commandId } = normalizeManifestCommandId(entry);
|
|
118
|
+
return enabledCommandIds.has(commandId);
|
|
119
|
+
});
|
|
120
|
+
if (filteredEntries.length !== enabledCommandIds.size) {
|
|
121
|
+
const foundCommandIds = new Set(filteredEntries.map((entry) => normalizeManifestCommandId(entry).commandId));
|
|
122
|
+
for (const commandId of enabledCommandIds) {
|
|
123
|
+
if (!foundCommandIds.has(commandId)) {
|
|
124
|
+
throw new Error(`OPENCLI_RUNTIME_COMMAND_NOT_FOUND:${commandId}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return filteredEntries;
|
|
129
|
+
}
|
|
130
|
+
function normalizeManifestCommandId(entry) {
|
|
131
|
+
const site = typeof entry.site === "string" ? entry.site.trim() : "";
|
|
132
|
+
const name = typeof entry.name === "string" ? entry.name.trim() : "";
|
|
133
|
+
if (!site || !name) {
|
|
134
|
+
throw new Error("OPENCLI_RUNTIME_MANIFEST_ENTRY_INVALID");
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
commandId: `${site}/${name}`,
|
|
138
|
+
site
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function copyPackageJson(sourcePath, targetPath) {
|
|
142
|
+
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
|
|
143
|
+
fs.copyFileSync(sourcePath, targetPath);
|
|
144
|
+
}
|
|
145
|
+
function writeManifest(targetPath, manifestEntries) {
|
|
146
|
+
fs.writeFileSync(targetPath, `${JSON.stringify(manifestEntries, null, 2)}\n`, "utf8");
|
|
147
|
+
}
|
|
148
|
+
function linkDirectory(sourcePath, targetPath) {
|
|
149
|
+
fs.rmSync(targetPath, { recursive: true, force: true });
|
|
150
|
+
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
|
|
151
|
+
fs.symlinkSync(sourcePath, targetPath, process.platform === "win32" ? "junction" : "dir");
|
|
152
|
+
}
|
|
153
|
+
function copyPrunedClis(input) {
|
|
154
|
+
fs.mkdirSync(input.targetClisRoot, { recursive: true });
|
|
155
|
+
const entries = fs.readdirSync(input.sourceClisRoot, { withFileTypes: true });
|
|
156
|
+
for (const entry of entries) {
|
|
157
|
+
if (!entry.isDirectory()) {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
const shouldCopy = entry.name.startsWith("_") || input.enabledSites.has(entry.name);
|
|
161
|
+
if (!shouldCopy) {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
fs.cpSync(path.join(input.sourceClisRoot, entry.name), path.join(input.targetClisRoot, entry.name), { recursive: true });
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function writeOpenCliShim(runtimeRootPath) {
|
|
168
|
+
const binDir = path.join(runtimeRootPath, "bin");
|
|
169
|
+
const scriptPath = path.join(binDir, "opencli");
|
|
170
|
+
const cmdPath = path.join(binDir, "opencli.cmd");
|
|
171
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
172
|
+
fs.writeFileSync(scriptPath, `#!/usr/bin/env node
|
|
173
|
+
import { spawn } from "node:child_process";
|
|
174
|
+
import path from "node:path";
|
|
175
|
+
import { fileURLToPath } from "node:url";
|
|
176
|
+
|
|
177
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
178
|
+
const runtimeRoot = path.resolve(path.dirname(__filename), "..");
|
|
179
|
+
const mainScript = path.join(runtimeRoot, "dist", "src", "main.js");
|
|
180
|
+
const env = { ...process.env };
|
|
181
|
+
const realHome = env.CODINGNS_OPENCLI_REAL_HOME?.trim();
|
|
182
|
+
const realUserProfile = env.CODINGNS_OPENCLI_REAL_USERPROFILE?.trim();
|
|
183
|
+
|
|
184
|
+
if (realHome) {
|
|
185
|
+
env.HOME = realHome;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (realUserProfile) {
|
|
189
|
+
env.USERPROFILE = realUserProfile;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const child = spawn(process.execPath, ["--preserve-symlinks-main", mainScript, ...process.argv.slice(2)], {
|
|
193
|
+
stdio: "inherit",
|
|
194
|
+
env
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
child.on("error", (error) => {
|
|
198
|
+
process.stderr.write(\`\${error instanceof Error ? error.message : String(error)}\\n\`);
|
|
199
|
+
process.exit(1);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
child.on("exit", (code, signal) => {
|
|
203
|
+
if (signal) {
|
|
204
|
+
process.kill(process.pid, signal);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
process.exit(code ?? 1);
|
|
209
|
+
});
|
|
210
|
+
`, "utf8");
|
|
211
|
+
fs.chmodSync(scriptPath, 0o755);
|
|
212
|
+
fs.writeFileSync(cmdPath, "@echo off\r\nnode \"%~dp0\\opencli\" %*\r\n", "utf8");
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=opencli-runtime-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opencli-runtime-builder.js","sourceRoot":"","sources":["../../../../src/modules/opencli/opencli-runtime-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAGpD,OAAO,EAAE,+BAA+B,EAA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E,CAAC,aAAa,CACd,UAAU,EACV;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsCH,EACG,MAAM,CACP,CAAC;IACF,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IAChC,EAAE,CAAC,aAAa,CACd,OAAO,EACP,6CAA6C,EAC7C,MAAM,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function resolveOpenCliRuntimeStoreRoot(hostDataRootPath: string): string;
|
|
2
|
+
export declare function resolveOpenCliRuntimeRoot(hostDataRootPath: string, profileId: string): string;
|
|
3
|
+
export declare function createOpenCliRuntimeStagingRoot(runtimeRootPath: string): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
export function resolveOpenCliRuntimeStoreRoot(hostDataRootPath) {
|
|
3
|
+
return path.join(hostDataRootPath, "opencli-runtimes");
|
|
4
|
+
}
|
|
5
|
+
export function resolveOpenCliRuntimeRoot(hostDataRootPath, profileId) {
|
|
6
|
+
return path.join(resolveOpenCliRuntimeStoreRoot(hostDataRootPath), profileId);
|
|
7
|
+
}
|
|
8
|
+
export function createOpenCliRuntimeStagingRoot(runtimeRootPath) {
|
|
9
|
+
return `${runtimeRootPath}.tmp-${process.pid}-${Date.now()}`;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=opencli-runtime-layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opencli-runtime-layout.js","sourceRoot":"","sources":["../../../../src/modules/opencli/opencli-runtime-layout.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,UAAU,8BAA8B,CAAC,gBAAwB;IACrE,OAAO,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,CAAC;AACzD,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,gBAAwB,EAAE,SAAiB;IACnF,OAAO,IAAI,CAAC,IAAI,CAAC,8BAA8B,CAAC,gBAAgB,CAAC,EAAE,SAAS,CAAC,CAAC;AAChF,CAAC;AAED,MAAM,UAAU,+BAA+B,CAAC,eAAuB;IACrE,OAAO,GAAG,eAAe,QAAQ,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;AAC/D,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { OpenCliProviderRecord, OpenCliRuntimeProfileRecord } from "../../types/domain.js";
|
|
2
|
+
import type { OpenCliCatalogEntryRepository } from "../../storage/repositories/opencli-catalog-entry-repository.js";
|
|
3
|
+
import type { OpenCliProviderRepository } from "../../storage/repositories/opencli-provider-repository.js";
|
|
4
|
+
import type { OpenCliRuntimeProfileRepository } from "../../storage/repositories/opencli-runtime-profile-repository.js";
|
|
5
|
+
export interface OpenCliRuntimeProfileServiceOptions {
|
|
6
|
+
now?: () => string;
|
|
7
|
+
runtimeStorageRootPath: string;
|
|
8
|
+
}
|
|
9
|
+
export interface OpenCliDesiredRuntimeProfile {
|
|
10
|
+
provider: OpenCliProviderRecord;
|
|
11
|
+
enabledCommandIds: string[];
|
|
12
|
+
contentHash: string;
|
|
13
|
+
profile: OpenCliRuntimeProfileRecord;
|
|
14
|
+
}
|
|
15
|
+
export declare class OpenCliRuntimeProfileService {
|
|
16
|
+
private readonly providerRepository;
|
|
17
|
+
private readonly catalogEntryRepository;
|
|
18
|
+
private readonly runtimeProfileRepository;
|
|
19
|
+
private readonly now;
|
|
20
|
+
private readonly runtimeStorageRootPath;
|
|
21
|
+
constructor(providerRepository: OpenCliProviderRepository, catalogEntryRepository: OpenCliCatalogEntryRepository, runtimeProfileRepository: OpenCliRuntimeProfileRepository, options: OpenCliRuntimeProfileServiceOptions);
|
|
22
|
+
findOrCreateDesiredProfile(): OpenCliDesiredRuntimeProfile;
|
|
23
|
+
private markOutdatedProfilesAsStale;
|
|
24
|
+
}
|
|
25
|
+
export declare function computeOpenCliRuntimeProfileHash(input: {
|
|
26
|
+
version: string;
|
|
27
|
+
sourceInstallPath: string;
|
|
28
|
+
enabledCommandIds: readonly string[];
|
|
29
|
+
}): string;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { hashContent } from "../../shared/utils/hash.js";
|
|
3
|
+
import { nowIso } from "../../shared/utils/time.js";
|
|
4
|
+
import { resolveOpenCliRuntimeRoot } from "./opencli-runtime-layout.js";
|
|
5
|
+
export class OpenCliRuntimeProfileService {
|
|
6
|
+
providerRepository;
|
|
7
|
+
catalogEntryRepository;
|
|
8
|
+
runtimeProfileRepository;
|
|
9
|
+
now;
|
|
10
|
+
runtimeStorageRootPath;
|
|
11
|
+
constructor(providerRepository, catalogEntryRepository, runtimeProfileRepository, options) {
|
|
12
|
+
this.providerRepository = providerRepository;
|
|
13
|
+
this.catalogEntryRepository = catalogEntryRepository;
|
|
14
|
+
this.runtimeProfileRepository = runtimeProfileRepository;
|
|
15
|
+
this.now = options.now ?? nowIso;
|
|
16
|
+
this.runtimeStorageRootPath = path.resolve(options.runtimeStorageRootPath);
|
|
17
|
+
}
|
|
18
|
+
findOrCreateDesiredProfile() {
|
|
19
|
+
const provider = this.providerRepository.get();
|
|
20
|
+
const source = assertInstalledSource(provider);
|
|
21
|
+
const catalogEntries = this.catalogEntryRepository.list();
|
|
22
|
+
const enabledCommandIds = collectEnabledCommandIds(catalogEntries);
|
|
23
|
+
const contentHash = computeOpenCliRuntimeProfileHash({
|
|
24
|
+
version: source.version,
|
|
25
|
+
sourceInstallPath: source.installPath,
|
|
26
|
+
enabledCommandIds
|
|
27
|
+
});
|
|
28
|
+
this.markOutdatedProfilesAsStale(source.installPath, source.version);
|
|
29
|
+
const existingProfile = this.runtimeProfileRepository.findByContentHash(contentHash);
|
|
30
|
+
if (existingProfile) {
|
|
31
|
+
return {
|
|
32
|
+
provider,
|
|
33
|
+
enabledCommandIds,
|
|
34
|
+
contentHash,
|
|
35
|
+
profile: existingProfile
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const timestamp = this.now();
|
|
39
|
+
const profileId = `opencli-runtime-${contentHash.slice(0, 16)}`;
|
|
40
|
+
const profile = this.runtimeProfileRepository.upsert({
|
|
41
|
+
id: profileId,
|
|
42
|
+
version: source.version,
|
|
43
|
+
sourceInstallPath: source.installPath,
|
|
44
|
+
enabledCommandIdsJson: JSON.stringify(enabledCommandIds),
|
|
45
|
+
runtimeRootPath: resolveOpenCliRuntimeRoot(this.runtimeStorageRootPath, profileId),
|
|
46
|
+
status: "pending",
|
|
47
|
+
contentHash,
|
|
48
|
+
createdAt: timestamp,
|
|
49
|
+
updatedAt: timestamp,
|
|
50
|
+
lastErrorCode: null,
|
|
51
|
+
lastErrorDetail: null
|
|
52
|
+
});
|
|
53
|
+
return {
|
|
54
|
+
provider,
|
|
55
|
+
enabledCommandIds,
|
|
56
|
+
contentHash,
|
|
57
|
+
profile
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
markOutdatedProfilesAsStale(sourceInstallPath, version) {
|
|
61
|
+
const profiles = this.runtimeProfileRepository.list();
|
|
62
|
+
for (const profile of profiles) {
|
|
63
|
+
if (profile.status === "stale"
|
|
64
|
+
|| (profile.sourceInstallPath === sourceInstallPath && profile.version === version)) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
this.runtimeProfileRepository.upsert({
|
|
68
|
+
...profile,
|
|
69
|
+
status: "stale",
|
|
70
|
+
updatedAt: this.now()
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export function computeOpenCliRuntimeProfileHash(input) {
|
|
76
|
+
return hashContent(JSON.stringify({
|
|
77
|
+
version: input.version,
|
|
78
|
+
sourceInstallPath: input.sourceInstallPath,
|
|
79
|
+
enabledCommandIds: [...input.enabledCommandIds]
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
function collectEnabledCommandIds(entries) {
|
|
83
|
+
return entries
|
|
84
|
+
.filter((entry) => entry.enabled)
|
|
85
|
+
.sort((left, right) => {
|
|
86
|
+
if (left.sortOrder !== right.sortOrder) {
|
|
87
|
+
return left.sortOrder - right.sortOrder;
|
|
88
|
+
}
|
|
89
|
+
return left.commandId.localeCompare(right.commandId);
|
|
90
|
+
})
|
|
91
|
+
.map((entry) => entry.commandId);
|
|
92
|
+
}
|
|
93
|
+
function assertInstalledSource(provider) {
|
|
94
|
+
const installPath = provider.installPath?.trim() ?? "";
|
|
95
|
+
const version = provider.version?.trim() ?? "";
|
|
96
|
+
if (provider.installState !== "installed" || !installPath || !version) {
|
|
97
|
+
throw new Error("OPENCLI_RUNTIME_SOURCE_UNAVAILABLE");
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
installPath,
|
|
101
|
+
version
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=opencli-runtime-profile-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opencli-runtime-profile-service.js","sourceRoot":"","sources":["../../../../src/modules/opencli/opencli-runtime-profile-service.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AASpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAcxE,MAAM,OAAO,4BAA4B;IAKpB;IACA;IACA;IANF,GAAG,CAAe;IAClB,sBAAsB,CAAS;IAEhD,YACmB,kBAA6C,EAC7C,sBAAqD,EACrD,wBAAyD,EAC1E,OAA4C;QAH3B,uBAAkB,GAAlB,kBAAkB,CAA2B;QAC7C,2BAAsB,GAAtB,sBAAsB,CAA+B;QACrD,6BAAwB,GAAxB,wBAAwB,CAAiC;QAG1E,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,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AC,SAAS,KAAK,KAAK,CAAC,SAAS,EAAE,CAAC;YACvC,OAAO,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;QAC1C,CAAC;QAED,OAAO,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IACvD,CAAC,CAAC;SACD,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,qBAAqB,CAAC,QAA+B;IAI5D,MAAM,WAAW,GAAG,QAAQ,CAAC,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACvD,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAE/C,IAAI,QAAQ,CAAC,YAAY,KAAK,WAAW,IAAI,CAAC,WAAW,IAAI,CAAC,OAAO,EAAE,CAAC;QACtE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACxD,CAAC;IAED,OAAO;QACL,WAAW;QACX,OAAO;KACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { OpenCliProviderRepository } from "../../storage/repositories/opencli-provider-repository.js";
|
|
2
|
+
import type { OpenCliRuntimeProfileRepository } from "../../storage/repositories/opencli-runtime-profile-repository.js";
|
|
3
|
+
import { OpenCliRuntimeBuilder } from "./opencli-runtime-builder.js";
|
|
4
|
+
import type { OpenCliRuntimeProfileService } from "./opencli-runtime-profile-service.js";
|
|
5
|
+
export interface OpenCliRuntimeResolverOptions {
|
|
6
|
+
env?: NodeJS.ProcessEnv;
|
|
7
|
+
homeDir?: string;
|
|
8
|
+
userProfile?: string | null;
|
|
9
|
+
}
|
|
10
|
+
export interface OpenCliSessionRuntimeResolution {
|
|
11
|
+
availability: "disabled" | "unavailable" | "ready";
|
|
12
|
+
runtimeRootPath: string | null;
|
|
13
|
+
runtimeBinPath: string | null;
|
|
14
|
+
realHome: string | null;
|
|
15
|
+
realUserProfile: string | null;
|
|
16
|
+
errorCode: string | null;
|
|
17
|
+
errorDetail: string | null;
|
|
18
|
+
}
|
|
19
|
+
export declare class OpenCliRuntimeResolver {
|
|
20
|
+
private readonly providerRepository;
|
|
21
|
+
private readonly runtimeProfileRepository;
|
|
22
|
+
private readonly runtimeProfileService;
|
|
23
|
+
private readonly runtimeBuilder;
|
|
24
|
+
private readonly env;
|
|
25
|
+
private readonly realHome;
|
|
26
|
+
private readonly realUserProfile;
|
|
27
|
+
constructor(providerRepository: OpenCliProviderRepository, runtimeProfileRepository: OpenCliRuntimeProfileRepository, runtimeProfileService: OpenCliRuntimeProfileService, runtimeBuilder: OpenCliRuntimeBuilder, options?: OpenCliRuntimeResolverOptions);
|
|
28
|
+
resolveSessionRuntime(): OpenCliSessionRuntimeResolution;
|
|
29
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
export class OpenCliRuntimeResolver {
|
|
4
|
+
providerRepository;
|
|
5
|
+
runtimeProfileRepository;
|
|
6
|
+
runtimeProfileService;
|
|
7
|
+
runtimeBuilder;
|
|
8
|
+
env;
|
|
9
|
+
realHome;
|
|
10
|
+
realUserProfile;
|
|
11
|
+
constructor(providerRepository, runtimeProfileRepository, runtimeProfileService, runtimeBuilder, options = {}) {
|
|
12
|
+
this.providerRepository = providerRepository;
|
|
13
|
+
this.runtimeProfileRepository = runtimeProfileRepository;
|
|
14
|
+
this.runtimeProfileService = runtimeProfileService;
|
|
15
|
+
this.runtimeBuilder = runtimeBuilder;
|
|
16
|
+
this.env = options.env ?? process.env;
|
|
17
|
+
this.realHome = normalizeOptionalValue(options.homeDir ?? os.homedir());
|
|
18
|
+
this.realUserProfile = normalizeOptionalValue(options.userProfile ?? this.env.USERPROFILE ?? this.realHome);
|
|
19
|
+
}
|
|
20
|
+
resolveSessionRuntime() {
|
|
21
|
+
const provider = this.providerRepository.get();
|
|
22
|
+
if (!provider.enabled) {
|
|
23
|
+
return unavailableResolution("disabled");
|
|
24
|
+
}
|
|
25
|
+
const installPath = provider.installPath?.trim() ?? "";
|
|
26
|
+
const version = provider.version?.trim() ?? "";
|
|
27
|
+
if (provider.installState !== "installed" || !installPath || !version) {
|
|
28
|
+
return unavailableResolution("unavailable");
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const desiredProfile = this.runtimeProfileService.findOrCreateDesiredProfile();
|
|
32
|
+
const resolvedProfile = this.runtimeBuilder.buildProfile(desiredProfile.profile);
|
|
33
|
+
if (resolvedProfile.status !== "ready") {
|
|
34
|
+
this.providerRepository.upsert({
|
|
35
|
+
...provider,
|
|
36
|
+
activeRuntimeId: null,
|
|
37
|
+
healthState: "runtime_build_failed",
|
|
38
|
+
lastErrorCode: resolvedProfile.lastErrorCode,
|
|
39
|
+
lastErrorDetail: resolvedProfile.lastErrorDetail
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
availability: "unavailable",
|
|
43
|
+
runtimeRootPath: null,
|
|
44
|
+
runtimeBinPath: null,
|
|
45
|
+
realHome: this.realHome,
|
|
46
|
+
realUserProfile: this.realUserProfile,
|
|
47
|
+
errorCode: resolvedProfile.lastErrorCode,
|
|
48
|
+
errorDetail: resolvedProfile.lastErrorDetail
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
this.providerRepository.upsert({
|
|
52
|
+
...provider,
|
|
53
|
+
activeRuntimeId: resolvedProfile.id,
|
|
54
|
+
healthState: resolveHealthyStateAfterRuntimeReady(provider.healthState),
|
|
55
|
+
lastErrorCode: null,
|
|
56
|
+
lastErrorDetail: null
|
|
57
|
+
});
|
|
58
|
+
return {
|
|
59
|
+
availability: "ready",
|
|
60
|
+
runtimeRootPath: resolvedProfile.runtimeRootPath,
|
|
61
|
+
runtimeBinPath: path.join(resolvedProfile.runtimeRootPath, "bin"),
|
|
62
|
+
realHome: this.realHome,
|
|
63
|
+
realUserProfile: this.realUserProfile,
|
|
64
|
+
errorCode: null,
|
|
65
|
+
errorDetail: null
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
70
|
+
this.providerRepository.upsert({
|
|
71
|
+
...provider,
|
|
72
|
+
activeRuntimeId: null,
|
|
73
|
+
healthState: "runtime_build_failed",
|
|
74
|
+
lastErrorCode: "OPENCLI_RUNTIME_RESOLVE_FAILED",
|
|
75
|
+
lastErrorDetail: detail
|
|
76
|
+
});
|
|
77
|
+
return {
|
|
78
|
+
availability: "unavailable",
|
|
79
|
+
runtimeRootPath: null,
|
|
80
|
+
runtimeBinPath: null,
|
|
81
|
+
realHome: this.realHome,
|
|
82
|
+
realUserProfile: this.realUserProfile,
|
|
83
|
+
errorCode: "OPENCLI_RUNTIME_RESOLVE_FAILED",
|
|
84
|
+
errorDetail: detail
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function resolveHealthyStateAfterRuntimeReady(current) {
|
|
90
|
+
if (current === "runtime_build_failed") {
|
|
91
|
+
return "binary_ready";
|
|
92
|
+
}
|
|
93
|
+
return current;
|
|
94
|
+
}
|
|
95
|
+
function unavailableResolution(availability) {
|
|
96
|
+
return {
|
|
97
|
+
availability,
|
|
98
|
+
runtimeRootPath: null,
|
|
99
|
+
runtimeBinPath: null,
|
|
100
|
+
realHome: null,
|
|
101
|
+
realUserProfile: null,
|
|
102
|
+
errorCode: null,
|
|
103
|
+
errorDetail: null
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function normalizeOptionalValue(value) {
|
|
107
|
+
const normalized = value?.trim() ?? "";
|
|
108
|
+
return normalized.length > 0 ? normalized : null;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=opencli-runtime-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opencli-runtime-resolver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UAAU,CAAC,CAAC,CAAC,IAAI,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { OpenCliCatalogEntryRepository } from "../../storage/repositories/opencli-catalog-entry-repository.js";
|
|
2
|
+
import type { OpenCliProviderRepository } from "../../storage/repositories/opencli-provider-repository.js";
|
|
3
|
+
export declare class OpenCliSessionPromptService {
|
|
4
|
+
private readonly providerRepository;
|
|
5
|
+
private readonly catalogEntryRepository;
|
|
6
|
+
constructor(providerRepository: Pick<OpenCliProviderRepository, "get">, catalogEntryRepository: Pick<OpenCliCatalogEntryRepository, "list">);
|
|
7
|
+
buildPrompt(input: {
|
|
8
|
+
provider: string;
|
|
9
|
+
runtimeEnv: Record<string, string>;
|
|
10
|
+
}): string | null;
|
|
11
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const OPENCLI_PROMPT_PROVIDER_IDS = new Set(["codex", "claude-code", "legna-code"]);
|
|
2
|
+
const MAX_PROMPT_COMMANDS = 40;
|
|
3
|
+
export class OpenCliSessionPromptService {
|
|
4
|
+
providerRepository;
|
|
5
|
+
catalogEntryRepository;
|
|
6
|
+
constructor(providerRepository, catalogEntryRepository) {
|
|
7
|
+
this.providerRepository = providerRepository;
|
|
8
|
+
this.catalogEntryRepository = catalogEntryRepository;
|
|
9
|
+
}
|
|
10
|
+
buildPrompt(input) {
|
|
11
|
+
if (!OPENCLI_PROMPT_PROVIDER_IDS.has(input.provider)) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const runtimeRootPath = input.runtimeEnv.CODINGNS_OPENCLI_RUNTIME_ROOT?.trim() ?? "";
|
|
15
|
+
if (!runtimeRootPath) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const provider = this.providerRepository.get();
|
|
19
|
+
if (!provider.enabled) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const enabledEntries = this.catalogEntryRepository
|
|
23
|
+
.list()
|
|
24
|
+
.filter((entry) => entry.enabled)
|
|
25
|
+
.sort((left, right) => left.sortOrder - right.sortOrder || left.commandId.localeCompare(right.commandId));
|
|
26
|
+
if (enabledEntries.length === 0) {
|
|
27
|
+
return [
|
|
28
|
+
"## OpenCLI CLI技能",
|
|
29
|
+
"- 当前会话已经注入 CodingNS 管理的 OpenCLI 运行时,但当前没有启用任何 CLI技能。",
|
|
30
|
+
"- 不要调用 `opencli`,除非用户先在面板里启用具体命令。"
|
|
31
|
+
].join("\n");
|
|
32
|
+
}
|
|
33
|
+
const siteSummaries = buildSiteSummaries(enabledEntries);
|
|
34
|
+
const visibleCommandIds = enabledEntries
|
|
35
|
+
.slice(0, MAX_PROMPT_COMMANDS)
|
|
36
|
+
.map((entry) => entry.commandId);
|
|
37
|
+
const hiddenCommandCount = enabledEntries.length - visibleCommandIds.length;
|
|
38
|
+
return [
|
|
39
|
+
"## OpenCLI CLI技能",
|
|
40
|
+
"- 当前会话已经注入 CodingNS 管理的裁剪版 OpenCLI 运行时,可以直接在 shell 里使用 `opencli`。",
|
|
41
|
+
"- 只能把下面这些已启用命令当成当前会话可见能力;不在列表里的命令,视为当前会话不可用。",
|
|
42
|
+
"- 如需先确认目录,优先执行 `opencli list -f json`,再调用具体命令。",
|
|
43
|
+
"- 目录里存在命令,不等于当前环境一定可运行;标记为依赖浏览器的命令,在浏览器桥缺失时仍可能失败。",
|
|
44
|
+
`- 已启用站点:${siteSummaries.join(";")}`,
|
|
45
|
+
`- 已启用命令:${visibleCommandIds.join("、")}${hiddenCommandCount > 0 ? ` 等另外 ${hiddenCommandCount} 个` : ""}`
|
|
46
|
+
].join("\n");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function buildSiteSummaries(entries) {
|
|
50
|
+
const grouped = new Map();
|
|
51
|
+
for (const entry of entries) {
|
|
52
|
+
const current = grouped.get(entry.site) ?? {
|
|
53
|
+
total: 0,
|
|
54
|
+
browserDependent: 0
|
|
55
|
+
};
|
|
56
|
+
current.total += 1;
|
|
57
|
+
current.browserDependent += entry.browser ? 1 : 0;
|
|
58
|
+
grouped.set(entry.site, current);
|
|
59
|
+
}
|
|
60
|
+
return [...grouped.entries()]
|
|
61
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
62
|
+
.map(([site, summary]) => summary.browserDependent > 0
|
|
63
|
+
? `${site}(${summary.total} 个,其中 ${summary.browserDependent} 个依赖浏览器)`
|
|
64
|
+
: `${site}(${summary.total} 个,可直接运行)`);
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=opencli-session-prompt-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opencli-session-prompt-service.js","sourceRoot":"","sources":["../../../../src/modules/opencli/opencli-session-prompt-service.ts"],"names":[],"mappings":"AAGA,MAAM,2BAA2B,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,aAAa,EAAE,YAAY,CAAC,CAAC,CAAC;AACpF,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAE/B,MAAM,OAAO,2BAA2B;IAEnB;IACA;IAFnB,YACmB,kBAA0D,EAC1D,sBAAmE;QADnE,uBAAkB,GAAlB,kBAAkB,CAAwC;QAC1D,2BAAsB,GAAtB,sBAAsB,CAA6C;IACnF,CAAC;IAEJ,WAAW,CAAC,KAGX;QACC,IAAI,CAAC,2BAA2B,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;YACrD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,eAAe,GAAG,KAAK,CAAC,UAAU,CAAC,6BAA6B,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QAErF,IAAI,CAAC,eAAe,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,kBAAkB,CAAC,GAAG,EAAE,CAAC;QAE/C,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;YACtB,OAAO,IAAI,CAAC;QAC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