@finogeeks2026/finshield-opencode 0.0.0-stage → 0.11.50
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/DESIGN.md +593 -0
- package/LICENSE.rtf +28 -0
- package/README.md +132 -2
- package/THIRD-PARTY-NOTICES.md +3131 -0
- package/bin/node.exe +4 -0
- package/dist/gui-experimental.cjs +96 -0
- package/dist/updater/server.js +1046 -0
- package/install/download-source.json +3 -0
- package/install/runtime.js +60 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/LICENSE.rtf +28 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/README.md +116 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/bin/finsafe_native.dll +0 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/native-build.json +5 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/@koromix/koffi-win32-x64/README.md +6 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/@koromix/koffi-win32-x64/index.js +12 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/@koromix/koffi-win32-x64/package.json +24 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/@koromix/koffi-win32-x64/win32_x64/koffi.lib +0 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/@koromix/koffi-win32-x64/win32_x64/koffi.node +0 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/CHANGELOG.md +1183 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/LICENSE.txt +22 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/README.md +42 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/cnoke.cjs +816 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/benchmarks.md +80 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/callbacks.md +182 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/composites.md +549 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/contribute.md +163 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/index.md +46 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/load.md +191 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/migration.md +256 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/misc.md +76 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/output.md +299 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/pointers.md +385 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/primitives.md +151 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/start.md +110 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/types.md +88 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/unions.md +0 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/values.md +134 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/index.cjs +1 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/index.d.ts +389 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/index.js +2 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/indirect.cjs +1 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/indirect.js +2 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/lib/native/base/base.cc +11064 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/lib/native/base/base.hh +5951 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/lib/native/base/unicode.inc +408 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/package.json +68 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/CMakeLists.txt +249 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/index.cjs +296 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/index.js +281 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/indirect.cjs +295 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/indirect.js +280 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/arm64.cc +1408 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/arm64_asm.S +216 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/arm64_asm.asm +181 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/loong64.cc +5 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/loong64_asm.S +200 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/riscv64.cc +1345 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/riscv64_asm.S +200 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x64sysv.cc +1434 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x64sysv_asm.S +224 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x64win.cc +1086 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x64win_asm.S +162 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x64win_asm.asm +189 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x86.cc +1185 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x86_asm.S +217 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x86_asm.asm +174 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/call.cc +2094 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/call.hh +179 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/errno.inc +462 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/ffi.cc +3009 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/ffi.hh +461 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/parser.cc +218 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/parser.hh +54 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/primitives.inc +36 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/static.cjs +130 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/static.js +133 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/trampolines.cjs +77 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/type.cc +725 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/type.hh +71 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/util.cc +1040 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/util.hh +493 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/uv.cc +214 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/uv.def +11 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/uv.hh +112 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/win32.cc +198 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/win32.hh +148 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-addon-api/LICENSE.md +9 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-addon-api/README.md +95 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-addon-api/napi-inl.deprecated.h +186 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-addon-api/napi-inl.h +7211 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-addon-api/napi.h +3421 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/LICENSE +21 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/README.md +95 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/def/js_native_api.def +125 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/def/node_api.def +157 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/include/js_native_api.h +591 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/include/js_native_api_types.h +210 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/include/node_api.h +265 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/include/node_api_types.h +58 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/package.json +36 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/release.json +4 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/src/native.js +85 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/src/shell.js +20 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/src/status.js +57 -0
- package/package.json +47 -4
- package/policy/candidate.yaml +347 -0
- package/release.json +4 -0
- package/src/activation.js +2 -0
- package/src/attachment.js +34 -0
- package/src/connector.js +91 -0
- package/src/contract.js +8 -0
- package/src/desktop-contract.js +4 -0
- package/src/desktop.js +25 -0
- package/src/gui.tsx +58 -0
- package/src/host.js +38 -0
- package/src/index.js +12 -0
- package/src/instance-settings.js +27 -0
- package/src/known-folders.js +22 -0
- package/src/management.js +17 -0
- package/src/preparation.js +18 -0
- package/src/presentation.js +153 -0
- package/src/settings.js +18 -0
- package/ui/feedback.cjs +45 -0
- package/ui/page.cjs +225 -0
- package/ui/state.cjs +44 -0
- package/updater/bootstrap.js +41 -0
- package/updater/common/activation.js +81 -0
- package/updater/common/coordinator.js +329 -0
- package/updater/common/download.js +57 -0
- package/updater/common/index.js +12 -0
- package/updater/common/package.js +53 -0
- package/updater/common/protocol.js +38 -0
- package/updater/common/transport.js +65 -0
- package/updater/coordinator.js +2 -0
- package/updater/launch.js +40 -0
- package/updater/management.js +9 -0
- package/updater/native.js +18 -0
- package/updater/operations.js +45 -0
- package/updater/protocol.js +1 -0
- package/updater/server.js +100 -0
- package/updater/transport.js +10 -0
- package/updater/windows-launch-reader.js +40 -0
- package/updater/windows-launch.js +96 -0
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
// Fixed native owners decide installation, authorization and process identity.
|
|
2
|
+
// Startup keeps or wraps. Running Exit ends Main; the user reopens manually.
|
|
3
|
+
export function decideStartup({hostInSelectedAppContainer,authorizationComplete}) {
|
|
4
|
+
return !hostInSelectedAppContainer&&authorizationComplete?'wrap':'keep';
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function createUpdater({ports,startup,application="application",prepareUpdates=false}) {
|
|
8
|
+
const clients=new Map(),sessions=new Map(),tasks=new Map(),operations=new Set(),requests=new Set();
|
|
9
|
+
let sequence=0,draining=false,startupReleased=false,finish;
|
|
10
|
+
const closed=new Promise(resolve=>{finish=resolve;});
|
|
11
|
+
const resource=b=>JSON.stringify([b.installationResource??b.installation,b.configurationResource??b.configuration,b.profile]);
|
|
12
|
+
const taskKey=b=>JSON.stringify([resource(b),b.requestedRelease]);
|
|
13
|
+
// One live connection belongs to the current selected target of this updater.
|
|
14
|
+
// A target change obtains that target; HTTP requests do not enter this path.
|
|
15
|
+
let shell;
|
|
16
|
+
async function obtainTargetShell(binding) {
|
|
17
|
+
const target=resource(binding);
|
|
18
|
+
if(shell?.target===target)return shell.connection;
|
|
19
|
+
const connection=await ports.backend?.(binding);
|
|
20
|
+
if(connection)shell={target,connection};
|
|
21
|
+
return connection;
|
|
22
|
+
}
|
|
23
|
+
const failure=error=>error.result??{phase:error.authority==='uac_cancelled'?'cancelled':'failed',error:error.message};
|
|
24
|
+
const active=s=>s?.authorization_in_progress===true;
|
|
25
|
+
// A live replacement owns shared work. Its terminal result belongs to the
|
|
26
|
+
// verified Host binding that submitted it, not every Host under this Main.
|
|
27
|
+
const attemptFor=value=>{
|
|
28
|
+
const attempt=value.session.attempt;
|
|
29
|
+
return attempt&&(attempt.transition||attempt.binding.pid===value.binding.pid)?attempt:undefined;
|
|
30
|
+
};
|
|
31
|
+
function tracked(binding,operation) {
|
|
32
|
+
const work={binding};operations.add(work);
|
|
33
|
+
work.promise=Promise.resolve().then(operation).finally(()=>operations.delete(work));
|
|
34
|
+
work.promise.catch(()=>{});return work.promise;
|
|
35
|
+
}
|
|
36
|
+
function status(value,authorization) {
|
|
37
|
+
const session=value.session,task=session.task??value.task,attempt=attemptFor(value);
|
|
38
|
+
const observed=session.wrapping?{phase:'restarting'}:attempt?.state??authorization??task?.state;
|
|
39
|
+
const matchingProtected=value.binding.protected&&!task?.update
|
|
40
|
+
&&(task?.target?resource(value.binding)===resource(task.target):authorization!==undefined);
|
|
41
|
+
const state=observed?.phase==='ready'&&matchingProtected?{phase:'protected'}:
|
|
42
|
+
observed?.phase==='protected'&&!value.binding.protected?{phase:'starting'}:observed;
|
|
43
|
+
const result=value.result??state??{phase:session.startupError?'failed':'starting'};
|
|
44
|
+
const error=[result.error,session.startupError,task?.callError].filter(Boolean).join('; ');
|
|
45
|
+
const reminderId=authorization?(authorization.attempt||resource(task?.target??value.binding)):task?.id;
|
|
46
|
+
return {...result,...(error?{error}:{}),
|
|
47
|
+
...(authorization&&task?.reason?{reason:task.reason}:{}),
|
|
48
|
+
currentProtected:value.binding.protected===true,currentRelease:session.currentRelease,requestedRelease:task?.binding.requestedRelease??value.binding.requestedRelease,
|
|
49
|
+
reminderDismissed:authorization?session.dismissedReminder===reminderId:task?.dismissed===true,reminderId,
|
|
50
|
+
reopenRequired:!draining&&!session.closed&&!attempt&&state?.phase==='ready'};
|
|
51
|
+
}
|
|
52
|
+
async function observedStatus(value) {
|
|
53
|
+
const result=status(value),task=value.session.task??value.task,target=task?.target??value.binding;
|
|
54
|
+
if((task&&!task.authorization)||(result.phase!=='starting'&&!task?.authorization)||value.result||value.session.wrapping||attemptFor(value)
|
|
55
|
+
||!shell||shell.target!==resource(target))return result;
|
|
56
|
+
if(task?.observeAfter>Date.now())return result;
|
|
57
|
+
try {
|
|
58
|
+
const state=await ports.preparation(target,shell.connection);
|
|
59
|
+
value.authorizationAttempt??=active(state)?state.attempt:undefined;
|
|
60
|
+
const observed=value.authorizationAttempt&&ports.progress
|
|
61
|
+
?await readTask(target,shell.connection,state,value.authorizationAttempt):state;
|
|
62
|
+
if(!active(observed))delete value.authorizationAttempt;
|
|
63
|
+
return status(value,observed);
|
|
64
|
+
} catch(error) {
|
|
65
|
+
if(error.code==='observation_superseded')delete value.authorizationAttempt;
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function sessionFor(binding) {
|
|
70
|
+
let session=sessions.get(binding.mainKey)??[...sessions.values()].find(current=>current.wrapping);
|
|
71
|
+
if(!session) {
|
|
72
|
+
session={mainKey:binding.mainKey,binding,mainBinding:binding,bindings:new Set(),closed:false,wrapping:false};
|
|
73
|
+
sessions.set(binding.mainKey,session);
|
|
74
|
+
}
|
|
75
|
+
session.binding=binding;
|
|
76
|
+
if(session.attempt&&!session.attempt.transition&&session.attempt.state.phase==='completed')session.attempt=undefined;
|
|
77
|
+
return session;
|
|
78
|
+
}
|
|
79
|
+
async function readTask(binding,connection,state,attempt) {
|
|
80
|
+
const progress=await ports.progress(binding,connection,attempt);
|
|
81
|
+
if(active(progress))return {...state,progress};
|
|
82
|
+
const current=await ports.preparation(binding,connection);
|
|
83
|
+
if(current.attempt!==attempt)throw Object.assign(Error('Authorization observation was superseded'),
|
|
84
|
+
{status:409,code:'observation_superseded'});
|
|
85
|
+
return current;
|
|
86
|
+
}
|
|
87
|
+
async function wrapRestart(session,target,onStopped) {
|
|
88
|
+
session.wrapping=true;
|
|
89
|
+
try {
|
|
90
|
+
await ports.wrap(target,mainKey=>{
|
|
91
|
+
// retain_replacement updates this target's native Binding. Host rebinds
|
|
92
|
+
// create independent native owners and must not replace lifecycle ownership.
|
|
93
|
+
session.mainBinding=target;
|
|
94
|
+
if(mainKey&&mainKey!==session.mainKey) {
|
|
95
|
+
sessions.delete(session.mainKey);
|
|
96
|
+
session.mainKey=mainKey;sessions.set(mainKey,session);
|
|
97
|
+
for(const value of clients.values())if(value.session===session&&value.binding.mainKey!==mainKey)value.released=true;
|
|
98
|
+
}
|
|
99
|
+
},onStopped);
|
|
100
|
+
} finally {session.wrapping=false;}
|
|
101
|
+
await ports.watchMain?.(session.mainBinding);
|
|
102
|
+
}
|
|
103
|
+
function executeStartup(binding,target) {
|
|
104
|
+
const session=sessionFor(binding);
|
|
105
|
+
if(session.wrapping||session.attempt?.transition)return {accepted:true};
|
|
106
|
+
const attempt={binding,state:{phase:'restarting'},transition:true};session.attempt=attempt;
|
|
107
|
+
session.wrapping=true;
|
|
108
|
+
attempt.promise=tracked(binding,async()=>{
|
|
109
|
+
try {await wrapRestart(session,target,()=>{});attempt.state={phase:'completed'};}
|
|
110
|
+
catch(error) {
|
|
111
|
+
attempt.state=failure(error);ports.report?.(error,target,'wrap');
|
|
112
|
+
if(!await ports.mainAlive(startup??binding))stop();
|
|
113
|
+
} finally {attempt.transition=false;}
|
|
114
|
+
});
|
|
115
|
+
return {accepted:true};
|
|
116
|
+
}
|
|
117
|
+
function exit(session) {
|
|
118
|
+
const attempt={binding:session.binding,state:{phase:'exiting'},transition:true};session.attempt=attempt;
|
|
119
|
+
attempt.promise=tracked(session.binding,async()=>{
|
|
120
|
+
try {await ports.exit(session.binding);stop();}
|
|
121
|
+
catch(error){attempt.state=failure(error);ports.report?.(error,session.binding,'exit');}
|
|
122
|
+
finally{attempt.transition=false;}
|
|
123
|
+
});
|
|
124
|
+
return {accepted:true};
|
|
125
|
+
}
|
|
126
|
+
async function assess(task,session,value) {
|
|
127
|
+
try {
|
|
128
|
+
const b=task.binding,release=b.requestedRelease;
|
|
129
|
+
if(!/^\d+\.\d+\.\d+$/.test(release))throw Error('A requested stable native release is required');
|
|
130
|
+
task.target=await ports.select(b,release);
|
|
131
|
+
const current=await ports.installation(b);
|
|
132
|
+
session.currentRelease=current?.version;
|
|
133
|
+
const readOnly=b.manageInstallation===false||b.settings?.manageInstallation===false;
|
|
134
|
+
if(readOnly&&task.installOnly)throw Error('The selected FinSAFE installation is read-only to this plugin');
|
|
135
|
+
task.update=!readOnly&&Boolean(current&¤t.version!==release);
|
|
136
|
+
const alreadyProtected=b.protected&&(readOnly||current?.version===release)&&resource(task.target)===resource(b);
|
|
137
|
+
if(alreadyProtected&&!task.installOnly) {
|
|
138
|
+
task.state={phase:'protected'};return;
|
|
139
|
+
}
|
|
140
|
+
const installed=readOnly?current:await ports.installation(task.target);
|
|
141
|
+
let needsSetup=!readOnly&&(!installed||installed.version!==release),backendObtained=false,connection;
|
|
142
|
+
if(!needsSetup&&!task.installOnly) {
|
|
143
|
+
try{connection=await obtainTargetShell(task.target);backendObtained=true;}
|
|
144
|
+
catch(error){
|
|
145
|
+
if(readOnly||error.code!=='ENOENT'||error.path!==task.target.settings?.executable)throw error;
|
|
146
|
+
needsSetup=true;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if(needsSetup) {
|
|
150
|
+
task.state={phase:'downloading'};
|
|
151
|
+
task.download=new AbortController();
|
|
152
|
+
task.staged=await ports.stage(task.target,release,task.download.signal);task.download=undefined;
|
|
153
|
+
if(draining||session.closed||!await ports.mainAlive(b))return;
|
|
154
|
+
task.state={phase:'installing'};
|
|
155
|
+
const setup=await ports.install(task.target,release,task.staged);
|
|
156
|
+
if(setup.phase!=='completed'){task.state=setup;return;}
|
|
157
|
+
// Setup can create previously absent directories. Publish their actual
|
|
158
|
+
// native identities before a re-enabled client joins this ongoing task.
|
|
159
|
+
Object.assign(task.target,await ports.select(b,release));
|
|
160
|
+
await ports.selected?.(b,task.target);
|
|
161
|
+
}
|
|
162
|
+
if(draining||session.closed||!await ports.mainAlive(b))return;
|
|
163
|
+
if(task.installOnly&&!prepareUpdates) {
|
|
164
|
+
if(!needsSetup)await ports.selected?.(b,task.target);
|
|
165
|
+
task.state={phase:'ready',reason:'update',authorizationPending:true};return;
|
|
166
|
+
}
|
|
167
|
+
if(!backendObtained)connection=await obtainTargetShell(task.target);
|
|
168
|
+
task.reason=task.update?'update':needsSetup?'install':'authorization';
|
|
169
|
+
task.state={phase:'authorizing',reason:task.reason};
|
|
170
|
+
// Native acknowledgment establishes that this request has started. Until
|
|
171
|
+
// then, Shell can still expose the previous task or an absent Effective.
|
|
172
|
+
const submission=readOnly?undefined:await ports.prepare(task.target,connection);
|
|
173
|
+
task.authorization=true;
|
|
174
|
+
// Wait three seconds after ACK to improve status-query accuracy while
|
|
175
|
+
// Shell's cached observations settle. Native execution continues now.
|
|
176
|
+
if(!readOnly)task.observeAfter=Date.now()+3000;
|
|
177
|
+
if(!readOnly) {
|
|
178
|
+
const completion=submission?.completion?await submission.completion:submission;
|
|
179
|
+
if(Number.isInteger(completion?.exit_code)&&completion.exit_code!==0)
|
|
180
|
+
throw Error(completion.error||`Desktop authorization command exited (${completion.exit_code})`);
|
|
181
|
+
}
|
|
182
|
+
} catch(error){
|
|
183
|
+
if(task.authorization)task.callError=error.message;else task.state=failure(error);
|
|
184
|
+
ports.report?.(error,task.target??session.binding,'prepare');
|
|
185
|
+
}
|
|
186
|
+
finally{task.done=true;tasks.delete(taskKey(task.binding));}
|
|
187
|
+
}
|
|
188
|
+
function stop() {
|
|
189
|
+
draining=true;
|
|
190
|
+
for(const session of new Set(sessions.values()))session.closed=true;
|
|
191
|
+
for(const task of tasks.values())task.download?.abort();
|
|
192
|
+
finish();
|
|
193
|
+
}
|
|
194
|
+
async function drain() {
|
|
195
|
+
stop();
|
|
196
|
+
for(;;) {
|
|
197
|
+
const work=[...requests,...operations].map(item=>item.promise??item);
|
|
198
|
+
if(!work.length)break;
|
|
199
|
+
await Promise.allSettled(work);
|
|
200
|
+
}
|
|
201
|
+
for(const session of new Set(sessions.values()))for(const binding of session.bindings) {
|
|
202
|
+
await ports.detach(binding);
|
|
203
|
+
}
|
|
204
|
+
if(startup&&!startupReleased){startupReleased=true;await ports.detach(startup);}
|
|
205
|
+
}
|
|
206
|
+
async function beginAssessment(value,installOnly=false) {
|
|
207
|
+
const {binding,session}=value;
|
|
208
|
+
const attempt=attemptFor(value);
|
|
209
|
+
if((value.task&&!value.task.done)||session.wrapping||attempt?.transition)return {accepted:true};
|
|
210
|
+
session.startupError=undefined;session.attempt=undefined;
|
|
211
|
+
let task=tasks.get(taskKey(binding))??[...tasks.values()].find(t=>!t.done&&t.target
|
|
212
|
+
&&t.binding.requestedRelease===binding.requestedRelease&&resource(t.target)===resource(binding));
|
|
213
|
+
if(!task||task.done) {
|
|
214
|
+
const ownInstall=binding.installationResource??binding.installation;
|
|
215
|
+
const ownConfig=binding.configurationResource??binding.configuration;
|
|
216
|
+
if([...tasks.values()].some(t=>!t.done&&((t.binding.installationResource??t.binding.installation)===ownInstall
|
|
217
|
+
||(t.binding.configurationResource??t.binding.configuration)===ownConfig)&&resource(t.binding)!==resource(binding)))
|
|
218
|
+
throw Error('Selected installation/configuration conflict with active native work');
|
|
219
|
+
task={id:String(++sequence),binding,installOnly,state:{phase:'starting'},done:false};
|
|
220
|
+
tasks.set(taskKey(binding),task);
|
|
221
|
+
task.promise=tracked(binding,()=>assess(task,session,value));
|
|
222
|
+
}
|
|
223
|
+
value.task=task;session.task=task;return {accepted:true};
|
|
224
|
+
}
|
|
225
|
+
return {
|
|
226
|
+
closed,
|
|
227
|
+
async admit(binding) {
|
|
228
|
+
if(sessions.size&&!sessions.has(binding.mainKey)&&![...sessions.values()].some(session=>session.wrapping))
|
|
229
|
+
throw Error(`Updater already owns another ${application} Main`);
|
|
230
|
+
const session=sessionFor(binding);
|
|
231
|
+
if(session.wrapping||session.attempt?.transition)return {period:'keep'};
|
|
232
|
+
session.startupError=undefined;
|
|
233
|
+
let target,authorizationComplete=false;
|
|
234
|
+
try {
|
|
235
|
+
if(!binding.protected) {
|
|
236
|
+
target=await ports.select(binding,binding.requestedRelease,{startup:true});
|
|
237
|
+
if(ports.startupReady) {
|
|
238
|
+
const connection=await obtainTargetShell(target);
|
|
239
|
+
authorizationComplete=await ports.startupReady(target,connection);
|
|
240
|
+
} else {
|
|
241
|
+
const connection=await obtainTargetShell(target);
|
|
242
|
+
const state=await ports.preparation(target,connection);
|
|
243
|
+
authorizationComplete=state?.prepared===true&&!active(state);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
} catch(error) {
|
|
247
|
+
if(error.cancelled===true)return {period:'keep',cancelled:true};
|
|
248
|
+
if(error.code!=='ENOENT'||error.path!==target?.settings?.executable) {
|
|
249
|
+
session.startupError=error.message;
|
|
250
|
+
ports.report?.(error,target??binding,'startup_readiness');
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const period=decideStartup({hostInSelectedAppContainer:binding.protected===true,authorizationComplete});
|
|
254
|
+
return {period,...(period==='wrap'?{target}:{}),...(session.startupError?{error:session.startupError}:{})};
|
|
255
|
+
},
|
|
256
|
+
executeStartup,
|
|
257
|
+
async bind(peer) {
|
|
258
|
+
const binding=await ports.bind(peer),id=String(++sequence);
|
|
259
|
+
const session=sessionFor(binding);
|
|
260
|
+
session.bindings.add(binding);session.binding=binding;
|
|
261
|
+
clients.set(id,{binding,session,released:false});return id;
|
|
262
|
+
},
|
|
263
|
+
request(id,operation,fields={}) {
|
|
264
|
+
const request=(async()=>{
|
|
265
|
+
if(Object.keys(fields).some(key=>operation!=='install'||key!=='release'))throw Error('Unknown operation fields');
|
|
266
|
+
if(!['status','ensure','install','exit','later','restore','release','uninstall'].includes(operation))throw Error('Unknown operation');
|
|
267
|
+
const value=clients.get(id);
|
|
268
|
+
if(!value||value.released)throw Error('Unknown client binding');
|
|
269
|
+
const {binding,session}=value;
|
|
270
|
+
if(operation==='status')return observedStatus(value);
|
|
271
|
+
if(operation==='exit')return exit(session);
|
|
272
|
+
if(operation==='restore'||operation==='release') {
|
|
273
|
+
if(operation==='release')value.released=true;
|
|
274
|
+
const pendingWork=[session.attempt?.transition&&session.attempt.promise,
|
|
275
|
+
session.task&&!session.task.done&&session.task.promise].filter(Boolean);
|
|
276
|
+
if(pendingWork.length&&operation==='release') {
|
|
277
|
+
void tracked(binding,async()=>{await Promise.allSettled(pendingWork);await ports.restore(binding);}).catch(error=>ports.report?.(error));
|
|
278
|
+
return {released:true,cleanupPending:true};
|
|
279
|
+
}
|
|
280
|
+
await tracked(binding,async()=>{await Promise.allSettled(pendingWork);await ports.restore(binding);});
|
|
281
|
+
return operation==='release'?{released:true}:{restored:true};
|
|
282
|
+
}
|
|
283
|
+
if(draining||session.closed)throw Error('Updater is draining');
|
|
284
|
+
if(!await ports.alive(binding))throw Error(`Bound ${application} process departed`);
|
|
285
|
+
if(operation==='ensure') {
|
|
286
|
+
value.ensureIntent=true;
|
|
287
|
+
return beginAssessment(value);
|
|
288
|
+
}
|
|
289
|
+
if(operation==='install')return beginAssessment({...value,task:undefined,
|
|
290
|
+
binding:{...binding,requestedRelease:fields.release}},true);
|
|
291
|
+
if(operation==='later') {
|
|
292
|
+
const task=session.task??value.task;
|
|
293
|
+
const observed=await observedStatus(value);
|
|
294
|
+
if(observed.phase!=='ready')throw Error('No current reopen reminder');
|
|
295
|
+
session.dismissedReminder=observed.reminderId;
|
|
296
|
+
if(task)task.dismissed=true;return {dismissed:true};
|
|
297
|
+
}
|
|
298
|
+
if(operation==='uninstall') {
|
|
299
|
+
if(binding.protected)throw Error('Native uninstall requires an ordinary session');
|
|
300
|
+
if([...operations].some(work=>resource(work.binding)===resource(binding)))throw Error('Native operation conflict');
|
|
301
|
+
try {await ports.restore(binding);}
|
|
302
|
+
catch(error){ports.report?.(error,binding,'uninstall_cleanup');}
|
|
303
|
+
void tracked(binding,async()=>{try{const result=await ports.uninstall(binding);
|
|
304
|
+
value.result={phase:result?.code?'failed':'completed',nativeUninstall:result};}
|
|
305
|
+
catch(error){value.result=failure(error);}});
|
|
306
|
+
return {accepted:true};
|
|
307
|
+
}
|
|
308
|
+
})();
|
|
309
|
+
if(operation==='status')return request;
|
|
310
|
+
requests.add(request);return request.finally(()=>requests.delete(request));
|
|
311
|
+
},
|
|
312
|
+
async observeMainExits() {
|
|
313
|
+
if(draining)return true;
|
|
314
|
+
const current=[...new Set(sessions.values())];
|
|
315
|
+
const replacingMain=session=>session.wrapping&&!ports.retainsMainDuringWrap;
|
|
316
|
+
if(!current.length){if(startup&&!await ports.mainAlive(startup)){stop();return true;}return false;}
|
|
317
|
+
for(const session of current) {
|
|
318
|
+
if(replacingMain(session))continue;
|
|
319
|
+
if(!await ports.mainAlive(session.mainBinding))session.closed=true;
|
|
320
|
+
}
|
|
321
|
+
if(current.every(session=>session.closed||replacingMain(session))) {
|
|
322
|
+
if(current.every(replacingMain))return false;
|
|
323
|
+
stop();return true;
|
|
324
|
+
}
|
|
325
|
+
return false;
|
|
326
|
+
},
|
|
327
|
+
stop,drain,
|
|
328
|
+
};
|
|
329
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {createHash} from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
export function verifyPayload(bytes,sums,name) {
|
|
4
|
+
const matches=sums.split(/\r?\n/).map(line=>/^([a-f0-9]{64})\s+\*?(.+)$/i.exec(line))
|
|
5
|
+
.filter(match=>match?.[2]===name);
|
|
6
|
+
if(matches.length!==1)throw new Error('Expected exactly one official Windows payload checksum');
|
|
7
|
+
if(createHash('sha256').update(bytes).digest('hex')!==matches[0][1].toLowerCase())
|
|
8
|
+
throw new Error('FinSAFE payload SHA256 mismatch');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Race the two official sources; only verified bytes can win. */
|
|
12
|
+
export async function downloadInstaller(version,cdnBaseUrl,options={}) {
|
|
13
|
+
options.signal?.throwIfAborted();
|
|
14
|
+
const controller=new AbortController();
|
|
15
|
+
const signal=options.signal?AbortSignal.any([options.signal,controller.signal]):controller.signal;
|
|
16
|
+
const name=`finshield-${version}-x64-setup.exe`;
|
|
17
|
+
async function download(url,format) {
|
|
18
|
+
try {
|
|
19
|
+
const response=await fetch(url,{signal:AbortSignal.any([signal,AbortSignal.timeout(30_000)])});
|
|
20
|
+
if(!response.ok)throw new Error(`HTTP ${response.status}`);
|
|
21
|
+
return await response[format]();
|
|
22
|
+
} catch(error) {
|
|
23
|
+
throw new Error(`FinShield download failed: ${error.message}: ${url}`,{cause:error});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async function cdn() {
|
|
27
|
+
const base=`${cdnBaseUrl.replace(/\/$/,'')}/releases/download/v${version}`;
|
|
28
|
+
const metadata=await download(`${base}/release.json`,'json');
|
|
29
|
+
const assets=metadata?.version===version&&Array.isArray(metadata.assets)
|
|
30
|
+
?metadata.assets.filter(asset=>asset?.name===name&&asset.kind==='windows-installer'):[];
|
|
31
|
+
const asset=assets[0],prefix=`finshield-${version}-x64-setup-`;
|
|
32
|
+
if(assets.length!==1||typeof asset.mirror_name!=='string'||!asset.mirror_name.startsWith(prefix)
|
|
33
|
+
||!(/^[a-f0-9]{32}\.exe$/).test(asset.mirror_name.slice(prefix.length))
|
|
34
|
+
||!(/^[a-f0-9]{64}$/i).test(asset.sha256))
|
|
35
|
+
throw new Error('Invalid FinShield release metadata for requested Windows installer');
|
|
36
|
+
const bytes=Buffer.from(await download(`${base}/${asset.mirror_name}`,'arrayBuffer'));
|
|
37
|
+
verifyPayload(bytes,`${asset.sha256} ${name}`,name);
|
|
38
|
+
return bytes;
|
|
39
|
+
}
|
|
40
|
+
async function github() {
|
|
41
|
+
const base=`https://github.com/finogeeks/finsafe/releases/download/v${version}`;
|
|
42
|
+
const [payload,sums]=await Promise.all([
|
|
43
|
+
download(`${base}/${name}`,'arrayBuffer'),download(`${base}/SHA256SUMS`,'text')]);
|
|
44
|
+
const bytes=Buffer.from(payload);
|
|
45
|
+
verifyPayload(bytes,sums,name);
|
|
46
|
+
return bytes;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
return await Promise.any([cdn(),github()]);
|
|
50
|
+
} catch(error) {
|
|
51
|
+
options.signal?.throwIfAborted();
|
|
52
|
+
throw new AggregateError(error.errors,
|
|
53
|
+
`FinShield CDN and GitHub download failed: ${error.errors.map(e=>e.message).join('; ')}`);
|
|
54
|
+
} finally {
|
|
55
|
+
controller.abort();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export {createActivation} from './activation.js';
|
|
2
|
+
export {createUpdater,decideStartup} from './coordinator.js';
|
|
3
|
+
export {connectUpdater,obtainUpdater,handleRequest} from './transport.js';
|
|
4
|
+
export * from './protocol.js';
|
|
5
|
+
import {appendFile} from 'node:fs/promises';
|
|
6
|
+
|
|
7
|
+
// Diagnostics never participate in an operation's result or readiness.
|
|
8
|
+
export function createDiagnostics(destination,{append=appendFile}={}) {
|
|
9
|
+
return fields=>{
|
|
10
|
+
try {if(destination)void append(destination,JSON.stringify(fields)+'\n').catch(()=>{});}catch{}
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {readFileSync,existsSync} from 'node:fs';
|
|
2
|
+
import {mkdir,mkdtemp,readdir,readFile,writeFile,rename,stat,rm} from 'node:fs/promises';
|
|
3
|
+
import {createRequire} from 'node:module';
|
|
4
|
+
import {join,isAbsolute,dirname,resolve} from 'node:path';
|
|
5
|
+
|
|
6
|
+
const sdkName='@finogeeks2026/finsafe-sdk';
|
|
7
|
+
|
|
8
|
+
/** All plugin loaders use this package's version and its own SDK path. */
|
|
9
|
+
export function packageSdk(root,{sourceRoot=root}={}) {
|
|
10
|
+
const read=directory=>JSON.parse(readFileSync(join(directory,'package.json'),'utf8'));
|
|
11
|
+
const plugin=read(root);
|
|
12
|
+
const sdkRoot=join(sourceRoot,'node_modules',sdkName);
|
|
13
|
+
return {root:sdkRoot,version:plugin.version,
|
|
14
|
+
load:()=>createRequire(join(root,'package.json'))(join(sdkRoot,'src','native.js'))};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Stage the complete delivered package. One atomic directory per release. */
|
|
18
|
+
export async function stagePluginPackage(source,base,{sdkSourceRoot=source,overrides={}}={}) {
|
|
19
|
+
const packaged=packageSdk(source,{sourceRoot:sdkSourceRoot});
|
|
20
|
+
const manifest=JSON.parse(readFileSync(join(source,'package.json'),'utf8'));
|
|
21
|
+
const target=join(base,packaged.version);
|
|
22
|
+
if(existsSync(target)){packageSdk(target);return target;}
|
|
23
|
+
await mkdir(base,{recursive:true});const pending=await mkdtemp(join(base,'.stage-'));
|
|
24
|
+
async function copy(from,to){
|
|
25
|
+
await mkdir(to,{recursive:true});
|
|
26
|
+
for(const item of await readdir(from,{withFileTypes:true})){
|
|
27
|
+
const origin=join(from,item.name),destination=join(to,item.name);
|
|
28
|
+
if(item.isDirectory())await copy(origin,destination);
|
|
29
|
+
else if(item.isFile())await writeFile(destination,await readFile(origin));
|
|
30
|
+
else throw Error('Linked staged package entry is unsupported');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
try {for(const name of new Set([...manifest.files,'package.json','release.json'])){
|
|
34
|
+
if(isAbsolute(name)||name.split(/[\\/]/).includes('..'))throw Error('Invalid package delivery path');
|
|
35
|
+
const origin=join(name==='release.json'?sdkSourceRoot:source,name),destination=join(pending,name);
|
|
36
|
+
if(!existsSync(origin))continue;
|
|
37
|
+
// A files entry can select a nested file or a directory; readFile is also
|
|
38
|
+
// supported by Electron for packaged virtual files.
|
|
39
|
+
if((await stat(origin)).isDirectory())await copy(origin,destination);
|
|
40
|
+
else {await mkdir(join(destination,'..'),{recursive:true});await writeFile(destination,await readFile(origin));}
|
|
41
|
+
}
|
|
42
|
+
for(const [targetName,sourceName] of Object.entries(overrides)){
|
|
43
|
+
const destination=join(pending,targetName);await mkdir(dirname(destination),{recursive:true});
|
|
44
|
+
await writeFile(destination,await readFile(join(source,sourceName)));
|
|
45
|
+
}
|
|
46
|
+
await copy(packaged.root,join(pending,'node_modules',sdkName));
|
|
47
|
+
try{await rename(pending,target);}catch(error){if(!existsSync(target))throw error;}
|
|
48
|
+
packageSdk(target);return target;
|
|
49
|
+
}finally{
|
|
50
|
+
if(dirname(resolve(pending))!==resolve(base))throw Error('Invalid package staging cleanup path');
|
|
51
|
+
await rm(pending,{recursive:true,force:true});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export const protocol=1;
|
|
2
|
+
export const operations=['hello','bind','admit','status','ensure','install','exit','later','restore','release','uninstall'];
|
|
3
|
+
// Full per-path diagnostics stay with native owners, outside bounded IPC frames.
|
|
4
|
+
export function projectState(value) {
|
|
5
|
+
if(typeof value?.phase!=='string'||value.phase.length>64) throw Error('Invalid native phase');
|
|
6
|
+
const result={phase:value.phase,reopenRequired:value.reopenRequired};
|
|
7
|
+
for(const name of ['currentProtected','authorizationPending','reminderDismissed'])if(typeof value[name]==='boolean')result[name]=value[name];
|
|
8
|
+
for(const name of ['currentRelease','requestedRelease','reason','reminderId'])if(typeof value[name]==='string')result[name]=value[name];
|
|
9
|
+
if(value.error) result.error=String(value.error).slice(0,2048);
|
|
10
|
+
if(value.authorization) {
|
|
11
|
+
result.authorization={};
|
|
12
|
+
for(const name of ['phase','prepared','authorization_in_progress','exit_code'])
|
|
13
|
+
if(value.authorization[name]!==undefined)result.authorization[name]=value.authorization[name];
|
|
14
|
+
if(value.authorization.error)result.authorization.error=String(value.authorization.error).slice(0,2048);
|
|
15
|
+
}
|
|
16
|
+
if(value.progress) {
|
|
17
|
+
const percent=value.progress.overall_percent??null;
|
|
18
|
+
if(percent!==null&&(typeof percent!=='number'||!Number.isFinite(percent))) throw Error('Invalid native percentage');
|
|
19
|
+
result.progress={overall_percent:percent};
|
|
20
|
+
const current=Array.isArray(value.progress.items)?value.progress.items.find(item=>item.state==='start'):undefined;
|
|
21
|
+
if(typeof current?.path==='string')result.progress.items=[{path:current.path.slice(0,1024),
|
|
22
|
+
...(typeof current.state==='string'?{state:current.state.slice(0,64)}:{})}];
|
|
23
|
+
}
|
|
24
|
+
for(const name of ['prepared','authorization_in_progress']) if(typeof value[name]==='boolean') result[name]=value[name];
|
|
25
|
+
if(value.nativeSetup) result.nativeSetup={code:value.nativeSetup.code,phase:value.nativeSetup.phase};
|
|
26
|
+
if(value.nativeUninstall) result.nativeUninstall={code:value.nativeUninstall.code};
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
export function validateRequest(value) {
|
|
30
|
+
if(!value||typeof value!=='object'||Array.isArray(value)) throw Error('Invalid updater request');
|
|
31
|
+
if(value.protocol!==undefined&&!Number.isSafeInteger(value.protocol)) throw Error('Invalid updater framing label');
|
|
32
|
+
if(!operations.includes(value.operation)) throw Error('Unknown updater operation');
|
|
33
|
+
const allowed=['hello','bind','admit'].includes(value.operation)?(value.operation==='hello'?['protocol','operation']:['protocol','operation','context']):value.operation==='install'?['protocol','operation','client','release']:['protocol','operation','client'];
|
|
34
|
+
if(Object.keys(value).some(key=>!allowed.includes(key))) throw Error('Unknown updater request fields');
|
|
35
|
+
if(!['hello','bind','admit'].includes(value.operation)&&typeof value.client!=='string') throw Error('Missing updater client binding');
|
|
36
|
+
if(value.operation==='install'&&typeof value.release!=='string')throw Error('Missing installation release');
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {protocol} from './protocol.js';
|
|
2
|
+
|
|
3
|
+
export async function handleRequest(message,{dispatch,reply}) {
|
|
4
|
+
let continuation,response;
|
|
5
|
+
try {response={ok:true,value:await dispatch(message,action=>{continuation=action;})};}
|
|
6
|
+
catch(error){response={ok:false,error:error.message.slice(0,2048)};}
|
|
7
|
+
await reply(response);
|
|
8
|
+
if(response.ok)continuation?.();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function connectUpdater(staged,{call}) {
|
|
12
|
+
let usageContext;
|
|
13
|
+
const request=async(operation,fields={},options={})=>{
|
|
14
|
+
if(fields.context?.usage!==undefined) {
|
|
15
|
+
// Old updaters reject unknown binding fields. Reuse their original payload.
|
|
16
|
+
if(usageContext===undefined)await request('hello',{},options);
|
|
17
|
+
if(!usageContext) {
|
|
18
|
+
const {usage,...context}=fields.context;
|
|
19
|
+
fields={...fields,context};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const message={protocol,operation,...fields};
|
|
23
|
+
const result=await call({action:'request',root:staged.root,request:message,...options});
|
|
24
|
+
if(!result.ok) throw Error(result.error);
|
|
25
|
+
if(operation==='hello') {
|
|
26
|
+
usageContext=result.value?.usageContext===true;
|
|
27
|
+
}
|
|
28
|
+
return result.value;
|
|
29
|
+
};
|
|
30
|
+
return {call,request};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function obtainUpdater(staged,settings,{connect,start,context,startup=true,validateHello=()=>{},incompatible,
|
|
34
|
+
now=Date.now,deadlineMs=10000,releaseLaunchAfterHello=false}={}) {
|
|
35
|
+
const connection=connect(staged);
|
|
36
|
+
const old=await connection.call({action:'open_updater_job'});
|
|
37
|
+
let ownsLaunch=false;
|
|
38
|
+
const admit=async(deadline,launch)=>{
|
|
39
|
+
const options={deadline,...(launch?{launch}: {})};
|
|
40
|
+
const hello=await connection.request('hello',{},options);
|
|
41
|
+
validateHello(hello);
|
|
42
|
+
if(launch&&releaseLaunchAfterHello){
|
|
43
|
+
await connection.call({action:'release_updater_launch',launch});
|
|
44
|
+
ownsLaunch=false;
|
|
45
|
+
delete options.launch;
|
|
46
|
+
}
|
|
47
|
+
if(context&&startup){const decision=await connection.request('admit',{context},options);connection.period=decision.period;connection.startupError=decision.error;connection.cancelled=decision.cancelled;connection.admitted=true;}
|
|
48
|
+
};
|
|
49
|
+
if(old.job)await connection.call({action:'recover_updater_job',job:old.job});
|
|
50
|
+
const deadline=now()+deadlineMs;
|
|
51
|
+
const launched=await (start??(request=>connection.call({action:'bootstrap',...request})))({
|
|
52
|
+
node:staged.node,entry:staged.entry,deadline,
|
|
53
|
+
installation:settings.installation,configuration:settings.configuration,context});
|
|
54
|
+
ownsLaunch=true;
|
|
55
|
+
try {
|
|
56
|
+
await admit(deadline,launched.launch);
|
|
57
|
+
}catch(error) {
|
|
58
|
+
try {if(ownsLaunch)await connection.call({action:'stop_updater_launch',launch:launched.launch});}
|
|
59
|
+
catch(cleanup){throw new AggregateError([error,cleanup],`${error.message}; startup cleanup: ${cleanup.message}`);}
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
if(ownsLaunch)await connection.call({action:'release_updater_launch',launch:launched.launch});
|
|
63
|
+
connection.startupDeadline=deadline;
|
|
64
|
+
return connection;
|
|
65
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// AppSeam replaces only Host. OpenCode reconnects its existing Main natively.
|
|
2
|
+
export async function launchHost(binding,{replace,confirm,record=()=>{},listen,onStopped=()=>{},observeReplacement=()=>{}}) {
|
|
3
|
+
if(listen)await listen();
|
|
4
|
+
const oldHostPid=binding.pid,result=await replace();
|
|
5
|
+
if(result.main_pid!==binding.main||result.mainKey!==binding.mainKey)
|
|
6
|
+
throw Error('OpenCode Main identity changed during Host handoff');
|
|
7
|
+
onStopped(false); // Old Host exited; Main was retained.
|
|
8
|
+
record('ac-host-ready',{oldMainPid:binding.main,oldHostPid,
|
|
9
|
+
mainPid:result.main_pid,mainKey:result.mainKey,newHostPid:result.host_pid,corePid:result.core_pid});
|
|
10
|
+
await confirm(result);
|
|
11
|
+
binding.pid=result.host_pid;binding.protected=true;
|
|
12
|
+
observeReplacement(result.mainKey);
|
|
13
|
+
record('main-host-connected',{mainKey:result.mainKey,hostPid:result.host_pid});
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Transient acknowledgment owned by one handoff, including a rebind that races
|
|
18
|
+
// the CLI readiness response. Native bind has verified every observed peer.
|
|
19
|
+
export function createConnectionConfirmation({timeout=45000}={}){
|
|
20
|
+
const attempts=new Map();
|
|
21
|
+
return {
|
|
22
|
+
begin(mainKey){
|
|
23
|
+
if(attempts.has(mainKey))throw Error('OpenCode Host handoff is already active');
|
|
24
|
+
let resolve,reject,timer,expected;
|
|
25
|
+
const completion=new Promise((yes,no)=>{resolve=yes;reject=no;}),seen=new Set();
|
|
26
|
+
const attempt={seen,observe(pid){seen.add(pid);if(pid===expected)resolve();}};
|
|
27
|
+
attempts.set(mainKey,attempt);
|
|
28
|
+
return {async wait(result){
|
|
29
|
+
expected=result.host_pid;
|
|
30
|
+
if(seen.has(expected))return;
|
|
31
|
+
timer=setTimeout(()=>reject(Error('OpenCode Main did not confirm its business connection to the protected Host')),timeout);
|
|
32
|
+
try{await completion;}finally{clearTimeout(timer);}
|
|
33
|
+
},dispose(){clearTimeout(timer);attempts.delete(mainKey);}};
|
|
34
|
+
},
|
|
35
|
+
observe(binding){
|
|
36
|
+
if(binding.protected&&binding.context?.connectedHostPid===binding.pid)
|
|
37
|
+
attempts.get(binding.mainKey)?.observe(binding.pid);
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// OpenCode management. Plugin removal must retain the FinSAFE installation.
|
|
2
|
+
import {createUpdater} from '../updater/coordinator.js';
|
|
3
|
+
export function createManagement(options){
|
|
4
|
+
const updater=createUpdater(options),request=updater.request;
|
|
5
|
+
updater.request=(id,operation,fields)=>operation==='uninstall'
|
|
6
|
+
?Promise.reject(Error('Plugin removal retains FinSAFE runtime, configuration and authorization'))
|
|
7
|
+
:request(id,operation,fields);
|
|
8
|
+
return updater;
|
|
9
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {createRequire} from 'node:module';
|
|
2
|
+
import {join} from 'node:path';
|
|
3
|
+
import {packageSdk} from './common/package.js';
|
|
4
|
+
|
|
5
|
+
export function nativeAdapter(root,{require=createRequire(join(root,'package.json')),
|
|
6
|
+
sdk=packageSdk(root).load()}={}) {
|
|
7
|
+
const native=sdk.createClient();
|
|
8
|
+
const call=request=>native({
|
|
9
|
+
module:'app_seam.opencode',
|
|
10
|
+
request:request.action==='stage_configuration'
|
|
11
|
+
?{...request,candidate:join(root,'policy','candidate.yaml')}:request,
|
|
12
|
+
});
|
|
13
|
+
call.watchMain=(request,onExit)=>native.watchMain({module:'app_seam.opencode',request},onExit);
|
|
14
|
+
call.buildInfo=native.buildInfo;
|
|
15
|
+
call.libraryPath=native.libraryPath;
|
|
16
|
+
call.sdkRoot=native.sdkRoot;
|
|
17
|
+
return call;
|
|
18
|
+
}
|