@notis_ai/cli 0.2.24 → 0.2.26
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 +186 -5
- package/config/notis_app_design_rules.json +36 -14
- package/config/portal-route-roots.json +1 -0
- package/dist/agent-hooks/notis-agent-hook.mjs +2784 -541
- package/dist/base-skills/notis-cli/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-cli/references/intelligence.md +1 -1
- package/dist/base-skills/notis-query/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-query/SKILL.md +0 -1
- package/dist/base-skills/notis-query/references/documents.md +7 -0
- package/dist/base-skills/notis-query/references/query.md +1 -0
- package/dist/base-skills/notis-spaces/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-spaces/SKILL.md +96 -24
- package/dist/base-skills/notis-spaces/references/architecture.md +4 -3
- package/dist/base-skills/notis-spaces/references/design.md +37 -18
- package/dist/base-skills/notis-spaces/references/reading.md +8 -1
- package/dist/base-skills/notis-spaces/references/reports.md +6 -6
- package/dist/base-skills/notis-spaces/references/sdk.md +71 -7
- package/dist/base-skills/notis-spaces/references/store.md +22 -13
- package/dist/base-skills/notis-spaces/references/views.md +99 -6
- package/dist/sdk/package.json +3 -0
- package/dist/sdk/src/cloudComputerWords.ts +53 -0
- package/dist/sdk/src/components/Audience.tsx +76 -0
- package/dist/sdk/src/components/DocumentPage.tsx +15 -4
- package/dist/sdk/src/components/MarkdownEditor.tsx +44 -14
- package/dist/sdk/src/components/MultiSelectActionBar.tsx +16 -5
- package/dist/sdk/src/components/Skeleton.tsx +162 -6
- package/dist/sdk/src/hooks/useAction.ts +12 -2
- package/dist/sdk/src/hooks/useAgentQueue.ts +125 -0
- package/dist/sdk/src/hooks/useCloudComputerJob.ts +142 -0
- package/dist/sdk/src/hooks/useCloudComputerService.ts +388 -0
- package/dist/sdk/src/hooks/useCloudComputerShell.ts +95 -7
- package/dist/sdk/src/hooks/useCollectionInteractions.ts +40 -2
- package/dist/sdk/src/hooks/useItemThread.ts +58 -0
- package/dist/sdk/src/hooks/useMarqueeSelection.ts +6 -1
- package/dist/sdk/src/hooks/useNativeDocuments.ts +61 -8
- package/dist/sdk/src/hooks/useNotisNavigation.ts +31 -8
- package/dist/sdk/src/hooks/useQuery.ts +67 -10
- package/dist/sdk/src/hooks/useViewParams.ts +47 -11
- package/dist/sdk/src/index.ts +31 -4
- package/dist/sdk/src/interactions.ts +2 -0
- package/dist/sdk/src/nativeData.ts +2 -0
- package/dist/sdk/src/optimisticRows.ts +329 -0
- package/dist/sdk/src/perf.ts +188 -0
- package/dist/sdk/src/provider.tsx +2 -1
- package/dist/sdk/src/queryCache.ts +366 -17
- package/dist/sdk/src/runtime.ts +55 -4
- package/dist/sdk/src/skeleton.ts +103 -0
- package/dist/sdk/src/space.ts +662 -28
- package/dist/sdk/src/spacePublicUI.ts +36 -0
- package/dist/sdk/src/ui/engine/step.ts +54 -0
- package/dist/sdk/src/ui/icons.tsx +3 -1
- package/dist/sdk/src/words/shell.ts +1 -0
- package/dist/skill-sync/index.js +7 -2
- package/dist/skill-sync-worker.mjs +40 -26
- package/dist/space-harness/host.js +272 -105
- package/dist/space-sdk/dist/chunk-BWHAORT4.js +5 -0
- package/dist/space-sdk/dist/index.js +9 -4
- package/dist/space-sdk/dist/ui.js +12 -12
- package/dist/space-sdk/package.json +3 -0
- package/dist/space-sdk/src/cloudComputerWords.d.ts +34 -0
- package/dist/space-sdk/src/components/Audience.d.ts +46 -0
- package/dist/space-sdk/src/components/DocumentPage.d.ts +3 -1
- package/dist/space-sdk/src/components/MarkdownEditor.d.ts +21 -0
- package/dist/space-sdk/src/components/MultiSelectActionBar.d.ts +5 -1
- package/dist/space-sdk/src/components/Skeleton.d.ts +7 -2
- package/dist/space-sdk/src/hooks/useAction.d.ts +8 -1
- package/dist/space-sdk/src/hooks/useAgentQueue.d.ts +61 -0
- package/dist/space-sdk/src/hooks/useCloudComputerJob.d.ts +35 -0
- package/dist/space-sdk/src/hooks/useCloudComputerService.d.ts +75 -0
- package/dist/space-sdk/src/hooks/useCloudComputerShell.d.ts +36 -3
- package/dist/space-sdk/src/hooks/useCollectionInteractions.d.ts +6 -0
- package/dist/space-sdk/src/hooks/useItemThread.d.ts +32 -0
- package/dist/space-sdk/src/hooks/useMarqueeSelection.d.ts +2 -1
- package/dist/space-sdk/src/hooks/useNativeDocumentBody.d.ts +1 -0
- package/dist/space-sdk/src/hooks/useNativeDocuments.d.ts +20 -5
- package/dist/space-sdk/src/hooks/useNotisNavigation.d.ts +11 -2
- package/dist/space-sdk/src/hooks/useQuery.d.ts +24 -2
- package/dist/space-sdk/src/hooks/useViewParams.d.ts +2 -0
- package/dist/space-sdk/src/index.d.ts +24 -4
- package/dist/space-sdk/src/nativeData.d.ts +6 -0
- package/dist/space-sdk/src/queryCache.d.ts +97 -2
- package/dist/space-sdk/src/runtime.d.ts +53 -4
- package/dist/space-sdk/src/skeleton.d.ts +42 -0
- package/dist/space-sdk/src/space.ts +662 -28
- package/dist/space-sdk/src/tailwind-candidates.d.ts +754 -5
- package/dist/space-sdk/src/ui/cloud/CloudComputerFrame.d.ts +29 -0
- package/dist/space-sdk/src/ui/cloud/CloudComputerWaking.d.ts +20 -0
- package/dist/space-sdk/src/ui/comments/CommentPane.d.ts +15 -2
- package/dist/space-sdk/src/ui/comments/PassageComments.d.ts +50 -0
- package/dist/space-sdk/src/ui/comments/commentFiles.d.ts +64 -0
- package/dist/space-sdk/src/ui/comments/commentModel.d.ts +49 -1
- package/dist/space-sdk/src/ui/comments/commentWords.d.ts +26 -0
- package/dist/space-sdk/src/ui/comments/index.d.ts +4 -0
- package/dist/space-sdk/src/ui/comments/passageModel.d.ts +82 -0
- package/dist/space-sdk/src/ui/comments/useComments.d.ts +34 -4
- package/dist/space-sdk/src/ui/comments/usePassageComments.d.ts +67 -0
- package/dist/space-sdk/src/ui/engine/index.d.ts +2 -2
- package/dist/space-sdk/src/ui/engine/step.d.ts +9 -0
- package/dist/space-sdk/src/ui/fields/fields.d.ts +2 -1
- package/dist/space-sdk/src/ui/index.d.ts +4 -0
- package/dist/space-sdk/src/ui/layout/Panels.d.ts +9 -2
- package/dist/space-sdk/src/ui/layout/SidePane.d.ts +42 -0
- package/dist/space-sdk/src/ui/layout/index.d.ts +2 -1
- package/dist/space-sdk/src/ui/layout/panelMath.d.ts +11 -2
- package/dist/space-sdk/src/ui/list/ListReader.d.ts +38 -7
- package/dist/space-sdk/src/ui/list/Row.d.ts +4 -0
- package/dist/space-sdk/src/ui/list/SelectionBar.d.ts +9 -4
- package/dist/space-sdk/src/ui/list/useListKeys.d.ts +4 -0
- package/dist/space-sdk/src/words/shell.ts +1 -0
- package/dist/view-renderer/dist/host.js +355 -188
- package/dist/view-renderer/dist/theme.css +1 -1
- package/dist/view-renderer/src/host.tsx +4 -1
- package/dist/view-renderer/src/index.js +3 -0
- package/dist/view-renderer/src/pool.js +8 -4
- package/dist/view-renderer/src/renderer.js +92 -23
- package/dist/view-renderer/src/skeleton.js +450 -0
- package/package.json +4 -4
- package/skills/notis-cli/AGENT_INSTRUCTIONS.md +8 -4
- package/skills/notis-onboarding/BRIEF.md +15 -9
- package/skills/notis-spaces/cli.md +43 -4
- package/src/command-specs/auth.js +5 -3
- package/src/command-specs/cc.js +410 -0
- package/src/command-specs/computer.js +320 -0
- package/src/command-specs/diagnostics.js +2 -13
- package/src/command-specs/documents.js +22 -4
- package/src/command-specs/index.js +7 -0
- package/src/command-specs/onboarding.js +127 -7
- package/src/command-specs/skills.js +2 -2
- package/src/command-specs/spaces.js +162 -30
- package/src/command-specs/tools.js +26 -8
- package/src/command-specs/views.js +4 -1
- package/src/runtime/agent-setup.js +20 -2
- package/src/runtime/app-boundary-validator.js +2 -1
- package/src/runtime/app-platform.js +13 -0
- package/src/runtime/auth-recovery.js +5 -0
- package/src/runtime/channel.js +16 -2
- package/src/runtime/cloud-transfer.js +587 -0
- package/src/runtime/computer-ssh.js +127 -0
- package/src/runtime/oauth.js +50 -4
- package/src/runtime/skill-sync/index.ts +20 -1
- package/src/runtime/skill-sync/local-scanner.ts +1 -0
- package/src/runtime/skill-sync/types.ts +2 -0
- package/src/runtime/space-audience.js +94 -0
- package/src/runtime/space-collection-scaffold.js +2 -1
- package/src/runtime/space-fixture-broker.js +2 -1
- package/src/runtime/space-lock.js +1 -4
- package/src/runtime/space-platform.js +18 -2
- package/src/runtime/space-source.js +105 -7
- package/src/runtime/space-test-server.js +13 -2
- package/src/runtime/space-verification.js +99 -6
- package/src/runtime/space-view-manifest.js +22 -4
- package/src/runtime/sync-skills.js +24 -20
- package/src/runtime/transport.js +19 -0
- package/src/runtime/view-render.js +2 -2
- package/template/.harness/index.html.tmpl +1 -1
- package/dist/skill-sync/index.js.map +0 -7
- package/dist/space-sdk/dist/chunk-SVZATGZB.js +0 -5
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// Local files for `notis computer ssh`: this device's key, the SSH config
|
|
2
|
+
// block for `ssh notis-computer`, the proxy wrapper and the computer's host key.
|
|
3
|
+
// Everything lives in ~/.ssh/notis; ~/.ssh/config only gains one Include line.
|
|
4
|
+
|
|
5
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
6
|
+
import { homedir } from 'node:os';
|
|
7
|
+
import { dirname, join } from 'node:path';
|
|
8
|
+
|
|
9
|
+
export const SSH_HOST_ALIAS = 'notis-computer';
|
|
10
|
+
export const SSH_USER = 'user';
|
|
11
|
+
export const INCLUDE_MARKER = '# notis-computer-ssh';
|
|
12
|
+
const HOST_KEY_TYPE = /^(ssh-ed25519|ssh-rsa|ecdsa-sha2-nistp(256|384|521)|sk-ssh-ed25519@openssh\.com|sk-ecdsa-sha2-nistp256@openssh\.com|rsa-sha2-(256|512))$/;
|
|
13
|
+
|
|
14
|
+
export function sshPaths(home = homedir()) {
|
|
15
|
+
const dir = join(home, '.ssh', 'notis');
|
|
16
|
+
return {
|
|
17
|
+
sshDir: join(home, '.ssh'),
|
|
18
|
+
dir,
|
|
19
|
+
userConfig: join(home, '.ssh', 'config'),
|
|
20
|
+
config: join(dir, 'config'),
|
|
21
|
+
key: join(dir, 'id_ed25519'),
|
|
22
|
+
publicKey: join(dir, 'id_ed25519.pub'),
|
|
23
|
+
proxy: join(dir, 'proxy'),
|
|
24
|
+
knownHosts: join(dir, 'known_hosts'),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function shellQuote(value) {
|
|
29
|
+
return `'${String(value).replace(/'/g, `'\\''`)}'`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// ssh_config tokens are split on whitespace; a quoted path survives spaces.
|
|
33
|
+
function configPath(value) {
|
|
34
|
+
return /[\s"]/.test(value) ? `"${value.replace(/"/g, '\\"')}"` : value;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function sshConfigText(paths) {
|
|
38
|
+
return [
|
|
39
|
+
'# Written by notis computer ssh --setup. Run it again to refresh this file.',
|
|
40
|
+
`Host ${SSH_HOST_ALIAS}`,
|
|
41
|
+
` HostName ${SSH_HOST_ALIAS}`,
|
|
42
|
+
` User ${SSH_USER}`,
|
|
43
|
+
` IdentityFile ${configPath(paths.key)}`,
|
|
44
|
+
' IdentitiesOnly yes',
|
|
45
|
+
// The proxy asks Notis where the computer is (and starts it when stopped),
|
|
46
|
+
// writes its current host key, then relays the connection.
|
|
47
|
+
` ProxyCommand ${configPath(paths.proxy)}`,
|
|
48
|
+
` HostKeyAlias ${SSH_HOST_ALIAS}`,
|
|
49
|
+
` UserKnownHostsFile ${configPath(paths.knownHosts)}`,
|
|
50
|
+
' StrictHostKeyChecking yes',
|
|
51
|
+
' ServerAliveInterval 15',
|
|
52
|
+
' ServerAliveCountMax 4',
|
|
53
|
+
'',
|
|
54
|
+
].join('\n');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// The proxy pins this CLI, profile and config file: ssh runs it from any
|
|
58
|
+
// directory and apps such as T3 Desktop start it without the shell's
|
|
59
|
+
// environment, where a bare `notis` could pick another profile, an older CLI or
|
|
60
|
+
// the default config without that profile.
|
|
61
|
+
export function proxyScriptText({ nodePath, cliPath, profileName, configFile }) {
|
|
62
|
+
const profile = profileName ? ` --profile ${shellQuote(profileName)}` : '';
|
|
63
|
+
return [
|
|
64
|
+
'#!/bin/sh',
|
|
65
|
+
'# Written by notis computer ssh --setup.',
|
|
66
|
+
...(configFile ? [`NOTIS_CLI_CONFIG_FILE=${shellQuote(configFile)}`, 'export NOTIS_CLI_CONFIG_FILE'] : []),
|
|
67
|
+
`NODE=${shellQuote(nodePath)}`,
|
|
68
|
+
`CLI=${shellQuote(cliPath)}`,
|
|
69
|
+
`if [ -x "$NODE" ] && [ -f "$CLI" ]; then exec "$NODE" "$CLI"${profile} computer ssh --proxy; fi`,
|
|
70
|
+
`if command -v notis >/dev/null 2>&1; then exec notis${profile} computer ssh --proxy; fi`,
|
|
71
|
+
`exec npx --yes --package @notis_ai/cli@latest -- notis${profile} computer ssh --proxy`,
|
|
72
|
+
'',
|
|
73
|
+
].join('\n');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Include only works before the first Host block, so the line goes on top.
|
|
77
|
+
export function withInclude(existing, paths) {
|
|
78
|
+
const text = existing || '';
|
|
79
|
+
if (text.includes(INCLUDE_MARKER)) return text;
|
|
80
|
+
return `Include ${configPath(paths.config)} ${INCLUDE_MARKER}\n${text ? `\n${text}` : ''}`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// boat may send a bare key or a known_hosts line; ssh needs `<alias> <type> <key>`.
|
|
84
|
+
export function knownHostsText(hostKey) {
|
|
85
|
+
const lines = [];
|
|
86
|
+
for (const raw of String(hostKey || '').split(/\r?\n/)) {
|
|
87
|
+
const fields = raw.trim().split(/\s+/).filter(Boolean);
|
|
88
|
+
const typeIndex = fields.findIndex(field => HOST_KEY_TYPE.test(field));
|
|
89
|
+
if (typeIndex < 0 || !fields[typeIndex + 1]) continue;
|
|
90
|
+
lines.push(`${SSH_HOST_ALIAS} ${fields[typeIndex]} ${fields[typeIndex + 1]}`);
|
|
91
|
+
}
|
|
92
|
+
return lines.length ? `${lines.join('\n')}\n` : '';
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function writeAtomic(path, text, mode) {
|
|
96
|
+
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
97
|
+
const temp = `${path}.${process.pid}.tmp`;
|
|
98
|
+
writeFileSync(temp, text, { mode });
|
|
99
|
+
chmodSync(temp, mode);
|
|
100
|
+
renameSync(temp, path);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function writeSshFiles({ paths, nodePath, cliPath, profileName, configFile }) {
|
|
104
|
+
mkdirSync(paths.sshDir, { recursive: true, mode: 0o700 });
|
|
105
|
+
writeAtomic(paths.config, sshConfigText(paths), 0o600);
|
|
106
|
+
writeAtomic(paths.proxy, proxyScriptText({ nodePath, cliPath, profileName, configFile }), 0o700);
|
|
107
|
+
const existing = existsSync(paths.userConfig) ? readFileSync(paths.userConfig, 'utf8') : '';
|
|
108
|
+
const next = withInclude(existing, paths);
|
|
109
|
+
if (next !== existing) writeAtomic(paths.userConfig, next, 0o600);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function writeHostKey(paths, hostKey) {
|
|
113
|
+
const text = knownHostsText(hostKey);
|
|
114
|
+
if (!text) return false;
|
|
115
|
+
writeAtomic(paths.knownHosts, text, 0o600);
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// The connect reply names a host and port; ssh's own HostName is only a label.
|
|
120
|
+
export function parseConnectReply(payload) {
|
|
121
|
+
const host = typeof payload?.host === 'string' ? payload.host.trim() : '';
|
|
122
|
+
const port = Number(payload?.port);
|
|
123
|
+
if (payload?.status !== 'ready' || !host || !Number.isInteger(port) || port < 1 || port > 65535) {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
return { host, port, user: payload.user || SSH_USER, hostKey: payload.host_key || '' };
|
|
127
|
+
}
|
package/src/runtime/oauth.js
CHANGED
|
@@ -913,6 +913,41 @@ function openBrowser(url) {
|
|
|
913
913
|
}
|
|
914
914
|
}
|
|
915
915
|
|
|
916
|
+
/**
|
|
917
|
+
* Whether a CLI an agent runs may open the sign-in page for the person at this computer, rather than asking them to
|
|
918
|
+
* click a link. Never over SSH (the page would open on a screen nobody is looking at), in CI, on Linux without a
|
|
919
|
+
* display, inside node's test runner, or when BROWSER=none or NOTIS_NO_BROWSER is set.
|
|
920
|
+
*/
|
|
921
|
+
export function canOpenBrowser(env = process.env, platform = process.platform) {
|
|
922
|
+
if (env.NOTIS_NO_BROWSER || env.BROWSER === 'none' || env.NODE_TEST_CONTEXT) return false;
|
|
923
|
+
if (env.CI && !['0', 'false'].includes(String(env.CI).toLowerCase())) return false;
|
|
924
|
+
if (env.SSH_CONNECTION || env.SSH_CLIENT || env.SSH_TTY) return false;
|
|
925
|
+
if (platform === 'linux') return Boolean(env.DISPLAY || env.WAYLAND_DISPLAY);
|
|
926
|
+
return platform === 'darwin' || platform === 'win32';
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
/**
|
|
930
|
+
* Opens the sign-in page for an agent's run and says whether it did: the opener's exit code, or true when it is still
|
|
931
|
+
* running after `waitMs` (some xdg-open handlers stay up with the browser). A sandbox that refuses to launch apps
|
|
932
|
+
* reads as false, so the agent hands the person the link instead.
|
|
933
|
+
*/
|
|
934
|
+
export function openBrowserForAgent(url, { env = process.env, platform = process.platform, spawnImpl = spawn, waitMs = 3000 } = {}) {
|
|
935
|
+
if (!canOpenBrowser(env, platform)) return Promise.resolve(false);
|
|
936
|
+
const { command, args } = browserOpenCommand(url, platform);
|
|
937
|
+
return new Promise((resolve) => {
|
|
938
|
+
let child;
|
|
939
|
+
try {
|
|
940
|
+
child = spawnImpl(command, args, { detached: true, stdio: 'ignore' });
|
|
941
|
+
} catch {
|
|
942
|
+
resolve(false);
|
|
943
|
+
return;
|
|
944
|
+
}
|
|
945
|
+
const timer = setTimeout(() => { child.unref?.(); resolve(true); }, waitMs);
|
|
946
|
+
child.on('error', () => { clearTimeout(timer); resolve(false); });
|
|
947
|
+
child.on('exit', (code) => { clearTimeout(timer); resolve(code === 0); });
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
|
|
916
951
|
function storedOAuthMetadata(runtime, profile) {
|
|
917
952
|
const issuer = String(profile.oauth_issuer || '').replace(/\/+$/, '');
|
|
918
953
|
const apiBase = getOAuthApiBase(profile)
|
|
@@ -2333,6 +2368,8 @@ export async function loginWithOAuth(
|
|
|
2333
2368
|
authorize_url: live.authorize_url,
|
|
2334
2369
|
expires_in: Math.max(0, Number(live.expires_at) - Math.floor(Date.now() / 1000)),
|
|
2335
2370
|
hand_off: 'browser_callback',
|
|
2371
|
+
// The page opened on the first run; opening it again on every confirmation would stack tabs.
|
|
2372
|
+
browser_opened: false,
|
|
2336
2373
|
confirm_command: confirmCommand(
|
|
2337
2374
|
runtime.profileName,
|
|
2338
2375
|
authorizationChannel(metadata, runtime),
|
|
@@ -2532,6 +2569,10 @@ export async function loginWithOAuth(
|
|
|
2532
2569
|
expires_at: Math.floor(Date.now() / 1000) + listenerTtlSeconds,
|
|
2533
2570
|
});
|
|
2534
2571
|
detachedListenerPublished = true;
|
|
2572
|
+
// The person is at this computer even when an agent runs the CLI: open the page for them.
|
|
2573
|
+
const browserOpened = options.browser === false
|
|
2574
|
+
? false
|
|
2575
|
+
: await (options.openAgentBrowser || openBrowserForAgent)(authorizeUrl);
|
|
2535
2576
|
return {
|
|
2536
2577
|
agentAuthorization: {
|
|
2537
2578
|
authorize_url: authorizeUrl,
|
|
@@ -2540,6 +2581,7 @@ export async function loginWithOAuth(
|
|
|
2540
2581
|
// child is holding, and the credential is written before the user is
|
|
2541
2582
|
// told they are connected.
|
|
2542
2583
|
hand_off: 'browser_callback',
|
|
2584
|
+
browser_opened: browserOpened,
|
|
2543
2585
|
confirm_command: confirmCommand(
|
|
2544
2586
|
runtime.profileName,
|
|
2545
2587
|
authorizationChannel(metadata, runtime),
|
|
@@ -2674,7 +2716,7 @@ function lockIsStale() {
|
|
|
2674
2716
|
}
|
|
2675
2717
|
}
|
|
2676
2718
|
|
|
2677
|
-
async function acquireRefreshLock(runtime, waitMs = OAUTH_REFRESH_LOCK_WAIT_MS) {
|
|
2719
|
+
async function acquireRefreshLock(runtime, staleAccessToken, waitMs = OAUTH_REFRESH_LOCK_WAIT_MS) {
|
|
2678
2720
|
mkdirSync(join(homedir(), '.notis'), { recursive: true });
|
|
2679
2721
|
const deadline = Date.now() + waitMs;
|
|
2680
2722
|
for (;;) {
|
|
@@ -2686,7 +2728,7 @@ async function acquireRefreshLock(runtime, waitMs = OAUTH_REFRESH_LOCK_WAIT_MS)
|
|
|
2686
2728
|
const profile = getProfile(loadConfig(), runtime.profileName);
|
|
2687
2729
|
if (
|
|
2688
2730
|
profile.oauth_access_token
|
|
2689
|
-
&& profile.oauth_access_token !==
|
|
2731
|
+
&& profile.oauth_access_token !== staleAccessToken
|
|
2690
2732
|
&& !credentialIsExpired({ credentialKind: 'oauth' }, profile)
|
|
2691
2733
|
) {
|
|
2692
2734
|
updateRuntimeFromOAuthProfile(runtime, profile);
|
|
@@ -2730,6 +2772,10 @@ export async function refreshOAuthCredential(runtime, fetchImpl = fetch, tokenRe
|
|
|
2730
2772
|
// Refresh rotates the same stored grant that login publishes and logout
|
|
2731
2773
|
// removes. Join their global -> profile lock order so a token rotation can
|
|
2732
2774
|
// never be mistaken for a successor authorization by a concurrent logout.
|
|
2775
|
+
// The token this caller found unusable. Requests running in parallel in one
|
|
2776
|
+
// process share `runtime`, so the first to finish updates it for all; compare
|
|
2777
|
+
// against what this caller saw, or every waiting request renews once more.
|
|
2778
|
+
const staleAccessToken = runtime.oauthAccessToken;
|
|
2733
2779
|
const globalLock = await acquireListenerGlobalLock({ waitMs: OAUTH_REFRESH_LOCK_WAIT_MS });
|
|
2734
2780
|
let profileLock = null;
|
|
2735
2781
|
let ownsLock = false;
|
|
@@ -2737,7 +2783,7 @@ export async function refreshOAuthCredential(runtime, fetchImpl = fetch, tokenRe
|
|
|
2737
2783
|
let metadata = null;
|
|
2738
2784
|
try {
|
|
2739
2785
|
profileLock = await acquireListenerStartLock(runtime);
|
|
2740
|
-
ownsLock = await acquireRefreshLock(runtime);
|
|
2786
|
+
ownsLock = await acquireRefreshLock(runtime, staleAccessToken);
|
|
2741
2787
|
if (!ownsLock) return true;
|
|
2742
2788
|
stopTouchingLocks = keepLockFoldersFresh([profileLock, oauthLockDir()]);
|
|
2743
2789
|
const config = loadConfig();
|
|
@@ -2745,7 +2791,7 @@ export async function refreshOAuthCredential(runtime, fetchImpl = fetch, tokenRe
|
|
|
2745
2791
|
assertOAuthApiTarget(runtime, profile);
|
|
2746
2792
|
if (
|
|
2747
2793
|
profile.oauth_access_token
|
|
2748
|
-
&& profile.oauth_access_token !==
|
|
2794
|
+
&& profile.oauth_access_token !== staleAccessToken
|
|
2749
2795
|
&& !credentialIsExpired({ credentialKind: 'oauth' }, profile)
|
|
2750
2796
|
) {
|
|
2751
2797
|
updateRuntimeFromOAuthProfile(runtime, profile);
|
|
@@ -3,6 +3,7 @@ import { promises as fs } from 'node:fs';
|
|
|
3
3
|
import { dirname, join } from 'node:path';
|
|
4
4
|
import type {
|
|
5
5
|
AgentTargets,
|
|
6
|
+
CloudSkill,
|
|
6
7
|
LocalSkill,
|
|
7
8
|
NotisSyncState,
|
|
8
9
|
SkillSyncFailure,
|
|
@@ -467,6 +468,24 @@ function applyLegacyFirstRunState(
|
|
|
467
468
|
};
|
|
468
469
|
}
|
|
469
470
|
|
|
471
|
+
/**
|
|
472
|
+
* The files the previous write applied. A native folder whose state row lost that
|
|
473
|
+
* record (state written before it existed, or a row rebuilt while the Skill was
|
|
474
|
+
* unavailable) still names them in its identity marker; when every one of them is
|
|
475
|
+
* unedited they are the previous sync's output, so a newer revision replaces them
|
|
476
|
+
* instead of failing as a local conflict on every sync.
|
|
477
|
+
*/
|
|
478
|
+
function previouslyAppliedFiles(
|
|
479
|
+
skill: CloudSkill,
|
|
480
|
+
local: LocalSkill | undefined,
|
|
481
|
+
previousState: NotisSyncState,
|
|
482
|
+
): readonly string[] | undefined {
|
|
483
|
+
const recorded = previousNativeState(previousState, skill)?.appliedFiles;
|
|
484
|
+
if (recorded || !isNativeSkill(skill) || !local?.nativeManagedFiles) return recorded;
|
|
485
|
+
return local.nativeFilesCurrent === true && local.cloudId === skill.id
|
|
486
|
+
&& local.folderHash === local.nativeBaseFolderHash ? local.nativeManagedFiles : undefined;
|
|
487
|
+
}
|
|
488
|
+
|
|
470
489
|
async function writePulledSkillsToScopedMirror(
|
|
471
490
|
pullResponse: SyncPullResponse,
|
|
472
491
|
localSkills: LocalSkill[],
|
|
@@ -507,7 +526,7 @@ async function writePulledSkillsToScopedMirror(
|
|
|
507
526
|
deps.writeCloudSkillToDisk(skill, bundleBytes, syncPaths, {
|
|
508
527
|
// What the last write put there. Everything else in the folder was
|
|
509
528
|
// produced locally and survives this one.
|
|
510
|
-
previouslyApplied:
|
|
529
|
+
previouslyApplied: previouslyAppliedFiles(skill, local, previousState),
|
|
511
530
|
...(isNativeSkill(skill) && local ? { expectedFolderHash: local.folderHash } : {}),
|
|
512
531
|
...(legacyBaseline ? { legacyBaseline } : {}),
|
|
513
532
|
}),
|
|
@@ -752,6 +752,7 @@ export async function scanLocalSkills(
|
|
|
752
752
|
const editedName = nativeFrontmatterName(skillMd);
|
|
753
753
|
Object.assign(skill, { cloudId: identity.cloudId, nativeReference: identity.reference,
|
|
754
754
|
nativeScope: identity.scope, nativeBaseFolderHash: identity.folderHash, nativeFilesCurrent: current,
|
|
755
|
+
nativeManagedFiles: [...Object.keys(identity.files), NATIVE_IDENTITY_FILE].sort(),
|
|
755
756
|
displayName: editedName && editedName !== identity.frontmatterName ? editedName : identity.displayName });
|
|
756
757
|
}
|
|
757
758
|
if (sourceUrls[entry.name]) {
|
|
@@ -68,6 +68,8 @@ export interface LocalSkill {
|
|
|
68
68
|
nativeScope?: string;
|
|
69
69
|
nativeFilesCurrent?: boolean;
|
|
70
70
|
nativeBaseFolderHash?: string;
|
|
71
|
+
/** Every file the identity marker says the last native write applied, the marker included. */
|
|
72
|
+
nativeManagedFiles?: string[];
|
|
71
73
|
}
|
|
72
74
|
|
|
73
75
|
export interface BundleFile {
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Editor-only parts of a Space (truths SPC-069 to SPC-074). A source marks the whole view, a list
|
|
3
|
+
* (`shows`), an action or a param with `editorsOnly: true`, and a database column with
|
|
4
|
+
* `resources[alias].columns: { Column: { editorsOnly: true } }`. Unmarked parts are public.
|
|
5
|
+
*
|
|
6
|
+
* The manifest never carries the markers on the items it copies: it carries one top-level
|
|
7
|
+
* `editors_only` summary instead (absent when nothing is marked, so unmarked manifests stay
|
|
8
|
+
* byte-identical). server/lib/space_audience.py re-checks it on every release.
|
|
9
|
+
*/
|
|
10
|
+
import { usageError } from './errors.js';
|
|
11
|
+
|
|
12
|
+
const plain = value => Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
13
|
+
// Python's casefold, closely enough for property names (as space-view-manifest.js matches them).
|
|
14
|
+
const fold = value => String(value).toUpperCase().toLowerCase();
|
|
15
|
+
|
|
16
|
+
/** Whether `value` marks a part editor-only: absent is public, the literal true is editors only. */
|
|
17
|
+
export function editorsOnlyFlag(value, where) {
|
|
18
|
+
if (value === undefined) return false;
|
|
19
|
+
if (value !== true) throw usageError(`${where}: editorsOnly is true, or left out for a part the public sees.`);
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** A copy without the editorsOnly marker, so the manifest item reads exactly as an unmarked one. */
|
|
24
|
+
export function withoutMarker(value) {
|
|
25
|
+
if (!plain(value) || !Object.hasOwn(value, 'editorsOnly')) return value;
|
|
26
|
+
const { editorsOnly, ...rest } = value;
|
|
27
|
+
return rest;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The editor-only column names of one database resource (`columns`), checked against the schema of a
|
|
32
|
+
* database the same release creates. A linked database's schema is checked on the server at verify and deploy.
|
|
33
|
+
*/
|
|
34
|
+
export function editorOnlyColumns(alias, resource) {
|
|
35
|
+
if (!plain(resource) || resource.columns === undefined) return [];
|
|
36
|
+
const columns = resource.columns;
|
|
37
|
+
if (resource.kind !== 'database') throw usageError(`Resource ${alias}: only a database declares editor-only columns.`);
|
|
38
|
+
if (!plain(columns) || !Object.keys(columns).length || Object.keys(columns).length > 200) {
|
|
39
|
+
throw usageError(`Database ${alias}: declare columns as { Column: { editorsOnly: true } }, naming at least one property.`);
|
|
40
|
+
}
|
|
41
|
+
const schema = resource.create?.schema;
|
|
42
|
+
const properties = plain(schema?.properties) ? Object.entries(schema.properties).filter(([, prop]) => plain(prop)) : null;
|
|
43
|
+
for (const [name, marker] of Object.entries(columns)) {
|
|
44
|
+
if (!name.trim() || name.length > 200) throw usageError(`Database ${alias}: a column names a property of 1 to 200 characters.`);
|
|
45
|
+
if (!plain(marker) || Object.keys(marker).join(',') !== 'editorsOnly' || marker.editorsOnly !== true) {
|
|
46
|
+
throw usageError(`Database ${alias}: column "${name}" is { editorsOnly: true }.`);
|
|
47
|
+
}
|
|
48
|
+
if (properties && !properties.some(([key, prop]) => key === name || fold(prop.name ?? key) === fold(name))) {
|
|
49
|
+
throw usageError(`Database ${alias}: "${name}" is not a property of the database this Space creates.`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return Object.keys(columns).sort();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The resources as the manifest carries them: without their `columns` markers. */
|
|
56
|
+
export function manifestResources(resources) {
|
|
57
|
+
return Object.fromEntries(Object.entries(resources || {}).map(([alias, resource]) => {
|
|
58
|
+
if (!plain(resource) || !Object.hasOwn(resource, 'columns')) return [alias, resource];
|
|
59
|
+
const { columns, ...rest } = resource;
|
|
60
|
+
return [alias, rest];
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The actions as the manifest (and so the release) carries them: without their editorsOnly markers. */
|
|
65
|
+
export function manifestActions(actions) {
|
|
66
|
+
return Object.fromEntries(Object.entries(actions || {}).map(([id, template]) => [id, withoutMarker(template)]));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The view's params or shows as the manifest carries them: without their editorsOnly markers. */
|
|
70
|
+
export function manifestDeclarations(declarations) {
|
|
71
|
+
return Object.fromEntries(Object.entries(declarations).map(([name, value]) => [name, withoutMarker(value)]));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const marked = items => Object.entries(items || {}).filter(([, value]) => plain(value) && value.editorsOnly === true)
|
|
75
|
+
.map(([name]) => name).sort();
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The one `editors_only` manifest key: `{ view?, shows?, actions?, params?, columns? }`, sorted and
|
|
79
|
+
* without empty members, or undefined when nothing is editor-only. The markers are validated where
|
|
80
|
+
* each part is (space-source.js and space-view-manifest.js).
|
|
81
|
+
*/
|
|
82
|
+
export function editorsOnlySummary(definition) {
|
|
83
|
+
const columns = Object.fromEntries(Object.entries(definition.resources || {})
|
|
84
|
+
.map(([alias, resource]) => [alias, plain(resource?.columns) ? Object.keys(resource.columns).sort() : []])
|
|
85
|
+
.filter(([, names]) => names.length).sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0)));
|
|
86
|
+
const summary = {
|
|
87
|
+
...(definition.editorsOnly === true ? { view: true } : {}),
|
|
88
|
+
...(marked(definition.shows).length ? { shows: marked(definition.shows) } : {}),
|
|
89
|
+
...(marked(definition.actions).length ? { actions: marked(definition.actions) } : {}),
|
|
90
|
+
...(marked(definition.params).length ? { params: marked(definition.params) } : {}),
|
|
91
|
+
...(Object.keys(columns).length ? { columns } : {}),
|
|
92
|
+
};
|
|
93
|
+
return Object.keys(summary).length ? summary : undefined;
|
|
94
|
+
}
|
|
@@ -15,7 +15,8 @@ export async function scaffoldSpaceCollection({ projectDir, name, databaseKey, p
|
|
|
15
15
|
mkdirSync(join(projectDir, 'spaces', 'collection'), { recursive: true });
|
|
16
16
|
writeFileSync(join(projectDir, 'notis.config.ts'), `import { defineSpaces } from '@notis/sdk/config';
|
|
17
17
|
export default defineSpaces({ spaces: { collection: { definition: 'spaces/collection/space.config.ts' } } });\n`);
|
|
18
|
-
|
|
18
|
+
// icon stays empty until the agent picks one (phosphor:<kebab-name>): deploy refuses an empty icon.
|
|
19
|
+
const definition = { specVersion: 2, name, description: `Browse and edit ${name} records.`, icon: '', path, entry: './view.tsx', layout: '../../app/layout.tsx',
|
|
19
20
|
readableContext: `Browse ${name} records. The item parameter opens one record with its properties, collaborative body and sharing controls.`,
|
|
20
21
|
verificationFixtures: './verification.json',
|
|
21
22
|
resources: { [databaseKey]: { kind: 'database', key: databaseKey } },
|
|
@@ -6,7 +6,7 @@ const object = value => value && typeof value === 'object' && !Array.isArray(val
|
|
|
6
6
|
const exact = (value, keys) => object(value) && Object.keys(value).sort().join(',') === [...keys].sort().join(',');
|
|
7
7
|
|
|
8
8
|
export function createSpaceFixtureBroker({ release, capabilities, width, outputs = ['markdown', 'screenshot'],
|
|
9
|
-
authorizationMode = 'authorize_missing', unavailableActions = [] }) {
|
|
9
|
+
authorizationMode = 'authorize_missing', unavailableActions = [], onFailure }) {
|
|
10
10
|
const engine = createSpaceFixtureEngine(release);
|
|
11
11
|
const frozen = spaceHarnessSnapshot(release, capabilities, engine, { authorizationMode, unavailableActions });
|
|
12
12
|
const calls = [];
|
|
@@ -33,6 +33,7 @@ export function createSpaceFixtureBroker({ release, capabilities, width, outputs
|
|
|
33
33
|
} catch (error) {
|
|
34
34
|
// Keep the reason with the call so verify reports which read failed and what the fixture lacks.
|
|
35
35
|
log.error = String(error?.message || error).slice(0, 2000);
|
|
36
|
+
onFailure?.(log);
|
|
36
37
|
throw error;
|
|
37
38
|
}
|
|
38
39
|
log.ok = true;
|
|
@@ -317,7 +317,7 @@ export function applyPublication({ lock, folders, result }) {
|
|
|
317
317
|
return { lock: next, resources: resourceEntries(applied.space_links || []) };
|
|
318
318
|
}
|
|
319
319
|
|
|
320
|
-
/** One line describing what a deploy changed
|
|
320
|
+
/** One line describing what a deploy changed. */
|
|
321
321
|
export function describeAppliedChanges(result) {
|
|
322
322
|
const applied = result?.applied;
|
|
323
323
|
if (!applied) return '';
|
|
@@ -330,8 +330,5 @@ export function describeAppliedChanges(result) {
|
|
|
330
330
|
const removed = (applied.links || []).flatMap((link) => (link.removed || []).map((entry) => `${entry.alias} (${link.kind})`));
|
|
331
331
|
if (added.length) parts.push(`Links added: ${added.join(', ')}`);
|
|
332
332
|
if (removed.length) parts.push(`Links removed: ${removed.join(', ')}`);
|
|
333
|
-
for (const review of result.reviews || []) {
|
|
334
|
-
if (review.review_url) parts.push(`Review ${review.alias}: ${review.review_url}`);
|
|
335
|
-
}
|
|
336
333
|
return parts.length ? ` ${parts.join('. ')}.` : '';
|
|
337
334
|
}
|
|
@@ -5,19 +5,35 @@ import { appFilesDigest, buildArtifact, freezeSourceWorkspace, prepareAppRelease
|
|
|
5
5
|
import { validateProjectBoundary, validateProjectDesign, validateSourceDesign } from './app-boundary-validator.js';
|
|
6
6
|
import { collectSelectedSpaceSource, loadSelectedSpace } from './space-source.js';
|
|
7
7
|
import { viewManifestFields } from './space-view-manifest.js';
|
|
8
|
+
import { editorsOnlySummary, manifestActions, manifestResources } from './space-audience.js';
|
|
8
9
|
import { usageError } from './errors.js';
|
|
9
10
|
import { assertSourceRoot } from './source-root.js';
|
|
10
11
|
|
|
12
|
+
const SPACE_ICON = /^(phosphor:[a-z0-9]+(-[a-z0-9]+)*|https:\/\/\S{1,2000})$/;
|
|
13
|
+
|
|
14
|
+
/** Publication requires a chosen icon: the manifest carries an empty one until the agent sets it. */
|
|
15
|
+
export function requireSpaceIcon(manifest, key) {
|
|
16
|
+
if (typeof manifest?.icon === 'string' && SPACE_ICON.test(manifest.icon.trim())) return;
|
|
17
|
+
throw usageError(`Set icon in the ${key} Space's space.config.ts before deploying: a Phosphor icon that fits what the Space is about, `
|
|
18
|
+
+ "written 'phosphor:<kebab-name>' (for example 'phosphor:calendar-check'), or an https image URL. Nothing was published.");
|
|
19
|
+
}
|
|
20
|
+
|
|
11
21
|
export function generateSpaceManifest(selection) {
|
|
12
22
|
const definition = selection.definition;
|
|
23
|
+
const editorsOnly = editorsOnlySummary(definition);
|
|
13
24
|
return { schema: 'notis-space/v1', kind: selection.entry ? 'presentation' : 'container', local_key: selection.key,
|
|
14
|
-
name: definition.name, description: definition.description || '', icon: definition.icon ||
|
|
15
|
-
|
|
25
|
+
name: definition.name, description: definition.description || '', icon: definition.icon || '', accent: definition.accent || null,
|
|
26
|
+
// Editor-only markers never ride on the copied items: the one editors_only key below carries them.
|
|
27
|
+
resources: manifestResources(definition.resources), actions: manifestActions(definition.actions),
|
|
16
28
|
...(definition.navigation ? { navigation: definition.navigation } : {}),
|
|
17
29
|
// Absent when none, so manifests without viewer reads stay byte-identical.
|
|
18
30
|
...(definition.viewerReads?.length ? { viewer_reads: [...definition.viewerReads].sort() } : {}),
|
|
19
31
|
// Absent when undeclared, for the same reason.
|
|
20
32
|
...(definition.cloudComputer ? { cloud_computer: definition.cloudComputer } : {}),
|
|
33
|
+
// Agents its database changes wake; absent when undeclared.
|
|
34
|
+
...(definition.agents?.length ? { agents: definition.agents } : {}),
|
|
35
|
+
// Absent when nothing is editor-only (SPC-073: unmarked means public).
|
|
36
|
+
...(editorsOnly ? { editors_only: editorsOnly } : {}),
|
|
21
37
|
readable_context: definition.readableContext || '', collection: definition.collection || null,
|
|
22
38
|
// V4 declarations are mandatory for every presentation; the wire schema stays v1.
|
|
23
39
|
...viewManifestFields(definition, { entry: selection.entry, resources: definition.resources || {} }),
|
|
@@ -5,8 +5,9 @@ import { dirname, extname, join, relative, resolve, sep } from 'node:path';
|
|
|
5
5
|
import { collectSourceFiles, loadAppConfig } from './app-platform.js';
|
|
6
6
|
import { usageError } from './errors.js';
|
|
7
7
|
import { VIEW_DEFINITION_FIELDS, viewManifestFields } from './space-view-manifest.js';
|
|
8
|
+
import { editorOnlyColumns, editorsOnlyFlag, withoutMarker } from './space-audience.js';
|
|
8
9
|
|
|
9
|
-
const CONFIG_FIELDS = new Set(['name', 'description', 'icon', 'accent', 'entry', 'layout', 'readableContext', 'resources', 'actions', 'navigation', 'viewerReads', 'cloudComputer', 'collection', 'sourceIncludes', 'verificationFixtures', ...VIEW_DEFINITION_FIELDS]);
|
|
10
|
+
const CONFIG_FIELDS = new Set(['name', 'description', 'icon', 'accent', 'entry', 'layout', 'readableContext', 'resources', 'actions', 'navigation', 'viewerReads', 'cloudComputer', 'agents', 'collection', 'sourceIncludes', 'verificationFixtures', 'editorsOnly', ...VIEW_DEFINITION_FIELDS]);
|
|
10
11
|
/** Reads with each signed-in viewer's own authority (never an issuer grant); see docs/notis-spaces-platform.md. */
|
|
11
12
|
export const VIEWER_READ_FAMILIES = Object.freeze(['databases', 'skills']);
|
|
12
13
|
const WORKSPACE_INDEXES = new Set(['notis.config.ts', 'notis.config.js', 'notis.config.mjs']);
|
|
@@ -88,6 +89,64 @@ function localPath(value) {
|
|
|
88
89
|
return value.replace(/^\.\//, '').replace(/\/$/, '');
|
|
89
90
|
}
|
|
90
91
|
|
|
92
|
+
const CLOUD_COMPUTER_LEVELS = ['read', 'shell'];
|
|
93
|
+
const CLOUD_COMPUTER_FIELDS = ['access', 'services'];
|
|
94
|
+
const CLOUD_SERVICE_FIELDS = ['id', 'command', 'cwd', 'ready'];
|
|
95
|
+
const CLOUD_SERVICE_ID = /^[a-z][a-z0-9-]{0,39}$/;
|
|
96
|
+
const MAX_CLOUD_SERVICES = 4;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* `cloudComputer` is 'read' | 'shell' | { access, services? }. The object is copied
|
|
100
|
+
* into the manifest as-is, so every rule here matches the server's own check.
|
|
101
|
+
*/
|
|
102
|
+
export function validateCloudComputer(value) {
|
|
103
|
+
const levels = "cloudComputer is 'read', 'shell' or { access: 'read' | 'shell', services? }: the page uses each signed-in viewer's own cloud computer once that viewer allows it.";
|
|
104
|
+
if (typeof value === 'string') {
|
|
105
|
+
if (!CLOUD_COMPUTER_LEVELS.includes(value)) throw usageError(levels);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) throw usageError(levels);
|
|
109
|
+
const unknown = Object.keys(value).filter(name => !CLOUD_COMPUTER_FIELDS.includes(name)).sort();
|
|
110
|
+
if (unknown.length) throw usageError(`Unsupported cloudComputer fields: ${unknown.join(', ')}. Use access and services.`);
|
|
111
|
+
if (!CLOUD_COMPUTER_LEVELS.includes(value.access)) throw usageError(levels);
|
|
112
|
+
if (value.services === undefined) return;
|
|
113
|
+
if (!Array.isArray(value.services)) throw usageError('cloudComputer.services is a list of { id, command, cwd?, ready? }.');
|
|
114
|
+
if (value.services.length && value.access !== 'shell') throw usageError("cloudComputer.services needs access: 'shell'.");
|
|
115
|
+
if (value.services.length > MAX_CLOUD_SERVICES) throw usageError(`cloudComputer declares at most ${MAX_CLOUD_SERVICES} services.`);
|
|
116
|
+
const seen = new Set();
|
|
117
|
+
for (const service of value.services) {
|
|
118
|
+
if (!service || typeof service !== 'object' || Array.isArray(service)) throw usageError('Each cloudComputer service is { id, command, cwd?, ready? }.');
|
|
119
|
+
const extra = Object.keys(service).filter(name => !CLOUD_SERVICE_FIELDS.includes(name)).sort();
|
|
120
|
+
if (extra.length) throw usageError(`Unsupported cloudComputer service fields: ${extra.join(', ')}. Use id, command, cwd and ready.`);
|
|
121
|
+
if (typeof service.id !== 'string' || !CLOUD_SERVICE_ID.test(service.id)) {
|
|
122
|
+
throw usageError('A cloudComputer service id starts with a lowercase letter, then up to 39 lowercase letters, digits or dashes.');
|
|
123
|
+
}
|
|
124
|
+
if (seen.has(service.id)) throw usageError(`cloudComputer service ${service.id} is declared twice.`);
|
|
125
|
+
seen.add(service.id);
|
|
126
|
+
const label = `cloudComputer service ${service.id}`;
|
|
127
|
+
if (typeof service.command !== 'string' || !service.command.trim() || service.command.length > 4096 || service.command.includes('\0')) {
|
|
128
|
+
throw usageError(`${label} needs a command of 1 to 4096 characters.`);
|
|
129
|
+
}
|
|
130
|
+
if (service.cwd !== undefined) {
|
|
131
|
+
if (typeof service.cwd === 'string') {
|
|
132
|
+
if (!service.cwd || service.cwd.length > 1024 || service.cwd.includes('\0')
|
|
133
|
+
|| service.cwd.split('/').some(part => part === '..')
|
|
134
|
+
|| (service.cwd.startsWith('/') && service.cwd !== '/vercel/sandbox' && !service.cwd.startsWith('/vercel/sandbox/'))) {
|
|
135
|
+
throw usageError(`${label} cwd is a cloud computer folder inside /vercel/sandbox, or { space: '<folder>' } inside the Space folder.`);
|
|
136
|
+
}
|
|
137
|
+
} else if (!service.cwd || typeof service.cwd !== 'object' || Array.isArray(service.cwd)
|
|
138
|
+
|| Object.keys(service.cwd).join(',') !== 'space' || typeof service.cwd.space !== 'string'
|
|
139
|
+
|| service.cwd.space.length > 1024 || service.cwd.space.startsWith('/') || service.cwd.space.includes('\0')
|
|
140
|
+
|| service.cwd.space.includes('\\') || service.cwd.space.split('/').some(part => part === '..')) {
|
|
141
|
+
throw usageError(`${label} cwd { space } is a folder relative to the Space folder, without a leading / or .. ('' or '.' is the Space folder).`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (service.ready !== undefined && (typeof service.ready !== 'string' || !service.ready.startsWith('/') || service.ready.length > 512)) {
|
|
145
|
+
throw usageError(`${label} ready is a path starting with / of at most 512 characters.`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
91
150
|
export async function loadSelectedSpace(projectDir, selectedKey) {
|
|
92
151
|
projectDir = realpathSync(projectDir);
|
|
93
152
|
selectedKey = key(selectedKey, 'Space');
|
|
@@ -130,11 +189,16 @@ export async function loadSelectedSpace(projectDir, selectedKey) {
|
|
|
130
189
|
if (!target || typeof target !== 'object' || Object.keys(target).join(',') !== 'key') throw usageError('A navigation reference needs one portable key.');
|
|
131
190
|
key(target.key, 'Navigation target');
|
|
132
191
|
}
|
|
192
|
+
// Editor-only parts (SPC-074): the whole view here, its columns on each database resource below.
|
|
193
|
+
if (editorsOnlyFlag(definition.editorsOnly, 'This view') && !entry) {
|
|
194
|
+
throw usageError('A container has no page, so it cannot be editors-only. Mark the views inside it.');
|
|
195
|
+
}
|
|
133
196
|
for (const [alias, resource] of Object.entries(resources)) {
|
|
134
197
|
key(alias, 'Resource alias');
|
|
198
|
+
editorOnlyColumns(alias, resource);
|
|
135
199
|
if (resource?.kind === 'database' && resource.create != null) {
|
|
136
200
|
const value = resource.create;
|
|
137
|
-
if (Object.keys(resource).some(name => !['kind', 'create'].includes(name))
|
|
201
|
+
if (Object.keys(resource).some(name => !['kind', 'create', 'columns'].includes(name))
|
|
138
202
|
|| !value || typeof value !== 'object' || Array.isArray(value)
|
|
139
203
|
|| Object.keys(value).some(name => !['name', 'schema', 'starterRows'].includes(name))
|
|
140
204
|
|| typeof value.name !== 'string' || !value.name.trim() || value.name.length > 200
|
|
@@ -149,7 +213,9 @@ export async function loadSelectedSpace(projectDir, selectedKey) {
|
|
|
149
213
|
continue;
|
|
150
214
|
}
|
|
151
215
|
if (!resource || !['database', 'document', 'skill', 'automation'].includes(resource.kind) || typeof resource.key !== 'string'
|
|
152
|
-
|| Object.keys(resource).some(name => !['kind', 'key'].includes(name)))
|
|
216
|
+
|| Object.keys(resource).some(name => !['kind', 'key', ...(resource.kind === 'database' ? ['columns'] : [])].includes(name))) {
|
|
217
|
+
throw usageError(`Invalid resource reference: ${alias}`);
|
|
218
|
+
}
|
|
153
219
|
}
|
|
154
220
|
if (definition.viewerReads != null && (!Array.isArray(definition.viewerReads)
|
|
155
221
|
|| definition.viewerReads.some(family => !VIEWER_READ_FAMILIES.includes(family))
|
|
@@ -157,15 +223,16 @@ export async function loadSelectedSpace(projectDir, selectedKey) {
|
|
|
157
223
|
throw usageError("viewerReads lists 'databases' and/or 'skills' once each: the page reads what each signed-in viewer can open.");
|
|
158
224
|
}
|
|
159
225
|
if (definition.viewerReads?.length && !entry) throw usageError('A container has no page, so it cannot declare viewerReads.');
|
|
160
|
-
if (definition.cloudComputer != null
|
|
161
|
-
throw usageError("cloudComputer is 'read' or 'shell': the page uses each signed-in viewer's own cloud computer once that viewer allows it.");
|
|
162
|
-
}
|
|
226
|
+
if (definition.cloudComputer != null) validateCloudComputer(definition.cloudComputer);
|
|
163
227
|
if (definition.cloudComputer != null && !entry) throw usageError('A container has no page, so it cannot use the cloud computer.');
|
|
228
|
+
if (definition.agents != null) validateSpaceAgents(definition.agents, resources);
|
|
164
229
|
if (definition.collection && (resources[definition.collection.database]?.kind !== 'database' || !definition.collection.titleProperty)) {
|
|
165
230
|
throw usageError('A collection needs a declared database binding and title property.');
|
|
166
231
|
}
|
|
167
|
-
for (const [actionId,
|
|
232
|
+
for (const [actionId, declared] of Object.entries(definition.actions || {})) {
|
|
168
233
|
key(actionId, 'Action');
|
|
234
|
+
editorsOnlyFlag(declared?.editorsOnly, `Action ${actionId}`);
|
|
235
|
+
const template = withoutMarker(declared);
|
|
169
236
|
if (!template || typeof template.tool !== 'string' || !template.tool || Object.keys(template).sort().join(',') !== 'arguments,inputs,tool'
|
|
170
237
|
|| template.inputs?.type !== 'object' || template.inputs?.additionalProperties !== false || !template.arguments || Array.isArray(template.arguments)) {
|
|
171
238
|
throw usageError(`Action ${actionId} needs the canonical closed inputs/tool/arguments template.`);
|
|
@@ -288,3 +355,34 @@ export function collectSelectedSpaceSource(projectDir, selection, { buildInputs
|
|
|
288
355
|
return result;
|
|
289
356
|
} finally { compiler.close(); }
|
|
290
357
|
}
|
|
358
|
+
|
|
359
|
+
const AGENT_FIELDS = ['id', 'on', 'thread', 'runtime', 'skill', 'wake', 'columns'];
|
|
360
|
+
const AGENT_COLUMNS = ['thread', 'scope', 'answer', 'author'];
|
|
361
|
+
|
|
362
|
+
/** The `agents` a Space's database changes wake (server/lib/space_agents.py repeats every check). */
|
|
363
|
+
export function validateSpaceAgents(agents, resources = {}) {
|
|
364
|
+
if (!Array.isArray(agents) || agents.length < 1 || agents.length > 8) throw usageError('Declare agents as a list of 1 to 8 agents.');
|
|
365
|
+
const seen = new Set();
|
|
366
|
+
for (const agent of agents) {
|
|
367
|
+
if (!agent || typeof agent !== 'object' || Array.isArray(agent) || Object.keys(agent).some(name => !AGENT_FIELDS.includes(name))) {
|
|
368
|
+
throw usageError(`Each agent takes ${AGENT_FIELDS.join(', ')} only.`);
|
|
369
|
+
}
|
|
370
|
+
if (typeof agent.id !== 'string' || !/^[a-z][a-z0-9_-]{0,39}$/.test(agent.id) || seen.has(agent.id)) {
|
|
371
|
+
throw usageError('Each agent needs its own short id: lowercase letters, digits, - and _.');
|
|
372
|
+
}
|
|
373
|
+
seen.add(agent.id);
|
|
374
|
+
const on = agent.on;
|
|
375
|
+
if (!on || typeof on !== 'object' || Object.keys(on).some(name => !['database', 'event'].includes(name)) || resources[on.database]?.kind !== 'database') {
|
|
376
|
+
throw usageError(`Agent ${agent.id} watches one of this Space's database resources: on: { database: '<alias>' }.`);
|
|
377
|
+
}
|
|
378
|
+
if (on.event != null && !['created', 'changed'].includes(on.event)) throw usageError(`Agent ${agent.id} wakes on 'created' or 'changed'.`);
|
|
379
|
+
if (agent.thread != null && !['best_match', 'space'].includes(agent.thread)) throw usageError(`Agent ${agent.id} uses thread 'best_match' or 'space'.`);
|
|
380
|
+
if (agent.runtime != null && !['notis', 'cloud_computer'].includes(agent.runtime)) throw usageError(`Agent ${agent.id} runs on 'notis' or 'cloud_computer'.`);
|
|
381
|
+
if (agent.wake != null && !['all', 'sent'].includes(agent.wake)) throw usageError(`Agent ${agent.id} wakes for 'all' comments or only those 'sent' to it.`);
|
|
382
|
+
if (agent.skill != null && resources[agent.skill]?.kind !== 'skill') throw usageError(`Agent ${agent.id} names a Skill this Space links.`);
|
|
383
|
+
if (agent.columns != null && (typeof agent.columns !== 'object' || Array.isArray(agent.columns)
|
|
384
|
+
|| Object.entries(agent.columns).some(([name, value]) => !AGENT_COLUMNS.includes(name) || typeof value !== 'string' || !value || value.length > 100))) {
|
|
385
|
+
throw usageError(`Agent ${agent.id} renames only the ${AGENT_COLUMNS.join(', ')} columns.`);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|