@solidnumber/cli 2.30.2 → 2.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.CATALOG = void 0;
37
+ exports.platformOf = platformOf;
38
+ exports.cleanInputs = cleanInputs;
39
+ exports.serviceStateFrom = serviceStateFrom;
40
+ exports.gatewayFrom = gatewayFrom;
41
+ exports.runAction = runAction;
42
+ /**
43
+ * The named actions the helper can run on this machine — and nothing else.
44
+ *
45
+ * The same list as the platform's (solid-backend/services/remote/actions.py). The
46
+ * platform asks for an action by NAME with named inputs; this file decides what that
47
+ * name means here. A name that is not in this list is refused, whoever asks.
48
+ *
49
+ * ⛔ NO SHELL. Every action runs one fixed program with its arguments as an array
50
+ * (`execFile`), never a command line. An input is a NAME (letters, digits and a few
51
+ * separators) or a LABEL as it reads on screen (a name that may also carry a space
52
+ * and the marks a label has); it is checked before it is used, and reaches the
53
+ * program as data.
54
+ * ⛔ ADDING AN ACTION is a decision about what may be done on someone's computer: add
55
+ * it here AND in the platform's list, with its undo and its proof.
56
+ *
57
+ * `exec` is handed in, so every action is testable without touching a machine.
58
+ */
59
+ const os = __importStar(require("os"));
60
+ const helper_ui_1 = require("./helper-ui");
61
+ const NAME = /^[A-Za-z0-9][A-Za-z0-9_.@-]{0,79}$/;
62
+ const LABEL = /^[A-Za-z0-9][A-Za-z0-9 _.@:&/()#+,-]{0,79}$/;
63
+ // The inputs that are a label as it reads on screen; every other input is a name.
64
+ const LABELS = new Set(['control', 'value']);
65
+ exports.CATALOG = {
66
+ 'system.info': { kind: 'probe', inputs: [] },
67
+ 'network.settings': { kind: 'probe', inputs: [] },
68
+ 'service.state': { kind: 'probe', inputs: ['service'] },
69
+ 'process.running': { kind: 'probe', inputs: ['name'] },
70
+ 'service.stop': { kind: 'act', inputs: ['service'] },
71
+ 'service.start': { kind: 'act', inputs: ['service'] },
72
+ // A program's own window, by the labels on it (helper-ui.ts). Windows and Mac.
73
+ 'ui.read': { kind: 'probe', inputs: ['program'] },
74
+ 'ui.set': { kind: 'act', inputs: ['program', 'control', 'value'] },
75
+ 'ui.press': { kind: 'act', inputs: ['program', 'control'] },
76
+ };
77
+ function platformOf(nodePlatform = process.platform) {
78
+ return nodePlatform === 'win32' ? 'windows' : nodePlatform === 'darwin' ? 'mac' : nodePlatform === 'linux' ? 'linux' : null;
79
+ }
80
+ /** PURE. The inputs exactly as this action takes them, or the reason they are refused. */
81
+ function cleanInputs(action, inputs) {
82
+ const spec = Object.prototype.hasOwnProperty.call(exports.CATALOG, action) ? exports.CATALOG[action] : null;
83
+ if (!spec)
84
+ return { reason: 'unknown_action' };
85
+ const given = inputs && typeof inputs === 'object' ? inputs : {};
86
+ if (Object.keys(given).some((k) => !spec.inputs.includes(k)))
87
+ return { reason: 'unknown_input' };
88
+ const out = {};
89
+ for (const key of spec.inputs) {
90
+ const value = given[key];
91
+ if (typeof value !== 'string' || !(LABELS.has(key) ? LABEL : NAME).test(value))
92
+ return { reason: 'bad_input' };
93
+ out[key] = value;
94
+ }
95
+ return { inputs: out };
96
+ }
97
+ /** PURE. A service's state from what the platform's own tool printed. */
98
+ function serviceStateFrom(platform, code, stdout) {
99
+ const text = stdout.toLowerCase();
100
+ if (platform === 'windows')
101
+ return /state\s*:\s*4\s+running/.test(text) ? 'running' : /state\s*:\s*1\s+stopped/.test(text) ? 'stopped' : 'unknown';
102
+ if (platform === 'linux')
103
+ return text.trim() === 'active' ? 'running' : ['inactive', 'failed', 'deactivating'].includes(text.trim()) ? 'stopped' : 'unknown';
104
+ if (code !== 0)
105
+ return 'unknown';
106
+ return /"pid"\s*=\s*\d+/.test(text) ? 'running' : 'stopped';
107
+ }
108
+ /** PURE. The default gateway from what the platform's own tool printed. */
109
+ function gatewayFrom(platform, stdout) {
110
+ const found = platform === 'mac' ? /gateway:\s*([0-9a-f.:]+)/i.exec(stdout)
111
+ : platform === 'linux' ? /default via\s+([0-9a-f.:]+)/i.exec(stdout)
112
+ : /([0-9]{1,3}(?:\.[0-9]{1,3}){3})/.exec(stdout);
113
+ return found ? found[1] : '';
114
+ }
115
+ async function serviceState(platform, service, exec) {
116
+ const run = platform === 'windows' ? exec('sc.exe', ['query', service])
117
+ : platform === 'linux' ? exec('systemctl', ['is-active', service])
118
+ : exec('launchctl', ['list', service]);
119
+ const { code, stdout } = await run;
120
+ return serviceStateFrom(platform, code, stdout);
121
+ }
122
+ /** Run ONE named action. Never throws: a failure is `{ ok: false, reason }`. */
123
+ async function runAction(action, rawInputs, platform, exec, host = os) {
124
+ const cleaned = cleanInputs(action, rawInputs);
125
+ if (!cleaned.inputs)
126
+ return { ok: false, reason: cleaned.reason };
127
+ if (!platform)
128
+ return { ok: false, reason: 'unsupported_platform' };
129
+ const inputs = cleaned.inputs;
130
+ try {
131
+ switch (action) {
132
+ case 'system.info':
133
+ return { ok: true, data: { platform, release: host.release(), arch: host.arch() } };
134
+ case 'network.settings': {
135
+ const own = Object.values(host.networkInterfaces()).flat()
136
+ .find((n) => n && !n.internal && n.family === 'IPv4');
137
+ const route = platform === 'mac' ? await exec('route', ['-n', 'get', 'default'])
138
+ : platform === 'linux' ? await exec('ip', ['route', 'show', 'default'])
139
+ : await exec('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command',
140
+ '(Get-NetRoute -DestinationPrefix 0.0.0.0/0 | Select-Object -First 1).NextHop']);
141
+ if (!own)
142
+ return { ok: false, reason: 'no_network' };
143
+ return { ok: true, data: { address: own.address, subnet_mask: own.netmask, gateway: gatewayFrom(platform, route.stdout) } };
144
+ }
145
+ case 'service.state': {
146
+ const state = await serviceState(platform, inputs.service, exec);
147
+ return state === 'unknown' ? { ok: false, reason: 'service_not_found' } : { ok: true, data: { service: inputs.service, state } };
148
+ }
149
+ case 'process.running': {
150
+ const found = platform === 'windows'
151
+ ? (await exec('tasklist.exe', ['/FI', `IMAGENAME eq ${inputs.name}`, '/NH'])).stdout.toLowerCase().includes(inputs.name.toLowerCase())
152
+ : (await exec('pgrep', ['-x', inputs.name])).code === 0;
153
+ return { ok: true, data: { name: inputs.name, running: found } };
154
+ }
155
+ case 'service.stop':
156
+ case 'service.start': {
157
+ const verb = action === 'service.stop' ? 'stop' : 'start';
158
+ const done = platform === 'windows' ? await exec('sc.exe', [verb, inputs.service])
159
+ : platform === 'linux' ? await exec('systemctl', [verb, inputs.service])
160
+ : await exec('launchctl', [verb, inputs.service]);
161
+ // What was asked is not what happened: read the state back before answering.
162
+ const state = await serviceState(platform, inputs.service, exec);
163
+ const wanted = verb === 'stop' ? 'stopped' : 'running';
164
+ if (state !== wanted)
165
+ return { ok: false, reason: done.code !== 0 ? 'not_permitted_or_failed' : 'state_did_not_change', data: { service: inputs.service, state } };
166
+ return { ok: true, data: { service: inputs.service, state } };
167
+ }
168
+ case 'ui.read':
169
+ case 'ui.set':
170
+ case 'ui.press':
171
+ return await (0, helper_ui_1.runUi)(action, inputs, platform, exec);
172
+ default:
173
+ return { ok: false, reason: 'unknown_action' };
174
+ }
175
+ }
176
+ catch {
177
+ return { ok: false, reason: 'could_not_run' };
178
+ }
179
+ }
180
+ //# sourceMappingURL=helper-actions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helper-actions.js","sourceRoot":"","sources":["../../src/lib/helper-actions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,gCAEC;AAGD,kCAYC;AAGD,4CAMC;AAGD,kCAKC;AAWD,8BAoDC;AA7ID;;;;;;;;;;;;;;;;GAgBG;AACH,uCAAyB;AACzB,2CAAoC;AAQpC,MAAM,IAAI,GAAG,oCAAoC,CAAC;AAClD,MAAM,KAAK,GAAG,6CAA6C,CAAC;AAC5D,kFAAkF;AAClF,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;AAEhC,QAAA,OAAO,GAAqD;IACvE,aAAa,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE;IAC5C,kBAAkB,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE;IACjD,eAAe,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,SAAS,CAAC,EAAE;IACvD,iBAAiB,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE;IACtD,cAAc,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,SAAS,CAAC,EAAE;IACpD,e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O,MAAM,IAAA,iBAAK,EAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;YACrD;gBACE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC;QACnD,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC;IAChD,CAAC;AACH,CAAC"}
@@ -0,0 +1,35 @@
1
+ export type HelperIdentity = {
2
+ api_url: string;
3
+ token: string;
4
+ endpoint_id: number;
5
+ name: string;
6
+ };
7
+ type Fetch = (url: string, init: {
8
+ method: string;
9
+ headers: Record<string, string>;
10
+ body: string;
11
+ }) => Promise<{
12
+ ok: boolean;
13
+ status: number;
14
+ json: () => Promise<unknown>;
15
+ }>;
16
+ export declare const HELPER_FILE: string;
17
+ export declare function loadIdentity(file?: string): HelperIdentity | null;
18
+ export declare function saveIdentity(identity: HelperIdentity, file?: string): void;
19
+ export declare function forgetIdentity(file?: string): boolean;
20
+ /** PURE. Where the helper's socket connects, from the API's address. */
21
+ export declare function socketUrl(apiUrl: string, token: string): string;
22
+ export declare class HelperClient {
23
+ private readonly apiUrl;
24
+ private readonly fetcher;
25
+ constructor(apiUrl: string, fetcher?: Fetch);
26
+ private post;
27
+ /** Spend a one-use code: this machine becomes an endpoint and is handed its token. */
28
+ enrol(code: string, platform: string | null, version: string): Promise<HelperIdentity | null>;
29
+ /** The person typed the session's code here. The grant's id, or null. */
30
+ approve(token: string, code: string): Promise<number | null>;
31
+ stop(token: string): Promise<boolean>;
32
+ answer(token: string, rid: string, result: Record<string, unknown>): Promise<boolean>;
33
+ }
34
+ export {};
35
+ //# sourceMappingURL=helper-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helper-client.d.ts","sourceRoot":"","sources":["../../src/lib/helper-client.ts"],"names":[],"mappings":"AAaA,MAAM,MAAM,cAAc,GAAG;IA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AG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAM5D,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIrC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;CAG5F"}
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.HelperClient = exports.HELPER_FILE = void 0;
37
+ exports.loadIdentity = loadIdentity;
38
+ exports.saveIdentity = saveIdentity;
39
+ exports.forgetIdentity = forgetIdentity;
40
+ exports.socketUrl = socketUrl;
41
+ /**
42
+ * The helper's line to the platform: enrol this machine, hear requests, answer them.
43
+ *
44
+ * It only DIALS OUT. Nothing here listens on the machine's network. The machine's
45
+ * token is kept in ~/.solid/helper.json, readable by this user only, and is separate
46
+ * from a signed-in CLI: a helper on a customer's computer holds no company login.
47
+ *
48
+ * `fetch` and the socket are handed in, so the client is testable with neither.
49
+ */
50
+ const fs = __importStar(require("fs"));
51
+ const os = __importStar(require("os"));
52
+ const path = __importStar(require("path"));
53
+ exports.HELPER_FILE = path.join(os.homedir(), '.solid', 'helper.json');
54
+ function loadIdentity(file = exports.HELPER_FILE) {
55
+ try {
56
+ const data = JSON.parse(fs.readFileSync(file, 'utf8'));
57
+ return typeof data?.token === 'string' && data.token.length >= 32 && typeof data?.api_url === 'string' ? data : null;
58
+ }
59
+ catch {
60
+ return null;
61
+ }
62
+ }
63
+ function saveIdentity(identity, file = exports.HELPER_FILE) {
64
+ fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
65
+ fs.writeFileSync(file, JSON.stringify(identity, null, 2), { mode: 0o600 });
66
+ fs.chmodSync(file, 0o600);
67
+ }
68
+ function forgetIdentity(file = exports.HELPER_FILE) {
69
+ try {
70
+ fs.unlinkSync(file);
71
+ return true;
72
+ }
73
+ catch {
74
+ return false;
75
+ }
76
+ }
77
+ /** PURE. Where the helper's socket connects, from the API's address. */
78
+ function socketUrl(apiUrl, token) {
79
+ return `${apiUrl.replace(/\/+$/, '').replace(/^http/, 'ws')}/api/v1/remote/helper/connect?token=${encodeURIComponent(token)}`;
80
+ }
81
+ class HelperClient {
82
+ apiUrl;
83
+ fetcher;
84
+ constructor(apiUrl, fetcher = fetch) {
85
+ this.apiUrl = apiUrl;
86
+ this.fetcher = fetcher;
87
+ }
88
+ async post(pathname, body) {
89
+ try {
90
+ const res = await this.fetcher(`${this.apiUrl.replace(/\/+$/, '')}/api/v1/remote/helper/${pathname}`, {
91
+ method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body),
92
+ });
93
+ let data = {};
94
+ try {
95
+ data = await res.json();
96
+ }
97
+ catch { /* an empty answer */ }
98
+ return { ok: res.ok, status: res.status, data: (data && typeof data === 'object' ? data : {}) };
99
+ }
100
+ catch {
101
+ return { ok: false, status: 0, data: {} };
102
+ }
103
+ }
104
+ /** Spend a one-use code: this machine becomes an endpoint and is handed its token. */
105
+ async enrol(code, platform, version) {
106
+ const out = await this.post('enrol', { code, platform, version });
107
+ const { token, endpoint_id, name } = out.data;
108
+ if (!out.ok || typeof token !== 'string' || typeof endpoint_id !== 'number')
109
+ return null;
110
+ return { api_url: this.apiUrl, token, endpoint_id, name: typeof name === 'string' ? name : '' };
111
+ }
112
+ /** The person typed the session's code here. The grant's id, or null. */
113
+ async approve(token, code) {
114
+ const out = await this.post('approve', { token, code });
115
+ const id = out.data.grant_id;
116
+ return out.ok && typeof id === 'number' ? id : null;
117
+ }
118
+ async stop(token) {
119
+ return (await this.post('stop', { token })).ok;
120
+ }
121
+ async answer(token, rid, result) {
122
+ return (await this.post('result', { token, rid, result })).ok;
123
+ }
124
+ }
125
+ exports.HelperClient = HelperClient;
126
+ //# sourceMappingURL=helper-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helper-client.js","sourceRoot":"","sources":["../../src/lib/helper-client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,oCAOC;AAED,oCAIC;AAED,wCAEC;AAGD,8BAEC;AAxCD;;;;;;;;GAQG;AACH,uCAAyB;AACzB,uCAAyB;AACzB,2CAA6B;AAKhB,QAAA,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC;AAE5E,SAAgB,YAAY,CAAC,OAAe,mBAAW;IACrD,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,IAAI,CA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,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,IAAkE,CAAC;QAC5G,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,WAAW,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC;QACzF,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IAClG,CAAC;IAED,yEAAyE;IACzE,KAAK,CAAC,OAAO,CAAC,KAAa,EAAE,IAAY;QACvC,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACxD,MAAM,EAAE,GAAI,GAAG,CAAC,IAA+B,CAAC,QAAQ,CAAC;QACzD,OAAO,GAAG,CAAC,EAAE,IAAI,OAAO,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,KAAa;QACtB,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,KAAa,EAAE,GAAW,EAAE,MAA+B;QACtE,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAChE,CAAC;CACF;AAtCD,oCAsCC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * The helper's own decisions — what it will do for a request, and what it refuses.
3
+ *
4
+ * The platform can ask. This is the second check, on the person's own machine, and it
5
+ * does not trust the first:
6
+ *
7
+ * ⛔ NOTHING RUNS WITHOUT A GRANT THIS MACHINE APPROVED. The person typed a code
8
+ * here; the platform answered with that grant's id; only a request naming that
9
+ * id is run. A request with no grant, another grant, or after Stop is refused.
10
+ * ⛔ ONLY A NAME IN THIS MACHINE'S OWN LIST. See helper-actions.ts.
11
+ * ⛔ STOP IS LOCAL AND IMMEDIATE. It clears the grant here before it tells anyone.
12
+ *
13
+ * Pure state plus an injected runner, so each rule is testable.
14
+ */
15
+ import { type ActionResult, type Exec, type Platform } from './helper-actions';
16
+ export type HelperRequest = {
17
+ type?: unknown;
18
+ rid?: unknown;
19
+ action?: unknown;
20
+ kind?: unknown;
21
+ inputs?: unknown;
22
+ grant_id?: unknown;
23
+ };
24
+ export type Did = {
25
+ at: number;
26
+ action: string;
27
+ ok: boolean;
28
+ reason?: string;
29
+ };
30
+ export declare class HelperSession {
31
+ private readonly platform;
32
+ private readonly exec;
33
+ private readonly now;
34
+ private grantId;
35
+ readonly log: Did[];
36
+ constructor(platform: Platform | null, exec: Exec, now?: () => number);
37
+ get granted(): boolean;
38
+ /** The platform confirmed the code the person typed here. */
39
+ approved(grantId: unknown): boolean;
40
+ /** Stop: theirs (pressed here) or the platform's (the grant ended). Always wins. */
41
+ stop(): void;
42
+ /** One request from the platform → the answer to send back, or null to send nothing. */
43
+ handle(request: HelperRequest): Promise<{
44
+ rid: string;
45
+ result: ActionResult;
46
+ } | null>;
47
+ }
48
+ //# sourceMappingURL=helper-session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helper-session.d.ts","sourceRoot":"","sources":["../../src/lib/helper-session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAa,KAAK,YAAY,EAAE,KAAK,IAAI,EAAE,KAAK,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE1F,MAAM,MAAM,aAAa,GAAG;IAAE,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,GAAG,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AACtI,MAAM,MAAM,GAAG,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/E,qBAAa,aAAa;IAIZ,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAAmB,OAAO,CAAC,QAAQ,CAAC,IAAI;IAC3E,OAAO,CAAC,QAAQ,CAAC,GAAG;IAJtB,OAAO,CAAC,OAAO,CAAuB;IACtC,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,CAAM;gBAEI,QAAQ,EAAE,QAAQ,GAAG,IAAI,EAAmB,IAAI,EAAE,IAAI,EAChE,GAAG,GAAE,MAAM,MAAiB;IAE/C,IAAI,OAAO,IAAI,OAAO,CAAkC;IAExD,6DAA6D;IAC7D,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO;IAMnC,oFAAoF;IACpF,IAAI,IAAI,IAAI;IAEZ,wFAAwF;IAClF,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,YAAY,CAAA;KAAE,GAAG,IAAI,CAAC;CAe5F"}
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HelperSession = void 0;
4
+ /**
5
+ * The helper's own decisions — what it will do for a request, and what it refuses.
6
+ *
7
+ * The platform can ask. This is the second check, on the person's own machine, and it
8
+ * does not trust the first:
9
+ *
10
+ * ⛔ NOTHING RUNS WITHOUT A GRANT THIS MACHINE APPROVED. The person typed a code
11
+ * here; the platform answered with that grant's id; only a request naming that
12
+ * id is run. A request with no grant, another grant, or after Stop is refused.
13
+ * ⛔ ONLY A NAME IN THIS MACHINE'S OWN LIST. See helper-actions.ts.
14
+ * ⛔ STOP IS LOCAL AND IMMEDIATE. It clears the grant here before it tells anyone.
15
+ *
16
+ * Pure state plus an injected runner, so each rule is testable.
17
+ */
18
+ const helper_actions_1 = require("./helper-actions");
19
+ class HelperSession {
20
+ platform;
21
+ exec;
22
+ now;
23
+ grantId = null;
24
+ log = [];
25
+ constructor(platform, exec, now = Date.now) {
26
+ this.platform = platform;
27
+ this.exec = exec;
28
+ this.now = now;
29
+ }
30
+ get granted() { return this.grantId !== null; }
31
+ /** The platform confirmed the code the person typed here. */
32
+ approved(grantId) {
33
+ if (typeof grantId !== 'number' || !Number.isInteger(grantId) || grantId <= 0)
34
+ return false;
35
+ this.grantId = grantId;
36
+ return true;
37
+ }
38
+ /** Stop: theirs (pressed here) or the platform's (the grant ended). Always wins. */
39
+ stop() { this.grantId = null; }
40
+ /** One request from the platform → the answer to send back, or null to send nothing. */
41
+ async handle(request) {
42
+ if (!request || typeof request !== 'object')
43
+ return null;
44
+ if (request.type === 'grant_ended' || request.type === 'retired') {
45
+ this.stop();
46
+ return null;
47
+ }
48
+ if (request.type !== 'do' || typeof request.rid !== 'string' || !request.rid)
49
+ return null;
50
+ const action = typeof request.action === 'string' ? request.action : '';
51
+ const refuse = (reason) => {
52
+ this.log.push({ at: this.now(), action, ok: false, reason });
53
+ return { rid: request.rid, result: { ok: false, reason } };
54
+ };
55
+ if (this.grantId === null)
56
+ return refuse('no_grant_on_this_machine');
57
+ if (request.grant_id !== this.grantId)
58
+ return refuse('grant_not_this_one');
59
+ const result = await (0, helper_actions_1.runAction)(action, request.inputs, this.platform, this.exec);
60
+ this.log.push({ at: this.now(), action, ok: result.ok, reason: result.reason });
61
+ return { rid: request.rid, result };
62
+ }
63
+ }
64
+ exports.HelperSession = HelperSession;
65
+ //# sourceMappingURL=helper-session.js.map
@@ -0,0 +1 @@
1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CAAC;QAC1F,MAAM,MAAM,GAAG,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;QACxE,MAAM,MAAM,GAAG,CAAC,MAAc,EAAE,EAAE;YAChC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;YAC7D,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,GAAa,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC;QACvE,CAAC,CAAC;QACF,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI;YAAE,OAAO,MAAM,CAAC,0BAA0B,CAAC,CAAC;QACrE,IAAI,OAAO,CAAC,QAAQ,KAAK,IAAI,CAAC,OAAO;YAAE,OAAO,MAAM,CAAC,oBAAoB,CAAC,CAAC;QAC3E,MAAM,MAAM,GAAG,MAAM,IAAA,0BAAS,EAAC,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QACjF,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;QAChF,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC;IACtC,CAAC;CACF;AAnCD,sCAmCC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * A program's own window, by the labels on it: read its controls, set one, press one.
3
+ *
4
+ * Through the system's accessibility layer — UI Automation on Windows, System Events
5
+ * on a Mac. Not on Linux.
6
+ *
7
+ * ⛔ A CONTROL IS FOUND BY ITS LABEL, never by where it is on the screen, in the front
8
+ * window of the one program that was named.
9
+ * ⛔ THE SCRIPTS ARE FIXED TEXT. The program, the label and the value reach them as
10
+ * data (environment variables on Windows, arguments on a Mac) and are never joined
11
+ * into the script.
12
+ * ⛔ A PASSWORD FIELD is never read and never filled. The script checks on the machine
13
+ * and refuses, whatever was asked.
14
+ *
15
+ * ⚠️ On a Mac the terminal running the helper needs Accessibility permission (System
16
+ * Settings → Privacy & Security → Accessibility). Without it every action answers
17
+ * `not_permitted`.
18
+ */
19
+ import type { ActionResult, Exec, Platform } from './helper-actions';
20
+ export type UiMode = 'read' | 'set' | 'press';
21
+ export declare const UI_TIMEOUT_MS = 10000;
22
+ export declare const WINDOWS_SCRIPT = "\n$ErrorActionPreference = 'Stop'\n$T = [char]9\ntry {\n Add-Type -AssemblyName UIAutomationClient\n Add-Type -AssemblyName UIAutomationTypes\n $mode = $env:SOLID_UI_MODE\n $prog = $env:SOLID_UI_PROGRAM -replace '\\.exe$', ''\n $ctl = $env:SOLID_UI_CONTROL\n $val = $env:SOLID_UI_VALUE\n $p = Get-Process -Name $prog -ErrorAction SilentlyContinue | Where-Object { $_.MainWindowHandle -ne 0 } | Select-Object -First 1\n if (-not $p) { 'ERR' + $T + 'program_not_running'; exit 0 }\n $AE = [System.Windows.Automation.AutomationElement]\n $Scope = [System.Windows.Automation.TreeScope]::Descendants\n $root = $AE::FromHandle($p.MainWindowHandle)\n $all = $root.FindAll($Scope, [System.Windows.Automation.Condition]::TrueCondition)\n function Kind($e) { return ($e.Current.ControlType.ProgrammaticName -replace '^ControlType\\.', '') }\n function Val($e) {\n if ($e.Current.IsPassword) { return '(hidden)' }\n $o = $null\n if ($e.TryGetCurrentPattern([System.Windows.Automation.ValuePattern]::Pattern, [ref]$o)) { return [string]$o.Current.Value }\n if ($e.TryGetCurrentPattern([System.Windows.Automation.TogglePattern]::Pattern, [ref]$o)) { return [string]$o.Current.ToggleState }\n if ($e.TryGetCurrentPattern([System.Windows.Automation.SelectionPattern]::Pattern, [ref]$o)) {\n $s = $o.Current.GetSelection()\n if ($s.Length -gt 0) { return [string]$s[0].Current.Name }\n }\n return ''\n }\n if ($mode -eq 'read') {\n 'WIN' + $T + ($root.Current.Name -replace '\\s+', ' ')\n $n = 0\n foreach ($e in $all) {\n $k = Kind $e\n if (@('Button', 'Edit', 'ComboBox', 'CheckBox', 'RadioButton', 'TabItem', 'MenuItem', 'List', 'Hyperlink') -notcontains $k) { continue }\n $name = [string]$e.Current.Name\n if (-not $name) { continue }\n 'CTL' + $T + $k + $T + ($name -replace '\\s+', ' ') + $T + ((Val $e) -replace '\\s+', ' ')\n $n++\n if ($n -ge 60) { break }\n }\n exit 0\n }\n if ($mode -eq 'set') {\n foreach ($e in $all) {\n $k = Kind $e\n if (@('Edit', 'ComboBox') -notcontains $k) { continue }\n if ([string]$e.Current.Name -ne $ctl) { continue }\n if ($e.Current.IsPassword) { 'ERR' + $T + 'password_field'; exit 0 }\n $o = $null\n if ($e.TryGetCurrentPattern([System.Windows.Automation.ValuePattern]::Pattern, [ref]$o) -and (-not $o.Current.IsReadOnly)) {\n $o.SetValue($val)\n } elseif ($k -eq 'ComboBox') {\n $x = $null\n if ($e.TryGetCurrentPattern([System.Windows.Automation.ExpandCollapsePattern]::Pattern, [ref]$x)) { $x.Expand() }\n $cond = New-Object System.Windows.Automation.PropertyCondition($AE::NameProperty, $val)\n $item = $e.FindFirst($Scope, $cond)\n if (-not $item) { if ($x) { $x.Collapse() }; 'ERR' + $T + 'value_not_offered'; exit 0 }\n $s = $null\n if ($item.TryGetCurrentPattern([System.Windows.Automation.SelectionItemPattern]::Pattern, [ref]$s)) { $s.Select() }\n if ($x) { $x.Collapse() }\n } else { 'ERR' + $T + 'control_read_only'; exit 0 }\n 'OK' + $T + ((Val $e) -replace '\\s+', ' ')\n exit 0\n }\n 'ERR' + $T + 'control_not_found'\n exit 0\n }\n if ($mode -eq 'press') {\n foreach ($e in $all) {\n $k = Kind $e\n if (@('Button', 'CheckBox', 'RadioButton', 'TabItem', 'MenuItem', 'Hyperlink') -notcontains $k) { continue }\n if ([string]$e.Current.Name -ne $ctl) { continue }\n if (-not $e.Current.IsEnabled) { 'ERR' + $T + 'control_disabled'; exit 0 }\n $o = $null\n if ($e.TryGetCurrentPattern([System.Windows.Automation.InvokePattern]::Pattern, [ref]$o)) { $o.Invoke() }\n elseif ($e.TryGetCurrentPattern([System.Windows.Automation.TogglePattern]::Pattern, [ref]$o)) { $o.Toggle() }\n elseif ($e.TryGetCurrentPattern([System.Windows.Automation.SelectionItemPattern]::Pattern, [ref]$o)) { $o.Select() }\n else { 'ERR' + $T + 'control_cannot_be_pressed'; exit 0 }\n 'OK'\n exit 0\n }\n 'ERR' + $T + 'control_not_found'\n exit 0\n }\n 'ERR' + $T + 'unknown_mode'\n} catch {\n 'ERR' + $T + 'script' + $T + '0'\n}\n";
23
+ export declare const MAC_SCRIPT = "\non labelOf(el)\n tell application \"System Events\"\n set nm to missing value\n try\n set nm to name of el\n end try\n if nm is missing value or nm is \"\" then\n try\n set nm to description of el\n end try\n end if\n if nm is missing value then set nm to \"\"\n return nm as text\n end tell\nend labelOf\n\non valueOf(el)\n tell application \"System Events\"\n set sr to \"\"\n try\n set sr to subrole of el\n end try\n if sr is \"AXSecureTextField\" then return \"(hidden)\"\n set v to \"\"\n try\n set v to (value of el) as text\n end try\n return v\n end tell\nend valueOf\n\non run argv\n set mode to item 1 of argv\n set prog to item 2 of argv\n set ctl to \"\"\n set val to \"\"\n if (count of argv) > 2 then set ctl to item 3 of argv\n if (count of argv) > 3 then set val to item 4 of argv\n try\n tell application \"System Events\"\n if not (exists application process prog) then return \"ERR\" & tab & \"program_not_running\"\n tell application process prog\n if (count of windows) is 0 then return \"ERR\" & tab & \"no_window\"\n set w to window 1\n set wname to \"\"\n try\n set wname to (name of w) as text\n end try\n set els to entire contents of w\n end tell\n if mode is \"read\" then\n set out to \"WIN\" & tab & wname\n set n to 0\n repeat with el in els\n set r to \"\"\n try\n set r to role of el\n end try\n if r is in {\"AXButton\", \"AXTextField\", \"AXTextArea\", \"AXCheckBox\", \"AXRadioButton\", \"AXPopUpButton\", \"AXComboBox\", \"AXMenuButton\"} then\n set nm to my labelOf(el)\n if nm is not \"\" then\n set out to out & linefeed & \"CTL\" & tab & r & tab & nm & tab & my valueOf(el)\n set n to n + 1\n if n is greater than or equal to 60 then exit repeat\n end if\n end if\n end repeat\n return out\n end if\n if mode is \"set\" then\n repeat with el in els\n set r to \"\"\n try\n set r to role of el\n end try\n if r is in {\"AXTextField\", \"AXTextArea\", \"AXComboBox\", \"AXPopUpButton\"} then\n if my labelOf(el) is ctl then\n set sr to \"\"\n try\n set sr to subrole of el\n end try\n if sr is \"AXSecureTextField\" then return \"ERR\" & tab & \"password_field\"\n if r is \"AXPopUpButton\" then\n click el\n delay 0.3\n try\n click menu item val of menu 1 of el\n on error\n key code 53\n return \"ERR\" & tab & \"value_not_offered\"\n end try\n else\n set value of el to val\n end if\n delay 0.2\n return \"OK\" & tab & my valueOf(el)\n end if\n end if\n end repeat\n return \"ERR\" & tab & \"control_not_found\"\n end if\n if mode is \"press\" then\n repeat with el in els\n set r to \"\"\n try\n set r to role of el\n end try\n if r is in {\"AXButton\", \"AXCheckBox\", \"AXRadioButton\", \"AXMenuButton\"} then\n if my labelOf(el) is ctl then\n set canPress to true\n try\n set canPress to enabled of el\n end try\n if canPress is false then return \"ERR\" & tab & \"control_disabled\"\n click el\n return \"OK\"\n end if\n end if\n end repeat\n return \"ERR\" & tab & \"control_not_found\"\n end if\n end tell\n return \"ERR\" & tab & \"unknown_mode\"\n on error errText number errNum\n return \"ERR\" & tab & \"script\" & tab & (errNum as text)\n end try\nend run\n";
24
+ export type UiParsed = {
25
+ error?: string;
26
+ window?: string;
27
+ controls?: string[];
28
+ ok?: boolean;
29
+ value?: string;
30
+ };
31
+ /** PURE. What a script printed → what it means. Anything unreadable is a failure. */
32
+ export declare function uiFrom(stdout: string): UiParsed;
33
+ /** Run one window action. `inputs` have already been checked against the catalog. */
34
+ export declare function runUi(action: string, inputs: Record<string, string>, platform: Platform, exec: Exec): Promise<ActionResult>;
35
+ //# sourceMappingURL=helper-ui.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helper-ui.d.ts","sourceRoot":"","sources":["../../src/lib/helper-ui.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAErE,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,CAAC;AAC9C,eAAO,MAAM,aAAa,QAAQ,CAAC;AAKnC,eAAO,MAAM,cAAc,gjIAwF1B,CAAC;AAGF,eAAO,MAAM,UAAU,48HAgItB,CAAC;AAgBF,MAAM,MAAM,QAAQ,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,EAAE,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9G,qFAAqF;AACrF,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,CAkB/C;AAgBD,qFAAqF;AACrF,wBAAsB,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,YAAY,CAAC,CAejI"}