@finogeeks2026/finshield-kilo 0.0.0-stage → 0.11.1-debug.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.rtf +28 -0
- package/README-zh.md +52 -0
- package/README.md +185 -3
- package/THIRD-PARTY-NOTICES.md +212 -0
- package/bin/finshield_kilo_native.dll +0 -0
- package/install/download-source.json +3 -0
- package/install/runtime.js +138 -0
- package/package.json +67 -6
- package/policy/candidate.yaml +364 -0
- package/src/activation.js +75 -0
- package/src/arguments.mjs +32 -0
- package/src/connector.js +91 -0
- package/src/handoff.mjs +26 -0
- package/src/known-folders.mjs +20 -0
- package/src/lifecycle-settings.mjs +29 -0
- package/src/management.mjs +113 -0
- package/src/native.mjs +112 -0
- package/src/options.mjs +23 -0
- package/src/preparation.js +55 -0
- package/src/tui.mjs +42 -0
- package/updater/coordinator.js +296 -0
- package/updater/host.mjs +89 -0
- package/updater/native.js +28 -0
- package/updater/protocol.js +40 -0
- package/updater/server.mjs +143 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {win32 as path} from 'node:path';
|
|
2
|
+
import {readFileSync, existsSync} from 'node:fs';
|
|
3
|
+
import {absolutePath} from './options.mjs';
|
|
4
|
+
|
|
5
|
+
const manifest = JSON.parse(readFileSync(new URL('../package.json', import.meta.url)));
|
|
6
|
+
export const pluginVersion = manifest.version;
|
|
7
|
+
export const release = manifest.finshield.nativeVersion;
|
|
8
|
+
export function lifecycleSettings(options = {}, env = process.env) {
|
|
9
|
+
if (!options || typeof options !== 'object' || Array.isArray(options)) throw Error('FinShield options must be an object');
|
|
10
|
+
for (const key of Object.keys(options))
|
|
11
|
+
if (!['nativeVersionRoot', 'configurationVersionRoot', 'stateDirectory', 'visible'].includes(key)) throw Error(`Unknown FinShield option: ${key}`);
|
|
12
|
+
const installed = (name, ...parts) => path.join(absolutePath(env[name], name), ...parts);
|
|
13
|
+
const nativeVersionRoot = options.nativeVersionRoot ?? installed('ProgramFiles', 'FinSAFE', 'kilo-plugin-versions');
|
|
14
|
+
const configurationVersionRoot = options.configurationVersionRoot ?? installed('ProgramData', 'FinSAFE', 'kilo-plugin-versions');
|
|
15
|
+
const stateDirectory = options.stateDirectory ?? installed('LOCALAPPDATA', 'FinSAFE', 'kilo');
|
|
16
|
+
const selection = path.join(stateDirectory, 'selected.json');
|
|
17
|
+
const current = existsSync(selection) ? JSON.parse(readFileSync(selection, 'utf8')) : {};
|
|
18
|
+
if (!current || typeof current !== 'object' || Array.isArray(current)
|
|
19
|
+
|| Object.keys(current).some(key => !['installation', 'configuration'].includes(key))) throw Error('Invalid selected FinShield instance settings');
|
|
20
|
+
const result = {nativeVersionRoot, configurationVersionRoot,
|
|
21
|
+
installation: current.installation ?? path.join(nativeVersionRoot, release), configuration: current.configuration ?? path.join(configurationVersionRoot, release, 'config'),
|
|
22
|
+
stateDirectory,
|
|
23
|
+
downloadRoot: installed('LOCALAPPDATA', 'FinSAFE', 'kilo', 'downloads'),
|
|
24
|
+
runtimeRoot: installed('LOCALAPPDATA', 'FinSAFE', 'kilo-updater'), localAppData: absolutePath(env.LOCALAPPDATA, 'LOCALAPPDATA'),
|
|
25
|
+
visible: options.visible ?? true};
|
|
26
|
+
for (const [key, value] of Object.entries(result)) if (key !== 'visible') absolutePath(value, key);
|
|
27
|
+
if (typeof result.visible !== 'boolean') throw Error('visible must be a boolean');
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import {pluginVersion} from './lifecycle-settings.mjs';
|
|
2
|
+
export const packageName = '@finogeeks2026/finshield-kilo';
|
|
3
|
+
const preparationPhases = new Set(['starting', 'downloading', 'installing', 'authorizing', 'waiting-authorization']);
|
|
4
|
+
const phaseNames = {starting: 'Starting FinShield', downloading: 'Downloading FinShield', installing: 'Installing FinShield',
|
|
5
|
+
authorizing: 'Authorizing Kilo access', 'waiting-authorization': 'Waiting for existing authorization',
|
|
6
|
+
ready: 'Ready to restart', protected: 'Protected', restarting: 'Restarting Kilo',
|
|
7
|
+
cancelled: 'Preparation cancelled', failed: 'Preparation failed', 'reboot-required': 'Windows restart required'};
|
|
8
|
+
const phaseName = state => phaseNames[state.phase] ?? state.phase;
|
|
9
|
+
const percentage = state => {
|
|
10
|
+
const value = state.progress?.overall_percent;
|
|
11
|
+
return Number.isFinite(value) && value >= 0 && value <= 100 ? value : undefined;
|
|
12
|
+
};
|
|
13
|
+
const progressText = state => {
|
|
14
|
+
const percent = percentage(state);
|
|
15
|
+
if (percent === undefined) return 'Progress not reported yet';
|
|
16
|
+
const filled = Math.floor(percent / 5);
|
|
17
|
+
return `[${'#'.repeat(filled)}${'-'.repeat(20 - filled)}] ${percent}%`;
|
|
18
|
+
};
|
|
19
|
+
const panelKey = state => JSON.stringify([state.phase, percentage(state), state.error, state.currentProtected,
|
|
20
|
+
state.currentRelease, state.requestedRelease, state.restartPolicy]);
|
|
21
|
+
|
|
22
|
+
export function registerManagement(api, activation, {observe, schedule = setInterval, cancel = clearInterval}) {
|
|
23
|
+
let disposed = false, viewing = false, busy = false, reminder, automaticShown = false, rendered, lastNotice;
|
|
24
|
+
let selected = 'background';
|
|
25
|
+
const fail = error => api.ui.toast({variant: 'error', message: `FinShield: ${error.message}`});
|
|
26
|
+
async function status() {
|
|
27
|
+
const token = observe();
|
|
28
|
+
return {...await activation.status(), currentProtected: token.appContainer === true};
|
|
29
|
+
}
|
|
30
|
+
function confirmRestart() {
|
|
31
|
+
viewing = false;
|
|
32
|
+
api.ui.dialog.replace(() => api.ui.DialogConfirm({title: 'Restart Kilo with FinShield?',
|
|
33
|
+
message: 'FinShield is ready. The current Kilo process will close. Running work will stop. A protected Kilo will open in its terminal.',
|
|
34
|
+
onConfirm: () => {api.ui.dialog.clear();void activation.restart().catch(fail);},
|
|
35
|
+
onCancel: () => {api.ui.dialog.clear();void activation.later().catch(fail);}}));
|
|
36
|
+
}
|
|
37
|
+
function renderPanel(state) {
|
|
38
|
+
const preparing = !state.currentProtected && preparationPhases.has(state.phase);
|
|
39
|
+
if (preparing) automaticShown = true;
|
|
40
|
+
const protectedText = state.currentProtected ? 'Protected (AppContainer)' : 'Not protected';
|
|
41
|
+
const wrapper = state.currentProtected ? state.currentRelease ?? 'unavailable' : 'none (ordinary Kilo)';
|
|
42
|
+
const rows = [
|
|
43
|
+
{title: protectedText, value: 'status', description: `Plugin: ${pluginVersion}. Preparation: ${state.phase}. Current wrapper: ${wrapper}; requested release: ${state.requestedRelease ?? 'loading'}`, disabled: true},
|
|
44
|
+
{title: phaseName(state), value: 'phase', disabled: true},
|
|
45
|
+
...(preparing || percentage(state) !== undefined ? [{title: progressText(state), value: 'progress', disabled: true,
|
|
46
|
+
description: preparing ? 'Closing this panel does not cancel native preparation.' : undefined}] : []),
|
|
47
|
+
...(state.error ? [{title: 'Operation failed', value: 'error', description: state.error, disabled: true}] : []),
|
|
48
|
+
{title: preparing ? 'Continue in background' : 'Close panel', value: 'background'},
|
|
49
|
+
{title: 'Refresh status', value: 'refresh'},
|
|
50
|
+
{title: 'Restart with prepared protection', value: 'restart', disabled: state.phase !== 'ready' || state.restartPolicy !== 'confirm'},
|
|
51
|
+
{title: 'Update plugin through Kilo', value: 'update', description: `Use Install plugin with the full target version of ${packageName}; select the original install scope.`},
|
|
52
|
+
{title: 'Disable plugin', value: 'disable', description: 'Future starts stop loading FinShield. This running AppContainer remains confined until exit.'},
|
|
53
|
+
{title: 'Uninstall selected native FinShield', value: 'uninstall', disabled: state.currentProtected,
|
|
54
|
+
description: 'Separate from disabling the plugin. Native Windows uninstall owns authorization cleanup and UAC.'},
|
|
55
|
+
{title: 'Removal and recovery instructions', value: 'help'},
|
|
56
|
+
];
|
|
57
|
+
api.ui.dialog.replace(() => api.ui.DialogSelect({title: preparing ? 'FinShield preparation' : 'FinShield', options: rows,
|
|
58
|
+
skipFilter: true, current: selected, onMove: option => {selected = option.value;}, onSelect: option => {
|
|
59
|
+
if (option.disabled || busy) return;
|
|
60
|
+
if (option.value === 'background') {api.ui.dialog.clear();return;}
|
|
61
|
+
if (option.value === 'refresh') {void show();return;}
|
|
62
|
+
if (option.value === 'restart') {confirmRestart();return;}
|
|
63
|
+
if (option.value === 'update') {
|
|
64
|
+
api.ui.dialog.replace(() => api.ui.DialogConfirm({title: 'Update through Kilo', message:
|
|
65
|
+
`Install ${packageName} with the full target version in the original scope. Current plugin: ${pluginVersion}. Kilo 7.8.27 does not reload an existing plugin's code after installation. Save your work, close Kilo, and reopen it normally to load the new plugin. It will prepare the requested native version and offer a protected restart.`,
|
|
66
|
+
onCancel: () => {void show();}, onConfirm: () => {viewing = false;api.ui.dialog.clear();api.keymap.dispatchCommand('plugins.install');}}));return;
|
|
67
|
+
}
|
|
68
|
+
if (option.value === 'help') {
|
|
69
|
+
api.ui.dialog.replace(() => api.ui.DialogAlert({title: 'FinShield removal and recovery', message:
|
|
70
|
+
`Disable this plugin in Kilo's Plugins command before removing its entry from the TUI configuration used for installation. Kilo owns its package cache. Native FinShield is a separate Windows installation; use its registered Windows uninstall entry and verify the selected installation path. A protected session stays confined until exit.\n\nAfter a cancelled or failed preparation, correct the reported cause, close Kilo and start it again to request a new native attempt. No automatic permission retry is performed.`}));return;
|
|
71
|
+
}
|
|
72
|
+
const nativeRemoval = option.value === 'uninstall';
|
|
73
|
+
api.ui.dialog.replace(() => api.ui.DialogConfirm({title: nativeRemoval ? 'Uninstall native FinShield?' : 'Disable FinShield plugin?',
|
|
74
|
+
message: nativeRemoval ? 'Windows will run the selected native uninstaller, including authorization cleanup. This does not remove the Kilo plugin. Disable/remove the plugin for permanent removal; an enabled plugin prepares again on the next start.' :
|
|
75
|
+
'Disable the plugin for future starts? A currently protected Kilo keeps its confinement until it exits.',
|
|
76
|
+
onCancel: () => {void show();}, onConfirm: () => {
|
|
77
|
+
busy = true;api.ui.dialog.clear();
|
|
78
|
+
void (nativeRemoval ? activation.uninstall() : api.plugins.deactivate(packageName))
|
|
79
|
+
.catch(fail).finally(() => {busy = false;if (!disposed && nativeRemoval) void show();});
|
|
80
|
+
}}));
|
|
81
|
+
}}), () => {viewing = false;rendered = undefined;});
|
|
82
|
+
// Kilo closes the old dialog synchronously during replace. Set ownership
|
|
83
|
+
// after replacement so that old onClose cannot stop progress refreshes.
|
|
84
|
+
viewing = true;rendered = panelKey(state);
|
|
85
|
+
}
|
|
86
|
+
async function show() {
|
|
87
|
+
try {
|
|
88
|
+
const state = await status();if (!disposed) renderPanel(state);
|
|
89
|
+
} catch (error) {fail(error);}
|
|
90
|
+
}
|
|
91
|
+
const unregister = api.keymap.registerLayer({commands: [{name: 'finshield.manage', title: 'FinShield', category: 'Tools', namespace: 'palette', run: show}]});
|
|
92
|
+
const timer = schedule(() => {
|
|
93
|
+
void status().then(state => {
|
|
94
|
+
if (disposed || busy) return;
|
|
95
|
+
const notice = JSON.stringify([state.phase, state.error, state.currentProtected]);
|
|
96
|
+
if (notice !== lastNotice) {
|
|
97
|
+
lastNotice = notice;
|
|
98
|
+
api.ui.toast({title: 'FinShield', duration: state.error ? 15000 : 8000,
|
|
99
|
+
variant: state.error || state.phase === 'failed' ? 'error' : state.phase === 'cancelled' ? 'warning' : state.currentProtected ? 'success' : 'info',
|
|
100
|
+
message: `${phaseName(state)}${state.error ? ': ' + state.error : '. Open FinShield for progress and protection status.'}`});
|
|
101
|
+
}
|
|
102
|
+
if (state.phase === 'ready' && state.restartPolicy === 'confirm' && !state.reminderDismissed && state.reminderId !== reminder) {
|
|
103
|
+
reminder = state.reminderId;confirmRestart();
|
|
104
|
+
} else if (viewing) {
|
|
105
|
+
if (!api.ui.dialog.open) viewing = false;
|
|
106
|
+
else if (rendered !== panelKey(state)) renderPanel(state);
|
|
107
|
+
} else if (!automaticShown && !state.currentProtected && preparationPhases.has(state.phase) && !api.ui.dialog.open) {
|
|
108
|
+
renderPanel(state);
|
|
109
|
+
}
|
|
110
|
+
}).catch(fail);
|
|
111
|
+
}, 2000);
|
|
112
|
+
return {show, dispose() {disposed = true;cancel(timer);unregister?.();}};
|
|
113
|
+
}
|
package/src/native.mjs
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import koffi from 'koffi';
|
|
2
|
+
|
|
3
|
+
export function windowsNative() {
|
|
4
|
+
if (process.platform !== 'win32' || process.arch !== 'x64') throw Error('FinShield Kilo requires Windows x64');
|
|
5
|
+
const kernel = koffi.load('kernel32.dll'), security = koffi.load('advapi32.dll');
|
|
6
|
+
const fn = signature => kernel.func(signature);
|
|
7
|
+
const api = {
|
|
8
|
+
error: fn('uint32 __stdcall GetLastError()'),
|
|
9
|
+
current: fn('uintptr_t __stdcall GetCurrentProcess()'),
|
|
10
|
+
close: fn('int __stdcall CloseHandle(uintptr_t)'),
|
|
11
|
+
open: fn('uintptr_t __stdcall OpenProcess(uint32, int, uint32)'),
|
|
12
|
+
times: fn('int __stdcall GetProcessTimes(uintptr_t, void*, void*, void*, void*)'),
|
|
13
|
+
wait: fn('uint32 __stdcall WaitForSingleObject(uintptr_t, uint32)'),
|
|
14
|
+
exit: fn('int __stdcall GetExitCodeProcess(uintptr_t, void*)'),
|
|
15
|
+
kill: fn('int __stdcall TerminateProcess(uintptr_t, uint32)'),
|
|
16
|
+
inJob: fn('int __stdcall IsProcessInJob(uintptr_t, uintptr_t, void*)'),
|
|
17
|
+
create: fn('int __stdcall CreateProcessW(str16, void*, void*, void*, int, uint32, void*, str16, void*, void*)'),
|
|
18
|
+
compare: fn('int __stdcall CompareStringOrdinal(str16, int, str16, int, int)'),
|
|
19
|
+
openToken: security.func('int __stdcall OpenProcessToken(uintptr_t, uint32, void*)'),
|
|
20
|
+
tokenInfo: security.func('int __stdcall GetTokenInformation(uintptr_t, int, void*, uint32, void*)'),
|
|
21
|
+
};
|
|
22
|
+
const checked = (ok, operation) => {if (!ok) throw Error(`${operation}: Win32 ${api.error()}`);};
|
|
23
|
+
function created(handle) {
|
|
24
|
+
const time = Buffer.alloc(8);
|
|
25
|
+
checked(api.times(handle, time, Buffer.alloc(8), Buffer.alloc(8), Buffer.alloc(8)), 'GetProcessTimes');
|
|
26
|
+
return time.readBigUInt64LE().toString();
|
|
27
|
+
}
|
|
28
|
+
function currentIdentity() {
|
|
29
|
+
const handle = api.current(), out = Buffer.alloc(8);
|
|
30
|
+
checked(api.openToken(handle, 8, out), 'OpenProcessToken');
|
|
31
|
+
const token = out.readBigUInt64LE();
|
|
32
|
+
try {
|
|
33
|
+
const value = Buffer.alloc(4), needed = Buffer.alloc(4), job = Buffer.alloc(4);
|
|
34
|
+
checked(api.tokenInfo(token, 29, value, value.length, needed), 'TokenIsAppContainer');
|
|
35
|
+
checked(api.inJob(handle, 0, job), 'IsProcessInJob');
|
|
36
|
+
return {pid: process.pid, created: created(handle), appContainer: value.readUInt32LE() !== 0,
|
|
37
|
+
inJob: job.readUInt32LE() !== 0};
|
|
38
|
+
} finally {api.close(token);}
|
|
39
|
+
}
|
|
40
|
+
function owner(handle, pid) {
|
|
41
|
+
let closed = false;
|
|
42
|
+
return {pid, created: created(handle),
|
|
43
|
+
close() {if (!closed) {closed = true; api.close(handle);}},
|
|
44
|
+
async wait(timeout = 0xffffffff) {
|
|
45
|
+
const result = await new Promise((resolve, reject) => api.wait.async(handle, timeout,
|
|
46
|
+
(error, value) => error ? reject(error) : resolve(value)));
|
|
47
|
+
if (result === 258) throw Error(`Process ${pid} exit timed out`);
|
|
48
|
+
if (result !== 0) throw Error(`WaitForSingleObject: ${result}`);
|
|
49
|
+
const value = Buffer.alloc(4);
|
|
50
|
+
checked(api.exit(handle, value), 'GetExitCodeProcess');
|
|
51
|
+
return value.readUInt32LE();
|
|
52
|
+
},
|
|
53
|
+
async stop() {
|
|
54
|
+
const status = api.wait(handle, 0);
|
|
55
|
+
if (status === 258) checked(api.kill(handle, 0), 'TerminateProcess');
|
|
56
|
+
else if (status !== 0) throw Error(`WaitForSingleObject: ${status}`);
|
|
57
|
+
return this.wait(10000);
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function retain(pid) {
|
|
62
|
+
const handle = api.open(0x100000 | 0x1000 | 1, 0, pid);
|
|
63
|
+
checked(handle, 'OpenProcess');
|
|
64
|
+
return owner(handle, pid);
|
|
65
|
+
}
|
|
66
|
+
function openOriginal(identity) {
|
|
67
|
+
const processOwner = retain(identity.pid);
|
|
68
|
+
if (processOwner.created !== identity.created) {
|
|
69
|
+
processOwner.close(); throw Error('Original process creation time differs');
|
|
70
|
+
}
|
|
71
|
+
return processOwner;
|
|
72
|
+
}
|
|
73
|
+
function launch({executable, args, cwd, env}, {visible = false, inheritConsole = false, breakaway = false} = {}) {
|
|
74
|
+
const quote = value => '"' + value.replace(/(\\*)"/g, '$1$1\\"').replace(/\\+$/g, '$&$&') + '"';
|
|
75
|
+
const command = Buffer.from([executable, ...args].map(quote).join(' ') + '\0', 'utf16le');
|
|
76
|
+
if (command.length / 2 > 32767) throw Error('Command exceeds Windows length limit');
|
|
77
|
+
const entries = Object.entries(env).filter(([, value]) => value !== undefined);
|
|
78
|
+
entries.sort(([a], [b]) => {
|
|
79
|
+
const result = api.compare(a, -1, b, -1, 1);
|
|
80
|
+
checked(result, 'CompareStringOrdinal'); return result - 2;
|
|
81
|
+
});
|
|
82
|
+
const environment = Buffer.from(entries.map(([key, value]) => `${key}=${value}`).join('\0') + '\0\0', 'utf16le');
|
|
83
|
+
const startup = Buffer.alloc(104), info = Buffer.alloc(24);
|
|
84
|
+
startup.writeUInt32LE(104);
|
|
85
|
+
startup.writeUInt32LE(inheritConsole ? 0 : 1, 60);
|
|
86
|
+
startup.writeUInt16LE(visible ? 1 : 0, 64);
|
|
87
|
+
checked(api.create(executable, command, null, null, 0, (inheritConsole ? 0x400 : 0x410) | (breakaway ? 0x01000000 : 0),
|
|
88
|
+
environment, cwd, startup, info), 'CreateProcessW');
|
|
89
|
+
const handle = info.readBigUInt64LE(), thread = info.readBigUInt64LE(8), pid = info.readUInt32LE(16);
|
|
90
|
+
api.close(thread);
|
|
91
|
+
return owner(handle, pid);
|
|
92
|
+
}
|
|
93
|
+
const messageBox = koffi.load('user32.dll').func('int __stdcall MessageBoxW(uintptr_t, str16, str16, uint32)');
|
|
94
|
+
function consoleText() {
|
|
95
|
+
const open = fn('uintptr_t __stdcall CreateFileW(str16,uint32,uint32,void*,uint32,uint32,uintptr_t)');
|
|
96
|
+
const info = fn('int __stdcall GetConsoleScreenBufferInfo(uintptr_t,void*)');
|
|
97
|
+
const read = fn('int __stdcall ReadConsoleOutputCharacterW(uintptr_t,void*,uint32,uint32,void*)');
|
|
98
|
+
const handle = BigInt(open('CONOUT$', 0x80000000, 3, null, 3, 0, 0));
|
|
99
|
+
checked(handle !== 0xffffffffffffffffn, 'Open console diagnostic');
|
|
100
|
+
try {
|
|
101
|
+
const state = Buffer.alloc(22);checked(info(handle, state), 'GetConsoleScreenBufferInfo');
|
|
102
|
+
const width = state.readInt16LE(14) - state.readInt16LE(10) + 1, height = state.readInt16LE(16) - state.readInt16LE(12) + 1;
|
|
103
|
+
const length = Math.min(width * height, 8192), data = Buffer.alloc(length * 2), count = Buffer.alloc(4);
|
|
104
|
+
checked(read(handle, data, length, (state.readUInt16LE(12) << 16) | state.readUInt16LE(10), count), 'ReadConsoleOutputCharacterW');
|
|
105
|
+
return data.subarray(0, count.readUInt32LE() * 2).toString('utf16le').trim();
|
|
106
|
+
} finally {api.close(handle);}
|
|
107
|
+
}
|
|
108
|
+
return {currentIdentity, openOriginal, retain, launch,
|
|
109
|
+
consoleText,
|
|
110
|
+
showError(message) {messageBox(0, message, 'FinShield Kilo could not start', 0x10);},
|
|
111
|
+
};
|
|
112
|
+
}
|
package/src/options.mjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {win32 as path} from 'node:path';
|
|
2
|
+
|
|
3
|
+
export function absolutePath(value, name) {
|
|
4
|
+
if (typeof value !== 'string' || value.includes('\0') || !path.isAbsolute(value) || path.parse(value).root.length < 2)
|
|
5
|
+
throw Error(`${name} must be a full absolute Windows path`);
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function resolveOptions(input = {}, env = process.env) {
|
|
10
|
+
if (!input || typeof input !== 'object' || Array.isArray(input)) throw Error('FinShield options must be an object');
|
|
11
|
+
for (const key of Object.keys(input))
|
|
12
|
+
if (!['finsafe', 'yamlPath', 'stateDirectory', 'visible'].includes(key)) throw Error(`Unknown FinShield option: ${key}`);
|
|
13
|
+
const installed = (key, ...parts) => path.join(absolutePath(env[key], key), ...parts);
|
|
14
|
+
const result = {
|
|
15
|
+
finsafe: input.finsafe ?? installed('ProgramFiles', 'FinSAFE', 'finsafe.exe'),
|
|
16
|
+
yamlPath: input.yamlPath ?? installed('ProgramData', 'FinSAFE', 'kilo-plugin', 'config', 'effective.yaml'),
|
|
17
|
+
stateDirectory: input.stateDirectory ?? installed('LOCALAPPDATA', 'FinSAFE', 'kilo'),
|
|
18
|
+
visible: input.visible ?? true,
|
|
19
|
+
};
|
|
20
|
+
for (const key of ['finsafe', 'yamlPath', 'stateDirectory']) absolutePath(result[key], key);
|
|
21
|
+
if (typeof result.visible !== 'boolean') throw Error('visible must be a boolean');
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {runFinSafe,submitDesktopAuthorization} from './connector.js';
|
|
2
|
+
|
|
3
|
+
// Thin transport: preparation state, submission and progress belong to native Desktop APIs.
|
|
4
|
+
const options=settings=>({env:{...process.env,LOCALAPPDATA:settings.localAppData,
|
|
5
|
+
...(settings.dshHome?{DSH_HOME:settings.dshHome}:{})}});
|
|
6
|
+
export function prepareRuntime(settings,{run=submitDesktopAuthorization}={}) {
|
|
7
|
+
return run(settings.executable,['desktop','authorization','ensure','--json','--yaml-path',settings.yamlPath,
|
|
8
|
+
...(settings.retainedWorker?['--retained-worker',settings.retainedWorker]:[])],
|
|
9
|
+
options(settings));
|
|
10
|
+
}
|
|
11
|
+
export async function readPreparation(settings,{run=runFinSafe}={}) {
|
|
12
|
+
const result=await run(settings.executable,['desktop','authorization','state','--json','--yaml-path',settings.yamlPath],
|
|
13
|
+
{...options(settings),readOnlyResult:true});
|
|
14
|
+
if(typeof result.prepared!=='boolean'||typeof result.authorization_in_progress!=='boolean'||typeof result.phase!=='string')
|
|
15
|
+
throw Error('Native authorization observation is incomplete');
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** One completion-spaced native observation per selected target. Submission
|
|
20
|
+
* acknowledgments/terminal results update this transport cache without a read. */
|
|
21
|
+
export function createPreparationObserver({read=readPreparation,now=Date.now,
|
|
22
|
+
wait=delay=>new Promise(done=>setTimeout(done,delay))}={}) {
|
|
23
|
+
const records=new Map();
|
|
24
|
+
const record=settings=>{const key=settings.yamlPath;let value=records.get(key);
|
|
25
|
+
if(!value){value={generation:0,finished:-Infinity,stale:true};records.set(key,value);}return value;};
|
|
26
|
+
const result=r=>r.error?Promise.reject(r.error):Promise.resolve(r.value);
|
|
27
|
+
const observe=settings=>{
|
|
28
|
+
const r=record(settings);
|
|
29
|
+
if(r.pending)return r.pending;
|
|
30
|
+
if(!r.stale&&now()-r.finished<2000)return result(r);
|
|
31
|
+
const generation=r.generation;
|
|
32
|
+
r.pending=(async()=>{
|
|
33
|
+
let queried=false;
|
|
34
|
+
try {
|
|
35
|
+
const remaining=2000-(now()-r.finished);if(remaining>0)await wait(remaining);
|
|
36
|
+
if(r.generation!==generation&&!r.stale)return result(r);
|
|
37
|
+
queried=true;
|
|
38
|
+
const value=await read(settings);
|
|
39
|
+
if(r.generation===generation){r.value=value;r.error=undefined;r.stale=false;}
|
|
40
|
+
}catch(error){if(r.generation===generation){r.error=error;r.stale=false;}}
|
|
41
|
+
finally{if(queried)r.finished=now();r.pending=undefined;}
|
|
42
|
+
if(r.stale)return observe(settings);
|
|
43
|
+
return result(r);
|
|
44
|
+
})();
|
|
45
|
+
return r.pending;
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
read:observe,
|
|
49
|
+
publish(settings,value) {
|
|
50
|
+
const r=record(settings);r.generation++;r.value={...value};delete r.value.completion;
|
|
51
|
+
r.error=undefined;r.stale=false;r.finished=now();
|
|
52
|
+
},
|
|
53
|
+
invalidate(settings){const r=record(settings);r.generation++;r.stale=true;},
|
|
54
|
+
};
|
|
55
|
+
}
|
package/src/tui.mjs
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {join} from 'node:path';
|
|
2
|
+
import {absolutePath} from './options.mjs';
|
|
3
|
+
import {lifecycleSettings} from './lifecycle-settings.mjs';
|
|
4
|
+
import {createActivation} from './activation.js';
|
|
5
|
+
import {registerManagement} from './management.mjs';
|
|
6
|
+
|
|
7
|
+
export async function initializeProduct(api, options, injected) {
|
|
8
|
+
let management;
|
|
9
|
+
try {
|
|
10
|
+
if (!injected && (process.platform !== 'win32' || process.arch !== 'x64')) throw Error('FinShield Kilo supports Windows x64');
|
|
11
|
+
if (api.app.version !== '7.8.27') throw Error(`Supported Kilo version is 7.8.27; this Kilo is ${api.app.version}`);
|
|
12
|
+
const ports = injected ?? await (async () => {
|
|
13
|
+
const {windowsNative} = await import('./native.mjs');
|
|
14
|
+
const {hostConnections} = await import('../updater/host.mjs');
|
|
15
|
+
const {knownFolderEnvironment} = await import('./known-folders.mjs');
|
|
16
|
+
const native = windowsNative();
|
|
17
|
+
return {observe: () => native.currentIdentity(), connect: hostConnections, env: knownFolderEnvironment()};
|
|
18
|
+
})();
|
|
19
|
+
api.ui.toast({variant: 'info', title: 'FinShield', duration: 10000,
|
|
20
|
+
message: 'Starting FinShield. Preparation progress will appear in Kilo; use the FinShield command to reopen it.'});
|
|
21
|
+
const settings = lifecycleSettings(options, ports.env);
|
|
22
|
+
if (ports.observe().appContainer) {
|
|
23
|
+
const paths = ports.clientPaths ? await ports.clientPaths() : (await api.client.path.get(undefined, {throwOnError: true})).data;
|
|
24
|
+
settings.clientSupportDirectory = join(absolutePath(paths?.state, 'Kilo state directory'), 'finshield-native');
|
|
25
|
+
}
|
|
26
|
+
const connections = await ports.connect(settings);
|
|
27
|
+
const report = error => api.ui.toast({variant: 'error', message: `FinShield: ${error.message}`});
|
|
28
|
+
const activation = createActivation({observe: ports.observe, obtain: connections.obtain, existing: connections.existing, report});
|
|
29
|
+
// Native uninstall stays with the ordinary coordinator. No host-side ACL code.
|
|
30
|
+
activation.uninstall = connections.uninstall ?? (async () => {throw Error('Open the selected native installation in Windows installed apps to uninstall it');});
|
|
31
|
+
management = registerManagement(api, activation, {observe: ports.observe, ...ports.observation});
|
|
32
|
+
api.lifecycle.onDispose(async () => {management.dispose();await activation.dispose();});
|
|
33
|
+
await activation.start();
|
|
34
|
+
api.ui.toast({variant: 'info', message: 'FinShield: use the FinShield command for protection and preparation status.'});
|
|
35
|
+
} catch (error) {
|
|
36
|
+
api.ui.dialog.replace(() => api.ui.DialogAlert({title: 'FinShield is unavailable', message:
|
|
37
|
+
`${error.message}\n\nProtection was not started by this plugin. Correct the reported cause and restart Kilo. A process already in AppContainer keeps its existing confinement.`}));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Kilo's third callback argument is package metadata, never appReady or a test port.
|
|
42
|
+
export default {id: '@finogeeks2026/finshield-kilo', tui(api, options) {return initializeProduct(api, options);}};
|