@notis_ai/cli 0.2.0-beta.178.1 → 0.2.0-beta.1792022492092.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 +548 -98
- package/config/portal-route-roots.json +47 -0
- package/dist/agent-hooks/notis-agent-hook.mjs +32901 -5934
- package/dist/base-skills/notis-apps/SKILL.md +76 -51
- package/dist/base-skills/notis-apps/references/architecture.md +116 -164
- package/dist/base-skills/notis-apps/references/design.md +26 -107
- package/dist/base-skills/notis-apps/references/memory.md +58 -0
- package/dist/base-skills/notis-apps/references/reading.md +52 -74
- package/dist/base-skills/notis-apps/references/release.md +105 -96
- package/dist/base-skills/notis-apps/references/sdk.md +115 -60
- package/dist/base-skills/notis-apps/references/troubleshooting.md +22 -21
- package/dist/base-skills/notis-apps/references/views.md +145 -0
- package/dist/base-skills/notis-cli/SKILL.md +29 -12
- package/dist/base-skills/notis-cli/references/app-delivery.md +12 -11
- package/dist/base-skills/notis-cli/references/intelligence.md +94 -0
- package/dist/base-skills/notis-cli/references/native-databases.md +6 -5
- package/dist/base-skills/notis-cli/references/tool-examples.md +4 -4
- package/dist/base-skills/notis-query/SKILL.md +34 -60
- package/dist/base-skills/notis-query/references/database-discovery.md +60 -59
- package/dist/base-skills/notis-query/references/documents.md +53 -39
- package/dist/base-skills/notis-query/references/query.md +57 -524
- package/dist/sdk/src/bundleModule.ts +79 -0
- package/dist/sdk/src/components/DocumentEditor.tsx +6 -3
- package/dist/sdk/src/components/DocumentPage.tsx +144 -0
- package/dist/sdk/src/components/RecordComponents.tsx +33 -0
- package/dist/sdk/src/components/RenderChartData.tsx +19 -0
- package/dist/sdk/src/config.ts +4 -26
- package/dist/sdk/src/documents.ts +2 -0
- package/dist/sdk/src/hooks/useAction.ts +28 -0
- package/dist/sdk/src/hooks/useBackend.ts +3 -2
- package/dist/sdk/src/hooks/useCloudComputer.ts +35 -4
- package/dist/sdk/src/hooks/useCloudComputerShell.ts +114 -0
- package/dist/sdk/src/hooks/useCollectionInteractions.ts +4 -2
- package/dist/sdk/src/hooks/useHandover.ts +7 -7
- package/dist/sdk/src/hooks/useNativeDocumentBody.ts +50 -0
- package/dist/sdk/src/hooks/useNativeDocuments.ts +83 -0
- package/dist/sdk/src/hooks/useNotis.ts +3 -0
- package/dist/sdk/src/hooks/useNotisNavigation.ts +26 -11
- package/dist/sdk/src/hooks/useQuery.ts +7 -4
- package/dist/sdk/src/hooks/useViewParams.ts +121 -0
- package/dist/sdk/src/hooks/useViewerReads.ts +129 -0
- package/dist/sdk/src/index.ts +36 -0
- package/dist/sdk/src/interactions/shortcuts.tsx +42 -5
- package/dist/sdk/src/nativeData.ts +39 -0
- package/dist/sdk/src/presentation.tsx +82 -0
- package/dist/sdk/src/provider.tsx +9 -4
- package/dist/sdk/src/queryCache.ts +5 -3
- package/dist/sdk/src/queryErrors.ts +51 -0
- package/dist/sdk/src/runtime.ts +163 -13
- package/dist/sdk/src/space.ts +425 -0
- package/dist/sdk/src/styles.css +96 -72
- package/dist/sdk/src/vite.ts +11 -1
- package/dist/skill-sync/index.js +571 -80
- package/dist/skill-sync/index.js.map +4 -4
- package/dist/skill-sync-worker.mjs +858 -233
- package/dist/space-harness/host.js +66 -0
- package/dist/view-renderer/dist/host.css +1 -0
- package/dist/view-renderer/dist/host.js +1028 -0
- package/dist/view-renderer/dist/theme.css +73 -0
- package/dist/view-renderer/src/dom.js +180 -0
- package/dist/view-renderer/src/errors.js +8 -0
- package/dist/view-renderer/src/host.tsx +175 -0
- package/dist/view-renderer/src/index.js +4 -0
- package/dist/view-renderer/src/pool.js +76 -0
- package/dist/view-renderer/src/remote-broker.js +59 -0
- package/dist/view-renderer/src/renderer.js +201 -0
- package/package.json +16 -5
- package/skills/notis-apps/cli.md +323 -163
- package/skills/notis-cli/AGENT_INSTRUCTIONS.md +3 -3
- package/skills/notis-onboarding/BRIEF.md +7 -3
- package/src/command-specs/apps.js +2 -1
- package/src/command-specs/auth.js +2 -2
- package/src/command-specs/files.js +29 -0
- package/src/command-specs/handover.js +331 -79
- package/src/command-specs/helpers.js +2 -0
- package/src/command-specs/index.js +11 -5
- package/src/command-specs/profile.js +42 -1
- package/src/command-specs/skills.js +242 -1
- package/src/command-specs/spaces.js +645 -0
- package/src/command-specs/tools.js +0 -6
- package/src/command-specs/views.js +69 -0
- package/src/runtime/agent-browser.js +92 -29
- package/src/runtime/app-boundary-validator.js +7 -4
- package/src/runtime/app-data-literals.js +82 -0
- package/src/runtime/app-platform.js +321 -253
- package/src/runtime/computer-identity.d.ts +30 -0
- package/src/runtime/computer-identity.js +151 -0
- package/src/runtime/config-lock.js +135 -0
- package/src/runtime/confined-space-build.js +74 -0
- package/src/runtime/confined-space-verify.js +49 -0
- package/src/runtime/delegated-context.js +5 -21
- package/src/runtime/native-record-files.js +47 -0
- package/src/runtime/oauth.js +18 -1
- package/src/runtime/profiles.js +5 -107
- package/src/runtime/retired-sdk-files.js +20 -0
- package/src/runtime/screenshot-framing.js +85 -0
- package/src/runtime/skill-sync/cloud-client.ts +26 -4
- package/src/runtime/skill-sync/index.ts +230 -35
- package/src/runtime/skill-sync/local-scanner.ts +188 -29
- package/src/runtime/skill-sync/native-identity.ts +102 -0
- package/src/runtime/skill-sync/native-plan.ts +70 -0
- package/src/runtime/skill-sync/sync-plan.ts +16 -9
- package/src/runtime/skill-sync/types.ts +32 -6
- package/src/runtime/source-root.js +32 -0
- package/src/runtime/space-collection-scaffold.js +66 -0
- package/src/runtime/space-database-structures.js +229 -0
- package/src/runtime/space-fixture-broker.js +50 -0
- package/src/runtime/space-lock.js +337 -0
- package/src/runtime/space-platform.js +105 -0
- package/src/runtime/space-source.js +281 -0
- package/src/runtime/space-test-server.js +327 -0
- package/src/runtime/space-verification.js +89 -0
- package/src/runtime/space-verify-browser-worker.js +51 -0
- package/src/runtime/space-view-manifest.js +254 -0
- package/src/runtime/store-screenshot.js +10 -7
- package/src/runtime/sync-skills.d.ts +3 -1
- package/src/runtime/sync-skills.js +10 -2
- package/src/runtime/transport.js +8 -6
- package/src/runtime/view-render.js +49 -0
- package/src/skill-sync-worker.js +14 -2
- package/src/space-harness-host.ts +103 -0
- package/template/.harness/index.html.tmpl +7 -10
- package/template/app/globals.css +1 -0
- package/src/command-specs/reports.js +0 -97
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface ComputerIdentity {
|
|
2
|
+
/** Stable UUID v4 for this computer, shared by every account on it. */
|
|
3
|
+
computerId: string;
|
|
4
|
+
/** The name the user chose, or null to use the computer's own name. */
|
|
5
|
+
name: string | null;
|
|
6
|
+
/** The computer's own name (macOS Computer Name, else the host name). */
|
|
7
|
+
defaultName: string;
|
|
8
|
+
/** `name ?? defaultName`, what the server and the user see. */
|
|
9
|
+
displayName: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ComputerIdentityOptions {
|
|
13
|
+
/** The CLI config file computer.json sits next to. Defaults to NOTIS_CLI_CONFIG_FILE or ~/.notis/config.json. */
|
|
14
|
+
configFile?: string;
|
|
15
|
+
platform?: NodeJS.Platform;
|
|
16
|
+
hostname?: () => string;
|
|
17
|
+
readMacComputerName?: () => string | null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const COMPUTER_IDENTITY_VERSION: number;
|
|
21
|
+
export const COMPUTER_NAME_MAX_LENGTH: number;
|
|
22
|
+
|
|
23
|
+
export function computerIdentityFile(configFile?: string): string;
|
|
24
|
+
export function normalizeComputerName(value: unknown): string | null;
|
|
25
|
+
export function defaultComputerName(options?: ComputerIdentityOptions): string;
|
|
26
|
+
export function readComputerIdentity(options?: ComputerIdentityOptions): ComputerIdentity;
|
|
27
|
+
export function setComputerName(
|
|
28
|
+
name: string | null,
|
|
29
|
+
options?: ComputerIdentityOptions,
|
|
30
|
+
): ComputerIdentity;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { execFileSync } from 'node:child_process';
|
|
3
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { hostname as osHostname } from 'node:os';
|
|
5
|
+
import { dirname, join } from 'node:path';
|
|
6
|
+
import { resolveCliConfigFile, withConfigFileWriteLock } from './config-lock.js';
|
|
7
|
+
|
|
8
|
+
// This computer's identity, shared by the CLI and Desktop: one stable id per
|
|
9
|
+
// computer (the server keeps one CLI sign-in and one local shell connection per
|
|
10
|
+
// computer) and the name the user sees for it. It lives next to the CLI config
|
|
11
|
+
// file, so NOTIS_CLI_CONFIG_FILE moves it too, and is written under the same
|
|
12
|
+
// lock as the config.
|
|
13
|
+
export const COMPUTER_IDENTITY_VERSION = 1;
|
|
14
|
+
export const COMPUTER_NAME_MAX_LENGTH = 64;
|
|
15
|
+
const COMPUTER_ID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
16
|
+
const FALLBACK_COMPUTER_NAME = 'Computer';
|
|
17
|
+
|
|
18
|
+
export function computerIdentityFile(configFile = resolveCliConfigFile()) {
|
|
19
|
+
return join(dirname(configFile), 'computer.json');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Trim, collapse whitespace and cap at 64 characters. Returns null for a name
|
|
24
|
+
* that is empty after cleanup, which means "use the computer's own name".
|
|
25
|
+
*/
|
|
26
|
+
export function normalizeComputerName(value) {
|
|
27
|
+
if (typeof value !== 'string') return null;
|
|
28
|
+
const collapsed = value.replace(/\s+/gu, ' ').trim();
|
|
29
|
+
if (!collapsed) return null;
|
|
30
|
+
// Count code points so a cut never splits a character in two.
|
|
31
|
+
const characters = Array.from(collapsed);
|
|
32
|
+
if (characters.length <= COMPUTER_NAME_MAX_LENGTH) return collapsed;
|
|
33
|
+
return characters.slice(0, COMPUTER_NAME_MAX_LENGTH).join('').trim();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function readMacComputerName() {
|
|
37
|
+
try {
|
|
38
|
+
return execFileSync('/usr/sbin/scutil', ['--get', 'ComputerName'], {
|
|
39
|
+
encoding: 'utf8',
|
|
40
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
41
|
+
timeout: 2_000,
|
|
42
|
+
});
|
|
43
|
+
} catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The computer's own name: the macOS Computer Name, else the host name without
|
|
50
|
+
* a trailing `.local`.
|
|
51
|
+
*/
|
|
52
|
+
export function defaultComputerName(options = {}) {
|
|
53
|
+
const platform = options.platform ?? process.platform;
|
|
54
|
+
if (platform === 'darwin') {
|
|
55
|
+
const macName = normalizeComputerName((options.readMacComputerName ?? readMacComputerName)());
|
|
56
|
+
if (macName) return macName;
|
|
57
|
+
}
|
|
58
|
+
let host = '';
|
|
59
|
+
try {
|
|
60
|
+
host = String((options.hostname ?? osHostname)() || '');
|
|
61
|
+
} catch {
|
|
62
|
+
host = '';
|
|
63
|
+
}
|
|
64
|
+
return normalizeComputerName(host.replace(/\.local\.?$/iu, '')) || FALLBACK_COMPUTER_NAME;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function parseIdentityFile(file) {
|
|
68
|
+
let raw;
|
|
69
|
+
try {
|
|
70
|
+
raw = JSON.parse(readFileSync(file, 'utf8'));
|
|
71
|
+
} catch {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null;
|
|
75
|
+
return raw;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function validStored(raw) {
|
|
79
|
+
if (!raw || raw.version !== COMPUTER_IDENTITY_VERSION) return null;
|
|
80
|
+
if (typeof raw.computer_id !== 'string' || !COMPUTER_ID_PATTERN.test(raw.computer_id)) return null;
|
|
81
|
+
return {
|
|
82
|
+
computerId: raw.computer_id.toLowerCase(),
|
|
83
|
+
name: normalizeComputerName(raw.name),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function writeIdentityFile(file, stored) {
|
|
88
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
89
|
+
const contents = {
|
|
90
|
+
version: COMPUTER_IDENTITY_VERSION,
|
|
91
|
+
computer_id: stored.computerId,
|
|
92
|
+
...(stored.name ? { name: stored.name } : {}),
|
|
93
|
+
};
|
|
94
|
+
const temporaryFile = `${file}.${process.pid}.${Date.now()}.tmp`;
|
|
95
|
+
writeFileSync(temporaryFile, `${JSON.stringify(contents, null, 2)}\n`, { mode: 0o600 });
|
|
96
|
+
renameSync(temporaryFile, file);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function withIdentity(stored, options) {
|
|
100
|
+
const defaultName = defaultComputerName(options);
|
|
101
|
+
return {
|
|
102
|
+
computerId: stored.computerId,
|
|
103
|
+
name: stored.name,
|
|
104
|
+
defaultName,
|
|
105
|
+
displayName: stored.name ?? defaultName,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Under the config lock: re-read so two first reads agree on one id, then
|
|
110
|
+
// create (or repair) the file only when it holds no valid identity.
|
|
111
|
+
function readOrCreateLocked(configFile, file) {
|
|
112
|
+
const raw = parseIdentityFile(file);
|
|
113
|
+
const existing = validStored(raw);
|
|
114
|
+
if (existing) return existing;
|
|
115
|
+
const created = {
|
|
116
|
+
computerId: randomUUID(),
|
|
117
|
+
// A file with a broken id keeps the name the user chose.
|
|
118
|
+
name: normalizeComputerName(raw?.name),
|
|
119
|
+
};
|
|
120
|
+
writeIdentityFile(file, created);
|
|
121
|
+
return created;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Read this computer's identity, creating `computer.json` on first read.
|
|
126
|
+
*/
|
|
127
|
+
export function readComputerIdentity(options = {}) {
|
|
128
|
+
const configFile = options.configFile ?? resolveCliConfigFile();
|
|
129
|
+
const file = computerIdentityFile(configFile);
|
|
130
|
+
const stored = validStored(parseIdentityFile(file))
|
|
131
|
+
?? withConfigFileWriteLock(configFile, () => readOrCreateLocked(configFile, file));
|
|
132
|
+
return withIdentity(stored, options);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Rename this computer for every account on it. An empty name goes back to the
|
|
137
|
+
* computer's own name.
|
|
138
|
+
*/
|
|
139
|
+
export function setComputerName(name, options = {}) {
|
|
140
|
+
const configFile = options.configFile ?? resolveCliConfigFile();
|
|
141
|
+
const file = computerIdentityFile(configFile);
|
|
142
|
+
const stored = withConfigFileWriteLock(configFile, () => {
|
|
143
|
+
const current = readOrCreateLocked(configFile, file);
|
|
144
|
+
const next = { computerId: current.computerId, name: normalizeComputerName(name) };
|
|
145
|
+
if (next.name !== current.name) {
|
|
146
|
+
writeIdentityFile(file, next);
|
|
147
|
+
}
|
|
148
|
+
return next;
|
|
149
|
+
});
|
|
150
|
+
return withIdentity(stored, options);
|
|
151
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import {
|
|
3
|
+
existsSync,
|
|
4
|
+
mkdirSync,
|
|
5
|
+
readFileSync,
|
|
6
|
+
renameSync,
|
|
7
|
+
rmSync,
|
|
8
|
+
statSync,
|
|
9
|
+
writeFileSync,
|
|
10
|
+
} from 'node:fs';
|
|
11
|
+
import { homedir } from 'node:os';
|
|
12
|
+
import { dirname, join, resolve } from 'node:path';
|
|
13
|
+
|
|
14
|
+
// Cross-process write lock over ~/.notis/config.json. Independent `notis`
|
|
15
|
+
// processes (a `login` in one terminal and a `tools exec` in another) and
|
|
16
|
+
// Desktop all rewrite the files in this directory, so the lock directory name
|
|
17
|
+
// and these three timings are the whole coordination protocol. Desktop keeps a
|
|
18
|
+
// TypeScript copy in electron/src/notis-config-file.ts. Guarded by the
|
|
19
|
+
// concurrency test in packages/cli/test/runtime-auth.test.js.
|
|
20
|
+
const CONFIG_WRITE_LOCK_TIMEOUT_MS = 5_000;
|
|
21
|
+
const CONFIG_WRITE_LOCK_STALE_MS = 2_000;
|
|
22
|
+
const CONFIG_WRITE_LOCK_POLL_MS = 10;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The shared CLI config file. NOTIS_CLI_CONFIG_FILE moves it (and every file
|
|
26
|
+
* kept next to it, such as computer.json) for tests and isolated runtimes.
|
|
27
|
+
*/
|
|
28
|
+
export function resolveCliConfigFile() {
|
|
29
|
+
const envConfigFile = process.env.NOTIS_CLI_CONFIG_FILE;
|
|
30
|
+
if (envConfigFile) {
|
|
31
|
+
return resolve(envConfigFile);
|
|
32
|
+
}
|
|
33
|
+
return join(homedir(), '.notis', 'config.json');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// The lock records who holds it and when they took it. Reclaiming a stale lock
|
|
37
|
+
// by mtime alone is not safe: the reclaimer cannot tell an abandoned lock from
|
|
38
|
+
// one it is about to steal from a live writer, and the victim's own release
|
|
39
|
+
// would then delete the thief's lock and admit a third writer. Both sides are
|
|
40
|
+
// on the same host, so the stored timestamp and Date.now() share a clock.
|
|
41
|
+
function readLockOwner(lockDirectory) {
|
|
42
|
+
try {
|
|
43
|
+
return JSON.parse(readFileSync(join(lockDirectory, 'owner'), 'utf-8'));
|
|
44
|
+
} catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function lockDirectoryMtime(lockDirectory) {
|
|
50
|
+
try {
|
|
51
|
+
return statSync(lockDirectory).mtimeMs;
|
|
52
|
+
} catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function publishConfigWriteLock(lockDirectory, ownerId) {
|
|
58
|
+
const candidateDirectory = `${lockDirectory}.candidate-${ownerId}`;
|
|
59
|
+
try {
|
|
60
|
+
mkdirSync(candidateDirectory);
|
|
61
|
+
writeFileSync(
|
|
62
|
+
join(candidateDirectory, 'owner'),
|
|
63
|
+
JSON.stringify({ id: ownerId, at: Date.now() }),
|
|
64
|
+
{ mode: 0o600 },
|
|
65
|
+
);
|
|
66
|
+
try {
|
|
67
|
+
renameSync(candidateDirectory, lockDirectory);
|
|
68
|
+
return true;
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (!existsSync(lockDirectory)) throw error;
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
} finally {
|
|
74
|
+
rmSync(candidateDirectory, { recursive: true, force: true });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Run `callback(configFile)` while holding `<configFile>.write-lock`.
|
|
80
|
+
*/
|
|
81
|
+
export function withConfigFileWriteLock(configFile, callback) {
|
|
82
|
+
const lockDirectory = `${configFile}.write-lock`;
|
|
83
|
+
const ownerId = `${process.pid}.${randomUUID()}`;
|
|
84
|
+
const deadline = Date.now() + CONFIG_WRITE_LOCK_TIMEOUT_MS;
|
|
85
|
+
mkdirSync(dirname(configFile), { recursive: true });
|
|
86
|
+
for (;;) {
|
|
87
|
+
if (!existsSync(lockDirectory) && publishConfigWriteLock(lockDirectory, ownerId)) {
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const owner = readLockOwner(lockDirectory);
|
|
92
|
+
const observedMtime = lockDirectoryMtime(lockDirectory);
|
|
93
|
+
const ownerIsStale =
|
|
94
|
+
owner?.id && Date.now() - Number(owner.at) > CONFIG_WRITE_LOCK_STALE_MS;
|
|
95
|
+
const ownerlessIsStale =
|
|
96
|
+
!owner
|
|
97
|
+
&& observedMtime !== null
|
|
98
|
+
&& Date.now() - observedMtime > CONFIG_WRITE_LOCK_STALE_MS;
|
|
99
|
+
if (ownerIsStale || ownerlessIsStale) {
|
|
100
|
+
try {
|
|
101
|
+
const currentOwner = readLockOwner(lockDirectory);
|
|
102
|
+
const ownerUnchanged = owner?.id
|
|
103
|
+
? currentOwner?.id === owner.id
|
|
104
|
+
: !currentOwner && lockDirectoryMtime(lockDirectory) === observedMtime;
|
|
105
|
+
if (ownerUnchanged) {
|
|
106
|
+
rmSync(lockDirectory, { recursive: true, force: true });
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
} catch {
|
|
110
|
+
// Losing the reclaim race is normal; fall through and keep waiting.
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (Date.now() >= deadline) {
|
|
114
|
+
throw new Error(`Timed out waiting to update ${configFile}`);
|
|
115
|
+
}
|
|
116
|
+
Atomics.wait(
|
|
117
|
+
new Int32Array(new SharedArrayBuffer(4)),
|
|
118
|
+
0,
|
|
119
|
+
0,
|
|
120
|
+
CONFIG_WRITE_LOCK_POLL_MS,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
return callback(configFile);
|
|
125
|
+
} finally {
|
|
126
|
+
try {
|
|
127
|
+
// Never release a lock that was reclaimed from us while we worked.
|
|
128
|
+
if (readLockOwner(lockDirectory)?.id === ownerId) {
|
|
129
|
+
rmSync(lockDirectory, { recursive: true, force: true });
|
|
130
|
+
}
|
|
131
|
+
} catch {
|
|
132
|
+
// The lock may already have been removed after an interrupted write.
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pinned first build of one Space for a confined local effect
|
|
3
|
+
* (server/lib/confined_effects/space_build.py).
|
|
4
|
+
*
|
|
5
|
+
* node confined-space-build.js <build-request.json>
|
|
6
|
+
*
|
|
7
|
+
* The backend starts this file from a hashed, read-only toolchain under the macOS
|
|
8
|
+
* sandbox (no network). It reuses the canonical selected-source freeze, manifest,
|
|
9
|
+
* V4 checks and build receipt (buildSpaceArtifact) and replaces only the build
|
|
10
|
+
* runner: the canonical Vite command runs with this same node executable and a
|
|
11
|
+
* rebuilt environment, never PATH npm, a package script or the caller's
|
|
12
|
+
* environment. It never refreshes the SDK or installs anything.
|
|
13
|
+
*/
|
|
14
|
+
import { spawn } from 'node:child_process';
|
|
15
|
+
import { readFileSync, realpathSync } from 'node:fs';
|
|
16
|
+
import { dirname, join } from 'node:path';
|
|
17
|
+
import { pathToFileURL } from 'node:url';
|
|
18
|
+
import { buildSpaceArtifact } from './space-platform.js';
|
|
19
|
+
|
|
20
|
+
const CANONICAL_BUILD_SCRIPTS = new Set(['vite build', 'vite build --configLoader runner']);
|
|
21
|
+
const OUTPUT_LIMIT = 32 * 1024;
|
|
22
|
+
|
|
23
|
+
export function pinnedBuildEnvironment(environment = process.env) {
|
|
24
|
+
return { PATH: [dirname(process.execPath), '/usr/bin', '/bin'].join(':'), HOME: environment.HOME || '',
|
|
25
|
+
TMPDIR: environment.TMPDIR || '', LANG: 'C', LC_ALL: 'C', NODE_ENV: 'production' };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function pinnedViteCommand(projectDir, executable = process.execPath) {
|
|
29
|
+
const pkg = JSON.parse(readFileSync(join(projectDir, 'package.json'), 'utf8'));
|
|
30
|
+
const script = String(pkg.scripts?.build || '').trim();
|
|
31
|
+
if (!CANONICAL_BUILD_SCRIPTS.has(script)) throw new Error('Only the canonical vite build script can run in a confined build.');
|
|
32
|
+
const vite = realpathSync(join(projectDir, 'node_modules', 'vite', 'bin', 'vite.js'));
|
|
33
|
+
return [executable, vite, 'build', '--configLoader', 'runner'];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** buildArtifact runBuild seam: the canonical build, pinned, with bounded captured output. */
|
|
37
|
+
export function runPinnedVite({ projectDir }) {
|
|
38
|
+
const [command, ...args] = pinnedViteCommand(projectDir);
|
|
39
|
+
return new Promise((resolvePromise, rejectPromise) => {
|
|
40
|
+
const child = spawn(command, args, { cwd: projectDir, env: pinnedBuildEnvironment(), stdio: ['ignore', 'pipe', 'pipe'] });
|
|
41
|
+
let output = '';
|
|
42
|
+
for (const stream of [child.stdout, child.stderr]) {
|
|
43
|
+
stream.on('data', chunk => { if (output.length < OUTPUT_LIMIT) output += chunk.toString().slice(0, OUTPUT_LIMIT - output.length); });
|
|
44
|
+
}
|
|
45
|
+
child.on('error', rejectPromise);
|
|
46
|
+
child.on('exit', (code, signal) => {
|
|
47
|
+
if (code === 0) resolvePromise();
|
|
48
|
+
else rejectPromise(new Error(`vite build failed (${signal || code})${output.trim() ? `:\n${output.trim()}` : ''}`));
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export async function runConfinedBuild(request) {
|
|
54
|
+
if (!request || typeof request.projectDir !== 'string' || typeof request.key !== 'string') {
|
|
55
|
+
throw new Error('The build request names one workspace and one Space key.');
|
|
56
|
+
}
|
|
57
|
+
const result = await buildSpaceArtifact(request.projectDir, request.key, { stdio: 'pipe', refreshSdk: false, runBuild: runPinnedVite });
|
|
58
|
+
// A summary only: the backend grades the saved build receipt bytes, not this line.
|
|
59
|
+
const { local_key, kind, name, spec_version } = result.manifest || {};
|
|
60
|
+
return { status: 'built', key: request.key, receipt_path: result.receiptPath, source_hash: result.sourceHash,
|
|
61
|
+
manifest: { local_key, kind, name, spec_version } };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function main(argv) {
|
|
65
|
+
const request = JSON.parse(readFileSync(argv[2], 'utf8'));
|
|
66
|
+
try {
|
|
67
|
+
process.stdout.write(JSON.stringify(await runConfinedBuild(request)) + '\n');
|
|
68
|
+
} catch (error) {
|
|
69
|
+
process.stdout.write(JSON.stringify({ status: 'failed', error: String(error?.message || error).slice(0, OUTPUT_LIMIT) }) + '\n');
|
|
70
|
+
process.exitCode = 1;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) await main(process.argv);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credential-free canonical verification of one accepted confined build
|
|
3
|
+
* (server/lib/confined_effects/space_build.py).
|
|
4
|
+
*
|
|
5
|
+
* node confined-space-verify.js <verify-request.json>
|
|
6
|
+
*
|
|
7
|
+
* Runs outside the build sandbox so Chromium keeps its own sandbox
|
|
8
|
+
* (chromiumSandbox: true in the shared renderer pool). The request carries the
|
|
9
|
+
* capabilities returned by backend source verification and the accepted build's
|
|
10
|
+
* exact source and artifact digests; anything else refuses before rendering.
|
|
11
|
+
* Rendering uses only the declared offline fixtures at 390 and 1440 (no live
|
|
12
|
+
* data, no deployment, no Store publication).
|
|
13
|
+
*/
|
|
14
|
+
import { readFileSync, realpathSync } from 'node:fs';
|
|
15
|
+
import { pathToFileURL } from 'node:url';
|
|
16
|
+
import { appFilesDigest } from './app-platform.js';
|
|
17
|
+
import { prepareSpaceRelease } from './space-platform.js';
|
|
18
|
+
import { verifySpaceRelease } from './space-verification.js';
|
|
19
|
+
|
|
20
|
+
export async function runConfinedVerification(request, { verify = verifySpaceRelease } = {}) {
|
|
21
|
+
if (!request || typeof request.projectDir !== 'string' || typeof request.key !== 'string'
|
|
22
|
+
|| typeof request.sourceDigest !== 'string' || typeof request.artifactDigest !== 'string'
|
|
23
|
+
|| !request.capabilities || typeof request.capabilities !== 'object') {
|
|
24
|
+
throw new Error('The verification request names one accepted build and its capabilities.');
|
|
25
|
+
}
|
|
26
|
+
const release = await prepareSpaceRelease(request.projectDir, request.key);
|
|
27
|
+
try {
|
|
28
|
+
const sourceDigest = appFilesDigest(release.sourceFiles), artifactDigest = appFilesDigest(release.files);
|
|
29
|
+
if (sourceDigest !== request.sourceDigest || artifactDigest !== request.artifactDigest) {
|
|
30
|
+
return { status: 'failed', error: 'build_changed', source_digest: sourceDigest, artifact_digest: artifactDigest };
|
|
31
|
+
}
|
|
32
|
+
const diagnostic = await verify(release, { capabilities: request.capabilities, timeoutMs: 45_000 });
|
|
33
|
+
return { status: diagnostic.status === 'passed' ? 'verified' : 'failed', diagnostic };
|
|
34
|
+
} finally { release.close(); }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function main(argv) {
|
|
38
|
+
const request = JSON.parse(readFileSync(argv[2], 'utf8'));
|
|
39
|
+
try {
|
|
40
|
+
const result = await runConfinedVerification(request);
|
|
41
|
+
process.stdout.write(JSON.stringify(result) + '\n');
|
|
42
|
+
process.exitCode = result.status === 'verified' ? 0 : 3;
|
|
43
|
+
} catch (error) {
|
|
44
|
+
process.stdout.write(JSON.stringify({ status: 'failed', error: String(error?.message || error).slice(0, 32 * 1024) }) + '\n');
|
|
45
|
+
process.exitCode = 1;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) await main(process.argv);
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* is already running has no business handing the same work back to Notis, and
|
|
6
6
|
* nothing about the loop it would create is self-limiting.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* message at the point of the mistake
|
|
12
|
-
*
|
|
8
|
+
* The guard covers the friendly command only. Agents start and steer threads
|
|
9
|
+
* on purpose through `LOCAL_NOTIS_CONTROL_THREADS`, so `notis tools exec` is
|
|
10
|
+
* not refused here and the server applies no extra check. What this adds is a
|
|
11
|
+
* clear message at the point of the common mistake: an agent running the
|
|
12
|
+
* hand-over its own instructions describe.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { existsSync } from 'node:fs';
|
|
@@ -50,19 +50,3 @@ export function assertNotDelegated(commandLabel, env = process.env) {
|
|
|
50
50
|
],
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Tools that hand work to a Notis agent, by canonical name.
|
|
56
|
-
*
|
|
57
|
-
* `notis handover` is not the only way to reach these: `notis tools exec` takes
|
|
58
|
-
* any tool name, and `tools exec-parallel` takes a list of them. Guarding only
|
|
59
|
-
* the friendly command would leave the escape hatch it exists to wrap.
|
|
60
|
-
*/
|
|
61
|
-
export const HANDOVER_TOOL_NAMES = new Set(['LOCAL_NOTIS_HAND_OVER']);
|
|
62
|
-
|
|
63
|
-
export function assertToolNotDelegated(toolName, env = process.env) {
|
|
64
|
-
if (!HANDOVER_TOOL_NAMES.has(String(toolName || '').toUpperCase())) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
assertNotDelegated(`tools exec ${toolName}`, env);
|
|
68
|
-
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { open } from 'node:fs/promises';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { basename, extname } from 'node:path';
|
|
4
|
+
import { httpRequest } from './transport.js';
|
|
5
|
+
import { usageError } from './errors.js';
|
|
6
|
+
|
|
7
|
+
const MAX_BYTES = 8 * 1024 * 1024;
|
|
8
|
+
const UUID = /^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/i;
|
|
9
|
+
const MIME = { '.html': 'text/html', '.htm': 'text/html', '.txt': 'text/plain', '.md': 'text/markdown',
|
|
10
|
+
'.json': 'application/json', '.pdf': 'application/pdf', '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.webp': 'image/webp' };
|
|
11
|
+
|
|
12
|
+
/** Reads a bounded local file, never interprets it and never attaches it to a row. */
|
|
13
|
+
export async function uploadNativeRecordFileWithCliRuntime({ runtime, target, recordKey, schemaRevision, requestId,
|
|
14
|
+
filePath, name = basename(filePath || ''), contentType = MIME[extname(filePath || '').toLowerCase()] || 'application/octet-stream',
|
|
15
|
+
signal, request = httpRequest }) {
|
|
16
|
+
if (!UUID.test(recordKey || '') || !UUID.test(requestId || '') || !Number.isSafeInteger(schemaRevision) || schemaRevision < 0
|
|
17
|
+
|| !target || typeof target !== 'object' || Array.isArray(target) || !filePath) {
|
|
18
|
+
throw usageError('Choose a local file, native target, record key, schema revision and stable request ID.');
|
|
19
|
+
}
|
|
20
|
+
const handle = await open(filePath, 'r');
|
|
21
|
+
let data;
|
|
22
|
+
try {
|
|
23
|
+
const stat = await handle.stat();
|
|
24
|
+
if (!stat.isFile() || stat.size < 1 || stat.size > MAX_BYTES) throw usageError('Choose a regular file up to 8 MB.');
|
|
25
|
+
const buffer = Buffer.alloc(MAX_BYTES + 1);
|
|
26
|
+
let length = 0;
|
|
27
|
+
while (length < buffer.length) {
|
|
28
|
+
const read = await handle.read(buffer, length, buffer.length - length, length);
|
|
29
|
+
if (!read.bytesRead) break;
|
|
30
|
+
length += read.bytesRead;
|
|
31
|
+
}
|
|
32
|
+
if (!length || length > MAX_BYTES) throw usageError('Choose a file up to 8 MB.');
|
|
33
|
+
data = buffer.subarray(0, length);
|
|
34
|
+
} finally { await handle.close(); }
|
|
35
|
+
const digest = createHash('sha256').update(data).digest('hex');
|
|
36
|
+
const body = { protocol: 1, target, record_key: recordKey, schema_revision: schemaRevision, request_id: requestId,
|
|
37
|
+
name, content_type: contentType, base64: data.toString('base64') };
|
|
38
|
+
// No automatic retry: repeating this command with the same request ID is the
|
|
39
|
+
// exact immutable intent; a mismatched request fails instead of overwriting.
|
|
40
|
+
const result = (await request({ runtime, method: 'POST', path: '/portal_native_files/upload', spacesProtocol: 1, body, signal })).payload;
|
|
41
|
+
if (result?.protocol !== 1 || result.record_key !== recordKey || result.request_id !== requestId
|
|
42
|
+
|| result.sha256 !== digest || result.size_bytes !== data.length || result.file?.name !== name
|
|
43
|
+
|| typeof result.file?.url !== 'string' || !/^https?:\/\//.test(result.file.url) || result.url !== result.file.url) {
|
|
44
|
+
throw usageError('The file upload is not confirmed. Repeat the same request ID and file bytes.');
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
package/src/runtime/oauth.js
CHANGED
|
@@ -21,6 +21,7 @@ import { execFileSync, spawn } from 'node:child_process';
|
|
|
21
21
|
import { createInterface } from 'node:readline/promises';
|
|
22
22
|
|
|
23
23
|
import { CliError, EXIT_CODES, usageError } from './errors.js';
|
|
24
|
+
import { readComputerIdentity } from './computer-identity.js';
|
|
24
25
|
import { getAuthRecovery, quoteShellArgument } from './auth-recovery.js';
|
|
25
26
|
import {
|
|
26
27
|
channelFromProfile,
|
|
@@ -674,7 +675,19 @@ function storedOAuthMetadata(runtime, profile) {
|
|
|
674
675
|
};
|
|
675
676
|
}
|
|
676
677
|
|
|
677
|
-
|
|
678
|
+
// This computer's id and name, so the server keeps one CLI sign-in per
|
|
679
|
+
// computer and lists it as "Notis CLI on <computer>". Best effort: a sign-in
|
|
680
|
+
// without them still works and maps to the shared legacy grant.
|
|
681
|
+
function cliDeviceParams() {
|
|
682
|
+
try {
|
|
683
|
+
const identity = readComputerIdentity({ configFile: resolveConfigFile() });
|
|
684
|
+
return { device_id: identity.computerId, device_name: identity.displayName };
|
|
685
|
+
} catch {
|
|
686
|
+
return {};
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
export function buildAuthorizeUrl(metadata, {
|
|
678
691
|
redirectUri,
|
|
679
692
|
challenge,
|
|
680
693
|
state,
|
|
@@ -689,6 +702,9 @@ function buildAuthorizeUrl(metadata, {
|
|
|
689
702
|
url.searchParams.set('code_challenge', challenge);
|
|
690
703
|
url.searchParams.set('code_challenge_method', 'S256');
|
|
691
704
|
url.searchParams.set('state', state);
|
|
705
|
+
for (const [key, value] of Object.entries(cliDeviceParams())) {
|
|
706
|
+
url.searchParams.set(key, value);
|
|
707
|
+
}
|
|
692
708
|
return url.toString();
|
|
693
709
|
}
|
|
694
710
|
|
|
@@ -2473,6 +2489,7 @@ export async function refreshOAuthCredential(runtime, fetchImpl = fetch) {
|
|
|
2473
2489
|
refresh_token: profile.oauth_refresh_token,
|
|
2474
2490
|
client_id: profile.oauth_client_id,
|
|
2475
2491
|
resource: metadata.resource,
|
|
2492
|
+
...cliDeviceParams(),
|
|
2476
2493
|
}),
|
|
2477
2494
|
},
|
|
2478
2495
|
fetchImpl,
|