@illuminis/comprism 0.1.8 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/{graph → build/machine/codemap}/read-python.js +2 -2
- package/out/{executor → build/machine/executor}/diagnostics.js +1 -1
- package/out/{executor → build/machine/executor}/hooks.js +1 -1
- package/out/{executor → build/machine/executor}/sandbox.js +1 -1
- package/out/build/machine/line/index.js +339 -0
- package/out/{commands/privacy.js → build/machine/runtime/home.js} +10 -19
- package/out/build/machine/runtime/needs.js +89 -0
- package/out/{lib → build/machine/runtime}/self.js +25 -3
- package/out/build/machine/terminal/jobs.js +67 -0
- package/out/build/machine/terminal/sign-in.js +212 -0
- package/out/build/machine/terminal/steps.js +460 -0
- package/out/build/machine/terminal/voice.js +136 -0
- package/out/build/machine/voice/record.js +286 -0
- package/out/cli-start.js +128 -0
- package/out/machine/line/index.js +339 -0
- package/out/machine/runtime/self.js +22 -0
- package/out/machine/terminal/clipboard.js +182 -0
- package/out/machine/terminal/jobs.js +67 -0
- package/out/machine/terminal/sign-in.js +212 -0
- package/out/machine/terminal/steps.js +460 -0
- package/out/machine/terminal/voice.js +136 -0
- package/out/machine/voice/record.js +79 -1
- package/out/native/dictate +0 -0
- package/out/server.generated.js +6 -0
- package/package.json +8 -40
- package/README.md +0 -343
- package/out/agent/command.d.ts +0 -157
- package/out/agent/command.js +0 -454
- package/out/agent/render.d.ts +0 -169
- package/out/agent/render.js +0 -689
- package/out/agent/session.d.ts +0 -334
- package/out/agent/session.js +0 -1232
- package/out/commands/agents.d.ts +0 -2
- package/out/commands/agents.js +0 -79
- package/out/commands/ask.d.ts +0 -1
- package/out/commands/ask.js +0 -222
- package/out/commands/codemap.d.ts +0 -2
- package/out/commands/codemap.js +0 -151
- package/out/commands/commands-thin.d.ts +0 -39
- package/out/commands/commands-thin.js +0 -244
- package/out/commands/config.d.ts +0 -1
- package/out/commands/config.js +0 -138
- package/out/commands/cost.d.ts +0 -1
- package/out/commands/cost.js +0 -167
- package/out/commands/decisionEngine.d.ts +0 -1
- package/out/commands/decisionEngine.js +0 -66
- package/out/commands/hooks.d.ts +0 -1
- package/out/commands/hooks.js +0 -83
- package/out/commands/install.d.ts +0 -206
- package/out/commands/install.js +0 -738
- package/out/commands/instructions.d.ts +0 -1
- package/out/commands/instructions.js +0 -113
- package/out/commands/integrations.d.ts +0 -3
- package/out/commands/integrations.js +0 -215
- package/out/commands/jobs.d.ts +0 -5
- package/out/commands/jobs.js +0 -157
- package/out/commands/keys.d.ts +0 -55
- package/out/commands/keys.js +0 -344
- package/out/commands/login.d.ts +0 -9
- package/out/commands/login.js +0 -606
- package/out/commands/memory.d.ts +0 -3
- package/out/commands/memory.js +0 -113
- package/out/commands/permissions.d.ts +0 -1
- package/out/commands/permissions.js +0 -94
- package/out/commands/plugins.d.ts +0 -4
- package/out/commands/plugins.js +0 -192
- package/out/commands/privacy.d.ts +0 -1
- package/out/commands/providerKey.d.ts +0 -32
- package/out/commands/providerKey.js +0 -108
- package/out/commands/repl.d.ts +0 -12
- package/out/commands/repl.js +0 -2303
- package/out/commands/report.d.ts +0 -39
- package/out/commands/report.js +0 -115
- package/out/commands/review.d.ts +0 -5
- package/out/commands/review.js +0 -223
- package/out/commands/sessions.d.ts +0 -23
- package/out/commands/sessions.js +0 -115
- package/out/commands/settings.d.ts +0 -23
- package/out/commands/settings.js +0 -153
- package/out/commands/skills.d.ts +0 -21
- package/out/commands/skills.js +0 -207
- package/out/commands/unattended.d.ts +0 -7
- package/out/commands/unattended.js +0 -351
- package/out/commands/update.d.ts +0 -1
- package/out/commands/update.js +0 -123
- package/out/commands/welcome.d.ts +0 -25
- package/out/commands/welcome.js +0 -223
- package/out/commands/worktrees.d.ts +0 -5
- package/out/commands/worktrees.js +0 -186
- package/out/executor/browser.d.ts +0 -14
- package/out/executor/diagnostics.d.ts +0 -2
- package/out/executor/documents.d.ts +0 -40
- package/out/executor/files.d.ts +0 -2
- package/out/executor/git.d.ts +0 -48
- package/out/executor/hooks.d.ts +0 -51
- package/out/executor/index.d.ts +0 -45
- package/out/executor/notebook.d.ts +0 -2
- package/out/executor/paths.d.ts +0 -20
- package/out/executor/sandbox.d.ts +0 -40
- package/out/executor/shell.d.ts +0 -86
- package/out/executor/toolservers.d.ts +0 -20
- package/out/executor/worktree.d.ts +0 -9
- package/out/graph/build.d.ts +0 -45
- package/out/graph/facts.d.ts +0 -47
- package/out/graph/files.d.ts +0 -45
- package/out/graph/read-locales.d.ts +0 -29
- package/out/graph/read-python.d.ts +0 -11
- package/out/graph/read-typescript.d.ts +0 -16
- package/out/graph/sync.d.ts +0 -66
- package/out/graph/sync.js +0 -242
- package/out/lib/attach.d.ts +0 -106
- package/out/lib/attach.js +0 -396
- package/out/lib/clipboard.d.ts +0 -23
- package/out/lib/commandlist.d.ts +0 -20
- package/out/lib/commandlist.js +0 -58
- package/out/lib/config.d.ts +0 -94
- package/out/lib/config.js +0 -197
- package/out/lib/connection.d.ts +0 -73
- package/out/lib/connection.js +0 -188
- package/out/lib/decision.d.ts +0 -22
- package/out/lib/decision.js +0 -50
- package/out/lib/fingerprint.d.ts +0 -25
- package/out/lib/fingerprint.js +0 -58
- package/out/lib/gateway.d.ts +0 -427
- package/out/lib/gateway.js +0 -226
- package/out/lib/history.d.ts +0 -24
- package/out/lib/history.js +0 -137
- package/out/lib/ide.d.ts +0 -19
- package/out/lib/ide.js +0 -131
- package/out/lib/keyboard.d.ts +0 -98
- package/out/lib/keyboard.js +0 -390
- package/out/lib/lastlogin.d.ts +0 -14
- package/out/lib/lastlogin.js +0 -105
- package/out/lib/machine.d.ts +0 -21
- package/out/lib/machine.js +0 -91
- package/out/lib/notify.d.ts +0 -4
- package/out/lib/notify.js +0 -52
- package/out/lib/output.d.ts +0 -48
- package/out/lib/output.js +0 -108
- package/out/lib/picker.d.ts +0 -1
- package/out/lib/picker.js +0 -158
- package/out/lib/project-ops.d.ts +0 -19
- package/out/lib/project-ops.js +0 -146
- package/out/lib/project.d.ts +0 -28
- package/out/lib/prompt.d.ts +0 -37
- package/out/lib/prompt.js +0 -142
- package/out/lib/queue.d.ts +0 -13
- package/out/lib/queue.js +0 -116
- package/out/lib/readiness.d.ts +0 -22
- package/out/lib/readiness.js +0 -207
- package/out/lib/self.d.ts +0 -23
- package/out/lib/servicecommand.d.ts +0 -14
- package/out/lib/servicecommand.js +0 -74
- package/out/lib/sessions.d.ts +0 -19
- package/out/lib/sessions.js +0 -221
- package/out/lib/startcache.d.ts +0 -13
- package/out/lib/startcache.js +0 -78
- package/out/lib/stdin.d.ts +0 -32
- package/out/lib/stdin.js +0 -117
- package/out/lib/store.d.ts +0 -40
- package/out/lib/store.js +0 -138
- package/out/lib/sync.d.ts +0 -18
- package/out/lib/sync.js +0 -81
- package/out/lib/types.d.ts +0 -417
- package/out/lib/types.js +0 -21
- package/out/lib/ui.d.ts +0 -123
- package/out/lib/ui.js +0 -299
- package/out/lib/version.d.ts +0 -23
- package/out/lib/version.js +0 -46
- package/out/lib/voice.d.ts +0 -49
- package/out/lib/voice.js +0 -236
- package/out/lib/words.d.ts +0 -20
- package/out/lib/words.js +0 -27
- package/out/machine/codemap/build.d.ts +0 -45
- package/out/machine/codemap/facts.d.ts +0 -47
- package/out/machine/codemap/files.d.ts +0 -45
- package/out/machine/codemap/read-locales.d.ts +0 -29
- package/out/machine/codemap/read-python.d.ts +0 -11
- package/out/machine/codemap/read-typescript.d.ts +0 -16
- package/out/machine/executor/browser.d.ts +0 -14
- package/out/machine/executor/diagnostics.d.ts +0 -2
- package/out/machine/executor/documents.d.ts +0 -40
- package/out/machine/executor/files.d.ts +0 -2
- package/out/machine/executor/git.d.ts +0 -48
- package/out/machine/executor/hooks.d.ts +0 -51
- package/out/machine/executor/index.d.ts +0 -45
- package/out/machine/executor/notebook.d.ts +0 -2
- package/out/machine/executor/paths.d.ts +0 -20
- package/out/machine/executor/sandbox.d.ts +0 -40
- package/out/machine/executor/shell.d.ts +0 -86
- package/out/machine/executor/toolservers.d.ts +0 -20
- package/out/machine/executor/worktree.d.ts +0 -9
- package/out/machine/folder/project.d.ts +0 -28
- package/out/machine/runtime/home.d.ts +0 -2
- package/out/machine/runtime/needs.d.ts +0 -30
- package/out/machine/runtime/self.d.ts +0 -23
- package/out/machine/voice/record.d.ts +0 -38
- package/out/postinstall.d.ts +0 -2
- package/out/postinstall.js +0 -120
- package/out/providers/anthropic.d.ts +0 -22
- package/out/providers/anthropic.js +0 -80
- package/out/providers/index.d.ts +0 -8
- package/out/providers/index.js +0 -84
- package/out/providers/openai.d.ts +0 -11
- package/out/providers/openai.js +0 -57
- package/out/thin.d.ts +0 -2
- package/out/thin.js +0 -855
- package/scripts/read_python.py +0 -270
- /package/out/{graph → build/machine/codemap}/build.js +0 -0
- /package/out/{graph → build/machine/codemap}/facts.js +0 -0
- /package/out/{graph → build/machine/codemap}/files.js +0 -0
- /package/out/{graph → build/machine/codemap}/read-locales.js +0 -0
- /package/out/{graph → build/machine/codemap}/read-typescript.js +0 -0
- /package/out/{executor → build/machine/executor}/browser.js +0 -0
- /package/out/{executor → build/machine/executor}/documents.js +0 -0
- /package/out/{executor → build/machine/executor}/files.js +0 -0
- /package/out/{executor → build/machine/executor}/git.js +0 -0
- /package/out/{executor → build/machine/executor}/index.js +0 -0
- /package/out/{executor → build/machine/executor}/notebook.js +0 -0
- /package/out/{executor → build/machine/executor}/paths.js +0 -0
- /package/out/{executor → build/machine/executor}/shell.js +0 -0
- /package/out/{executor → build/machine/executor}/toolservers.js +0 -0
- /package/out/{executor → build/machine/executor}/worktree.js +0 -0
- /package/out/{lib → build/machine/folder}/project.js +0 -0
- /package/out/{lib → build/machine/terminal}/clipboard.js +0 -0
package/out/commands/install.js
DELETED
|
@@ -1,738 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.WORKSPACE_KEY_HEADER = void 0;
|
|
7
|
-
exports.envScriptPath = envScriptPath;
|
|
8
|
-
exports.envScriptPathPs = envScriptPathPs;
|
|
9
|
-
exports.powershellProfiles = powershellProfiles;
|
|
10
|
-
exports.envScriptPs = envScriptPs;
|
|
11
|
-
exports.pidFilePath = pidFilePath;
|
|
12
|
-
exports.proxyLogPath = proxyLogPath;
|
|
13
|
-
exports.shellProfiles = shellProfiles;
|
|
14
|
-
exports.tenantBaseUrl = tenantBaseUrl;
|
|
15
|
-
exports.envScript = envScript;
|
|
16
|
-
exports.desktopConfigPath = desktopConfigPath;
|
|
17
|
-
exports.installDesktopConnector = installDesktopConnector;
|
|
18
|
-
exports.probeDesktopConnector = probeDesktopConnector;
|
|
19
|
-
exports.uninstallDesktopConnector = uninstallDesktopConnector;
|
|
20
|
-
exports.install = install;
|
|
21
|
-
exports.refreshEnvScript = refreshEnvScript;
|
|
22
|
-
exports.finishSetup = finishSetup;
|
|
23
|
-
exports.profileHasSetup = profileHasSetup;
|
|
24
|
-
exports.uninstall = uninstall;
|
|
25
|
-
exports.launchShellString = launchShellString;
|
|
26
|
-
exports.proxyHealthy = proxyHealthy;
|
|
27
|
-
exports.startDaemon = startDaemon;
|
|
28
|
-
exports.stopDaemon = stopDaemon;
|
|
29
|
-
/**
|
|
30
|
-
* Install and interception setup. Rules R1 and R2.
|
|
31
|
-
*
|
|
32
|
-
* R1 says one command installs everything, with nothing for the user to copy or
|
|
33
|
-
* paste. R2 says `claude` then just works, unchanged. Those two together rule
|
|
34
|
-
* out the obvious approach - printing an `export` line and hoping - so this file
|
|
35
|
-
* does the work instead.
|
|
36
|
-
*
|
|
37
|
-
* ── What the base URL points at, and why it is not this machine ───────────
|
|
38
|
-
*
|
|
39
|
-
* The tenant's own hosted endpoint: `https://{tenant}.completionprism.illuminis.ai`.
|
|
40
|
-
* Claude Code and every Anthropic SDK append `/v1/messages` to it themselves.
|
|
41
|
-
*
|
|
42
|
-
* It used to point at a proxy on 127.0.0.1 that this script started, and that
|
|
43
|
-
* was wrong in a way worth writing down, because it looked right for weeks. A
|
|
44
|
-
* local proxy means the pricing runs on the laptop, which means a second
|
|
45
|
-
* implementation of the equation in a second language - and those two drifted
|
|
46
|
-
* inside a day the first time, leaving two surfaces quoting different costs for
|
|
47
|
-
* the same work. It also means nothing is measured on any machine where the
|
|
48
|
-
* daemon is not running, and no receipt link that a colleague can open. One
|
|
49
|
-
* hosted interceptor removes all three at once: the CLI now renders and strips,
|
|
50
|
-
* and computes nothing.
|
|
51
|
-
*
|
|
52
|
-
* ── The shape, and why it is safe ─────────────────────────────────────────
|
|
53
|
-
*
|
|
54
|
-
* The install writes `~/.comprism/env.sh` and adds one sourcing line to the
|
|
55
|
-
* user's shell profile. That script does two things every time a shell opens,
|
|
56
|
-
* in this order, and the order is the whole safety argument:
|
|
57
|
-
*
|
|
58
|
-
* 1. Is the tenant endpoint answering? If yes, export the base URL.
|
|
59
|
-
* 2. **If it is not, export nothing.**
|
|
60
|
-
*
|
|
61
|
-
* Step 2 is the important one. A base URL pointing somewhere unreachable would
|
|
62
|
-
* break every AI tool on the machine, and "our measurement tool broke Claude
|
|
63
|
-
* Code" is the single worst outcome this product can produce - worse by far than
|
|
64
|
-
* missing a day of data. So the failure mode is silence: the user's tools talk
|
|
65
|
-
* straight to the provider exactly as they did before, and we record nothing.
|
|
66
|
-
* That is rule 10 and it is not negotiable.
|
|
67
|
-
*
|
|
68
|
-
* ── Why a shell profile at all ────────────────────────────────────────────
|
|
69
|
-
*
|
|
70
|
-
* Because the requirement is that plain `claude` is instrumented. A wrapper
|
|
71
|
-
* command would be less invasive and would not satisfy that. The line is
|
|
72
|
-
* fenced with markers, `comprism uninstall` removes it exactly, and the install
|
|
73
|
-
* says out loud what it touched.
|
|
74
|
-
*/
|
|
75
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
76
|
-
const node_os_1 = __importDefault(require("node:os"));
|
|
77
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
78
|
-
const node_child_process_1 = require("node:child_process");
|
|
79
|
-
const config_1 = require("../lib/config");
|
|
80
|
-
const connection_1 = require("../lib/connection");
|
|
81
|
-
const self_1 = require("../machine/runtime/self");
|
|
82
|
-
const words_1 = require("../lib/words");
|
|
83
|
-
/** The header the tenant reads to decide whether this machine may be served. */
|
|
84
|
-
exports.WORKSPACE_KEY_HEADER = 'x-comprism-key';
|
|
85
|
-
const MARKER_START = '# >>> comprism >>>';
|
|
86
|
-
const MARKER_END = '# <<< comprism <<<';
|
|
87
|
-
function envScriptPath() {
|
|
88
|
-
return node_path_1.default.join((0, config_1.homeDir)(), 'env.sh');
|
|
89
|
-
}
|
|
90
|
-
/** The PowerShell form of the setup script, for Windows (manual 1.2). */
|
|
91
|
-
function envScriptPathPs() {
|
|
92
|
-
return node_path_1.default.join((0, config_1.homeDir)(), 'env.ps1');
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* The PowerShell profiles to set up on Windows: Windows PowerShell's and,
|
|
96
|
-
* where it exists, PowerShell 7's. Windows PowerShell's is created when there
|
|
97
|
-
* is none, because it is the shell every Windows machine has.
|
|
98
|
-
*/
|
|
99
|
-
function powershellProfiles() {
|
|
100
|
-
if (process.platform !== 'win32' && !process.env.COMPRISM_TEST_POWERSHELL)
|
|
101
|
-
return [];
|
|
102
|
-
const docs = node_path_1.default.join(process.env.USERPROFILE || node_os_1.default.homedir(), 'Documents');
|
|
103
|
-
const classic = node_path_1.default.join(docs, 'WindowsPowerShell', 'Microsoft.PowerShell_profile.ps1');
|
|
104
|
-
const modern = node_path_1.default.join(docs, 'PowerShell', 'Microsoft.PowerShell_profile.ps1');
|
|
105
|
-
const out = [classic];
|
|
106
|
-
if (node_fs_1.default.existsSync(node_path_1.default.dirname(modern)))
|
|
107
|
-
out.push(modern);
|
|
108
|
-
return out;
|
|
109
|
-
}
|
|
110
|
-
/** The PowerShell script: the same rule as the POSIX one, in PowerShell. */
|
|
111
|
-
function envScriptPs(baseUrl, workspaceKey) {
|
|
112
|
-
const bin = (0, self_1.standaloneBinDir)();
|
|
113
|
-
const pathLine = node_fs_1.default.existsSync(node_path_1.default.join(bin, 'comprism.exe'))
|
|
114
|
-
? `if ($env:Path -notlike '*${bin.replace(/'/g, "''")}*') { $env:Path = '${bin.replace(/'/g, "''")};' + $env:Path }\n`
|
|
115
|
-
: '';
|
|
116
|
-
const head = '# Managed by comprism. Edit nothing here; run `comprism install` to regenerate.\n' + pathLine;
|
|
117
|
-
if (!baseUrl || !workspaceKey) {
|
|
118
|
-
return `${head}#\n# This machine is not signed in, so this sets nothing and your tools are untouched.\n`;
|
|
119
|
-
}
|
|
120
|
-
const q = (v) => v.replace(/'/g, "''");
|
|
121
|
-
return `${head}#
|
|
122
|
-
# Points AI clients at your CompletionPrism tenant so your work is measured.
|
|
123
|
-
# If the tenant is not reachable, this sets NOTHING and your tools talk
|
|
124
|
-
# straight to the provider exactly as they would without us.
|
|
125
|
-
try {
|
|
126
|
-
Invoke-WebRequest -Uri '${q(baseUrl)}/health' -UseBasicParsing -TimeoutSec 2 | Out-Null
|
|
127
|
-
$env:ANTHROPIC_BASE_URL = '${q(baseUrl)}'
|
|
128
|
-
$__comprism = '${exports.WORKSPACE_KEY_HEADER}: ${q(workspaceKey)}'
|
|
129
|
-
if (-not $env:ANTHROPIC_CUSTOM_HEADERS) { $env:ANTHROPIC_CUSTOM_HEADERS = $__comprism }
|
|
130
|
-
elseif ($env:ANTHROPIC_CUSTOM_HEADERS -notlike '*${exports.WORKSPACE_KEY_HEADER}*') {
|
|
131
|
-
$env:ANTHROPIC_CUSTOM_HEADERS = "$($env:ANTHROPIC_CUSTOM_HEADERS)\`n$__comprism"
|
|
132
|
-
}
|
|
133
|
-
Remove-Variable __comprism -ErrorAction SilentlyContinue
|
|
134
|
-
} catch { }
|
|
135
|
-
`;
|
|
136
|
-
}
|
|
137
|
-
function pidFilePath() {
|
|
138
|
-
return node_path_1.default.join((0, config_1.homeDir)(), 'proxy.pid');
|
|
139
|
-
}
|
|
140
|
-
function proxyLogPath() {
|
|
141
|
-
return node_path_1.default.join((0, config_1.homeDir)(), 'proxy.log');
|
|
142
|
-
}
|
|
143
|
-
/** Every profile we should add the line to, that actually exists. */
|
|
144
|
-
function shellProfiles() {
|
|
145
|
-
const home = node_os_1.default.homedir();
|
|
146
|
-
const candidates = ['.zshrc', '.bashrc', '.bash_profile', '.profile'];
|
|
147
|
-
const found = candidates
|
|
148
|
-
.map((f) => node_path_1.default.join(home, f))
|
|
149
|
-
.filter((p) => node_fs_1.default.existsSync(p));
|
|
150
|
-
// Windows shells read none of these, and the generated script is POSIX. An
|
|
151
|
-
// existing Git Bash profile is still set up; nothing is created, because a
|
|
152
|
-
// new .zshrc on Windows is litter that measures nothing.
|
|
153
|
-
if (process.platform === 'win32')
|
|
154
|
-
return found;
|
|
155
|
-
// A machine with none of them: create the one matching the login shell rather
|
|
156
|
-
// than silently doing nothing.
|
|
157
|
-
if (found.length === 0) {
|
|
158
|
-
const shell = process.env.SHELL || '';
|
|
159
|
-
return [node_path_1.default.join(home, shell.includes('bash') ? '.bashrc' : '.zshrc')];
|
|
160
|
-
}
|
|
161
|
-
return found;
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* The tenant's own endpoint, and never anything on this machine.
|
|
165
|
-
*
|
|
166
|
-
* Three sources, most specific first: what the caller passed, the connection
|
|
167
|
-
* `comprism login` stored, and the tenant and domain in config. Null when none
|
|
168
|
-
* of them names a tenant, and null is load-bearing - the install then writes a
|
|
169
|
-
* script that exports nothing rather than one that guesses a hostname.
|
|
170
|
-
*/
|
|
171
|
-
function tenantBaseUrl(explicit) {
|
|
172
|
-
const clean = (url) => url.replace(/\/+$/, '');
|
|
173
|
-
if (explicit)
|
|
174
|
-
return clean(explicit);
|
|
175
|
-
const connection = (0, connection_1.readConnection)();
|
|
176
|
-
if (connection?.url)
|
|
177
|
-
return clean(connection.url);
|
|
178
|
-
const cfg = (0, config_1.loadConfig)();
|
|
179
|
-
const portal = cfg.footer?.portal || {};
|
|
180
|
-
const slug = (cfg.footer?.tenant || '').trim().toLowerCase().replace(/[^a-z0-9-]/g, '');
|
|
181
|
-
const domain = portal.domain || 'completionprism.illuminis.ai';
|
|
182
|
-
return slug ? `https://${slug}.${domain}` : null;
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* The script every new shell sources.
|
|
186
|
-
*
|
|
187
|
-
* Written as POSIX shell so it works in bash and zsh alike, and deliberately
|
|
188
|
-
* silent: a shell startup file that prints things is a shell startup file people
|
|
189
|
-
* delete.
|
|
190
|
-
*
|
|
191
|
-
* `OPENAI_BASE_URL` is deliberately NOT set. The hosted interceptor speaks the
|
|
192
|
-
* Anthropic shape today, so pointing an OpenAI client at it would send that
|
|
193
|
-
* client somewhere with no route for it - breaking a working tool in order to
|
|
194
|
-
* measure it, which is the one thing this file exists to prevent. It comes back
|
|
195
|
-
* the day there is an OpenAI-shaped endpoint to point at.
|
|
196
|
-
*/
|
|
197
|
-
function envScript(baseUrl, workspaceKey) {
|
|
198
|
-
return envScriptBody(baseUrl, workspaceKey).replace(/^#!\/bin\/sh\n/, `#!/bin/sh\n${pathBlock()}`);
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* The install script puts the program in `~/.comprism/bin` (manual 1.1,
|
|
202
|
-
* Option 1), so the setup script puts that folder on the PATH, once. It is
|
|
203
|
-
* written only when the program is there, so an npm or Python install is
|
|
204
|
-
* unchanged.
|
|
205
|
-
*/
|
|
206
|
-
function pathBlock() {
|
|
207
|
-
const bin = (0, self_1.standaloneBinDir)();
|
|
208
|
-
if (!node_fs_1.default.existsSync(node_path_1.default.join(bin, 'comprism')))
|
|
209
|
-
return '';
|
|
210
|
-
return `case ":$PATH:" in *":${bin}:"*) : ;; *) PATH="${bin}:$PATH"; export PATH ;; esac\n`;
|
|
211
|
-
}
|
|
212
|
-
function envScriptBody(baseUrl, workspaceKey) {
|
|
213
|
-
if (!baseUrl) {
|
|
214
|
-
return `#!/bin/sh
|
|
215
|
-
# Managed by comprism. Edit nothing here; run \`comprism install\` to regenerate.
|
|
216
|
-
#
|
|
217
|
-
# No tenant is connected yet, so this exports nothing and your tools are
|
|
218
|
-
# untouched. Run \`comprism login\` and then \`comprism install\` again.
|
|
219
|
-
`;
|
|
220
|
-
}
|
|
221
|
-
// A base URL with no workspace key points every AI tool on this machine at a
|
|
222
|
-
// door that will refuse it. That is worse than not measuring: it breaks work
|
|
223
|
-
// in order to measure it, which rule 10 forbids outright. So an unenrolled
|
|
224
|
-
// machine exports NOTHING and talks to the provider exactly as before.
|
|
225
|
-
if (!workspaceKey) {
|
|
226
|
-
return `#!/bin/sh
|
|
227
|
-
# Managed by comprism. Edit nothing here; run \`comprism install\` to regenerate.
|
|
228
|
-
#
|
|
229
|
-
# This machine is not enrolled in a CompletionPrism workspace, so it exports
|
|
230
|
-
# nothing and your tools are untouched. Run \`comprism login\` to enroll it.
|
|
231
|
-
`;
|
|
232
|
-
}
|
|
233
|
-
return `#!/bin/sh
|
|
234
|
-
# Managed by comprism. Edit nothing here; run \`comprism install\` to regenerate.
|
|
235
|
-
#
|
|
236
|
-
# Points AI clients at your CompletionPrism tenant so your work is measured.
|
|
237
|
-
# If the tenant is not reachable, this exports NOTHING and your tools talk
|
|
238
|
-
# straight to the provider exactly as they would without us. Measurement is
|
|
239
|
-
# never worth breaking someone's work over.
|
|
240
|
-
|
|
241
|
-
__comprism_alive() {
|
|
242
|
-
curl -s -m 2 -o /dev/null "${baseUrl}/health" 2>/dev/null
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
if __comprism_alive; then
|
|
246
|
-
ANTHROPIC_BASE_URL="${baseUrl}"
|
|
247
|
-
export ANTHROPIC_BASE_URL
|
|
248
|
-
|
|
249
|
-
# Who this machine is, presented on every request. Anthropic clients read
|
|
250
|
-
# ANTHROPIC_CUSTOM_HEADERS as "Name: value" lines, so nothing has to be pasted
|
|
251
|
-
# into a tool's own configuration. An existing value is added to rather than
|
|
252
|
-
# replaced: it may well be carrying a corporate proxy's header, and taking that
|
|
253
|
-
# away to install ourselves would break the very thing we promise not to.
|
|
254
|
-
__comprism_header="${exports.WORKSPACE_KEY_HEADER}: ${workspaceKey}"
|
|
255
|
-
case "$ANTHROPIC_CUSTOM_HEADERS" in
|
|
256
|
-
*"${exports.WORKSPACE_KEY_HEADER}"*) : ;;
|
|
257
|
-
"") ANTHROPIC_CUSTOM_HEADERS="$__comprism_header" ;;
|
|
258
|
-
*) ANTHROPIC_CUSTOM_HEADERS="$ANTHROPIC_CUSTOM_HEADERS
|
|
259
|
-
$__comprism_header" ;;
|
|
260
|
-
esac
|
|
261
|
-
export ANTHROPIC_CUSTOM_HEADERS
|
|
262
|
-
unset __comprism_header
|
|
263
|
-
fi
|
|
264
|
-
|
|
265
|
-
unset -f __comprism_alive 2>/dev/null || true
|
|
266
|
-
`;
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Where the desktop client keeps its connector list, per platform.
|
|
270
|
-
*
|
|
271
|
-
* Only the directory the client itself created counts. Creating it ourselves on
|
|
272
|
-
* a machine with no desktop client would leave a config file for an application
|
|
273
|
-
* that is not installed, which is litter.
|
|
274
|
-
*/
|
|
275
|
-
function desktopConfigPath() {
|
|
276
|
-
const home = node_os_1.default.homedir();
|
|
277
|
-
if (process.platform === 'darwin') {
|
|
278
|
-
return node_path_1.default.join(home, 'Library', 'Application Support', 'Claude', 'claude_desktop_config.json');
|
|
279
|
-
}
|
|
280
|
-
if (process.platform === 'win32') {
|
|
281
|
-
return node_path_1.default.join(process.env.APPDATA || node_path_1.default.join(home, 'AppData', 'Roaming'), 'Claude', 'claude_desktop_config.json');
|
|
282
|
-
}
|
|
283
|
-
return node_path_1.default.join(home, '.config', 'Claude', 'claude_desktop_config.json');
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* Take our STDIO entry back out of Claude Desktop's config, and say what to add
|
|
287
|
-
* instead.
|
|
288
|
-
*
|
|
289
|
-
* This used to REGISTER a stdio server here - `node cli.js mcp` - and that was
|
|
290
|
-
* wrong in a way that cost a real afternoon. That server exposes `record_work`,
|
|
291
|
-
* `completion_receipt` and `coverage`: it only ever OBSERVES. It does not route,
|
|
292
|
-
* it does not answer, so there is no receipt for the client to render, and it
|
|
293
|
-
* appends to `~/.comprism/ledger.jsonl` on this laptop rather than to the
|
|
294
|
-
* tenant, so nothing it records can ever appear in the portal. The install then
|
|
295
|
-
* printed "Claude Desktop connector registered and answering", which was true of
|
|
296
|
-
* the handshake and false about the product.
|
|
297
|
-
*
|
|
298
|
-
* The connector that works is the hosted one, `{tenant}/mcp`, which runs the
|
|
299
|
-
* same nine steps as every other surface, returns the answer with the receipt
|
|
300
|
-
* attached, and writes the turn to the tenant. It is added by pasting its
|
|
301
|
-
* address into Claude Desktop's own Connectors dialog, because a remote
|
|
302
|
-
* connector is authorized by an OAuth consent screen that only the person
|
|
303
|
-
* sitting there can approve - there is nothing an installer could write into a
|
|
304
|
-
* file to stand in for that.
|
|
305
|
-
*
|
|
306
|
-
* So this now does the honest thing: removes a stale entry of ours if one is
|
|
307
|
-
* there, never writes one, and returns the address for the caller to print. Two
|
|
308
|
-
* things it still will never do: create the file on a machine where the desktop
|
|
309
|
-
* client is not installed, and overwrite a config it could not parse.
|
|
310
|
-
*/
|
|
311
|
-
function installDesktopConnector(_binary) {
|
|
312
|
-
const configPath = desktopConfigPath();
|
|
313
|
-
const dir = node_path_1.default.dirname(configPath);
|
|
314
|
-
if (!node_fs_1.default.existsSync(dir)) {
|
|
315
|
-
return {
|
|
316
|
-
configPath,
|
|
317
|
-
present: false,
|
|
318
|
-
registered: false,
|
|
319
|
-
staleRemoved: false,
|
|
320
|
-
note: 'Claude Desktop is not installed on this machine, so there is nothing to add here.',
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
if (!node_fs_1.default.existsSync(configPath)) {
|
|
324
|
-
return { configPath, present: true, registered: false, staleRemoved: false };
|
|
325
|
-
}
|
|
326
|
-
let config;
|
|
327
|
-
try {
|
|
328
|
-
config = JSON.parse(node_fs_1.default.readFileSync(configPath, 'utf8'));
|
|
329
|
-
}
|
|
330
|
-
catch {
|
|
331
|
-
return {
|
|
332
|
-
configPath,
|
|
333
|
-
present: true,
|
|
334
|
-
registered: false,
|
|
335
|
-
staleRemoved: false,
|
|
336
|
-
note: 'The desktop config could not be read as JSON, so it was left exactly as it is. '
|
|
337
|
-
+ 'Nothing was changed.',
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
// Only ever REMOVE, and only our own key. An earlier version of this installer
|
|
341
|
-
// wrote a stdio server here that could not produce a receipt or reach the
|
|
342
|
-
// tenant; leaving it behind means the client keeps offering the wrong tools
|
|
343
|
-
// beside the right ones, and the person cannot tell which is which.
|
|
344
|
-
const servers = config.mcpServers;
|
|
345
|
-
if (!servers || !servers.completionprism) {
|
|
346
|
-
return { configPath, present: true, registered: false, staleRemoved: false };
|
|
347
|
-
}
|
|
348
|
-
delete servers.completionprism;
|
|
349
|
-
if (Object.keys(servers).length === 0)
|
|
350
|
-
delete config.mcpServers;
|
|
351
|
-
else
|
|
352
|
-
config.mcpServers = servers;
|
|
353
|
-
node_fs_1.default.writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`);
|
|
354
|
-
return { configPath, present: true, registered: false, staleRemoved: true };
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* Start the connector exactly as the desktop client will, and see if it answers.
|
|
358
|
-
*
|
|
359
|
-
* Written after a live failure that the installer had already called a success.
|
|
360
|
-
* `npm install -g .` from a checkout leaves the global package as a SYMLINK back
|
|
361
|
-
* into the source folder; on macOS the desktop client is sandboxed out of
|
|
362
|
-
* `~/Documents`, so the connector died on `EPERM` the moment it was launched -
|
|
363
|
-
* and the only trace was a log file nobody thinks to open. The installer said
|
|
364
|
-
* "registered", which was true and useless.
|
|
365
|
-
*
|
|
366
|
-
* So registration is no longer the claim. This spawns the real command, speaks
|
|
367
|
-
* the real handshake and waits for the real reply. A connector that cannot start
|
|
368
|
-
* is reported as broken, with the reason, at install time.
|
|
369
|
-
*/
|
|
370
|
-
async function probeDesktopConnector(binary) {
|
|
371
|
-
const { command, args: baseArgs } = binary;
|
|
372
|
-
return new Promise((resolve) => {
|
|
373
|
-
let settled = false;
|
|
374
|
-
let child;
|
|
375
|
-
const done = (ok, detail) => {
|
|
376
|
-
if (settled)
|
|
377
|
-
return;
|
|
378
|
-
settled = true;
|
|
379
|
-
try {
|
|
380
|
-
child?.kill();
|
|
381
|
-
}
|
|
382
|
-
catch {
|
|
383
|
-
/* already gone */
|
|
384
|
-
}
|
|
385
|
-
resolve({ ok, detail });
|
|
386
|
-
};
|
|
387
|
-
try {
|
|
388
|
-
child = (0, node_child_process_1.spawn)(command, [...baseArgs, 'mcp'], {
|
|
389
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
catch (err) {
|
|
393
|
-
resolve({
|
|
394
|
-
ok: false,
|
|
395
|
-
detail: err instanceof Error ? err.message : (0, words_1.word)('connectorNotStarted'),
|
|
396
|
-
});
|
|
397
|
-
return;
|
|
398
|
-
}
|
|
399
|
-
let stdout = '';
|
|
400
|
-
let stderr = '';
|
|
401
|
-
child.stdout?.on('data', (d) => {
|
|
402
|
-
stdout += String(d);
|
|
403
|
-
if (stdout.includes('"serverInfo"'))
|
|
404
|
-
done(true, 'answered the handshake');
|
|
405
|
-
});
|
|
406
|
-
child.stderr?.on('data', (d) => {
|
|
407
|
-
stderr += String(d);
|
|
408
|
-
});
|
|
409
|
-
child.on('error', (err) => done(false, err.message));
|
|
410
|
-
child.on('exit', () => {
|
|
411
|
-
// The first meaningful line of a crash is the useful one; the stack is
|
|
412
|
-
// noise in an install report.
|
|
413
|
-
const first = stderr.split('\n').find((l) => /Error|error|EPERM|not found/.test(l));
|
|
414
|
-
done(false, first?.trim() || 'the connector exited without answering');
|
|
415
|
-
});
|
|
416
|
-
child.stdin?.write(`${JSON.stringify({
|
|
417
|
-
jsonrpc: '2.0',
|
|
418
|
-
id: 1,
|
|
419
|
-
method: 'initialize',
|
|
420
|
-
params: {
|
|
421
|
-
protocolVersion: '2025-06-18',
|
|
422
|
-
capabilities: {},
|
|
423
|
-
clientInfo: { name: 'comprism-install-probe', version: '1' },
|
|
424
|
-
},
|
|
425
|
-
})}\n`);
|
|
426
|
-
setTimeout(() => done(false, 'the connector did not answer within three seconds'), 3000);
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
/** Take the connector back out, leaving every other server alone. */
|
|
430
|
-
function uninstallDesktopConnector() {
|
|
431
|
-
const configPath = desktopConfigPath();
|
|
432
|
-
if (!node_fs_1.default.existsSync(configPath))
|
|
433
|
-
return false;
|
|
434
|
-
let config;
|
|
435
|
-
try {
|
|
436
|
-
config = JSON.parse(node_fs_1.default.readFileSync(configPath, 'utf8'));
|
|
437
|
-
}
|
|
438
|
-
catch {
|
|
439
|
-
return false;
|
|
440
|
-
}
|
|
441
|
-
const servers = config.mcpServers;
|
|
442
|
-
if (!servers || !servers.completionprism)
|
|
443
|
-
return false;
|
|
444
|
-
delete servers.completionprism;
|
|
445
|
-
node_fs_1.default.writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`);
|
|
446
|
-
return true;
|
|
447
|
-
}
|
|
448
|
-
/**
|
|
449
|
-
* Do the setup. Idempotent: running it twice changes nothing the second time.
|
|
450
|
-
*/
|
|
451
|
-
function install(options = {}) {
|
|
452
|
-
(0, config_1.ensureHome)();
|
|
453
|
-
// Prefer the globally installed binary; fall back to however we were invoked,
|
|
454
|
-
// so this works from a checkout as well as from an npm install.
|
|
455
|
-
const binary = options.binary ?? resolveBinary();
|
|
456
|
-
const baseUrl = tenantBaseUrl(options.baseUrl);
|
|
457
|
-
// Enrollment, not authentication: the tenant refuses interception to a machine
|
|
458
|
-
// that cannot say which workspace it belongs to, so this decides whether we
|
|
459
|
-
// configure anything at all.
|
|
460
|
-
const workspaceKey = options.workspaceKey ?? (0, connection_1.readConnection)()?.workspaceKey ?? null;
|
|
461
|
-
const scriptPath = envScriptPath();
|
|
462
|
-
node_fs_1.default.writeFileSync(scriptPath, envScript(baseUrl, workspaceKey), { mode: 0o700 });
|
|
463
|
-
const line = `${MARKER_START}\n[ -f "${scriptPath}" ] && . "${scriptPath}"\n${MARKER_END}`;
|
|
464
|
-
const touched = [];
|
|
465
|
-
const already = [];
|
|
466
|
-
// Windows: the same fenced line, in PowerShell's own profile (manual 1.2).
|
|
467
|
-
const psProfiles = powershellProfiles();
|
|
468
|
-
if (psProfiles.length) {
|
|
469
|
-
const ps = envScriptPathPs();
|
|
470
|
-
node_fs_1.default.writeFileSync(ps, envScriptPs(baseUrl, workspaceKey));
|
|
471
|
-
const psLine = `${MARKER_START}\nif (Test-Path '${ps.replace(/'/g, "''")}') { . '${ps.replace(/'/g, "''")}' }\n${MARKER_END}`;
|
|
472
|
-
for (const profile of psProfiles) {
|
|
473
|
-
node_fs_1.default.mkdirSync(node_path_1.default.dirname(profile), { recursive: true });
|
|
474
|
-
const contents = node_fs_1.default.existsSync(profile) ? node_fs_1.default.readFileSync(profile, 'utf8') : '';
|
|
475
|
-
if (contents.includes(MARKER_START)) {
|
|
476
|
-
const next = contents.replace(new RegExp(`${MARKER_START}[\\s\\S]*?${MARKER_END}`), psLine);
|
|
477
|
-
if (next !== contents)
|
|
478
|
-
node_fs_1.default.writeFileSync(profile, next);
|
|
479
|
-
already.push(profile);
|
|
480
|
-
}
|
|
481
|
-
else {
|
|
482
|
-
node_fs_1.default.appendFileSync(profile, `\n${psLine}\n`);
|
|
483
|
-
touched.push(profile);
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
for (const profile of shellProfiles()) {
|
|
488
|
-
let contents = '';
|
|
489
|
-
try {
|
|
490
|
-
contents = node_fs_1.default.readFileSync(profile, 'utf8');
|
|
491
|
-
}
|
|
492
|
-
catch {
|
|
493
|
-
contents = '';
|
|
494
|
-
}
|
|
495
|
-
if (contents.includes(MARKER_START)) {
|
|
496
|
-
// Replace the fenced block rather than appending a second one.
|
|
497
|
-
const next = contents.replace(new RegExp(`${MARKER_START}[\\s\\S]*?${MARKER_END}`), line);
|
|
498
|
-
if (next !== contents)
|
|
499
|
-
node_fs_1.default.writeFileSync(profile, next);
|
|
500
|
-
already.push(profile);
|
|
501
|
-
continue;
|
|
502
|
-
}
|
|
503
|
-
node_fs_1.default.appendFileSync(profile, `\n${line}\n`);
|
|
504
|
-
touched.push(profile);
|
|
505
|
-
}
|
|
506
|
-
return {
|
|
507
|
-
envScript: scriptPath,
|
|
508
|
-
profilesTouched: touched,
|
|
509
|
-
profilesAlreadyHad: already,
|
|
510
|
-
baseUrl,
|
|
511
|
-
enrolled: Boolean(workspaceKey),
|
|
512
|
-
binary,
|
|
513
|
-
// Absolute, deliberately: the desktop client is launched by launchd and
|
|
514
|
-
// has neither our shim nor node on its PATH. See `resolveDesktopBinary`.
|
|
515
|
-
desktop: installDesktopConnector(resolveDesktopBinary()),
|
|
516
|
-
};
|
|
517
|
-
}
|
|
518
|
-
/**
|
|
519
|
-
* Rewrite the generated script from the connection as it now stands.
|
|
520
|
-
*
|
|
521
|
-
* Sign in and sign out call this. Before, only the install wrote it, and the
|
|
522
|
-
* install runs before anybody has signed in, so the script said "not enrolled"
|
|
523
|
-
* forever and signing in never switched measurement on. After sign out it kept
|
|
524
|
-
* presenting a revoked key. Touches no shell profile: a machine that never had
|
|
525
|
-
* the line added is left exactly as it was.
|
|
526
|
-
*/
|
|
527
|
-
function refreshEnvScript() {
|
|
528
|
-
const script = envScriptPath();
|
|
529
|
-
if (!node_fs_1.default.existsSync(script))
|
|
530
|
-
return;
|
|
531
|
-
node_fs_1.default.writeFileSync(script, envScript(tenantBaseUrl(), (0, connection_1.readConnection)()?.workspaceKey ?? null), { mode: 0o700 });
|
|
532
|
-
const ps = envScriptPathPs();
|
|
533
|
-
if (node_fs_1.default.existsSync(ps))
|
|
534
|
-
node_fs_1.default.writeFileSync(ps, envScriptPs(tenantBaseUrl(), (0, connection_1.readConnection)()?.workspaceKey ?? null));
|
|
535
|
-
}
|
|
536
|
-
/**
|
|
537
|
-
* What sign in calls: refresh the setup script, and on a Python install that
|
|
538
|
-
* was never set up, do the setup now (manual 1.1, Option 3).
|
|
539
|
-
*
|
|
540
|
-
* npm runs the setup as it installs and the install script runs it itself, but
|
|
541
|
-
* pip has no step of its own, so the first sign in is the first moment this
|
|
542
|
-
* tool runs on a machine that asked for it. Returns the profiles it changed,
|
|
543
|
-
* for the caller to say so. Every other install is left to `refreshEnvScript`.
|
|
544
|
-
*/
|
|
545
|
-
function finishSetup() {
|
|
546
|
-
if ((0, self_1.installMethod)() === 'python' && !node_fs_1.default.existsSync(envScriptPath()))
|
|
547
|
-
return install().profilesTouched;
|
|
548
|
-
refreshEnvScript();
|
|
549
|
-
return [];
|
|
550
|
-
}
|
|
551
|
-
/** Does this profile carry our fenced line. */
|
|
552
|
-
function profileHasSetup(profile) {
|
|
553
|
-
try {
|
|
554
|
-
return node_fs_1.default.readFileSync(profile, 'utf8').includes(MARKER_START);
|
|
555
|
-
}
|
|
556
|
-
catch {
|
|
557
|
-
return false;
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
/**
|
|
561
|
-
* Take the line back out. An install you cannot cleanly undo is a liability.
|
|
562
|
-
*
|
|
563
|
-
* Removes only what the install wrote: the fenced profile block, the generated
|
|
564
|
-
* `env.sh` and our own Claude Desktop entry. The sign in and settings stay, and
|
|
565
|
-
* the caller says so, because deleting a live credential file is not revoking it.
|
|
566
|
-
*/
|
|
567
|
-
function uninstall() {
|
|
568
|
-
// Read first: once the program's folder is gone it can no longer be told.
|
|
569
|
-
const method = (0, self_1.installMethod)();
|
|
570
|
-
const cleaned = [];
|
|
571
|
-
for (const profile of [...powershellProfiles(), ...shellProfiles()]) {
|
|
572
|
-
let contents = '';
|
|
573
|
-
try {
|
|
574
|
-
contents = node_fs_1.default.readFileSync(profile, 'utf8');
|
|
575
|
-
}
|
|
576
|
-
catch {
|
|
577
|
-
continue;
|
|
578
|
-
}
|
|
579
|
-
if (!contents.includes(MARKER_START))
|
|
580
|
-
continue;
|
|
581
|
-
const next = contents
|
|
582
|
-
.replace(new RegExp(`\\n?${MARKER_START}[\\s\\S]*?${MARKER_END}\\n?`), '\n')
|
|
583
|
-
.replace(/\n{3,}/g, '\n\n');
|
|
584
|
-
node_fs_1.default.writeFileSync(profile, next);
|
|
585
|
-
cleaned.push(profile);
|
|
586
|
-
}
|
|
587
|
-
uninstallDesktopConnector();
|
|
588
|
-
const script = envScriptPath();
|
|
589
|
-
const scriptRemoved = node_fs_1.default.existsSync(script) || node_fs_1.default.existsSync(envScriptPathPs());
|
|
590
|
-
node_fs_1.default.rmSync(script, { force: true });
|
|
591
|
-
node_fs_1.default.rmSync(envScriptPathPs(), { force: true });
|
|
592
|
-
const programRemoved = method === 'script' ? removeStandaloneProgram() : false;
|
|
593
|
-
return { profilesCleaned: cleaned, scriptRemoved, programRemoved, method, kept: (0, config_1.homeDir)() };
|
|
594
|
-
}
|
|
595
|
-
/**
|
|
596
|
-
* The install script's program and its folder, and on Windows the PATH entry
|
|
597
|
-
* the installer added (manual 1.8). Only `~/.comprism/bin`: the sign in and
|
|
598
|
-
* settings beside it stay.
|
|
599
|
-
*
|
|
600
|
-
* A running program can be deleted on macOS and Linux. Windows refuses to
|
|
601
|
-
* delete it but allows it to be moved, so there the program is moved to the
|
|
602
|
-
* temporary folder and the folder removed at once; the moved copy is deleted a
|
|
603
|
-
* moment after this process exits. Everything is done before returning,
|
|
604
|
-
* rather than left to a background process: a background process can be
|
|
605
|
-
* stopped with its parent, and the first version, which worked that way, left
|
|
606
|
-
* the folder and the PATH entry behind on Windows Server.
|
|
607
|
-
*/
|
|
608
|
-
function removeStandaloneProgram() {
|
|
609
|
-
const bin = (0, self_1.standaloneBinDir)();
|
|
610
|
-
if (process.platform !== 'win32') {
|
|
611
|
-
node_fs_1.default.rmSync(bin, { recursive: true, force: true });
|
|
612
|
-
return true;
|
|
613
|
-
}
|
|
614
|
-
const q = (v) => v.replace(/'/g, "''");
|
|
615
|
-
(0, node_child_process_1.spawnSync)('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command',
|
|
616
|
-
`$b='${q(bin)}'; $p=[Environment]::GetEnvironmentVariable('Path','User'); `
|
|
617
|
-
+ `if ($p) { [Environment]::SetEnvironmentVariable('Path', (($p -split ';') | Where-Object { $_ -and $_ -ne $b }) -join ';', 'User') }`,
|
|
618
|
-
], { stdio: 'ignore', windowsHide: true });
|
|
619
|
-
const parked = node_path_1.default.join(node_os_1.default.tmpdir(), `comprism-removed-${process.pid}.exe`);
|
|
620
|
-
try {
|
|
621
|
-
node_fs_1.default.renameSync(node_path_1.default.join(bin, 'comprism.exe'), parked);
|
|
622
|
-
}
|
|
623
|
-
catch {
|
|
624
|
-
// Not there, or on another drive: the folder removal below says which.
|
|
625
|
-
}
|
|
626
|
-
try {
|
|
627
|
-
node_fs_1.default.rmSync(bin, { recursive: true, force: true });
|
|
628
|
-
}
|
|
629
|
-
catch {
|
|
630
|
-
return false;
|
|
631
|
-
}
|
|
632
|
-
(0, node_child_process_1.spawn)('cmd.exe', ['/d', '/c', `ping -n 3 127.0.0.1 >nul & del /f /q "${parked}"`], {
|
|
633
|
-
detached: true, stdio: 'ignore', windowsHide: true,
|
|
634
|
-
}).unref();
|
|
635
|
-
return true;
|
|
636
|
-
}
|
|
637
|
-
/** The shell form, quoted, for the profile script that must be a shell string. */
|
|
638
|
-
function launchShellString(launch) {
|
|
639
|
-
return [launch.command, ...launch.args]
|
|
640
|
-
.map((part) => (/[\s"'\\]/.test(part) ? `"${part.replace(/(["\\])/g, '\\$1')}"` : part))
|
|
641
|
-
.join(' ');
|
|
642
|
-
}
|
|
643
|
-
function resolveBinary() {
|
|
644
|
-
const compiled = node_path_1.default.join(__dirname, 'cli.js');
|
|
645
|
-
if (!node_fs_1.default.existsSync(compiled)) {
|
|
646
|
-
// Not running from a build - fall back to the name on PATH.
|
|
647
|
-
return { command: 'comprism', args: [] };
|
|
648
|
-
}
|
|
649
|
-
// Prefer the bare name when the shim on PATH is this same package, so the
|
|
650
|
-
// config keeps working if the package moves. Verified rather than assumed:
|
|
651
|
-
// a `comprism` belonging to some other install would be worse than a path.
|
|
652
|
-
for (const dir of (process.env.PATH || '').split(node_path_1.default.delimiter)) {
|
|
653
|
-
const shim = node_path_1.default.join(dir, 'comprism');
|
|
654
|
-
try {
|
|
655
|
-
if (node_fs_1.default.existsSync(shim) && node_fs_1.default.realpathSync(shim) === node_fs_1.default.realpathSync(compiled)) {
|
|
656
|
-
return { command: 'comprism', args: [] };
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
catch {
|
|
660
|
-
continue;
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
return { command: process.execPath, args: [compiled] };
|
|
664
|
-
}
|
|
665
|
-
/**
|
|
666
|
-
* How to start the CLI from an application launched by the Dock.
|
|
667
|
-
*
|
|
668
|
-
* ALWAYS absolute, never the bare name, and that is the difference between a
|
|
669
|
-
* connector that works and one that says "Server disconnected" forever.
|
|
670
|
-
*
|
|
671
|
-
* A desktop client is started by launchd, not by a shell. It inherits none of
|
|
672
|
-
* `~/.zshrc`, so `PATH` is `/usr/bin:/bin:/usr/sbin:/sbin` and `comprism` is
|
|
673
|
-
* not on it. Neither is `node`, which matters just as much: the shim's shebang
|
|
674
|
-
* is `#!/usr/bin/env node`, so even an absolute path to `cli.js` would fail to
|
|
675
|
-
* start. Naming the interpreter AND the script outright is the only form that
|
|
676
|
-
* does not depend on an environment we do not control.
|
|
677
|
-
*
|
|
678
|
-
* The shell profile keeps using `resolveBinary()`, where the bare name is
|
|
679
|
-
* genuinely better because it survives the package moving.
|
|
680
|
-
*/
|
|
681
|
-
function resolveDesktopBinary() {
|
|
682
|
-
if ((0, self_1.isStandalone)())
|
|
683
|
-
return { command: process.execPath, args: [] };
|
|
684
|
-
const compiled = node_path_1.default.join(__dirname, 'cli.js');
|
|
685
|
-
if (!node_fs_1.default.existsSync(compiled))
|
|
686
|
-
return resolveBinary();
|
|
687
|
-
return { command: process.execPath, args: [compiled] };
|
|
688
|
-
}
|
|
689
|
-
// ── the background service ──────────────────────────────────────────────────
|
|
690
|
-
async function proxyHealthy(port) {
|
|
691
|
-
try {
|
|
692
|
-
const res = await fetch(`http://127.0.0.1:${port}/__comprism/health`, {
|
|
693
|
-
signal: AbortSignal.timeout(1000),
|
|
694
|
-
});
|
|
695
|
-
return res.ok;
|
|
696
|
-
}
|
|
697
|
-
catch {
|
|
698
|
-
return false;
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
/**
|
|
702
|
-
* Start the proxy detached, so it outlives the shell that started it.
|
|
703
|
-
*
|
|
704
|
-
* Returns whether it came up. Never throws: a service that fails to start is a
|
|
705
|
-
* missing measurement, and the caller's job is to carry on regardless.
|
|
706
|
-
*/
|
|
707
|
-
async function startDaemon(port) {
|
|
708
|
-
if (await proxyHealthy(port))
|
|
709
|
-
return true;
|
|
710
|
-
(0, config_1.ensureHome)();
|
|
711
|
-
const out = node_fs_1.default.openSync(proxyLogPath(), 'a');
|
|
712
|
-
const child = (0, node_child_process_1.spawn)(...(0, self_1.selfLaunch)(['proxy', '--port', String(port)]), {
|
|
713
|
-
detached: true,
|
|
714
|
-
stdio: ['ignore', out, out],
|
|
715
|
-
});
|
|
716
|
-
child.unref();
|
|
717
|
-
if (child.pid)
|
|
718
|
-
node_fs_1.default.writeFileSync(pidFilePath(), String(child.pid));
|
|
719
|
-
for (let i = 0; i < 25; i++) {
|
|
720
|
-
if (await proxyHealthy(port))
|
|
721
|
-
return true;
|
|
722
|
-
await new Promise((r) => setTimeout(r, 120));
|
|
723
|
-
}
|
|
724
|
-
return false;
|
|
725
|
-
}
|
|
726
|
-
function stopDaemon() {
|
|
727
|
-
try {
|
|
728
|
-
const pid = Number(node_fs_1.default.readFileSync(pidFilePath(), 'utf8').trim());
|
|
729
|
-
if (!pid)
|
|
730
|
-
return false;
|
|
731
|
-
process.kill(pid, 'SIGTERM');
|
|
732
|
-
node_fs_1.default.rmSync(pidFilePath(), { force: true });
|
|
733
|
-
return true;
|
|
734
|
-
}
|
|
735
|
-
catch {
|
|
736
|
-
return false;
|
|
737
|
-
}
|
|
738
|
-
}
|