@notis_ai/cli 0.2.0-beta.156.1 → 0.2.0-beta.157.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/README.md +11 -45
- package/config/notis_app_design_rules.json +135 -0
- package/dist/agent-hooks/notis-agent-hook.mjs +5168 -7271
- package/dist/base-skills/notis-apps/SKILL.md +108 -194
- package/dist/base-skills/notis-cli/SKILL.md +64 -131
- package/package.json +1 -2
- package/skills/notis-apps/cli.md +34 -95
- package/skills/notis-cli/AGENT_INSTRUCTIONS.md +1 -1
- package/src/command-specs/apps.js +322 -1560
- package/src/runtime/agent-browser.js +169 -1
- package/src/runtime/app-boundary-validator.js +221 -0
- package/src/runtime/app-platform.js +359 -233
- package/src/runtime/app-test-server.js +292 -0
- package/template/app/page.tsx +45 -44
- package/template/components/page-heading.tsx +23 -0
- package/template/components/ui/badge.tsx +7 -4
- package/template/components/ui/card.tsx +24 -11
- package/template/components/ui/native-select.tsx +24 -0
- package/template/notis.config.ts +0 -1
- package/template/package.json +2 -2
- package/template/packages/sdk/package.json +1 -2
- package/template/packages/sdk/src/components/MultiSelectActionBar.tsx +20 -7
- package/template/packages/sdk/src/config.ts +0 -2
- package/template/packages/sdk/src/interactions.ts +2 -1
- package/template/packages/sdk/src/styles.css +28 -1
- package/src/runtime/app-dev-build-supervisor.js +0 -47
- package/src/runtime/app-dev-build.js +0 -41
- package/src/runtime/app-dev-consumers.js +0 -154
- package/src/runtime/app-dev-host-lock.js +0 -80
- package/src/runtime/app-dev-process-identity.js +0 -111
- package/src/runtime/app-dev-roots.js +0 -284
- package/src/runtime/app-dev-server.js +0 -1136
- package/src/runtime/app-dev-sessions.js +0 -185
- package/src/runtime/cli-mode.generated.js +0 -5
- package/src/runtime/cli-mode.js +0 -34
|
@@ -28,8 +28,35 @@
|
|
|
28
28
|
@apply mx-auto w-full max-w-[var(--portal-page-max-width)] px-4 py-6 md:px-4 md:py-8;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
/* Flat panel. No border, no shadow: the design bar allows a single hairline
|
|
32
|
+
* between sections and nothing around items. */
|
|
31
33
|
.notis-app-surface {
|
|
32
|
-
@apply rounded-2xl
|
|
34
|
+
@apply rounded-2xl bg-muted text-card-foreground;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* List rows: hover and selection are carried by background tint only. Rows
|
|
38
|
+
* read as tinted panels on mobile and as transparent rows on desktop. */
|
|
39
|
+
.list-row {
|
|
40
|
+
@apply rounded-xl bg-muted px-4 py-3 transition-colors lg:bg-transparent lg:hover:bg-muted/60;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.list-row-selected {
|
|
44
|
+
@apply bg-primary/[0.06] lg:bg-primary/[0.06] lg:hover:bg-primary/[0.06];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/* Split (list + detail) pages are full-bleed: use these instead of
|
|
48
|
+
* .notis-app-shell. The list pane is tinted and carries the one allowed
|
|
49
|
+
* hairline; the detail pane sits on the plain background. */
|
|
50
|
+
.notis-app-split {
|
|
51
|
+
@apply flex h-full min-h-0 w-full max-w-none flex-col lg:flex-row;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.notis-app-pane-list {
|
|
55
|
+
@apply w-full shrink-0 bg-muted/40 lg:w-80 lg:border-r lg:border-border xl:w-96;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.notis-app-pane-detail {
|
|
59
|
+
@apply min-w-0 flex-1 bg-background;
|
|
33
60
|
}
|
|
34
61
|
|
|
35
62
|
.notis-app-section {
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// A separate process retains ownership of the build group if the CLI crashes.
|
|
2
|
-
// IPC disconnect is the lifetime signal; unlike polling a PID it cannot mistake
|
|
3
|
-
// a reused PID for the original owner.
|
|
4
|
-
import { spawn } from 'node:child_process';
|
|
5
|
-
|
|
6
|
-
if (!process.send) throw new Error('Build supervisor requires an IPC owner');
|
|
7
|
-
let build;
|
|
8
|
-
let stopping = false;
|
|
9
|
-
function stop(code = 0) {
|
|
10
|
-
if (stopping) return;
|
|
11
|
-
stopping = true;
|
|
12
|
-
if (!build?.pid) process.exit(code);
|
|
13
|
-
if (process.platform === 'win32') {
|
|
14
|
-
const killer = spawn('taskkill', ['/pid', String(build.pid), '/t', '/f']);
|
|
15
|
-
killer.once('error', () => process.exit(1));
|
|
16
|
-
killer.once('exit', () => process.exit(code));
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const signalGroup = (signal) => {
|
|
20
|
-
try { process.kill(-build.pid, signal); } catch (error) {
|
|
21
|
-
if (error.code !== 'ESRCH') throw error;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
signalGroup('SIGTERM');
|
|
25
|
-
// npm can exit before Vite/esbuild. Keep the supervisor alive until the
|
|
26
|
-
// entire group has received the fallback signal.
|
|
27
|
-
setTimeout(() => {
|
|
28
|
-
signalGroup('SIGKILL');
|
|
29
|
-
process.exit(code);
|
|
30
|
-
}, 1000);
|
|
31
|
-
}
|
|
32
|
-
process.on('disconnect', () => stop());
|
|
33
|
-
process.on('SIGTERM', () => stop());
|
|
34
|
-
process.on('SIGINT', () => stop());
|
|
35
|
-
process.once('message', ({ command, args }) => {
|
|
36
|
-
if (stopping || !process.connected) return;
|
|
37
|
-
build = spawn(command, args, {
|
|
38
|
-
detached: process.platform !== 'win32',
|
|
39
|
-
stdio: 'inherit',
|
|
40
|
-
env: process.env,
|
|
41
|
-
});
|
|
42
|
-
build.once('spawn', () => {
|
|
43
|
-
if (process.connected) process.send({ pid: build.pid }, () => {});
|
|
44
|
-
});
|
|
45
|
-
build.once('error', () => stop(1));
|
|
46
|
-
build.once('exit', (code) => stop(code || 0));
|
|
47
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process';
|
|
2
|
-
import { EventEmitter } from 'node:events';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
|
-
|
|
5
|
-
// Expose the actual npm group identity so Desktop recovery and diagnostics
|
|
6
|
-
// retain their existing ownership contract. The supervisor owns its lifetime.
|
|
7
|
-
export async function startAppDevBuild(cwd, command = 'npm', args = ['run', 'build', '--', '--watch']) {
|
|
8
|
-
const supervisor = spawn(process.execPath, [fileURLToPath(new URL('./app-dev-build-supervisor.js', import.meta.url))], {
|
|
9
|
-
cwd,
|
|
10
|
-
stdio: ['ignore', 'inherit', 'inherit', 'ipc'],
|
|
11
|
-
env: { ...process.env, ELECTRON_RUN_AS_NODE: '1', NOTIS_DEV: '1' },
|
|
12
|
-
});
|
|
13
|
-
const build = new EventEmitter();
|
|
14
|
-
build.pid = null;
|
|
15
|
-
build.exitCode = null;
|
|
16
|
-
build.signalCode = null;
|
|
17
|
-
build.kill = (signal = 'SIGTERM') => supervisor.kill(signal);
|
|
18
|
-
await new Promise((resolve, reject) => {
|
|
19
|
-
supervisor.once('error', reject);
|
|
20
|
-
supervisor.once('exit', (code, signal) => {
|
|
21
|
-
build.exitCode = code;
|
|
22
|
-
build.signalCode = signal;
|
|
23
|
-
reject(new Error(`Build supervisor exited before startup (${code ?? signal})`));
|
|
24
|
-
build.emit('exit', code, signal);
|
|
25
|
-
});
|
|
26
|
-
supervisor.once('message', ({ pid }) => {
|
|
27
|
-
build.pid = pid;
|
|
28
|
-
resolve();
|
|
29
|
-
});
|
|
30
|
-
supervisor.send({ command, args }, (error) => { if (error) reject(error); });
|
|
31
|
-
});
|
|
32
|
-
return build;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export async function stopAppDevBuild(build) {
|
|
36
|
-
if (!build || build.exitCode !== null || build.signalCode !== null) return;
|
|
37
|
-
await new Promise((resolve) => {
|
|
38
|
-
build.once('exit', resolve);
|
|
39
|
-
build.kill('SIGTERM');
|
|
40
|
-
});
|
|
41
|
-
}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import {
|
|
3
|
-
existsSync,
|
|
4
|
-
lstatSync,
|
|
5
|
-
mkdirSync,
|
|
6
|
-
readFileSync,
|
|
7
|
-
renameSync,
|
|
8
|
-
rmSync,
|
|
9
|
-
writeFileSync,
|
|
10
|
-
} from 'node:fs';
|
|
11
|
-
import { homedir } from 'node:os';
|
|
12
|
-
import { dirname, join } from 'node:path';
|
|
13
|
-
|
|
14
|
-
export const DEFAULT_APP_DEV_CONSUMERS_FILE = join(homedir(), '.notis', 'app-dev-consumers.json');
|
|
15
|
-
export const APP_DEV_CONSUMER_EXPIRES_AFTER_MS = 10_000;
|
|
16
|
-
const waitArray = new Int32Array(new SharedArrayBuffer(4));
|
|
17
|
-
const CONSUMER_LOCK_STALE_AFTER_MS = 30_000;
|
|
18
|
-
|
|
19
|
-
function processIsRunning(pid) {
|
|
20
|
-
try {
|
|
21
|
-
process.kill(pid, 0);
|
|
22
|
-
return true;
|
|
23
|
-
} catch (error) {
|
|
24
|
-
return error?.code !== 'ESRCH';
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function reclaimConsumerLock(lockPath) {
|
|
29
|
-
const stat = lstatSync(lockPath);
|
|
30
|
-
if (!stat.isDirectory() || stat.isSymbolicLink()) {
|
|
31
|
-
throw new Error(`Refusing unsafe app development consumer lock: ${lockPath}`);
|
|
32
|
-
}
|
|
33
|
-
let ownerPid = null;
|
|
34
|
-
try {
|
|
35
|
-
const owner = readFileSync(join(lockPath, 'owner'), 'utf8').trim();
|
|
36
|
-
const parsed = Number.parseInt(owner.split('.')[0] || '', 10);
|
|
37
|
-
ownerPid = Number.isSafeInteger(parsed) && parsed > 0 ? parsed : null;
|
|
38
|
-
} catch {
|
|
39
|
-
// An interrupted owner write is reclaimed after the bounded stale window.
|
|
40
|
-
}
|
|
41
|
-
if (ownerPid !== null) return !processIsRunning(ownerPid);
|
|
42
|
-
return Date.now() - stat.mtimeMs >= CONSUMER_LOCK_STALE_AFTER_MS;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function withLock(filePath, callback) {
|
|
46
|
-
mkdirSync(dirname(filePath), { recursive: true, mode: 0o700 });
|
|
47
|
-
const lockPath = `${filePath}.lock`;
|
|
48
|
-
const owner = `${process.pid}.${randomUUID()}`;
|
|
49
|
-
const startedAt = Date.now();
|
|
50
|
-
while (true) {
|
|
51
|
-
try {
|
|
52
|
-
mkdirSync(lockPath, { mode: 0o700 });
|
|
53
|
-
writeFileSync(join(lockPath, 'owner'), owner, { mode: 0o600 });
|
|
54
|
-
break;
|
|
55
|
-
} catch (error) {
|
|
56
|
-
if (error?.code !== 'EEXIST') throw error;
|
|
57
|
-
try {
|
|
58
|
-
if (reclaimConsumerLock(lockPath)) {
|
|
59
|
-
rmSync(lockPath, { recursive: true, force: true });
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
} catch (lockError) {
|
|
63
|
-
if (lockError?.code === 'ENOENT') continue;
|
|
64
|
-
throw lockError;
|
|
65
|
-
}
|
|
66
|
-
if (Date.now() - startedAt > 2_000) {
|
|
67
|
-
throw new Error('App development consumer registry is busy.');
|
|
68
|
-
}
|
|
69
|
-
Atomics.wait(waitArray, 0, 0, 10);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
try {
|
|
73
|
-
return callback();
|
|
74
|
-
} finally {
|
|
75
|
-
try {
|
|
76
|
-
if (readFileSync(join(lockPath, 'owner'), 'utf8').trim() === owner) {
|
|
77
|
-
rmSync(lockPath, { recursive: true, force: true });
|
|
78
|
-
}
|
|
79
|
-
} catch {
|
|
80
|
-
// A replaced lock belongs to another writer.
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function normalize(value, now) {
|
|
86
|
-
const raw = value && typeof value === 'object' && Array.isArray(value.consumers)
|
|
87
|
-
? value.consumers
|
|
88
|
-
: [];
|
|
89
|
-
return raw.filter((lease) => {
|
|
90
|
-
const heartbeat = Date.parse(String(lease?.lastHeartbeatAt || ''));
|
|
91
|
-
return typeof lease?.instanceId === 'string'
|
|
92
|
-
&& typeof lease?.userId === 'string'
|
|
93
|
-
&& typeof lease?.apiBase === 'string'
|
|
94
|
-
&& Number.isSafeInteger(lease?.pid)
|
|
95
|
-
&& Number.isFinite(heartbeat)
|
|
96
|
-
&& now - heartbeat <= APP_DEV_CONSUMER_EXPIRES_AFTER_MS;
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export function readAppDevConsumers(filePath = DEFAULT_APP_DEV_CONSUMERS_FILE, now = Date.now()) {
|
|
101
|
-
if (!existsSync(filePath)) return [];
|
|
102
|
-
try {
|
|
103
|
-
return normalize(JSON.parse(readFileSync(filePath, 'utf8')), now);
|
|
104
|
-
} catch {
|
|
105
|
-
return [];
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function writeAppDevConsumers(filePath, consumers) {
|
|
110
|
-
mkdirSync(dirname(filePath), { recursive: true, mode: 0o700 });
|
|
111
|
-
const temporary = `${filePath}.${process.pid}.${randomUUID()}.tmp`;
|
|
112
|
-
writeFileSync(temporary, JSON.stringify({ version: 1, consumers }, null, 2), { mode: 0o600 });
|
|
113
|
-
renameSync(temporary, filePath);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export function heartbeatAppDevConsumer(
|
|
117
|
-
lease,
|
|
118
|
-
filePath = DEFAULT_APP_DEV_CONSUMERS_FILE,
|
|
119
|
-
) {
|
|
120
|
-
return withLock(filePath, () => {
|
|
121
|
-
const now = Date.now();
|
|
122
|
-
const next = readAppDevConsumers(filePath, now)
|
|
123
|
-
.filter((entry) => entry.instanceId !== lease.instanceId);
|
|
124
|
-
next.push({
|
|
125
|
-
...lease,
|
|
126
|
-
apiBase: lease.apiBase.replace(/\/$/, ''),
|
|
127
|
-
lastHeartbeatAt: new Date(now).toISOString(),
|
|
128
|
-
});
|
|
129
|
-
writeAppDevConsumers(filePath, next);
|
|
130
|
-
return next;
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export function removeAppDevConsumer(
|
|
135
|
-
instanceId,
|
|
136
|
-
filePath = DEFAULT_APP_DEV_CONSUMERS_FILE,
|
|
137
|
-
) {
|
|
138
|
-
return withLock(filePath, () => {
|
|
139
|
-
const next = readAppDevConsumers(filePath)
|
|
140
|
-
.filter((entry) => entry.instanceId !== instanceId);
|
|
141
|
-
writeAppDevConsumers(filePath, next);
|
|
142
|
-
return next;
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export function hasAppDevConsumer(consumers, { mode, userId, apiBase }) {
|
|
147
|
-
if (mode === 'machine') return consumers.length > 0;
|
|
148
|
-
if (mode !== 'environment') return true;
|
|
149
|
-
const normalizedApiBase = String(apiBase || '').replace(/\/$/, '');
|
|
150
|
-
return consumers.some((consumer) => (
|
|
151
|
-
consumer.userId === userId
|
|
152
|
-
&& consumer.apiBase.replace(/\/$/, '') === normalizedApiBase
|
|
153
|
-
));
|
|
154
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
-
import { lstatSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
-
import { homedir } from 'node:os';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
-
|
|
6
|
-
const DEFAULT_LOCK_ROOT = join(homedir(), '.notis', 'app-dev-host-locks');
|
|
7
|
-
const OWNER_FILE = 'owner.json';
|
|
8
|
-
|
|
9
|
-
function processIsRunning(pid) {
|
|
10
|
-
try {
|
|
11
|
-
process.kill(pid, 0);
|
|
12
|
-
return true;
|
|
13
|
-
} catch (error) {
|
|
14
|
-
return error?.code !== 'ESRCH';
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function lockName(identity, apiBase, projectDir) {
|
|
19
|
-
return createHash('sha256').update(`${identity}\0${apiBase}\0${projectDir}`).digest('hex');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function readOwner(path) {
|
|
23
|
-
try {
|
|
24
|
-
const value = JSON.parse(readFileSync(join(path, OWNER_FILE), 'utf8'));
|
|
25
|
-
return Number.isSafeInteger(value?.pid) && typeof value?.ownerId === 'string'
|
|
26
|
-
? { pid: value.pid, ownerId: value.ownerId }
|
|
27
|
-
: null;
|
|
28
|
-
} catch {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function reclaimable(path, now, staleAfterMs) {
|
|
34
|
-
const stat = lstatSync(path);
|
|
35
|
-
if (!stat.isDirectory() || stat.isSymbolicLink()) {
|
|
36
|
-
throw new Error(`Refusing unsafe app development host lock: ${path}`);
|
|
37
|
-
}
|
|
38
|
-
const owner = readOwner(path);
|
|
39
|
-
if (owner) return !processIsRunning(owner.pid);
|
|
40
|
-
return now - stat.mtimeMs >= staleAfterMs;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function tryAcquireAppDevHostLock(options) {
|
|
44
|
-
const lockRoot = options.lockRoot || DEFAULT_LOCK_ROOT;
|
|
45
|
-
mkdirSync(lockRoot, { recursive: true, mode: 0o700 });
|
|
46
|
-
const path = join(lockRoot, lockName(options.identity, options.apiBase, options.projectDir));
|
|
47
|
-
const ownerId = `${process.pid}.${randomUUID()}`;
|
|
48
|
-
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
49
|
-
try {
|
|
50
|
-
mkdirSync(path, { mode: 0o700 });
|
|
51
|
-
try {
|
|
52
|
-
writeFileSync(join(path, OWNER_FILE), JSON.stringify({ pid: process.pid, ownerId }), {
|
|
53
|
-
mode: 0o600,
|
|
54
|
-
});
|
|
55
|
-
} catch (error) {
|
|
56
|
-
rmSync(path, { recursive: true, force: true });
|
|
57
|
-
throw error;
|
|
58
|
-
}
|
|
59
|
-
return { path, ownerId };
|
|
60
|
-
} catch (error) {
|
|
61
|
-
if (error?.code !== 'EEXIST') throw error;
|
|
62
|
-
if (reclaimable(path, options.now ?? Date.now(), options.staleAfterMs ?? 60_000)) {
|
|
63
|
-
rmSync(path, { recursive: true, force: true });
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export function releaseAppDevHostLock(lock) {
|
|
73
|
-
try {
|
|
74
|
-
if (readOwner(lock.path)?.ownerId === lock.ownerId) {
|
|
75
|
-
rmSync(lock.path, { recursive: true, force: true });
|
|
76
|
-
}
|
|
77
|
-
} catch {
|
|
78
|
-
// A replaced lock belongs to another process.
|
|
79
|
-
}
|
|
80
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { execFileSync } from 'node:child_process';
|
|
2
|
-
import { readlinkSync, realpathSync } from 'node:fs';
|
|
3
|
-
|
|
4
|
-
export const NOTIS_APP_BUILD_COMMAND_FINGERPRINT = 'npm:run-build:watch:v1';
|
|
5
|
-
export const NOTIS_APPS_DEV_HOST_COMMAND_FINGERPRINT = 'notis:apps-dev:v1';
|
|
6
|
-
|
|
7
|
-
function normalizePath(value) {
|
|
8
|
-
if (typeof value !== 'string' || !value.trim()) return null;
|
|
9
|
-
try {
|
|
10
|
-
return realpathSync(value.trim());
|
|
11
|
-
} catch {
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function isExpectedNotisBuildCommand(command) {
|
|
17
|
-
if (typeof command !== 'string') return false;
|
|
18
|
-
return /(?:^|[/\s])npm(?:\s|$)/.test(command)
|
|
19
|
-
&& /\brun\s+build\b/.test(command)
|
|
20
|
-
&& /(?:^|\s)--watch(?:\s|$)/.test(command);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function isExpectedNotisAppsDevHostCommand(command) {
|
|
24
|
-
return typeof command === 'string'
|
|
25
|
-
&& /(?:notis(?:\.js)?|@notis_ai[/\\]cli)/.test(command)
|
|
26
|
-
&& /\bapps\s+dev\b/.test(command);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function readDarwinProcessCwd(pid, execute) {
|
|
30
|
-
const output = execute('lsof', ['-a', '-p', String(pid), '-d', 'cwd', '-Fn'], {
|
|
31
|
-
encoding: 'utf8',
|
|
32
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
33
|
-
});
|
|
34
|
-
const line = output.split('\n').find((entry) => entry.startsWith('n'));
|
|
35
|
-
return line ? line.slice(1) : null;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function inspectAppDevWatcherProcess(pid, {
|
|
39
|
-
platform = process.platform,
|
|
40
|
-
execute = execFileSync,
|
|
41
|
-
readLink = readlinkSync,
|
|
42
|
-
} = {}) {
|
|
43
|
-
if (!Number.isSafeInteger(pid) || pid <= 0 || platform === 'win32') return null;
|
|
44
|
-
try {
|
|
45
|
-
const ps = (field) => execute('ps', ['-o', `${field}=`, '-p', String(pid)], {
|
|
46
|
-
encoding: 'utf8',
|
|
47
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
48
|
-
}).trim();
|
|
49
|
-
const processGroupPid = Number.parseInt(ps('pgid'), 10);
|
|
50
|
-
const startIdentity = ps('lstart').replace(/\s+/g, ' ').trim();
|
|
51
|
-
const command = ps('command');
|
|
52
|
-
const cwd = platform === 'linux'
|
|
53
|
-
? readLink(`/proc/${pid}/cwd`)
|
|
54
|
-
: readDarwinProcessCwd(pid, execute);
|
|
55
|
-
const projectDir = normalizePath(cwd);
|
|
56
|
-
if (!Number.isSafeInteger(processGroupPid) || processGroupPid <= 0) return null;
|
|
57
|
-
if (!startIdentity || !command || !projectDir) return null;
|
|
58
|
-
return { pid, processGroupPid, startIdentity, command, projectDir };
|
|
59
|
-
} catch {
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function captureDesktopWatcherOwnership({
|
|
65
|
-
pid,
|
|
66
|
-
projectDir,
|
|
67
|
-
desktopOwnerId,
|
|
68
|
-
desktopOwnerScope,
|
|
69
|
-
inspect = inspectAppDevWatcherProcess,
|
|
70
|
-
} = {}) {
|
|
71
|
-
const owner = typeof desktopOwnerId === 'string' ? desktopOwnerId.trim() : '';
|
|
72
|
-
const ownerScope = typeof desktopOwnerScope === 'string' ? desktopOwnerScope.trim() : '';
|
|
73
|
-
const expectedProjectDir = normalizePath(projectDir);
|
|
74
|
-
if (!owner || !ownerScope || !expectedProjectDir) return null;
|
|
75
|
-
const identity = inspect(pid);
|
|
76
|
-
if (
|
|
77
|
-
!identity
|
|
78
|
-
|| identity.processGroupPid !== pid
|
|
79
|
-
|| identity.projectDir !== expectedProjectDir
|
|
80
|
-
|| !isExpectedNotisBuildCommand(identity.command)
|
|
81
|
-
) {
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
return {
|
|
85
|
-
desktopOwnerId: owner,
|
|
86
|
-
desktopOwnerScope: ownerScope,
|
|
87
|
-
watcherProcessGroupPid: identity.processGroupPid,
|
|
88
|
-
watcherStartIdentity: identity.startIdentity,
|
|
89
|
-
watcherProjectDir: identity.projectDir,
|
|
90
|
-
watcherCommandFingerprint: NOTIS_APP_BUILD_COMMAND_FINGERPRINT,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export function captureDesktopHostOwnership({
|
|
95
|
-
pid = process.pid,
|
|
96
|
-
desktopOwnerId,
|
|
97
|
-
desktopOwnerScope,
|
|
98
|
-
inspect = inspectAppDevWatcherProcess,
|
|
99
|
-
} = {}) {
|
|
100
|
-
const owner = typeof desktopOwnerId === 'string' ? desktopOwnerId.trim() : '';
|
|
101
|
-
const ownerScope = typeof desktopOwnerScope === 'string' ? desktopOwnerScope.trim() : '';
|
|
102
|
-
if (!owner || !ownerScope) return null;
|
|
103
|
-
const identity = inspect(pid);
|
|
104
|
-
if (!identity || !isExpectedNotisAppsDevHostCommand(identity.command)) return null;
|
|
105
|
-
return {
|
|
106
|
-
desktopOwnerId: owner,
|
|
107
|
-
desktopOwnerScope: ownerScope,
|
|
108
|
-
desktopHostStartIdentity: identity.startIdentity,
|
|
109
|
-
desktopHostCommandFingerprint: NOTIS_APPS_DEV_HOST_COMMAND_FINGERPRINT,
|
|
110
|
-
};
|
|
111
|
-
}
|