@notis_ai/cli 0.2.30 → 0.2.31
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 +1 -0
- package/dist/agent-hooks/notis-agent-hook.mjs +37890 -10794
- package/dist/base-skills/notis-cli/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-cli/references/native-databases.md +1 -1
- package/dist/base-skills/notis-query/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-query/references/query.md +6 -4
- package/dist/base-skills/notis-spaces/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-spaces/SKILL.md +8 -3
- package/dist/base-skills/notis-spaces/references/architecture.md +4 -1
- package/dist/base-skills/notis-spaces/references/design.md +7 -1
- package/dist/base-skills/notis-spaces/references/fixtures.md +27 -2
- package/dist/base-skills/notis-spaces/references/sdk.md +90 -31
- package/dist/base-skills/notis-spaces/references/troubleshooting.md +3 -0
- package/dist/base-skills/notis-spaces/references/views.md +20 -0
- package/dist/sdk/src/hooks/useNativeDocuments.ts +50 -12
- package/dist/sdk/src/index.ts +1 -1
- package/dist/sdk/src/space.ts +3 -1
- package/dist/sdk/src/tailwind.ts +53 -3
- package/dist/sdk/src/ui/icons.tsx +1 -0
- package/dist/sdk/src/words/types.ts +28 -0
- package/dist/skill-sync/index.js +10 -90
- package/dist/skill-sync-worker.mjs +50 -93
- package/dist/space-harness/host.js +150 -81
- package/dist/space-sdk/dist/chunk-3DFOGU26.js +3 -0
- package/dist/space-sdk/dist/index.js +2 -2
- package/dist/space-sdk/dist/ui.js +12 -12
- package/dist/space-sdk/src/hooks/useNativeDocuments.d.ts +23 -0
- package/dist/space-sdk/src/index.d.ts +1 -1
- package/dist/space-sdk/src/space.ts +3 -1
- package/dist/space-sdk/src/tailwind-candidates.d.ts +273 -2
- package/dist/space-sdk/src/tailwind.ts +53 -3
- package/dist/space-sdk/src/ui/blocks/DataTable.d.ts +19 -4
- package/dist/space-sdk/src/ui/blocks/Meter.d.ts +12 -3
- package/dist/space-sdk/src/ui/blocks/Tabs.d.ts +7 -1
- package/dist/space-sdk/src/ui/blocks/index.d.ts +1 -1
- package/dist/space-sdk/src/ui/charts/CalendarHeatmap.d.ts +69 -0
- package/dist/space-sdk/src/ui/charts/Chart.d.ts +18 -3
- package/dist/space-sdk/src/ui/charts/chartData.d.ts +19 -0
- package/dist/space-sdk/src/ui/charts/heatmapData.d.ts +81 -0
- package/dist/space-sdk/src/ui/index.d.ts +4 -2
- package/dist/space-sdk/src/ui/list/Row.d.ts +11 -1
- package/dist/space-sdk/src/ui/period/dateFormat.d.ts +2 -0
- package/dist/space-sdk/src/ui/period/dateWords.d.ts +9 -0
- package/dist/space-sdk/src/ui/period/periods.d.ts +15 -2
- package/dist/space-sdk/src/words/types.ts +28 -0
- package/dist/view-renderer/dist/host.js +219 -150
- package/dist/view-renderer/src/dom.js +3 -2
- package/dist/view-renderer/src/errors.js +9 -0
- package/dist/view-renderer/src/host.tsx +12 -5
- package/dist/view-renderer/src/remote-broker.js +3 -1
- package/dist/view-renderer/src/renderer.js +63 -16
- package/dist/view-renderer/src/skeleton.js +70 -18
- package/package.json +5 -4
- package/skills/notis-query/cli.md +3 -0
- package/src/command-specs/spaces.js +71 -15
- package/src/command-specs/tools.js +3 -0
- package/src/runtime/api-hosts.generated.js +35 -0
- package/src/runtime/api-hosts.js +27 -10
- package/src/runtime/app-platform.js +68 -24
- package/src/runtime/http-agent.js +53 -0
- package/src/runtime/native-record-files.js +11 -0
- package/src/runtime/oauth.js +2 -1
- package/src/runtime/skill-sync/cloud-client.ts +0 -10
- package/src/runtime/skill-sync/index.ts +13 -15
- package/src/runtime/skill-sync/local-scanner.ts +0 -67
- package/src/runtime/skill-sync/types.ts +1 -0
- package/src/runtime/skill-sync/write-cloud-skill.ts +7 -23
- package/src/runtime/space-dependencies.js +66 -0
- package/src/runtime/space-fixture-broker.js +23 -8
- package/src/runtime/space-platform.js +47 -3
- package/src/runtime/space-source.js +10 -1
- package/src/runtime/space-test-server.js +105 -6
- package/src/runtime/space-verification.js +103 -43
- package/src/runtime/space-view-manifest.js +38 -5
- package/src/runtime/transport.js +19 -4
- package/src/runtime/view-render.js +4 -1
- package/template/tailwind.config.ts +2 -35
- package/dist/space-sdk/dist/chunk-6GJ2BS7B.js +0 -3
|
@@ -953,54 +953,6 @@ async function createZipFromDirectory(directoryPath: string): Promise<string> {
|
|
|
953
953
|
}
|
|
954
954
|
}
|
|
955
955
|
|
|
956
|
-
async function extractZipToDirectory(
|
|
957
|
-
zipPath: string,
|
|
958
|
-
destinationDir: string,
|
|
959
|
-
): Promise<string[]> {
|
|
960
|
-
const extractRoot = await fs.mkdtemp(
|
|
961
|
-
path.join(os.tmpdir(), "notis-skill-extract-"),
|
|
962
|
-
);
|
|
963
|
-
|
|
964
|
-
try {
|
|
965
|
-
if (process.platform === "win32") {
|
|
966
|
-
await execFileAsync("powershell.exe", [
|
|
967
|
-
"-NoProfile",
|
|
968
|
-
"-Command",
|
|
969
|
-
`Expand-Archive -Path '${zipPath.replace(/'/g, "''")}' -DestinationPath '${extractRoot.replace(/'/g, "''")}' -Force`,
|
|
970
|
-
]);
|
|
971
|
-
} else {
|
|
972
|
-
await execFileAsync("unzip", ["-qq", zipPath, "-d", extractRoot]);
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
const extractedEntries = await fs.readdir(extractRoot, {
|
|
976
|
-
withFileTypes: true,
|
|
977
|
-
});
|
|
978
|
-
const extractedDirectory = extractedEntries.find((entry) =>
|
|
979
|
-
entry.isDirectory(),
|
|
980
|
-
);
|
|
981
|
-
const sourceDir = extractedDirectory
|
|
982
|
-
? path.join(extractRoot, extractedDirectory.name)
|
|
983
|
-
: extractRoot;
|
|
984
|
-
|
|
985
|
-
await fs.rm(destinationDir, { recursive: true, force: true });
|
|
986
|
-
await fs.mkdir(path.dirname(destinationDir), { recursive: true });
|
|
987
|
-
await fs.cp(sourceDir, destinationDir, { recursive: true });
|
|
988
|
-
return await listRelativeFiles(destinationDir);
|
|
989
|
-
} finally {
|
|
990
|
-
await fs.rm(extractRoot, { recursive: true, force: true });
|
|
991
|
-
}
|
|
992
|
-
}
|
|
993
|
-
|
|
994
|
-
async function listRelativeFiles(dirPath: string): Promise<string[]> {
|
|
995
|
-
try {
|
|
996
|
-
const files = await listFilesRecursive(dirPath);
|
|
997
|
-
return files.map((filePath) => toPosixRelativePath(dirPath, filePath)).sort();
|
|
998
|
-
} catch (error) {
|
|
999
|
-
if ((error as NodeJS.ErrnoException)?.code === "ENOENT") return [];
|
|
1000
|
-
throw error;
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
956
|
function toPosixRelativePath(rootDir: string, filePath: string): string {
|
|
1005
957
|
return path.relative(rootDir, filePath).split(path.sep).join("/");
|
|
1006
958
|
}
|
|
@@ -1178,14 +1130,12 @@ export async function captureNativeSkillFiles(skill: LocalSkill): Promise<Bundle
|
|
|
1178
1130
|
|
|
1179
1131
|
export async function writeCloudSkillToDisk(
|
|
1180
1132
|
skill: CloudSkill,
|
|
1181
|
-
bundleBytes?: Buffer,
|
|
1182
1133
|
paths: SkillSyncPaths = DEFAULT_SYNC_PATHS,
|
|
1183
1134
|
options: { previouslyApplied?: readonly string[]; expectedFolderHash?: string; legacyBaseline?: boolean } = {},
|
|
1184
1135
|
): Promise<SkillWriteOutcome | false> {
|
|
1185
1136
|
if (isNativeSkill(skill)) {
|
|
1186
1137
|
assertNativePull({ skills: [{ ...skill, name: 'native-' + skill.id }], skill_sync_protocol: 2, sync_scope: skill.native_scope,
|
|
1187
1138
|
sync_enabled: true, last_synced_at: null });
|
|
1188
|
-
if (bundleBytes?.length) throw new Error('Native Skills require their verified complete file response.');
|
|
1189
1139
|
}
|
|
1190
1140
|
const skillDir = path.join(
|
|
1191
1141
|
paths.skillsDir,
|
|
@@ -1196,23 +1146,6 @@ export async function writeCloudSkillToDisk(
|
|
|
1196
1146
|
// An unchanged legacy folder upgrading in place: shared files take the cloud version.
|
|
1197
1147
|
legacyBaseline: isNativeSkill(skill) && options.legacyBaseline === true && options.expectedFolderHash !== undefined };
|
|
1198
1148
|
|
|
1199
|
-
if (bundleBytes?.length) {
|
|
1200
|
-
const bundlePath = path.join(
|
|
1201
|
-
os.tmpdir(),
|
|
1202
|
-
`notis-skill-download-${Date.now()}-${Math.random().toString(36).slice(2)}.zip`,
|
|
1203
|
-
);
|
|
1204
|
-
try {
|
|
1205
|
-
await fs.writeFile(bundlePath, bundleBytes);
|
|
1206
|
-
let appliedFiles: string[] = [];
|
|
1207
|
-
await replaceSkillDirectoryAtomically(skillDir, async (stagingDir) => {
|
|
1208
|
-
appliedFiles = await extractZipToDirectory(bundlePath, stagingDir);
|
|
1209
|
-
}, preserve);
|
|
1210
|
-
return { written: true, appliedFiles };
|
|
1211
|
-
} finally {
|
|
1212
|
-
await fs.rm(bundlePath, { force: true });
|
|
1213
|
-
}
|
|
1214
|
-
}
|
|
1215
|
-
|
|
1216
1149
|
if (
|
|
1217
1150
|
!skill.skill_md &&
|
|
1218
1151
|
(!skill.bundle_files || skill.bundle_files.length === 0)
|
|
@@ -85,6 +85,7 @@ export interface CloudSkill {
|
|
|
85
85
|
skill_md: string | null;
|
|
86
86
|
agent_targets?: Partial<AgentTargets> | null;
|
|
87
87
|
skill_folder_hash?: string | null;
|
|
88
|
+
/** Where the Skill came from. Provenance only: sync never downloads it (SKL-059). */
|
|
88
89
|
skill_source_url?: string | null;
|
|
89
90
|
bundle_files?: BundleFile[] | null;
|
|
90
91
|
bundle_hydration_failed?: boolean | null;
|
|
@@ -1,35 +1,19 @@
|
|
|
1
1
|
import type { CloudSkill, SkillWriteOutcome } from './types';
|
|
2
2
|
|
|
3
3
|
interface WriteCloudSkillDependencies {
|
|
4
|
-
|
|
5
|
-
writeCloudSkillToDisk: (skill: CloudSkill, bundleBytes?: Buffer) => Promise<SkillWriteOutcome | boolean>;
|
|
4
|
+
writeCloudSkillToDisk: (skill: CloudSkill) => Promise<SkillWriteOutcome | boolean>;
|
|
6
5
|
onWarning?: (message: string, error: unknown) => void;
|
|
7
6
|
}
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Writes one pulled Skill from what the pull itself carries: its saved files
|
|
10
|
+
* (`bundle_files`) or, without them, its SKILL.md. Nothing is downloaded;
|
|
11
|
+
* `skill_source_url` only records where a Skill came from (SKL-059).
|
|
12
|
+
*/
|
|
13
|
+
export async function writeCloudSkill(
|
|
10
14
|
skill: CloudSkill,
|
|
11
15
|
dependencies: WriteCloudSkillDependencies,
|
|
12
16
|
): Promise<SkillWriteOutcome | boolean> {
|
|
13
|
-
if (skill.skill_source_url) {
|
|
14
|
-
try {
|
|
15
|
-
const bundleBytes = await dependencies.downloadSkillBundle(skill.skill_source_url);
|
|
16
|
-
const wroteBundleToDisk = await dependencies.writeCloudSkillToDisk(skill, bundleBytes);
|
|
17
|
-
if (wroteBundleToDisk) {
|
|
18
|
-
return wroteBundleToDisk;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
dependencies.onWarning?.(
|
|
22
|
-
`Bundle sync for "${skill.name}" produced no local changes, falling back to SKILL.md payload.`,
|
|
23
|
-
new Error('Bundle write returned false'),
|
|
24
|
-
);
|
|
25
|
-
} catch (error) {
|
|
26
|
-
dependencies.onWarning?.(
|
|
27
|
-
`Failed to apply bundle sync for "${skill.name}", falling back to SKILL.md payload.`,
|
|
28
|
-
error,
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
17
|
if (skill.bundle_hydration_failed) {
|
|
34
18
|
dependencies.onWarning?.(
|
|
35
19
|
`Skipping markdown fallback for synced skill "${skill.name}" because its stored bundle could not be hydrated by the server.`,
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Space workspace builds with its own packages (TypeScript, Vite, Tailwind, React, the SDK). A folder that
|
|
3
|
+
* has never been installed (a copy, a fresh clone, a scaffold) gets them on its first `notis spaces build`:
|
|
4
|
+
* `npm ci` from its lock file, `--prefer-offline` so every package this machine has already downloaded for
|
|
5
|
+
* another Space comes from npm's shared cache instead of the network. A workspace that is already installed
|
|
6
|
+
* is never touched.
|
|
7
|
+
*/
|
|
8
|
+
import { spawnSync } from 'node:child_process';
|
|
9
|
+
import { existsSync } from 'node:fs';
|
|
10
|
+
import { createRequire } from 'node:module';
|
|
11
|
+
import { join } from 'node:path';
|
|
12
|
+
import { usageError } from './errors.js';
|
|
13
|
+
import { npmFailureReason } from './app-platform.js';
|
|
14
|
+
|
|
15
|
+
const INSTALL_TIMEOUT_MS = 10 * 60_000;
|
|
16
|
+
// --include=dev: a build needs the devDependencies (TypeScript, Vite, Tailwind) even under NODE_ENV=production or omit=dev.
|
|
17
|
+
const INSTALL_FLAGS = Object.freeze(['--include=dev', '--prefer-offline', '--no-audit', '--no-fund']);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* True when the package a build loads first resolves from this workspace, the way the build resolves it:
|
|
21
|
+
* from its own node_modules or an ancestor's (an npm workspace member installed at the root).
|
|
22
|
+
*/
|
|
23
|
+
export function spaceDependenciesInstalled(projectDir) {
|
|
24
|
+
const require = createRequire(join(projectDir, 'package.json'));
|
|
25
|
+
try { require.resolve('typescript/package.json'); return true; } catch { return false; }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function runNpm(args, projectDir) {
|
|
29
|
+
// A verbose npm config can print more than spawnSync's 1 MB default before it finishes.
|
|
30
|
+
return spawnSync('npm', args, { cwd: projectDir, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 64 * 1024 * 1024,
|
|
31
|
+
timeout: INSTALL_TIMEOUT_MS, shell: process.platform === 'win32' });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Install this workspace's packages when it has none yet. Returns what it did, for the build answer:
|
|
36
|
+
* `null` when nothing was needed, else `{ command, seconds }`.
|
|
37
|
+
*/
|
|
38
|
+
export function ensureSpaceDependencies(projectDir, { log = () => {}, run = runNpm } = {}) {
|
|
39
|
+
if (!existsSync(join(projectDir, 'package.json')) || spaceDependenciesInstalled(projectDir)) return null;
|
|
40
|
+
const locked = existsSync(join(projectDir, 'package-lock.json'));
|
|
41
|
+
let args = [locked ? 'ci' : 'install', ...INSTALL_FLAGS];
|
|
42
|
+
let command = `npm ${args.join(' ')}`;
|
|
43
|
+
log(`This Space folder has no installed packages yet: running ${command} once (packages this machine already has come from npm's cache).`);
|
|
44
|
+
const started = Date.now();
|
|
45
|
+
let result = run(args, projectDir);
|
|
46
|
+
if (locked && result.status !== 0 && !result.error && /in sync/i.test(`${result.stderr || ''}\n${result.stdout || ''}`)) {
|
|
47
|
+
// package.json gained a package its lock file does not hold yet: npm install records it instead of refusing.
|
|
48
|
+
args = ['install', ...INSTALL_FLAGS];
|
|
49
|
+
command = `npm ${args.join(' ')}`;
|
|
50
|
+
log(`package-lock.json does not match package.json yet: running ${command} instead.`);
|
|
51
|
+
result = run(args, projectDir);
|
|
52
|
+
}
|
|
53
|
+
const seconds = Math.round((Date.now() - started) / 100) / 10;
|
|
54
|
+
if (result.error || result.status !== 0) {
|
|
55
|
+
const reason = result.error?.code === 'ETIMEDOUT' ? 'it did not finish within 10 minutes'
|
|
56
|
+
: result.error?.code === 'ENOENT' ? 'npm is not installed on this machine'
|
|
57
|
+
: npmFailureReason(`${result.stderr || ''}\n${result.stdout || ''}`) || `npm exited with code ${result.status}`;
|
|
58
|
+
throw usageError(`Installing this Space's packages failed (${command}: ${reason}). Nothing was built. `
|
|
59
|
+
+ `Fix that, or run ${command} in ${projectDir} yourself, then build again.`);
|
|
60
|
+
}
|
|
61
|
+
if (!spaceDependenciesInstalled(projectDir)) {
|
|
62
|
+
throw usageError(`${command} finished but TypeScript is still missing from this Space's packages. Add typescript to its devDependencies, then build again.`);
|
|
63
|
+
}
|
|
64
|
+
log(`Installed this Space's packages in ${seconds} s.`);
|
|
65
|
+
return { command, seconds };
|
|
66
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Pure fixture adapter for the exact CLI/service renderer; no network client. */
|
|
2
|
-
import { createSpaceFixtureEngine, spaceHarnessSnapshot } from './space-test-server.js';
|
|
2
|
+
import { createSpaceFixtureEngine, selectedFixtureContext, spaceHarnessSnapshot } from './space-test-server.js';
|
|
3
3
|
import { usageError } from './errors.js';
|
|
4
4
|
|
|
5
5
|
const object = value => value && typeof value === 'object' && !Array.isArray(value);
|
|
@@ -21,25 +21,38 @@ export function fixtureSkeletonParams(release) {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
24
|
+
* The fixture contexts verify opens the view in, in order: `[{ name, params, open }]` (`open`: the params open a list
|
|
25
|
+
* item through ListReader's default `open` param). Unreadable fixtures give none; verify reports them on its own.
|
|
26
|
+
*/
|
|
27
|
+
export function fixtureContexts(release) {
|
|
28
|
+
let engine;
|
|
29
|
+
try { engine = createSpaceFixtureEngine(release); } catch { return []; }
|
|
30
|
+
return engine.contexts.map(({ name, context }) => ({ name, params: structuredClone(context.params || {}),
|
|
31
|
+
open: typeof context.params?.open === 'string' && context.params.open.length > 0 }));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* `context` names the fixture context to open the view with (default: the first). `audience: 'public'` draws the view as the public sees it: the editor's descriptor with View as the public on, so
|
|
25
36
|
* the page applies the public floors itself (no editor-only lists, actions, params or columns), as in the Portal.
|
|
26
37
|
*/
|
|
27
38
|
export function createSpaceFixtureBroker({ release, capabilities, width, outputs = ['markdown', 'screenshot'],
|
|
28
|
-
authorizationMode = 'authorize_missing', unavailableActions = [], onFailure, params: paramsOverride, audience = 'editor' }) {
|
|
39
|
+
authorizationMode = 'authorize_missing', unavailableActions = [], onFailure, params: paramsOverride, audience = 'editor', context: contextName }) {
|
|
29
40
|
const engine = createSpaceFixtureEngine(release);
|
|
30
|
-
const
|
|
41
|
+
const selected = selectedFixtureContext(engine, contextName).context;
|
|
42
|
+
const frozen = spaceHarnessSnapshot(release, capabilities, engine, { authorizationMode, unavailableActions, context: contextName });
|
|
31
43
|
if (audience === 'public') frozen.descriptor.space.viewAs = 'public';
|
|
32
44
|
const calls = [];
|
|
33
45
|
// Skeleton capture may open the view with other params (a tab), on top of the fixture's own.
|
|
34
|
-
const params = structuredClone({ ...(
|
|
46
|
+
const params = structuredClone({ ...(selected.params || {}), ...(paramsOverride || {}) });
|
|
35
47
|
// The fixture's own "now" pins the browser clock, so a view that asks for the
|
|
36
48
|
// last hour sends the exact inputs its fixtures recorded.
|
|
37
|
-
const now =
|
|
49
|
+
const now = selected.now;
|
|
38
50
|
const fixedClock = typeof now === 'string' && Number.isFinite(Date.parse(now)) ? { fixed_clock: now } : {};
|
|
39
51
|
const value = { ...frozen, url: `https://app.notis.ai/verification/${encodeURIComponent(release.manifest.local_key)}`,
|
|
40
52
|
view: { space_id: frozen.descriptor.resource.id, name: release.manifest.name, revision: 1 },
|
|
41
|
-
locale:
|
|
42
|
-
markdownExport: release.manifest.markdown?.export_name || null, render_options: { outputs, width }, ...fixedClock
|
|
53
|
+
locale: selected.locale === 'fr' ? 'fr' : 'en', params,
|
|
54
|
+
markdownExport: release.manifest.markdown?.export_name || null, render_options: { outputs, width }, ...fixedClock,
|
|
55
|
+
asset_images: [...engine.imageUrls] };
|
|
43
56
|
return {
|
|
44
57
|
fixtureDigest: engine.digest,
|
|
45
58
|
calls,
|
|
@@ -80,6 +93,8 @@ export function createSpaceFixtureBroker({ release, capabilities, width, outputs
|
|
|
80
93
|
} else if (request?.operation === 'document_body' && exact(request, ['operation', 'record_key', 'binding', 'read_action'])) {
|
|
81
94
|
if (frozen.descriptor.space.actions[request.read_action]?.readOnly !== true) throw usageError('This document read action is unavailable.');
|
|
82
95
|
result = engine.executeBody({ operation: 'read', recordKey: request.record_key, binding: request.binding, readAction: request.read_action });
|
|
96
|
+
} else if (request?.operation === 'asset' && exact(request, ['operation', 'url', 'kind']) && request.kind === 'image') {
|
|
97
|
+
result = engine.executeImage(request.url);
|
|
83
98
|
} else if (['record', 'html', 'report'].includes(request?.operation) && exact(request, ['operation', 'record_key'])) {
|
|
84
99
|
result = engine.executeRecordView(request.operation, request.record_key);
|
|
85
100
|
} else {
|
|
@@ -8,6 +8,7 @@ import { viewManifestFields } from './space-view-manifest.js';
|
|
|
8
8
|
import { editorsOnlySummary, manifestActions, manifestResources } from './space-audience.js';
|
|
9
9
|
import { usageError } from './errors.js';
|
|
10
10
|
import { assertSourceRoot } from './source-root.js';
|
|
11
|
+
import { ensureSpaceDependencies } from './space-dependencies.js';
|
|
11
12
|
|
|
12
13
|
const SPACE_ICON = /^(phosphor:[a-z0-9]+(-[a-z0-9]+)*|https:\/\/\S{1,2000})$/;
|
|
13
14
|
|
|
@@ -102,9 +103,12 @@ function finalizeSelectedArtifact(projectDir) {
|
|
|
102
103
|
* dependencies; it is not another authoring project or dependency installation.
|
|
103
104
|
* The existing pinned freeze/receipt code owns all staging writes and cleanup.
|
|
104
105
|
*/
|
|
105
|
-
export async function buildSpaceRelease(projectDir, selectedKey, { stdio = 'inherit', refreshSdk = true, runBuild, designBar = 'enforce', designLog = null
|
|
106
|
+
export async function buildSpaceRelease(projectDir, selectedKey, { stdio = 'inherit', refreshSdk = true, runBuild, designBar = 'enforce', designLog = null,
|
|
107
|
+
installDependencies = false, installLog } = {}) {
|
|
106
108
|
projectDir = assertSourceRoot(projectDir);
|
|
107
109
|
if (refreshSdk) syncSpaceSdk(projectDir);
|
|
110
|
+
// After the SDK sync, so the install follows the lock file that sync keeps in step with the SDK.
|
|
111
|
+
const installed = installDependencies ? ensureSpaceDependencies(projectDir, { log: installLog }) : null;
|
|
108
112
|
const selection = await loadSelectedSpace(projectDir, selectedKey);
|
|
109
113
|
const sourceFiles = collectSelectedSpaceSource(projectDir, selection);
|
|
110
114
|
const sourceHash = appFilesDigest(sourceFiles);
|
|
@@ -122,7 +126,8 @@ export async function buildSpaceRelease(projectDir, selectedKey, { stdio = 'inhe
|
|
|
122
126
|
if (sourceHash !== appFilesDigest(collectSelectedSpaceSource(projectDir, current))) throw usageError('This Space source changed during the selected build. Build again.');
|
|
123
127
|
release = prepareAppRelease(staging.projectDir);
|
|
124
128
|
const close = release.close;
|
|
125
|
-
return { ...release, selectedKey, sourceHash, fixturePath: selection.fixturePath,
|
|
129
|
+
return { ...release, selectedKey, sourceHash, fixturePath: selection.fixturePath, ...(installed ? { installed } : {}),
|
|
130
|
+
close() { try { close(); } finally { staging.close(); } } };
|
|
126
131
|
} catch (error) {
|
|
127
132
|
try { release?.close(); } finally { staging.close(); }
|
|
128
133
|
throw error;
|
|
@@ -133,10 +138,49 @@ export async function buildSpaceArtifact(projectDir, selectedKey, options) {
|
|
|
133
138
|
const release = await buildSpaceRelease(projectDir, selectedKey, options);
|
|
134
139
|
try {
|
|
135
140
|
const receiptPath = saveSelectedBuild(projectDir, selectedKey, release);
|
|
136
|
-
return { manifest: release.manifest, receiptPath, sourceHash: release.sourceHash };
|
|
141
|
+
return { manifest: release.manifest, receiptPath, sourceHash: release.sourceHash, ...(release.installed ? { installed_dependencies: release.installed } : {}) };
|
|
137
142
|
} finally { release.close(); }
|
|
138
143
|
}
|
|
139
144
|
|
|
145
|
+
const SQL_READ_HEADER = /^\/\* notis-postgres-read-v\d+ \*\/\n/;
|
|
146
|
+
|
|
147
|
+
/** Declared actions whose query starts with a SQL read header line (the server's requests_read). */
|
|
148
|
+
export function sqlReadActions(manifest) {
|
|
149
|
+
return Object.fromEntries(Object.entries(manifest?.actions || {}).filter(([, template]) => {
|
|
150
|
+
let query = template?.arguments?.query;
|
|
151
|
+
if (query && typeof query === 'object') query = query.$literal ?? query.$sql?.parts?.[0];
|
|
152
|
+
return typeof query === 'string' && SQL_READ_HEADER.test(query);
|
|
153
|
+
}));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Check every declared SQL read with the server's compiler before verification. A compiled read
|
|
158
|
+
* passes unchanged; a header line and plain SELECT joins the release compiled, in memory only, so
|
|
159
|
+
* the source keeps the plain query and each build compiles it to the same bytes. A refused read
|
|
160
|
+
* stops here with the compiler's reason.
|
|
161
|
+
*/
|
|
162
|
+
export async function compileSpaceSqlReads(release, call) {
|
|
163
|
+
const actions = sqlReadActions(release.manifest);
|
|
164
|
+
if (!Object.keys(actions).length) return [];
|
|
165
|
+
let response;
|
|
166
|
+
try { response = await call('sql-reads', { actions }); }
|
|
167
|
+
catch (error) {
|
|
168
|
+
// A server from before this check: compiled reads go on to its own verification.
|
|
169
|
+
if (error?.httpStatus !== 404) throw error;
|
|
170
|
+
const plain = Object.values(actions).filter(template => !JSON.stringify(template.arguments.query).includes('/* guarded-relations:'));
|
|
171
|
+
if (!plain.length) return [];
|
|
172
|
+
throw usageError('This Notis server cannot compile SQL reads yet. Write each read compiled, or verify against a newer server.');
|
|
173
|
+
}
|
|
174
|
+
const compiled = response.payload?.actions || {};
|
|
175
|
+
const names = Object.keys(compiled).filter(name => Object.hasOwn(actions, name));
|
|
176
|
+
if (!names.length) return [];
|
|
177
|
+
const manifest = { ...release.manifest, actions: { ...release.manifest.actions } };
|
|
178
|
+
for (const name of names) manifest.actions[name] = compiled[name];
|
|
179
|
+
release.manifest = manifest;
|
|
180
|
+
release.files = { ...release.files, 'manifest.json': Buffer.from(JSON.stringify(manifest, null, 2), 'utf8').toString('base64') };
|
|
181
|
+
return names;
|
|
182
|
+
}
|
|
183
|
+
|
|
140
184
|
export async function prepareSpaceRelease(projectDir, selectedKey) {
|
|
141
185
|
const selection = await loadSelectedSpace(projectDir, selectedKey);
|
|
142
186
|
const source = collectSelectedSpaceSource(projectDir, selection);
|
|
@@ -4,6 +4,7 @@ import { realpathSync } from 'node:fs';
|
|
|
4
4
|
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
|
+
import { fixtureImageEntries } from './space-test-server.js';
|
|
7
8
|
import { VIEW_DEFINITION_FIELDS, viewManifestFields } from './space-view-manifest.js';
|
|
8
9
|
import { editorOnlyColumns, editorsOnlyFlag, withoutMarker } from './space-audience.js';
|
|
9
10
|
|
|
@@ -308,7 +309,15 @@ export function collectSelectedSpaceSource(projectDir, selection, { buildInputs
|
|
|
308
309
|
if (selection.entry) add(selection.entry);
|
|
309
310
|
if (selection.layout) add(selection.layout);
|
|
310
311
|
if (selection.markdown) add(selection.markdown);
|
|
311
|
-
if (selection.fixturePath)
|
|
312
|
+
if (selection.fixturePath) {
|
|
313
|
+
add(selection.fixturePath);
|
|
314
|
+
// The image files the fixtures show travel with them; verify reports a bad entry on its own.
|
|
315
|
+
let fixtures;
|
|
316
|
+
try { fixtures = JSON.parse(Buffer.from(files[selection.fixturePath], 'base64').toString('utf8')); } catch { fixtures = null; }
|
|
317
|
+
let images = [];
|
|
318
|
+
try { images = fixtureImageEntries(fixtures, selection.fixturePath); } catch { /* Reported by verify. */ }
|
|
319
|
+
for (const { path } of images) if (Object.hasOwn(files, path)) try { add(path); } catch { /* Verify names the file it cannot use. */ }
|
|
320
|
+
}
|
|
312
321
|
for (const include of selection.definition.sourceIncludes || []) {
|
|
313
322
|
const path = selection.resolveDefinitionPath(include);
|
|
314
323
|
const matches = Object.keys(files).filter(name => name === path || name.startsWith(path + '/'));
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
3
|
import { readFileSync } from 'node:fs';
|
|
4
4
|
import { createServer } from 'node:http';
|
|
5
|
-
import { dirname, join, resolve } from 'node:path';
|
|
5
|
+
import { dirname, extname, join, posix, resolve } from 'node:path';
|
|
6
6
|
import { isDeepStrictEqual } from 'node:util';
|
|
7
7
|
import { fileURLToPath } from 'node:url';
|
|
8
8
|
import Ajv2020 from 'ajv/dist/2020.js';
|
|
9
9
|
import addFormats from 'ajv-formats';
|
|
10
|
-
import { appFilesDigest } from './app-platform.js';
|
|
10
|
+
import { appFilesDigest, VERIFY_CONTEXT_NAME } from './app-platform.js';
|
|
11
11
|
import { usageError } from './errors.js';
|
|
12
12
|
|
|
13
13
|
const ROOT=resolve(dirname(fileURLToPath(import.meta.url)),'../..');
|
|
@@ -58,6 +58,83 @@ function recordViewExample(operation,key) {
|
|
|
58
58
|
}[operation];
|
|
59
59
|
return JSON.stringify({operation,record_key:key,result});
|
|
60
60
|
}
|
|
61
|
+
const FIXTURE_CONTEXTS_MAX=4;
|
|
62
|
+
/**
|
|
63
|
+
* View params a fixture opens the view with: a flat object, as a link carries them. Numbers and true or false are
|
|
64
|
+
* kept (the host passes every param as text, as it always did); nested values are refused.
|
|
65
|
+
*/
|
|
66
|
+
function checkContextFields(value,where) {
|
|
67
|
+
if(value.params!==undefined && (!object(value.params) || Object.values(value.params).some(item=>!['string','number','boolean'].includes(typeof item)))) {
|
|
68
|
+
throw usageError(`${where} params must be an object of text, number or true/false values, as a link carries them (for example {"period": "week"}).`);
|
|
69
|
+
}
|
|
70
|
+
if(value.now!==undefined && (typeof value.now!=='string' || !Number.isFinite(Date.parse(value.now)))) {
|
|
71
|
+
throw usageError(`${where} now must be a date string, such as "2026-03-01T09:00:00Z".`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The states verify opens the view in: `contexts` (1 to 4 named ones, each with optional params, now and locale), or
|
|
76
|
+
* the one `context`, named default. Each entry keeps the object the view receives as its runtime context.
|
|
77
|
+
*/
|
|
78
|
+
function fixtureContexts(fixtures) {
|
|
79
|
+
if(fixtures.contexts===undefined) {
|
|
80
|
+
const value=fixtures.context || {};
|
|
81
|
+
checkContextFields(value,'The fixture context');
|
|
82
|
+
return [{name:'default',context:value}];
|
|
83
|
+
}
|
|
84
|
+
if(fixtures.context!==undefined) throw usageError('Verification fixtures declare either context or contexts, not both. Move context into contexts as one named entry.');
|
|
85
|
+
const list=fixtures.contexts;
|
|
86
|
+
if(!Array.isArray(list) || !list.length || list.length>FIXTURE_CONTEXTS_MAX) throw usageError(`Declare contexts as a list of 1 to ${FIXTURE_CONTEXTS_MAX} named contexts.`);
|
|
87
|
+
const names=new Set();
|
|
88
|
+
return list.map((value,index)=>{
|
|
89
|
+
const where=`Fixture context ${index+1}`;
|
|
90
|
+
if(!object(value) || Object.keys(value).some(key=>!['name','params','now','locale'].includes(key))) {
|
|
91
|
+
throw usageError(`${where} takes only name, params, now and locale.`);
|
|
92
|
+
}
|
|
93
|
+
if(typeof value.name!=='string' || !VERIFY_CONTEXT_NAME.test(value.name)) {
|
|
94
|
+
throw usageError(`${where} needs a name of lowercase letters, digits, "-" or "_" (at most 32), such as "this-week".`);
|
|
95
|
+
}
|
|
96
|
+
if(names.has(value.name)) throw usageError(`Two fixture contexts are named ${value.name}; give each its own name.`);
|
|
97
|
+
names.add(value.name);
|
|
98
|
+
checkContextFields(value,`Fixture context ${value.name}`);
|
|
99
|
+
const {name,...context}=value;
|
|
100
|
+
return {name,context};
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Fixture images: a URL the fixture rows hold (a photo, a cover) shows an image file kept next to the fixtures.
|
|
105
|
+
export const FIXTURE_IMAGES_MAX=32;
|
|
106
|
+
export const FIXTURE_IMAGE_BYTES_MAX=2*1024*1024;
|
|
107
|
+
// All of them together stay under what one render may load (32 MB, view-renderer).
|
|
108
|
+
export const FIXTURE_IMAGES_TOTAL_BYTES_MAX=16*1024*1024;
|
|
109
|
+
const FIXTURE_IMAGE_TYPES={'.png':'image/png','.jpg':'image/jpeg','.jpeg':'image/jpeg','.webp':'image/webp','.gif':'image/gif','.avif':'image/avif'};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* `images` of a fixture file: `{ "<https URL a row holds>": "<image file, relative to the fixture file>" }`, as
|
|
113
|
+
* `[{url, path, type}]` with `path` relative to the Space folder. Throws on anything else.
|
|
114
|
+
*/
|
|
115
|
+
export function fixtureImageEntries(fixtures,fixturePath) {
|
|
116
|
+
const images=fixtures?.images;
|
|
117
|
+
if(images===undefined) return [];
|
|
118
|
+
const where=fixturePath ? ` in ${fixturePath}` : '';
|
|
119
|
+
if(!object(images) || Object.keys(images).length>FIXTURE_IMAGES_MAX) {
|
|
120
|
+
throw usageError(`Declare fixture images${where} as an object of at most ${FIXTURE_IMAGES_MAX} entries: {"https://example.com/photo.jpg": "./photos/photo.jpg"}.`);
|
|
121
|
+
}
|
|
122
|
+
const base=posix.dirname(fixturePath || 'fixtures.json');
|
|
123
|
+
return Object.entries(images).map(([url,file])=>{
|
|
124
|
+
let parsed;
|
|
125
|
+
try { parsed=new URL(url); } catch {}
|
|
126
|
+
if(!parsed || parsed.protocol!=='https:' || parsed.username || parsed.password || parsed.hash || parsed.href!==url) {
|
|
127
|
+
throw usageError(`Fixture image ${JSON.stringify(url)}${where} must be an https URL, written exactly as the fixture rows hold it.`);
|
|
128
|
+
}
|
|
129
|
+
const type=typeof file==='string' ? FIXTURE_IMAGE_TYPES[extname(file).toLowerCase()] : undefined;
|
|
130
|
+
const path=typeof file==='string' ? posix.normalize(posix.join(base,file)) : '';
|
|
131
|
+
if(!type || !path || posix.isAbsolute(file) || file.split(/[\\/]/).includes('..')) {
|
|
132
|
+
throw usageError(`Fixture image ${JSON.stringify(url)}${where} must name a .png, .jpg, .webp, .gif or .avif file in the fixture file's folder or below it.`);
|
|
133
|
+
}
|
|
134
|
+
return {url,path,type};
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
61
138
|
const VIEWER_READS={list_databases:'databases',get_database:'databases',query_database:'databases',list_skills:'skills',get_skill:'skills'};
|
|
62
139
|
|
|
63
140
|
/**
|
|
@@ -85,8 +162,18 @@ export function createSpaceFixtureEngine(release) {
|
|
|
85
162
|
try { fixtures=JSON.parse(Buffer.from(encoded,'base64').toString('utf8')); }
|
|
86
163
|
catch { throw usageError('Verification fixtures must be finite JSON objects.'); }
|
|
87
164
|
}
|
|
88
|
-
if(!object(fixtures) || Object.keys(fixtures).some(key=>!['actions','context','documentBodies','viewerReads','shown','recordViews'].includes(key)) || !object(fixtures.actions)
|
|
165
|
+
if(!object(fixtures) || Object.keys(fixtures).some(key=>!['actions','context','contexts','documentBodies','viewerReads','shown','recordViews','images'].includes(key)) || !object(fixtures.actions)
|
|
89
166
|
|| (fixtures.context!==undefined && !object(fixtures.context))) throw usageError('Verification fixtures declare actions and optional synthetic context.');
|
|
167
|
+
const contexts=fixtureContexts(fixtures);
|
|
168
|
+
const images=new Map(fixtureImageEntries(fixtures,release.fixturePath).map(entry=>{
|
|
169
|
+
const encoded=release.sourceFiles[entry.path];
|
|
170
|
+
if(typeof encoded!=='string') throw usageError(`Fixture image ${entry.path} for ${entry.url} is missing from the Space folder.`);
|
|
171
|
+
if(Buffer.byteLength(encoded,'base64')>FIXTURE_IMAGE_BYTES_MAX) throw usageError(`Fixture image ${entry.path} is larger than 2 MB; use a smaller picture.`);
|
|
172
|
+
return [entry.url,{mime_type:entry.type,data_base64:encoded}];
|
|
173
|
+
}));
|
|
174
|
+
if([...images.values()].reduce((total,image)=>total+Buffer.byteLength(image.data_base64,'base64'),0)>FIXTURE_IMAGES_TOTAL_BYTES_MAX) {
|
|
175
|
+
throw usageError(`Fixture images${release.fixturePath ? ` in ${release.fixturePath}` : ''} add up to more than 16 MB; use smaller pictures.`);
|
|
176
|
+
}
|
|
90
177
|
// Viewer reads have no grant: fixtures stand in for what a signed-in viewer could open.
|
|
91
178
|
const declaredReads=release.manifest.viewer_reads || [];
|
|
92
179
|
// V4: a declared list is served from fixtures per exact params, like a signed-in Editor's read.
|
|
@@ -202,7 +289,13 @@ export function createSpaceFixtureEngine(release) {
|
|
|
202
289
|
if(entry.operation==='html' && value.title!==undefined && value.title!==null && typeof value.title!=='string') throw usageError('HTML fixtures contain a record key, HTML and an optional title.');
|
|
203
290
|
if(entry.operation==='report' && (typeof value.source!=='string' || typeof value.export_name!=='string')) throw usageError('Report fixtures contain an explicit readonly source and export.');
|
|
204
291
|
}
|
|
205
|
-
return { context:fixtures.context || {}, digest:createHash('sha256').update(JSON.stringify(fixtures)).digest('hex'),
|
|
292
|
+
return { context:fixtures.context || {}, contexts, digest:[...images.values()].reduce((hash,image)=>hash.update(image.data_base64),createHash('sha256').update(JSON.stringify(fixtures))).digest('hex'),
|
|
293
|
+
imageUrls:[...images.keys()],
|
|
294
|
+
executeImage(url) {
|
|
295
|
+
const image=images.get(url);
|
|
296
|
+
if(!image) throw usageError(`The view shows the image ${url}, which its fixtures do not provide. Add it to images in ${release.fixturePath || 'its fixtures'}.`);
|
|
297
|
+
return {...image};
|
|
298
|
+
},
|
|
206
299
|
executeRecordView(operation,key) {
|
|
207
300
|
const match=recordViews.find(value=>value.operation===operation && value.record_key===key);
|
|
208
301
|
if(!match) {
|
|
@@ -241,7 +334,13 @@ export function createSpaceFixtureEngine(release) {
|
|
|
241
334
|
} };
|
|
242
335
|
}
|
|
243
336
|
|
|
244
|
-
|
|
337
|
+
/** The fixture context a render opens with: the named one of `contexts`, else the first (the only `context`). */
|
|
338
|
+
export function selectedFixtureContext(engine,name) {
|
|
339
|
+
const list=engine.contexts || [{name:'default',context:engine.context || {}}];
|
|
340
|
+
return (name===undefined ? list[0] : list.find(item=>item.name===name)) || (()=>{ throw usageError(`The fixtures have no context named ${JSON.stringify(String(name))}.`); })();
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export function spaceHarnessSnapshot(release,capabilities,engine,{authorizationMode='authorize_missing',unavailableActions=[],context:contextName}={}) {
|
|
245
344
|
if(release.manifest.kind!=='presentation') throw usageError('Containers do not have an executable preview.');
|
|
246
345
|
const manifest=release.manifest;
|
|
247
346
|
const names=Object.keys(manifest.actions || {}).sort();
|
|
@@ -288,7 +387,7 @@ export function spaceHarnessSnapshot(release,capabilities,engine,{authorizationM
|
|
|
288
387
|
...(viewerReads.length?{viewerReads}:{}),...viewDeclarations(manifest),
|
|
289
388
|
// A local verification renders as an Editor, with the editor-only summary the server gives Editors.
|
|
290
389
|
audience:'editor',...(manifest.editors_only?{editorsOnly:editorsOnlyDescriptor(manifest.editors_only)}:{})},
|
|
291
|
-
app:{id:identity,name:manifest.name},route:{slug:'view',path:'/',name:manifest.name},context:engine.context} };
|
|
390
|
+
app:{id:identity,name:manifest.name},route:{slug:'view',path:'/',name:manifest.name},context:selectedFixtureContext(engine,contextName).context} };
|
|
292
391
|
}
|
|
293
392
|
|
|
294
393
|
/** Existing CLI theme only; the legacy executable/JWT HTML is never served. */
|