@cortex-agent/server 2026.10.15-2 → 2026.10.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -31
- package/defaults/board/board.css +140 -62
- package/defaults/board/scaffold.html +36 -13
- package/defaults/plugins/cortex-board/skills/board/SKILL.md +30 -22
- package/defaults/plugins/cortex-system/plugin.json +2 -2
- package/defaults/plugins/cortex-system/skills/browser/SKILL.md +56 -0
- package/dist/agent-adapter/claude/adapter.d.ts +2 -5
- package/dist/agent-adapter/claude/adapter.js +6 -5
- package/dist/agent-adapter/claude/assistant-blocks.d.ts +5 -0
- package/dist/agent-adapter/claude/assistant-blocks.js +61 -0
- package/dist/agent-adapter/claude/cache-refresh.d.ts +58 -0
- package/dist/agent-adapter/claude/cache-refresh.js +145 -0
- package/dist/agent-adapter/claude/cache-touch.d.ts +12 -0
- package/dist/agent-adapter/claude/cache-touch.js +75 -0
- package/dist/agent-adapter/claude/event-parser.d.ts +8 -3
- package/dist/agent-adapter/claude/event-parser.js +33 -17
- package/dist/agent-adapter/claude/event-translator.d.ts +2 -0
- package/dist/agent-adapter/claude/event-translator.js +2 -0
- package/dist/agent-adapter/claude/session-options.d.ts +0 -4
- package/dist/agent-adapter/claude/session-options.js +0 -9
- package/dist/agent-adapter/claude/spawn-args.d.ts +0 -3
- package/dist/agent-adapter/claude/spawn-args.js +2 -5
- package/dist/agent-adapter/claude/transcript-clear.d.ts +42 -0
- package/dist/agent-adapter/claude/transcript-clear.js +217 -0
- package/dist/agent-adapter/claude/turn-machine.d.ts +3 -2
- package/dist/agent-adapter/claude/turn-machine.js +21 -68
- package/dist/agent-adapter/claude/window-warmup.d.ts +13 -0
- package/dist/agent-adapter/claude/window-warmup.js +38 -0
- package/dist/agent-adapter/continuation-phase.js +3 -0
- package/dist/agent-adapter/normalize/event-types.d.ts +8 -0
- package/dist/agent-adapter/pi/event-parser.d.ts +1 -1
- package/dist/agent-adapter/pi/event-parser.js +43 -27
- package/dist/agent-adapter/pi/mcp-bridge.d.ts +1 -1
- package/dist/agent-adapter/pi/pi-session.d.ts +2 -0
- package/dist/agent-adapter/pi/pi-session.js +15 -0
- package/dist/agent-adapter/pi/session-options.d.ts +2 -6
- package/dist/agent-adapter/pi/session-options.js +2 -11
- package/dist/agent-adapter/run-events.d.ts +10 -0
- package/dist/agent-adapter/run-events.js +2 -0
- package/dist/agent-adapter/types.d.ts +1 -1
- package/dist/client-bundle/manifest.json +1 -1
- package/dist/core/locales/en.d.ts +1 -0
- package/dist/core/locales/slices/commands.d.ts +1 -0
- package/dist/core/locales/slices/commands.js +2 -0
- package/dist/core/settings-spec.d.ts +25 -0
- package/dist/core/settings-spec.js +34 -0
- package/dist/domain/agents/engine-selection.js +1 -1
- package/dist/domain/agents/subagent/registry.d.ts +2 -0
- package/dist/domain/agents/subagent/registry.js +8 -0
- package/dist/domain/agents/subagent/runner.js +0 -1
- package/dist/domain/browser/broker.d.ts +99 -0
- package/dist/domain/browser/broker.js +487 -0
- package/dist/domain/costs/claude-account.js +21 -0
- package/dist/domain/costs/rate-limit-throttle.js +3 -1
- package/dist/domain/costs/reset-account.d.ts +2 -0
- package/dist/domain/costs/usage-service.d.ts +1 -1
- package/dist/domain/costs/usage-service.js +20 -7
- package/dist/domain/mcp/tools/ui-file.js +1 -1
- package/dist/domain/remote/device-browser.js +1 -1
- package/dist/domain/remote/device-chrome-commands.js +2 -0
- package/dist/domain/remote/device-port.js +2 -2
- package/dist/domain/runs/builders.d.ts +2 -2
- package/dist/domain/runs/builders.js +2 -3
- package/dist/domain/runs/engine-spec.d.ts +5 -0
- package/dist/domain/runs/engine-spec.js +1 -2
- package/dist/domain/runs/request.d.ts +0 -1
- package/dist/domain/sessions/session-lifecycle.d.ts +0 -4
- package/dist/domain/sessions/session-lifecycle.js +1 -1
- package/dist/domain/system/own-bin-path.d.ts +13 -0
- package/dist/domain/system/own-bin-path.js +36 -0
- package/dist/domain/system/terminal-cli/index.d.ts +58 -0
- package/dist/domain/system/terminal-cli/index.js +100 -0
- package/dist/domain/system/terminal-cli/posix-profiles.d.ts +23 -0
- package/dist/domain/system/terminal-cli/posix-profiles.js +74 -0
- package/dist/domain/system/terminal-cli/registrar.d.ts +12 -0
- package/dist/domain/system/terminal-cli/registrar.js +1 -0
- package/dist/domain/system/terminal-cli/shims.d.ts +27 -0
- package/dist/domain/system/terminal-cli/shims.js +108 -0
- package/dist/domain/system/terminal-cli/state.d.ts +7 -0
- package/dist/domain/system/terminal-cli/state.js +36 -0
- package/dist/domain/system/terminal-cli/windows-user-path.d.ts +13 -0
- package/dist/domain/system/terminal-cli/windows-user-path.js +67 -0
- package/dist/domain/tui-session/tui-session-service.js +1 -1
- package/dist/domain/tui-session/types.d.ts +1 -1
- package/dist/domain/ui-service/app-router.d.ts +17 -6
- package/dist/domain/ui-service/app-router.js +3 -1
- package/dist/domain/ui-service/assistant-snapshots.js +2 -0
- package/dist/domain/ui-service/inline-media-types.d.ts +18 -0
- package/dist/domain/ui-service/inline-media-types.js +1 -0
- package/dist/domain/ui-service/input-schemas.d.ts +17 -17
- package/dist/domain/ui-service/input-schemas.js +9 -9
- package/dist/domain/ui-service/mutate/models.d.ts +3 -0
- package/dist/domain/ui-service/mutate/models.js +21 -2
- package/dist/domain/ui-service/mutate/resolve-media.d.ts +4 -0
- package/dist/domain/ui-service/mutate/resolve-media.js +17 -0
- package/dist/domain/ui-service/mutate/sessions.js +1 -4
- package/dist/domain/ui-service/query/sessions.js +1 -1
- package/dist/domain/ui-service/types.d.ts +8 -10
- package/dist/domain/ui-service/ui-service.d.ts +9 -6
- package/dist/domain/ui-service/ui-service.js +4 -1
- package/dist/entry/app.js +23 -0
- package/dist/entry/browser-cli.d.ts +39 -0
- package/dist/entry/browser-cli.js +317 -0
- package/dist/entry/cli-help.d.ts +1 -0
- package/dist/entry/cli-help.js +30 -0
- package/dist/entry/cli.js +2 -0
- package/dist/entry/daemon.js +2 -0
- package/dist/entry/path-cli.d.ts +4 -0
- package/dist/entry/path-cli.js +65 -0
- package/dist/entry/shutdown.js +7 -0
- package/dist/entry/start-ui-http.js +8 -0
- package/dist/entry/ui-service-wiring.js +2 -0
- package/dist/events/event-types.d.ts +2 -1
- package/dist/orchestration/agent-runner.d.ts +2 -2
- package/dist/orchestration/agent-runner.js +6 -6
- package/dist/orchestration/browser-webhook.d.ts +11 -0
- package/dist/orchestration/browser-webhook.js +28 -0
- package/dist/orchestration/cache-keep-warm.d.ts +77 -0
- package/dist/orchestration/cache-keep-warm.js +213 -0
- package/dist/orchestration/claude-window-warmup.d.ts +40 -0
- package/dist/orchestration/claude-window-warmup.js +126 -0
- package/dist/orchestration/conversation-request.d.ts +4 -7
- package/dist/orchestration/conversation-request.js +1 -2
- package/dist/orchestration/delta-coalescer.d.ts +4 -2
- package/dist/orchestration/delta-coalescer.js +5 -5
- package/dist/orchestration/edit-retry.js +3 -6
- package/dist/orchestration/inline-media-eager.d.ts +13 -0
- package/dist/orchestration/inline-media-eager.js +58 -0
- package/dist/orchestration/inline-media.d.ts +22 -0
- package/dist/orchestration/inline-media.js +151 -0
- package/dist/orchestration/interactions/ask-user-resume.js +3 -7
- package/dist/orchestration/routing/commands/usage-format.js +3 -0
- package/dist/orchestration/routing/webhook.js +4 -0
- package/dist/orchestration/session-compact.js +5 -7
- package/dist/orchestration/session-events.d.ts +2 -1
- package/dist/orchestration/session-events.js +1 -0
- package/dist/orchestration/transcript-sink.d.ts +6 -0
- package/dist/orchestration/transcript-sink.js +21 -2
- package/dist/orchestration/turn/turn-prep.d.ts +0 -8
- package/dist/orchestration/turn/turn-prep.js +0 -51
- package/dist/orchestration/turn/turn.js +4 -0
- package/dist/platform/adapters/tui/ports.d.ts +1 -1
- package/dist/platform/adapters/tui/tui-transcript.js +2 -0
- package/dist/platform/browser/agent-browser.d.ts +50 -0
- package/dist/platform/browser/agent-browser.js +165 -0
- package/dist/platform/browser/managed-browser.d.ts +1 -11
- package/dist/platform/browser/managed-browser.js +4 -12
- package/dist/platform/ui-http/browser-stream.d.ts +110 -0
- package/dist/platform/ui-http/browser-stream.js +447 -0
- package/dist/platform/ui-http/ui-http-server.d.ts +12 -0
- package/dist/platform/ui-http/ui-http-server.js +23 -6
- package/dist/store/conversation-history-reader.js +8 -0
- package/dist/store/conversation-history-repo.d.ts +8 -1
- package/dist/store/conversation-history-repo.js +5 -0
- package/dist/store/session-registry-journal.d.ts +0 -8
- package/dist/store/session-registry-journal.js +5 -17
- package/dist/store/session-registry-repo.d.ts +2 -3
- package/dist/store/session-registry-repo.js +0 -2
- package/package.json +4 -2
- package/web/dist/assets/board-math-css-CB4GJ6qO.js +2 -0
- package/web/dist/assets/index-CaSZPg_H.css +1 -0
- package/web/dist/assets/index-CzOR7Edh.js +522 -0
- package/web/dist/assets/{index-DaViXAg-.js → index-cIGFv27z.js} +1 -1
- package/web/dist/index.html +3 -2
- package/web/dist/theme.css +6 -0
- package/dist/agent-adapter/browser-mcp-server.d.ts +0 -13
- package/dist/agent-adapter/browser-mcp-server.js +0 -28
- package/dist/agent-adapter/claude/browser-mcp.d.ts +0 -9
- package/dist/agent-adapter/claude/browser-mcp.js +0 -10
- package/web/dist/assets/index-Cgx3gdHV.css +0 -1
- package/web/dist/assets/index-CpZWBVHr.js +0 -494
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { EngineSelection } from '../agents/engine-selection.js';
|
|
2
2
|
import type { RunRequest } from './request.js';
|
|
3
3
|
/** The policy every direct run opens under: the engine runs the turn and returns, with no inline
|
|
4
|
-
* wait for background work (`background: 'none'`), cost recorded, hooks and ambient rules on,
|
|
5
|
-
* direct MCP surface
|
|
4
|
+
* wait for background work (`background: 'none'`), cost recorded, hooks and ambient rules on, and
|
|
5
|
+
* the direct MCP surface.
|
|
6
6
|
*
|
|
7
7
|
* `captureTranscripts` must stay true: Claude writes a per-turn transcript file unless told not
|
|
8
8
|
* to, `captureTranscriptLogs` defaults to ON, and only a frozen subagent child opts out.
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
import { randomUUID } from 'node:crypto';
|
|
10
10
|
import { bareSpec } from './spec-loader.js';
|
|
11
11
|
/** The policy every direct run opens under: the engine runs the turn and returns, with no inline
|
|
12
|
-
* wait for background work (`background: 'none'`), cost recorded, hooks and ambient rules on,
|
|
13
|
-
* direct MCP surface
|
|
12
|
+
* wait for background work (`background: 'none'`), cost recorded, hooks and ambient rules on, and
|
|
13
|
+
* the direct MCP surface.
|
|
14
14
|
*
|
|
15
15
|
* `captureTranscripts` must stay true: Claude writes a per-turn transcript file unless told not
|
|
16
16
|
* to, `captureTranscriptLogs` defaults to ON, and only a frozen subagent child opts out.
|
|
@@ -23,7 +23,6 @@ export const DIRECT_RUN_POLICY = {
|
|
|
23
23
|
hooks: true,
|
|
24
24
|
loadRules: true,
|
|
25
25
|
mcpComposition: 'direct',
|
|
26
|
-
browserCdpEndpoint: null,
|
|
27
26
|
captureTranscripts: true,
|
|
28
27
|
};
|
|
29
28
|
/** Build the `RunRequest` for a continuation run. Every field not named in `o` is the shared
|
|
@@ -25,6 +25,11 @@ export declare function filterScopedPlugins(dirs: string[] | undefined, scope: P
|
|
|
25
25
|
* The selection carries a logical mode, not a gateway URL. An absent mode uses direct routing.
|
|
26
26
|
*/
|
|
27
27
|
export declare function buildPiGatewaySubPath(mode: string | null, provider: string): string | undefined;
|
|
28
|
+
/** Environment comes only from the resolved route, not user configuration. */
|
|
29
|
+
export declare function routeEnvFields(route: ModeEnv | undefined): {
|
|
30
|
+
sets?: Record<string, string>;
|
|
31
|
+
unsets?: string[];
|
|
32
|
+
};
|
|
28
33
|
/**
|
|
29
34
|
* Group the resolved inputs into the backend-neutral {@link EngineSpec}.
|
|
30
35
|
* Pure re-grouping: every value, condition and defaulting rule is the original flat builder's.
|
|
@@ -66,7 +66,6 @@ function spawnPolicy(request) {
|
|
|
66
66
|
allowlist: request.policy.mcpToolAllowlist === undefined
|
|
67
67
|
? undefined : canonicalizeMcpToolAllowlist(request.policy.mcpToolAllowlist),
|
|
68
68
|
configPaths: request.isolation?.mcpConfigPaths,
|
|
69
|
-
browserCdpEndpoint: request.policy.browserCdpEndpoint ?? undefined,
|
|
70
69
|
},
|
|
71
70
|
flags: {
|
|
72
71
|
// The request states what the run WANTS; the spec states what the engine is TOLD. `hooks`
|
|
@@ -126,7 +125,7 @@ function routeEnvDeletes(route) {
|
|
|
126
125
|
return deletes;
|
|
127
126
|
}
|
|
128
127
|
/** Environment comes only from the resolved route, not user configuration. */
|
|
129
|
-
function routeEnvFields(route) {
|
|
128
|
+
export function routeEnvFields(route) {
|
|
130
129
|
const sets = route ? routeEnvSets(route) : {};
|
|
131
130
|
const unsets = route ? routeEnvDeletes(route) : [];
|
|
132
131
|
return {
|
|
@@ -67,7 +67,6 @@ export interface RunRequest {
|
|
|
67
67
|
settingSources?: string[];
|
|
68
68
|
mcpComposition: McpComposition;
|
|
69
69
|
mcpToolAllowlist?: string[];
|
|
70
|
-
browserCdpEndpoint?: string | null;
|
|
71
70
|
captureTranscripts: boolean;
|
|
72
71
|
};
|
|
73
72
|
/** Present only on a production benchmark session's runs: the trial facts each attempt is
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { EngineSelection } from '../agents/engine-selection.js';
|
|
2
2
|
import type { SessionOrigin } from '../../store/session-registry-repo.js';
|
|
3
|
-
import type { SessionBrowserOption } from '../../store/session-registry-journal.js';
|
|
4
3
|
export interface SessionRegistryWriter {
|
|
5
4
|
registerSession(opts: {
|
|
6
5
|
sessionId: string;
|
|
@@ -12,7 +11,6 @@ export interface SessionRegistryWriter {
|
|
|
12
11
|
label?: string | null;
|
|
13
12
|
selection?: EngineSelection | null;
|
|
14
13
|
agentName?: string | null;
|
|
15
|
-
browser?: SessionBrowserOption | null;
|
|
16
14
|
boardId?: string | null;
|
|
17
15
|
teamLeadId?: string | null;
|
|
18
16
|
workerName?: string | null;
|
|
@@ -29,7 +27,6 @@ export interface RegisterSessionRecordOpts {
|
|
|
29
27
|
selection?: EngineSelection | null;
|
|
30
28
|
/** The agent template; absent means the channel/global default. */
|
|
31
29
|
agentName?: string | null;
|
|
32
|
-
browser?: SessionBrowserOption | null;
|
|
33
30
|
boardId?: string | null;
|
|
34
31
|
teamLeadId?: string | null;
|
|
35
32
|
workerName?: string | null;
|
|
@@ -55,7 +52,6 @@ interface CreateDirectSessionOpts {
|
|
|
55
52
|
agentName?: string | null;
|
|
56
53
|
selection?: EngineSelection | null;
|
|
57
54
|
seedDefault?: boolean;
|
|
58
|
-
browser?: SessionBrowserOption | null;
|
|
59
55
|
boardId?: string | null;
|
|
60
56
|
teamLeadId?: string | null;
|
|
61
57
|
workerName?: string | null;
|
|
@@ -13,7 +13,7 @@ export async function registerSessionRecord(store, opts) {
|
|
|
13
13
|
sessionId: opts.sessionId, channel: opts.channel, backend: selection.backend,
|
|
14
14
|
kind: scheduled ? 'scheduled' : 'local', origin: scheduled ? 'scheduled' : 'direct',
|
|
15
15
|
projectId: opts.projectId, label: opts.label ?? null, selection,
|
|
16
|
-
agentName: opts.agentName ?? null,
|
|
16
|
+
agentName: opts.agentName ?? null, boardId: opts.boardId ?? null,
|
|
17
17
|
...(opts.teamLeadId
|
|
18
18
|
? { teamLeadId: opts.teamLeadId, workerName: opts.workerName ?? null, workerBrief: opts.workerBrief ?? null }
|
|
19
19
|
: {}),
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Directories that hold this server's own `node` and npm-linked bins (`cortex`, `cortex-signal`).
|
|
3
|
+
* The npm bin dir is absent for a repo checkout, which has no global prefix.
|
|
4
|
+
*/
|
|
5
|
+
export declare function ownBinDirs(execPath?: string, installRoot?: string, platform?: NodeJS.Platform): string[];
|
|
6
|
+
/** Prepend each dir missing from `pathEnv`; entries already present keep their position. */
|
|
7
|
+
export declare function withDirsOnPath(pathEnv: string, dirs: string[], platform?: NodeJS.Platform): string;
|
|
8
|
+
/**
|
|
9
|
+
* Sessions inherit this process's env, and skills, waitpoint recipes and Claude hooks call bare
|
|
10
|
+
* `cortex`, `cortex-signal` and `node`. Make them resolve to this install however the daemon was
|
|
11
|
+
* started (desktop app, init-written service unit, terminal restart).
|
|
12
|
+
*/
|
|
13
|
+
export declare function ensureOwnBinsOnPath(): void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import { INSTALL_ROOT } from '../../core/paths.js';
|
|
3
|
+
import { npmPrefixFromInstallRoot } from '../../core/utils.js';
|
|
4
|
+
const SERVER_PACKAGE = '@cortex-agent/server';
|
|
5
|
+
/**
|
|
6
|
+
* Directories that hold this server's own `node` and npm-linked bins (`cortex`, `cortex-signal`).
|
|
7
|
+
* The npm bin dir is absent for a repo checkout, which has no global prefix.
|
|
8
|
+
*/
|
|
9
|
+
export function ownBinDirs(execPath = process.execPath, installRoot = INSTALL_ROOT, platform = process.platform) {
|
|
10
|
+
const p = platform === 'win32' ? path.win32 : path.posix;
|
|
11
|
+
const dirs = [p.dirname(execPath)];
|
|
12
|
+
const prefix = npmPrefixFromInstallRoot(installRoot, SERVER_PACKAGE, platform);
|
|
13
|
+
if (prefix)
|
|
14
|
+
dirs.push(platform === 'win32' ? prefix : p.join(prefix, 'bin'));
|
|
15
|
+
return dirs;
|
|
16
|
+
}
|
|
17
|
+
/** Prepend each dir missing from `pathEnv`; entries already present keep their position. */
|
|
18
|
+
export function withDirsOnPath(pathEnv, dirs, platform = process.platform) {
|
|
19
|
+
const p = platform === 'win32' ? path.win32 : path.posix;
|
|
20
|
+
const key = (dir) => {
|
|
21
|
+
const normalized = p.normalize(dir).replace(/[\\/]+$/, '');
|
|
22
|
+
return platform === 'win32' ? normalized.toLowerCase() : normalized;
|
|
23
|
+
};
|
|
24
|
+
const entries = pathEnv.split(p.delimiter).filter(Boolean);
|
|
25
|
+
const present = new Set(entries.map(key));
|
|
26
|
+
const missing = dirs.filter((dir) => !present.has(key(dir)));
|
|
27
|
+
return [...missing, ...entries].join(p.delimiter);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Sessions inherit this process's env, and skills, waitpoint recipes and Claude hooks call bare
|
|
31
|
+
* `cortex`, `cortex-signal` and `node`. Make them resolve to this install however the daemon was
|
|
32
|
+
* started (desktop app, init-written service unit, terminal restart).
|
|
33
|
+
*/
|
|
34
|
+
export function ensureOwnBinsOnPath() {
|
|
35
|
+
process.env.PATH = withDirsOnPath(process.env.PATH ?? '', ownBinDirs());
|
|
36
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type PathRegistrar } from './registrar.js';
|
|
2
|
+
export interface TerminalCliContext {
|
|
3
|
+
home: string;
|
|
4
|
+
node: string;
|
|
5
|
+
installRoot: string;
|
|
6
|
+
platform: NodeJS.Platform;
|
|
7
|
+
pathEnv: string;
|
|
8
|
+
registrar: PathRegistrar;
|
|
9
|
+
}
|
|
10
|
+
/** Absolute paths of `names` found in `pathEnv`, skipping `excludeDirs`. */
|
|
11
|
+
export declare function findOnPath(names: string[], pathEnv: string, platform: NodeJS.Platform, excludeDirs?: string[]): string[];
|
|
12
|
+
export declare function defaultTerminalCliContext(home: string): TerminalCliContext;
|
|
13
|
+
export declare function installTerminalCli(ctx: TerminalCliContext, dryRun: boolean): {
|
|
14
|
+
ok: boolean;
|
|
15
|
+
action: string;
|
|
16
|
+
dry_run: boolean;
|
|
17
|
+
dir: string;
|
|
18
|
+
shims: string[];
|
|
19
|
+
written: string[];
|
|
20
|
+
path_targets: {
|
|
21
|
+
target: string;
|
|
22
|
+
changed: boolean;
|
|
23
|
+
}[];
|
|
24
|
+
shadowed: string[];
|
|
25
|
+
};
|
|
26
|
+
export declare function removeTerminalCli(ctx: TerminalCliContext, dryRun: boolean): {
|
|
27
|
+
ok: boolean;
|
|
28
|
+
action: string;
|
|
29
|
+
dry_run: boolean;
|
|
30
|
+
dir: string;
|
|
31
|
+
removed: string[];
|
|
32
|
+
path_targets: {
|
|
33
|
+
target: string;
|
|
34
|
+
changed: boolean;
|
|
35
|
+
}[];
|
|
36
|
+
};
|
|
37
|
+
export declare function terminalCliStatus(ctx: TerminalCliContext): {
|
|
38
|
+
ok: boolean;
|
|
39
|
+
dir: string;
|
|
40
|
+
installed: boolean;
|
|
41
|
+
shims: string[];
|
|
42
|
+
stale: string[];
|
|
43
|
+
path_targets: {
|
|
44
|
+
target: string;
|
|
45
|
+
registered: boolean;
|
|
46
|
+
}[];
|
|
47
|
+
on_current_path: boolean;
|
|
48
|
+
};
|
|
49
|
+
export type TerminalCliSync = {
|
|
50
|
+
action: 'skipped' | 'installed' | 'refreshed';
|
|
51
|
+
files: string[];
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Server start. A desktop-runtime install gets the terminal command unless the user removed it,
|
|
55
|
+
* which also covers installs that predate it once they update. Elsewhere, existing launchers are
|
|
56
|
+
* only re-pointed at the node and entry running now (e.g. after a bundled Node upgrade).
|
|
57
|
+
*/
|
|
58
|
+
export declare function syncTerminalCli(ctx: TerminalCliContext): TerminalCliSync;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as os from 'os';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import { INSTALL_ROOT } from '../../../core/paths.js';
|
|
5
|
+
import { ownBinDirs } from '../own-bin-path.js';
|
|
6
|
+
import { isChanged } from './registrar.js';
|
|
7
|
+
import { posixRegistrar } from './posix-profiles.js';
|
|
8
|
+
import { windowsRegistrar } from './windows-user-path.js';
|
|
9
|
+
import { listManagedShims, packageBins, refreshShims, removeShims, renderShims, shimDir, staleShims, writeShims, } from './shims.js';
|
|
10
|
+
import { isManagedRuntimeInstall, readTerminalCliState, writeTerminalCliState } from './state.js';
|
|
11
|
+
const pathApi = (platform) => (platform === 'win32' ? path.win32 : path.posix);
|
|
12
|
+
const pathKey = (dir, platform) => {
|
|
13
|
+
const normalized = pathApi(platform).normalize(dir).replace(/[\\/]+$/, '');
|
|
14
|
+
return platform === 'win32' ? normalized.toLowerCase() : normalized;
|
|
15
|
+
};
|
|
16
|
+
/** Absolute paths of `names` found in `pathEnv`, skipping `excludeDirs`. */
|
|
17
|
+
export function findOnPath(names, pathEnv, platform, excludeDirs = []) {
|
|
18
|
+
const p = pathApi(platform);
|
|
19
|
+
const excluded = new Set(excludeDirs.map((dir) => pathKey(dir, platform)));
|
|
20
|
+
const dirs = pathEnv.split(p.delimiter).filter((dir) => dir && !excluded.has(pathKey(dir, platform)));
|
|
21
|
+
return dirs.flatMap((dir) => names.map((name) => p.join(dir, name))).filter((file) => fs.existsSync(file));
|
|
22
|
+
}
|
|
23
|
+
function defaultRegistrar(platform, pathEnv) {
|
|
24
|
+
if (platform === 'win32')
|
|
25
|
+
return windowsRegistrar();
|
|
26
|
+
return posixRegistrar({
|
|
27
|
+
home: os.homedir(),
|
|
28
|
+
platform,
|
|
29
|
+
zdotdir: process.env.ZDOTDIR,
|
|
30
|
+
exists: fs.existsSync,
|
|
31
|
+
hasZsh: findOnPath(['zsh'], pathEnv, platform).length > 0,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
export function defaultTerminalCliContext(home) {
|
|
35
|
+
const platform = process.platform;
|
|
36
|
+
const pathEnv = process.env.PATH ?? '';
|
|
37
|
+
return { home, node: process.execPath, installRoot: INSTALL_ROOT, platform, pathEnv, registrar: defaultRegistrar(platform, pathEnv) };
|
|
38
|
+
}
|
|
39
|
+
function renderFor(ctx) {
|
|
40
|
+
return renderShims({ node: ctx.node, home: ctx.home, bins: packageBins(ctx.installRoot) }, ctx.platform);
|
|
41
|
+
}
|
|
42
|
+
const summarize = (changes) => changes.map((change) => ({ target: change.target, changed: isChanged(change) }));
|
|
43
|
+
/** Another `cortex` that new terminals will no longer reach first. */
|
|
44
|
+
function shadowedCortex(ctx, dir) {
|
|
45
|
+
const names = ctx.platform === 'win32' ? ['cortex.cmd', 'cortex.exe', 'cortex'] : ['cortex'];
|
|
46
|
+
return findOnPath(names, ctx.pathEnv, ctx.platform, [dir, ...ownBinDirs(ctx.node, ctx.installRoot, ctx.platform)]);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* PATH first, launchers second, state last: an interrupted install leaves no launchers behind, so
|
|
50
|
+
* the next server start sees it as not installed and runs it again.
|
|
51
|
+
*/
|
|
52
|
+
function applyInstall(ctx, dir, shims, changes) {
|
|
53
|
+
ctx.registrar.apply(changes);
|
|
54
|
+
const written = writeShims(dir, shims);
|
|
55
|
+
writeTerminalCliState(ctx.home, 'installed');
|
|
56
|
+
return written;
|
|
57
|
+
}
|
|
58
|
+
export function installTerminalCli(ctx, dryRun) {
|
|
59
|
+
const dir = shimDir(ctx.home);
|
|
60
|
+
const shims = renderFor(ctx);
|
|
61
|
+
const changes = ctx.registrar.plan(dir, 'add');
|
|
62
|
+
const written = dryRun ? staleShims(dir, shims) : applyInstall(ctx, dir, shims, changes);
|
|
63
|
+
return {
|
|
64
|
+
ok: true, action: 'install', dry_run: dryRun, dir, shims: shims.map((shim) => shim.file), written,
|
|
65
|
+
path_targets: summarize(changes), shadowed: shadowedCortex(ctx, dir),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export function removeTerminalCli(ctx, dryRun) {
|
|
69
|
+
const dir = shimDir(ctx.home);
|
|
70
|
+
const changes = ctx.registrar.plan(dir, 'remove');
|
|
71
|
+
const removed = dryRun ? listManagedShims(dir) : removeShims(dir);
|
|
72
|
+
if (!dryRun) {
|
|
73
|
+
ctx.registrar.apply(changes);
|
|
74
|
+
writeTerminalCliState(ctx.home, 'removed');
|
|
75
|
+
}
|
|
76
|
+
return { ok: true, action: 'remove', dry_run: dryRun, dir, removed, path_targets: summarize(changes) };
|
|
77
|
+
}
|
|
78
|
+
export function terminalCliStatus(ctx) {
|
|
79
|
+
const dir = shimDir(ctx.home);
|
|
80
|
+
const installed = listManagedShims(dir);
|
|
81
|
+
const stale = installed.length > 0 ? staleShims(dir, renderFor(ctx)) : [];
|
|
82
|
+
const registered = ctx.registrar.plan(dir, 'add').map((change) => ({ target: change.target, registered: !isChanged(change) }));
|
|
83
|
+
const onPath = ctx.pathEnv.split(pathApi(ctx.platform).delimiter).some((entry) => entry && pathKey(entry, ctx.platform) === pathKey(dir, ctx.platform));
|
|
84
|
+
return { ok: true, dir, installed: installed.length > 0, shims: installed, stale, path_targets: registered, on_current_path: onPath };
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Server start. A desktop-runtime install gets the terminal command unless the user removed it,
|
|
88
|
+
* which also covers installs that predate it once they update. Elsewhere, existing launchers are
|
|
89
|
+
* only re-pointed at the node and entry running now (e.g. after a bundled Node upgrade).
|
|
90
|
+
*/
|
|
91
|
+
export function syncTerminalCli(ctx) {
|
|
92
|
+
if (readTerminalCliState(ctx.home) === 'removed')
|
|
93
|
+
return { action: 'skipped', files: [] };
|
|
94
|
+
const dir = shimDir(ctx.home);
|
|
95
|
+
const missing = listManagedShims(dir).length === 0;
|
|
96
|
+
if (missing && isManagedRuntimeInstall(ctx.home, ctx.installRoot, ctx.platform)) {
|
|
97
|
+
return { action: 'installed', files: installTerminalCli(ctx, false).written };
|
|
98
|
+
}
|
|
99
|
+
return { action: 'refreshed', files: refreshShims(dir, renderFor(ctx)) };
|
|
100
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type PathRegistrar } from './registrar.js';
|
|
2
|
+
export declare function renderBlock(dir: string): string;
|
|
3
|
+
/**
|
|
4
|
+
* Insert or refresh the block. `top` serves ~/.bashrc, whose interactive guard would otherwise skip
|
|
5
|
+
* an appended block for non-interactive `ssh host cortex …`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function upsertBlock(content: string, block: string, position: 'top' | 'bottom'): string;
|
|
8
|
+
/** Undo `upsertBlock`, including the blank separator line it added. */
|
|
9
|
+
export declare function removeBlock(content: string): string;
|
|
10
|
+
interface ProfileEnv {
|
|
11
|
+
home: string;
|
|
12
|
+
platform: NodeJS.Platform;
|
|
13
|
+
zdotdir?: string;
|
|
14
|
+
exists: (file: string) => boolean;
|
|
15
|
+
hasZsh: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** rustup's set: ~/.profile always; bash files that exist; ~/.zshenv where zsh is in use. */
|
|
18
|
+
export declare function profileTargets(env: ProfileEnv): Array<{
|
|
19
|
+
file: string;
|
|
20
|
+
position: 'top' | 'bottom';
|
|
21
|
+
}>;
|
|
22
|
+
export declare function posixRegistrar(env: ProfileEnv): PathRegistrar;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { isChanged } from './registrar.js';
|
|
4
|
+
const BEGIN = '# >>> cortex >>>';
|
|
5
|
+
const END = '# <<< cortex <<<';
|
|
6
|
+
const BLOCK_RE = /# >>> cortex >>>\n[\s\S]*?\n# <<< cortex <<<\n?/;
|
|
7
|
+
const shQuote = (value) => `'${value.replace(/'/g, `'\\''`)}'`;
|
|
8
|
+
export function renderBlock(dir) {
|
|
9
|
+
const q = shQuote(dir);
|
|
10
|
+
return `${BEGIN}\ncase ":\${PATH}:" in *:${q}:*) ;; *) PATH=${q}:"$PATH"; export PATH ;; esac\n${END}\n`;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Insert or refresh the block. `top` serves ~/.bashrc, whose interactive guard would otherwise skip
|
|
14
|
+
* an appended block for non-interactive `ssh host cortex …`.
|
|
15
|
+
*/
|
|
16
|
+
export function upsertBlock(content, block, position) {
|
|
17
|
+
if (BLOCK_RE.test(content))
|
|
18
|
+
return content.replace(BLOCK_RE, () => block);
|
|
19
|
+
if (!content)
|
|
20
|
+
return block;
|
|
21
|
+
if (position === 'top')
|
|
22
|
+
return `${block}\n${content}`;
|
|
23
|
+
return `${content}${content.endsWith('\n') ? '' : '\n'}\n${block}`;
|
|
24
|
+
}
|
|
25
|
+
/** Undo `upsertBlock`, including the blank separator line it added. */
|
|
26
|
+
export function removeBlock(content) {
|
|
27
|
+
const match = BLOCK_RE.exec(content);
|
|
28
|
+
if (!match)
|
|
29
|
+
return content;
|
|
30
|
+
const before = content.slice(0, match.index);
|
|
31
|
+
const after = content.slice(match.index + match[0].length);
|
|
32
|
+
if (before === '')
|
|
33
|
+
return after.replace(/^\n/, '');
|
|
34
|
+
return (before.endsWith('\n\n') ? before.slice(0, -1) : before) + after;
|
|
35
|
+
}
|
|
36
|
+
/** rustup's set: ~/.profile always; bash files that exist; ~/.zshenv where zsh is in use. */
|
|
37
|
+
export function profileTargets(env) {
|
|
38
|
+
const at = (name) => path.join(env.home, name);
|
|
39
|
+
const targets = [{ file: at('.profile'), position: 'bottom' }];
|
|
40
|
+
if (env.exists(at('.bashrc')))
|
|
41
|
+
targets.push({ file: at('.bashrc'), position: 'top' });
|
|
42
|
+
if (env.exists(at('.bash_profile')))
|
|
43
|
+
targets.push({ file: at('.bash_profile'), position: 'bottom' });
|
|
44
|
+
const zdot = env.zdotdir || env.home;
|
|
45
|
+
const usesZsh = env.platform === 'darwin' || env.hasZsh || env.exists(path.join(zdot, '.zshrc'));
|
|
46
|
+
if (usesZsh)
|
|
47
|
+
targets.push({ file: path.join(zdot, '.zshenv'), position: 'bottom' });
|
|
48
|
+
return targets;
|
|
49
|
+
}
|
|
50
|
+
function readOrNull(file) {
|
|
51
|
+
try {
|
|
52
|
+
return fs.readFileSync(file, 'utf8');
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function planOne(file, position, dir, mode) {
|
|
59
|
+
const before = readOrNull(file);
|
|
60
|
+
if (mode === 'remove')
|
|
61
|
+
return { target: file, before, after: before === null ? null : removeBlock(before) };
|
|
62
|
+
return { target: file, before, after: upsertBlock(before ?? '', renderBlock(dir), position) };
|
|
63
|
+
}
|
|
64
|
+
export function posixRegistrar(env) {
|
|
65
|
+
return {
|
|
66
|
+
plan: (dir, mode) => profileTargets(env).map(({ file, position }) => planOne(file, position, dir, mode)),
|
|
67
|
+
apply: (changes) => {
|
|
68
|
+
for (const change of changes.filter(isChanged)) {
|
|
69
|
+
if (change.after !== null)
|
|
70
|
+
fs.writeFileSync(change.target, change.after);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** One place that puts the shim dir on PATH: a shell profile file or the Windows user Path. */
|
|
2
|
+
export interface PathChange {
|
|
3
|
+
target: string;
|
|
4
|
+
before: string | null;
|
|
5
|
+
after: string | null;
|
|
6
|
+
}
|
|
7
|
+
export type PathMode = 'add' | 'remove';
|
|
8
|
+
export interface PathRegistrar {
|
|
9
|
+
plan(dir: string, mode: PathMode): PathChange[];
|
|
10
|
+
apply(changes: PathChange[]): void;
|
|
11
|
+
}
|
|
12
|
+
export declare const isChanged: (change: PathChange) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const isChanged = (change) => change.before !== change.after;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Marks files this module owns; remove and refresh never touch a file without it. */
|
|
2
|
+
export declare const SHIM_MARKER = "cortex-managed-shim";
|
|
3
|
+
export interface ShimTarget {
|
|
4
|
+
node: string;
|
|
5
|
+
home: string;
|
|
6
|
+
bins: Array<{
|
|
7
|
+
name: string;
|
|
8
|
+
entry: string;
|
|
9
|
+
}>;
|
|
10
|
+
}
|
|
11
|
+
export interface RenderedShim {
|
|
12
|
+
file: string;
|
|
13
|
+
content: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function shimDir(home: string): string;
|
|
16
|
+
/** The package's `bin` map as absolute entry paths. */
|
|
17
|
+
export declare function packageBins(installRoot: string): ShimTarget['bins'];
|
|
18
|
+
export declare function renderShims(target: ShimTarget, platform?: NodeJS.Platform): RenderedShim[];
|
|
19
|
+
export declare function listManagedShims(dir: string): string[];
|
|
20
|
+
/** Shims whose on-disk content differs from `rendered` (missing ones included). */
|
|
21
|
+
export declare function staleShims(dir: string, rendered: RenderedShim[]): string[];
|
|
22
|
+
/** Write changed shims and drop managed ones no longer rendered; returns files written. */
|
|
23
|
+
export declare function writeShims(dir: string, rendered: RenderedShim[]): string[];
|
|
24
|
+
/** Delete managed shims, then the directory if nothing else is in it; returns files removed. */
|
|
25
|
+
export declare function removeShims(dir: string): string[];
|
|
26
|
+
/** Re-point existing shims at the running node and entry (e.g. after a bundled Node upgrade). */
|
|
27
|
+
export declare function refreshShims(dir: string, rendered: RenderedShim[]): string[];
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
/** Marks files this module owns; remove and refresh never touch a file without it. */
|
|
4
|
+
export const SHIM_MARKER = 'cortex-managed-shim';
|
|
5
|
+
const HEADER = `${SHIM_MARKER}: written by \`cortex path install\`, refreshed when the daemon starts.`;
|
|
6
|
+
export function shimDir(home) {
|
|
7
|
+
return path.join(home, 'runtime', 'bin');
|
|
8
|
+
}
|
|
9
|
+
/** The package's `bin` map as absolute entry paths. */
|
|
10
|
+
export function packageBins(installRoot) {
|
|
11
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(installRoot, 'package.json'), 'utf8'));
|
|
12
|
+
return Object.entries(manifest.bin ?? {}).map(([name, rel]) => ({ name, entry: path.join(installRoot, rel) }));
|
|
13
|
+
}
|
|
14
|
+
const shQuote = (value) => `'${value.replace(/'/g, `'\\''`)}'`;
|
|
15
|
+
function posixShim(node, entry, home, nodeDirOnPath) {
|
|
16
|
+
return [
|
|
17
|
+
'#!/bin/sh',
|
|
18
|
+
`# ${HEADER}`,
|
|
19
|
+
`if [ -z "\${CORTEX_HOME:-}" ]; then CORTEX_HOME=${shQuote(home)}; fi`,
|
|
20
|
+
'export CORTEX_HOME',
|
|
21
|
+
`PATH=${shQuote(nodeDirOnPath)}:"$PATH"; export PATH`,
|
|
22
|
+
`exec ${shQuote(node)} ${shQuote(entry)} "$@"`,
|
|
23
|
+
'',
|
|
24
|
+
].join('\n');
|
|
25
|
+
}
|
|
26
|
+
function cmdShim(node, entry, home) {
|
|
27
|
+
const esc = (value) => value.replace(/%/g, '%%');
|
|
28
|
+
return [
|
|
29
|
+
'@echo off',
|
|
30
|
+
`rem ${HEADER}`,
|
|
31
|
+
'setlocal',
|
|
32
|
+
`if not defined CORTEX_HOME set "CORTEX_HOME=${esc(home)}"`,
|
|
33
|
+
`set "PATH=${esc(path.win32.dirname(node))};%PATH%"`,
|
|
34
|
+
`"${esc(node)}" "${esc(entry)}" %*`,
|
|
35
|
+
'',
|
|
36
|
+
].join('\r\n');
|
|
37
|
+
}
|
|
38
|
+
/** `C:\x\y` → `C:/x/y` (native programs) and `/c/x/y` (Git Bash PATH entries). */
|
|
39
|
+
const forward = (winPath) => winPath.replace(/\\/g, '/');
|
|
40
|
+
const msys = (winPath) => forward(winPath).replace(/^([A-Za-z]):/, (_, drive) => `/${drive.toLowerCase()}`);
|
|
41
|
+
export function renderShims(target, platform = process.platform) {
|
|
42
|
+
if (platform !== 'win32') {
|
|
43
|
+
const nodeDir = path.posix.dirname(target.node);
|
|
44
|
+
return target.bins.map(({ name, entry }) => ({ file: name, content: posixShim(target.node, entry, target.home, nodeDir) }));
|
|
45
|
+
}
|
|
46
|
+
return target.bins.flatMap(({ name, entry }) => [
|
|
47
|
+
{ file: `${name}.cmd`, content: cmdShim(target.node, entry, target.home) },
|
|
48
|
+
{
|
|
49
|
+
file: name,
|
|
50
|
+
content: posixShim(forward(target.node), forward(entry), forward(target.home), msys(path.win32.dirname(target.node))),
|
|
51
|
+
},
|
|
52
|
+
]);
|
|
53
|
+
}
|
|
54
|
+
function readIfExists(file) {
|
|
55
|
+
try {
|
|
56
|
+
return fs.readFileSync(file, 'utf8');
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export function listManagedShims(dir) {
|
|
63
|
+
let names;
|
|
64
|
+
try {
|
|
65
|
+
names = fs.readdirSync(dir);
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
return names.filter((name) => readIfExists(path.join(dir, name))?.includes(SHIM_MARKER)).sort();
|
|
71
|
+
}
|
|
72
|
+
/** Shims whose on-disk content differs from `rendered` (missing ones included). */
|
|
73
|
+
export function staleShims(dir, rendered) {
|
|
74
|
+
return rendered.filter((shim) => readIfExists(path.join(dir, shim.file)) !== shim.content).map((shim) => shim.file);
|
|
75
|
+
}
|
|
76
|
+
/** Write changed shims and drop managed ones no longer rendered; returns files written. */
|
|
77
|
+
export function writeShims(dir, rendered) {
|
|
78
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
79
|
+
const written = staleShims(dir, rendered);
|
|
80
|
+
for (const file of written) {
|
|
81
|
+
const shim = rendered.find((candidate) => candidate.file === file);
|
|
82
|
+
fs.writeFileSync(path.join(dir, file), shim.content, { mode: 0o755 });
|
|
83
|
+
fs.chmodSync(path.join(dir, file), 0o755);
|
|
84
|
+
}
|
|
85
|
+
const keep = new Set(rendered.map((shim) => shim.file));
|
|
86
|
+
for (const name of listManagedShims(dir))
|
|
87
|
+
if (!keep.has(name))
|
|
88
|
+
fs.unlinkSync(path.join(dir, name));
|
|
89
|
+
return written;
|
|
90
|
+
}
|
|
91
|
+
/** Delete managed shims, then the directory if nothing else is in it; returns files removed. */
|
|
92
|
+
export function removeShims(dir) {
|
|
93
|
+
const removed = listManagedShims(dir);
|
|
94
|
+
for (const name of removed)
|
|
95
|
+
fs.unlinkSync(path.join(dir, name));
|
|
96
|
+
try {
|
|
97
|
+
if (fs.readdirSync(dir).length === 0)
|
|
98
|
+
fs.rmdirSync(dir);
|
|
99
|
+
}
|
|
100
|
+
catch { /* already gone */ }
|
|
101
|
+
return removed;
|
|
102
|
+
}
|
|
103
|
+
/** Re-point existing shims at the running node and entry (e.g. after a bundled Node upgrade). */
|
|
104
|
+
export function refreshShims(dir, rendered) {
|
|
105
|
+
if (listManagedShims(dir).length === 0)
|
|
106
|
+
return [];
|
|
107
|
+
return writeShims(dir, rendered);
|
|
108
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** The user's last explicit choice; `removed` keeps the server from adding the command back. */
|
|
2
|
+
export type TerminalCliState = 'installed' | 'removed';
|
|
3
|
+
export declare const terminalCliStateFile: (home: string) => string;
|
|
4
|
+
export declare function readTerminalCliState(home: string): TerminalCliState | null;
|
|
5
|
+
export declare function writeTerminalCliState(home: string, state: TerminalCliState): void;
|
|
6
|
+
/** The desktop app's private install: the server package lives in `<home>/runtime/prefix`. */
|
|
7
|
+
export declare function isManagedRuntimeInstall(home: string, installRoot: string, platform: NodeJS.Platform): boolean;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { npmPrefixFromInstallRoot } from '../../../core/utils.js';
|
|
4
|
+
export const terminalCliStateFile = (home) => path.join(home, 'runtime', 'terminal-cli.json');
|
|
5
|
+
export function readTerminalCliState(home) {
|
|
6
|
+
try {
|
|
7
|
+
const state = JSON.parse(fs.readFileSync(terminalCliStateFile(home), 'utf8'))?.state;
|
|
8
|
+
return state === 'installed' || state === 'removed' ? state : null;
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function writeTerminalCliState(home, state) {
|
|
15
|
+
const file = terminalCliStateFile(home);
|
|
16
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
17
|
+
fs.writeFileSync(file, `${JSON.stringify({ state, updated_at: new Date().toISOString() }, null, 2)}\n`);
|
|
18
|
+
}
|
|
19
|
+
function canonical(dir, platform) {
|
|
20
|
+
let resolved = dir;
|
|
21
|
+
try {
|
|
22
|
+
resolved = fs.realpathSync(dir);
|
|
23
|
+
}
|
|
24
|
+
catch { /* compare the literal path */ }
|
|
25
|
+
const p = platform === 'win32' ? path.win32 : path.posix;
|
|
26
|
+
const normalized = p.normalize(resolved).replace(/[\\/]+$/, '');
|
|
27
|
+
return platform === 'win32' ? normalized.toLowerCase() : normalized;
|
|
28
|
+
}
|
|
29
|
+
/** The desktop app's private install: the server package lives in `<home>/runtime/prefix`. */
|
|
30
|
+
export function isManagedRuntimeInstall(home, installRoot, platform) {
|
|
31
|
+
const prefix = npmPrefixFromInstallRoot(installRoot, '@cortex-agent/server', platform);
|
|
32
|
+
if (!prefix)
|
|
33
|
+
return false;
|
|
34
|
+
const p = platform === 'win32' ? path.win32 : path.posix;
|
|
35
|
+
return canonical(prefix, platform) === canonical(p.join(home, 'runtime', 'prefix'), platform);
|
|
36
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type PathRegistrar } from './registrar.js';
|
|
2
|
+
export declare const USER_PATH_TARGET = "HKCU\\Environment\\Path";
|
|
3
|
+
/** Prepend `dir` unless an equivalent entry exists; `null` means the value is absent. */
|
|
4
|
+
export declare function addUserPathEntry(raw: string | null, dir: string): string;
|
|
5
|
+
/** Drop `dir`, leaving every other byte of the value as it was. */
|
|
6
|
+
export declare function removeUserPathEntry(raw: string | null, dir: string): string | null;
|
|
7
|
+
/** Null when the user Path value does not exist. */
|
|
8
|
+
export declare function readUserPath(): string | null;
|
|
9
|
+
export declare function writeUserPath(value: string | null): void;
|
|
10
|
+
export declare function windowsRegistrar(io?: {
|
|
11
|
+
read: typeof readUserPath;
|
|
12
|
+
write: typeof writeUserPath;
|
|
13
|
+
}): PathRegistrar;
|