@notis_ai/cli 0.2.30 → 0.2.32
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 +15 -0
- package/config/notis_app_design_rules.json +22 -0
- package/dist/agent-hooks/notis-agent-hook.mjs +38244 -10823
- 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 +12 -4
- 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 +29 -2
- package/dist/base-skills/notis-spaces/references/reading.md +3 -1
- package/dist/base-skills/notis-spaces/references/release.md +3 -1
- package/dist/base-skills/notis-spaces/references/sdk.md +112 -33
- 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 +18 -1
- 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 +155 -82
- package/dist/space-sdk/dist/chunk-I4Z4UFGB.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 +315 -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/blocks.d.ts +18 -0
- package/dist/space-sdk/src/ui/blocks/index.d.ts +3 -3
- 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/icons.d.ts +6 -0
- package/dist/space-sdk/src/ui/index.d.ts +5 -3
- package/dist/space-sdk/src/ui/list/ListReader.d.ts +8 -0
- 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 +224 -151
- 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/skills/notis-spaces/cli.md +14 -0
- package/src/command-specs/spaces.js +138 -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-boundary-validator.js +248 -3
- package/src/runtime/app-data-literals.js +32 -23
- 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 +124 -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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { scaffoldSpaceCollection } from '../runtime/space-collection-scaffold.js';
|
|
2
2
|
import { appFilesDigest, clearSpaceScreenshots, loadAppConfig, pullAppSource, resolveProjectDir, saveSpacePendingScreenshots, saveSpaceScreenshots, saveSpaceVerification, spacePublicationIntent, syncSpaceSdk } from '../runtime/app-platform.js';
|
|
3
|
-
import { buildSpaceArtifact, prepareSpaceRelease, requireSpaceIcon } from '../runtime/space-platform.js';
|
|
3
|
+
import { buildSpaceArtifact, compileSpaceSqlReads, prepareSpaceRelease, requireSpaceIcon } from '../runtime/space-platform.js';
|
|
4
4
|
import { verifySpaceRelease } from '../runtime/space-verification.js';
|
|
5
5
|
import { loadSelectedSpace } from '../runtime/space-source.js';
|
|
6
6
|
import { refreshSpaceAuthoring } from '../runtime/space-database-structures.js';
|
|
@@ -145,11 +145,15 @@ function describePendingChanges(summary) {
|
|
|
145
145
|
|
|
146
146
|
const SKELETON_FILE = 'bundle/skeleton.json';
|
|
147
147
|
|
|
148
|
-
/**
|
|
148
|
+
/**
|
|
149
|
+
* Reviewable: where the screenshots of the loaded view are (each width in English and French, per fixture context),
|
|
150
|
+
* and each one that had not finished loading its data.
|
|
151
|
+
*/
|
|
149
152
|
function describeScreenshots(render) {
|
|
150
153
|
const renders = render?.renders || [];
|
|
151
154
|
const paths = renders.filter(value => value.loaded && value.screenshot_path).map(value => value.screenshot_path);
|
|
152
|
-
const parts =
|
|
155
|
+
const parts = render?.contexts?.length ? [`Fixture contexts checked: ${render.contexts.join(', ')}.`] : [];
|
|
156
|
+
if (paths.length) parts.push(`Screenshots after the data loaded: ${paths.join(', ')}.`);
|
|
153
157
|
for (const value of renders.filter(item => item.loaded === false)) {
|
|
154
158
|
const message = value.message;
|
|
155
159
|
if (message) parts.push(value.screenshot_path ? `${message.replace(/\.$/, '')}; ${value.screenshot_path} shows what it showed then.` : message);
|
|
@@ -162,11 +166,10 @@ function describeSkeleton(skeleton) {
|
|
|
162
166
|
if (!skeleton) return '';
|
|
163
167
|
const parts = [skeleton.status === 'captured' ? `Loading skeleton measured for ${skeleton.regions.join(', ')}${skeleton.audience === 'public' ? ', as the public sees the view' : ''}.`
|
|
164
168
|
: skeleton.status === 'failed' ? 'The loading skeleton could not be measured; the view keeps its fallback skeleton.' : ''];
|
|
165
|
-
const
|
|
166
|
-
if (
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
parts.push(`Loading state warnings (${findings.length}): ${shown.join(' ')}${findings.length > 5 ? ` And ${findings.length - 5} more in the diagnostic.` : ''}`);
|
|
169
|
+
const groups = groupFindings(skeleton.findings || []);
|
|
170
|
+
if (groups.length) {
|
|
171
|
+
const shown = groups.slice(0, 5).map(value => `${value.where ? `[${value.where}] ` : ''}${value.message}`);
|
|
172
|
+
parts.push(`Loading state warnings (${groups.length}): ${shown.join(' ')}${groups.length > 5 ? ` And ${groups.length - 5} more in the diagnostic.` : ''}`);
|
|
170
173
|
}
|
|
171
174
|
const paths = (skeleton.pending_screenshots || []).map(value => value.path).filter(Boolean);
|
|
172
175
|
if (paths.length) parts.push(`Loading screenshots: ${paths.join(', ')}.`);
|
|
@@ -174,6 +177,25 @@ function describeSkeleton(skeleton) {
|
|
|
174
177
|
return text ? ` ${text}` : '';
|
|
175
178
|
}
|
|
176
179
|
|
|
180
|
+
/**
|
|
181
|
+
* One line per identical finding across widths and locales: `{ where: '390 and 1440, EN and FR, reader', message }`.
|
|
182
|
+
* The reader's loading state and each fixture context stay apart.
|
|
183
|
+
*/
|
|
184
|
+
function groupFindings(findings) {
|
|
185
|
+
const groups = new Map();
|
|
186
|
+
for (const value of findings) {
|
|
187
|
+
const id = JSON.stringify([value.check, value.message, value.region ?? null, value.state ?? null, value.context ?? null]);
|
|
188
|
+
const group = groups.get(id) || { widths: new Set(), locales: new Set(), state: value.state, context: value.context, message: value.message };
|
|
189
|
+
if (value.width) group.widths.add(value.width);
|
|
190
|
+
if (value.locale) group.locales.add(value.locale);
|
|
191
|
+
groups.set(id, group);
|
|
192
|
+
}
|
|
193
|
+
const and = values => values.join(' and ');
|
|
194
|
+
return [...groups.values()].map(group => ({ message: group.message, where: [and([...group.widths].sort((a, b) => a - b)),
|
|
195
|
+
and([...group.locales].sort().map(value => value.toUpperCase())), group.context ? `context ${group.context}` : '', group.state || '']
|
|
196
|
+
.filter(Boolean).join(', ') }));
|
|
197
|
+
}
|
|
198
|
+
|
|
177
199
|
/** Same server verification for this Space, source, grants and authorization mode. */
|
|
178
200
|
function sameVerification(verification, body, sourceDigest) {
|
|
179
201
|
return verification?.valid === true && verification.space_id === body.space_id && verification.source_digest === sourceDigest
|
|
@@ -181,6 +203,28 @@ function sameVerification(verification, body, sourceDigest) {
|
|
|
181
203
|
&& (verification.authorization_mode ?? 'authorize_missing') === (body.authorization_mode ?? 'authorize_missing');
|
|
182
204
|
}
|
|
183
205
|
|
|
206
|
+
// What each server step of a verify or deploy is doing, said before it starts so a long wait never looks like a hang.
|
|
207
|
+
const RELEASE_STEPS = { 'sql-reads': 'Compiling the SQL reads', 'source-verify': 'Checking the source and its authorizations',
|
|
208
|
+
'source-publish': 'Publishing', 'source-stage': 'Preparing the candidate revision' };
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* A verify or deploy whose server step got no answer says how to continue: a deploy resumes under the same
|
|
212
|
+
* request ID (the server finishes or confirms that release, never a second one); a verify published nothing.
|
|
213
|
+
*/
|
|
214
|
+
function resumableReleaseError(error, ctx, intentKey) {
|
|
215
|
+
if (!(error instanceof CliError) || !['network_error', 'network_timeout'].includes(error.code)) return error;
|
|
216
|
+
// The same command: its folder, --space, --space-id and --profile decide which release the request ID resumes.
|
|
217
|
+
const command = `notis ${ctx.spec.command_path.join(' ')}`;
|
|
218
|
+
const next = intentKey
|
|
219
|
+
? `Nothing is lost: run the same ${command} command again (same folder and options) with --request-id ${intentKey}; `
|
|
220
|
+
+ 'it resumes this release and never publishes it twice.'
|
|
221
|
+
: `Nothing was published: run the same ${command} command again.`;
|
|
222
|
+
return new CliError({ code: error.code, message: `${error.message} ${next}`, exitCode: error.exitCode, retryable: true,
|
|
223
|
+
details: { ...error.details, ...(intentKey ? { request_id_to_reuse: intentKey } : {}) },
|
|
224
|
+
hints: [intentKey ? { command: `--request-id ${intentKey}`, reason: `Add to the same ${command} command to resume this release` }
|
|
225
|
+
: { command, reason: 'Run the same command again' }, ...(error.hints || [])], cause: error.cause });
|
|
226
|
+
}
|
|
227
|
+
|
|
184
228
|
async function sourceRelease(ctx, publish, stageOnly = false) {
|
|
185
229
|
const { directory, key } = await selected(ctx);
|
|
186
230
|
const spaceId = destinationSpaceId(ctx, directory);
|
|
@@ -191,6 +235,14 @@ async function sourceRelease(ctx, publish, stageOnly = false) {
|
|
|
191
235
|
const release = await prepareSpaceRelease(directory, key);
|
|
192
236
|
try {
|
|
193
237
|
if (publish) requireSpaceIcon(release.manifest, key);
|
|
238
|
+
const call = async (operation, data) => {
|
|
239
|
+
ctx.output.emitProgress?.({ phase: operation, message: `${RELEASE_STEPS[operation] || operation} on the server` });
|
|
240
|
+
try {
|
|
241
|
+
return await httpRequest({ runtime: { ...ctx.runtime, timeoutMs: Math.max(ctx.runtime.timeoutMs || 0, 600_000) },
|
|
242
|
+
method: 'POST', path: `/portal_spaces/${operation}`, body: data, spacesProtocol: true });
|
|
243
|
+
} catch (error) { throw resumableReleaseError(error, ctx, publish && !ctx.options.dryRun ? intentKey : null); }
|
|
244
|
+
};
|
|
245
|
+
const compiledReads = await compileSpaceSqlReads(release, call);
|
|
194
246
|
const identity = [ctx.runtime.apiBase.replace(/\/$/, ''), ctx.runtime.profileName, key, spaceId, intentKey];
|
|
195
247
|
let verification = publish && !ctx.options.dryRun ? spacePublicationIntent(directory, identity) : null;
|
|
196
248
|
const local = intentChanges(directory, spaceId, release.manifest,
|
|
@@ -200,8 +252,6 @@ async function sourceRelease(ctx, publish, stageOnly = false) {
|
|
|
200
252
|
...(ctx.options.reuseGrantsOnly ? { authorization_mode: 'reuse_only' } : {}),
|
|
201
253
|
...(local.changes ? { changes: local.changes } : {}) };
|
|
202
254
|
const sourceDigest = appFilesDigest(release.sourceFiles), builtDigest = appFilesDigest(release.files);
|
|
203
|
-
const call = (operation, data) => httpRequest({ runtime: { ...ctx.runtime, timeoutMs: Math.max(ctx.runtime.timeoutMs || 0, 600_000) },
|
|
204
|
-
method: 'POST', path: `/portal_spaces/${operation}`, body: data, spacesProtocol: true });
|
|
205
255
|
if (verification && (verification.local_changes_fingerprint ?? null) !== local.fingerprint) {
|
|
206
256
|
throw usageError('This request ID belongs to different Skill folders or list entries. Restore the state you first deployed to retry, or use a new request ID for a new release.');
|
|
207
257
|
}
|
|
@@ -220,6 +270,7 @@ async function sourceRelease(ctx, publish, stageOnly = false) {
|
|
|
220
270
|
const cancel = () => controller.abort();
|
|
221
271
|
process.once('SIGINT', cancel); process.once('SIGTERM', cancel);
|
|
222
272
|
let render;
|
|
273
|
+
ctx.output.emitProgress?.({ phase: 'render', message: 'Rendering the fixtures in a local browser' });
|
|
223
274
|
try { render = await verifySpaceRelease(release, { capabilities: verification.capabilities, signal: controller.signal,
|
|
224
275
|
authorizationMode: body.authorization_mode, unavailableActions: verification.unavailable_actions,
|
|
225
276
|
// Test seam only: the command context never carries it from user options.
|
|
@@ -227,7 +278,7 @@ async function sourceRelease(ctx, publish, stageOnly = false) {
|
|
|
227
278
|
finally { process.removeListener('SIGINT', cancel); process.removeListener('SIGTERM', cancel); }
|
|
228
279
|
const saved = saveSpaceScreenshots(directory, key, render.screenshots || []);
|
|
229
280
|
if (render.renders) render.renders = render.renders.map(value => {
|
|
230
|
-
const path = saved.find(item => item.width === value.width)?.path;
|
|
281
|
+
const path = saved.find(item => item.width === value.width && item.locale === value.locale && item.context === value.context)?.path;
|
|
231
282
|
return path ? { ...value, screenshot_path: path } : value;
|
|
232
283
|
});
|
|
233
284
|
if (render.skeleton) {
|
|
@@ -279,8 +330,9 @@ async function sourceRelease(ctx, publish, stageOnly = false) {
|
|
|
279
330
|
? (await call(stageOnly ? 'source-stage' : 'source-publish', { ...body, verification: serverVerification, request_id: intentKey })).payload
|
|
280
331
|
: serverVerification;
|
|
281
332
|
if (publish && !ctx.options.dryRun && !stageOnly) recordPublication(directory, local, result);
|
|
282
|
-
const data = { ...result, render, diagnostic_path: diagnosticPath, ...(local.summary ? { local_changes: local.summary } : {})
|
|
283
|
-
|
|
333
|
+
const data = { ...result, render, diagnostic_path: diagnosticPath, ...(local.summary ? { local_changes: local.summary } : {}),
|
|
334
|
+
...(compiledReads.length ? { compiled_sql_reads: compiledReads } : {}) };
|
|
335
|
+
const skeletonSummary = describeSkeleton(render.skeleton) + (compiledReads.length ? ` Compiled the SQL read${compiledReads.length > 1 ? 's' : ''} ${compiledReads.join(', ')}.` : ''), screenshotSummary = describeScreenshots(render);
|
|
284
336
|
return ctx.output.emitSuccess({ command: ctx.spec.command_path.join(' '), data,
|
|
285
337
|
humanSummary: publish && !ctx.options.dryRun
|
|
286
338
|
? stageOnly ? `Prepared ${key} as revision ${result.candidate_revision}. ${result.preview_url || 'This container has no executable preview.'} Live source was not changed.${describePendingChanges(local.summary).replace(/\.$/, '; they go live with notis spaces promote.')}${screenshotSummary}`
|
|
@@ -352,6 +404,60 @@ function refreshPulledSdk(projectDir) {
|
|
|
352
404
|
warnings: messages.filter((message) => warning.test(message)).map((message) => message.replace(warning, '')) };
|
|
353
405
|
}
|
|
354
406
|
|
|
407
|
+
function pageNumber(value, { flag, fallback, minimum, maximum }) {
|
|
408
|
+
if (value === undefined) return fallback;
|
|
409
|
+
const number = Number(value);
|
|
410
|
+
if (!Number.isSafeInteger(number) || number < minimum || number > maximum) {
|
|
411
|
+
throw usageError(`Pass ${flag} as a whole number from ${minimum} to ${maximum}.`);
|
|
412
|
+
}
|
|
413
|
+
return number;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/** One line per record: a tab or line break in a title would split the tab-separated output. */
|
|
417
|
+
const flatTitle = title => title.replace(/[\t\r\n]+/g, ' ');
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* The records of one database linked into a Space, through its link like any native read: the alias
|
|
421
|
+
* resolves among the links the caller can see, and the server's native query decides what they may open.
|
|
422
|
+
* A direct query on a link is an editor read; anyone else reads through the Space's declared actions.
|
|
423
|
+
*/
|
|
424
|
+
async function listSpaceRecords(ctx) {
|
|
425
|
+
const limit = pageNumber(ctx.options.limit, { flag: '--limit', fallback: 20, minimum: 1, maximum: 100 });
|
|
426
|
+
const offset = pageNumber(ctx.options.offset, { flag: '--offset', fallback: 0, minimum: 0, maximum: 1_000_000 });
|
|
427
|
+
const spaceId = ctx.args.spaceId, wanted = ctx.args.binding;
|
|
428
|
+
const query = new URLSearchParams({ space_id: spaceId });
|
|
429
|
+
const links = (await httpRequest({ runtime: ctx.runtime, method: 'GET', path: `/portal_spaces/space-links?${query}`,
|
|
430
|
+
spacesProtocol: true })).payload?.links;
|
|
431
|
+
const link = (Array.isArray(links) ? links : []).find(entry => entry?.kind === 'database'
|
|
432
|
+
&& (entry.binding_id === wanted || entry.alias === wanted));
|
|
433
|
+
if (!link) {
|
|
434
|
+
throw usageError(`This Space has no database link "${wanted}" you can open. List its links with notis spaces links list ${spaceId}.`);
|
|
435
|
+
}
|
|
436
|
+
const target = { space_id: spaceId, binding: link.binding_id, ...(ctx.options.record ? { document_id: ctx.options.record } : {}) };
|
|
437
|
+
// Oldest first, then by key, so --offset pages never skip or repeat a record.
|
|
438
|
+
const sorts = [{ field: { column: 'created_at' }, direction: 'asc' }, { field: { column: 'record_key' }, direction: 'asc' }];
|
|
439
|
+
let result;
|
|
440
|
+
try {
|
|
441
|
+
result = await httpRequest({ runtime: ctx.runtime, method: 'POST', path: '/portal_spaces/data', spacesProtocol: true,
|
|
442
|
+
body: { operation: 'query', target, input: { mode: 'rows', sorts, page_size: limit, offset, include_content: false } } });
|
|
443
|
+
} catch (error) {
|
|
444
|
+
if (error instanceof CliError && error.details?.error === 'action_required') {
|
|
445
|
+
throw new CliError({ code: error.code, message: 'Only an editor of this Space can list a linked database\'s records; anyone else reads them through the Space\'s declared actions.',
|
|
446
|
+
exitCode: error.exitCode, details: error.details });
|
|
447
|
+
}
|
|
448
|
+
throw error;
|
|
449
|
+
}
|
|
450
|
+
const answer = result.payload || {};
|
|
451
|
+
const records = (Array.isArray(answer.rows) ? answer.rows : []).map(row => ({ record_key: row.record_key,
|
|
452
|
+
title: typeof row.title === 'string' ? row.title : '' }));
|
|
453
|
+
const data = { space_id: spaceId, alias: link.alias, target, records, has_more: Boolean(answer.has_more),
|
|
454
|
+
next_offset: answer.next_offset ?? null, schema_revision: answer.schema_revision ?? null };
|
|
455
|
+
const lines = records.map(record => `${record.record_key}\t${flatTitle(record.title)}`);
|
|
456
|
+
if (data.has_more && data.next_offset !== null) lines.push(`More records: --offset ${data.next_offset}`);
|
|
457
|
+
return ctx.output.emitSuccess({ command: ctx.spec.command_path.join(' '), data,
|
|
458
|
+
humanSummary: lines.length ? lines.join('\n') : 'No records.', meta: { mutating: false, request_id: result.requestId } });
|
|
459
|
+
}
|
|
460
|
+
|
|
355
461
|
const idArgument = { token: '<space-id>', key: 'spaceId', description: 'Exact existing Space ID.' };
|
|
356
462
|
const recordOption = { flags: '--record <record-key>', description: 'Fixed record context, when this is a record-scoped Space.' };
|
|
357
463
|
const requestOption = { flags: '--request-id <key>', description: 'Stable intent key. Reuse after timeouts or lost replies.' };
|
|
@@ -552,6 +658,19 @@ export const spacesCommandSpecs = [
|
|
|
552
658
|
return remote(ctx, 'space-links', { method: 'GET', query: { space_id: ctx.args.spaceId } });
|
|
553
659
|
},
|
|
554
660
|
},
|
|
661
|
+
{
|
|
662
|
+
command_path: ['spaces', 'records'],
|
|
663
|
+
summary: 'List the records of one database linked into a Space you edit: record key and title, oldest first, one page at a time.',
|
|
664
|
+
when_to_use: 'Find the record keys and titles of a linked database, for example to write fixtures or link to one record. Editors only; anyone else reads through the Space\'s declared actions.',
|
|
665
|
+
args_schema: { arguments: [idArgument, { token: '<binding>', key: 'binding',
|
|
666
|
+
description: 'Database link alias or binding ID from spaces links list.' }], options: [
|
|
667
|
+
{ flags: '--limit <number>', description: 'Records per page, 1 to 100; defaults to 20.' },
|
|
668
|
+
{ flags: '--offset <number>', description: 'Zero-based start; pass next_offset from the previous page.' }, recordOption] },
|
|
669
|
+
examples: ['notis spaces records <space-id> tasks --limit 20'],
|
|
670
|
+
mutates: false, idempotent: true, require_auth: true,
|
|
671
|
+
backend_call: { type: 'http', path: '/portal_spaces/data' },
|
|
672
|
+
handler: listSpaceRecords,
|
|
673
|
+
},
|
|
555
674
|
{
|
|
556
675
|
command_path: ['spaces', 'links', 'remove'],
|
|
557
676
|
summary: 'Remove one database, Skill or automation link from a Space by its binding.',
|
|
@@ -926,8 +1045,12 @@ export const spacesCommandSpecs = [
|
|
|
926
1045
|
backend_call: { type: 'local', name: 'space_build' },
|
|
927
1046
|
async handler(ctx) {
|
|
928
1047
|
const { directory, key } = await selected(ctx);
|
|
929
|
-
|
|
930
|
-
|
|
1048
|
+
// A folder with no packages yet (a copy, a fresh clone) installs them once here, never asking for a separate npm ci.
|
|
1049
|
+
const result = await buildSpaceArtifact(directory, key, { stdio: ctx.output.isMachineMode() ? 'pipe' : 'inherit', installDependencies: true,
|
|
1050
|
+
installLog: message => ctx.output.emitProgress?.({ phase: 'install', message }) });
|
|
1051
|
+
const installed = result.installed_dependencies;
|
|
1052
|
+
return ctx.output.emitSuccess({ command: 'spaces build', data: result,
|
|
1053
|
+
humanSummary: `${installed ? `Installed this Space's packages (${installed.command}, ${installed.seconds} s). ` : ''}Built ${key}; no Space was published.` });
|
|
931
1054
|
},
|
|
932
1055
|
},
|
|
933
1056
|
{
|
|
@@ -2,6 +2,7 @@ import { accessSync, constants as fsConstants, createReadStream, existsSync, rea
|
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
3
|
import { basename } from 'node:path';
|
|
4
4
|
import { usageError } from '../runtime/errors.js';
|
|
5
|
+
import { ENV_FILE_MESSAGE, isEnvFileName } from '../runtime/native-record-files.js';
|
|
5
6
|
import {
|
|
6
7
|
canPrompt,
|
|
7
8
|
createStderrPrompter,
|
|
@@ -296,6 +297,7 @@ async function parseFileBindingSpec(spec, index) {
|
|
|
296
297
|
if (!localPath) {
|
|
297
298
|
throw usageError('--file local path is required');
|
|
298
299
|
}
|
|
300
|
+
if (isEnvFileName(localPath)) throw usageError(ENV_FILE_MESSAGE);
|
|
299
301
|
if (!existsSync(localPath)) {
|
|
300
302
|
throw usageError(`File not found: ${localPath}`);
|
|
301
303
|
}
|
|
@@ -762,6 +764,7 @@ export const toolsCommandSpecs = [
|
|
|
762
764
|
},
|
|
763
765
|
examples: [
|
|
764
766
|
'notis tools exec LOCAL_NOTIS_DATABASE_QUERY --arguments \'{"database_slug":"tasks","query":{}}\'',
|
|
767
|
+
'notis tools exec LOCAL_NOTIS_DATABASE_QUERY --arguments \'{"protocol":1,"target":{"database_id":"<database id>"},"input":{"mode":"rows"}}\'',
|
|
765
768
|
'notis tools exec LOCAL_NOTIS_DATABASE_GET_DATABASE --arguments \'{"database_slug":"tasks"}\'',
|
|
766
769
|
'notis tools exec LOCAL_NOTIS_DATABASE_QUERY --get-schema',
|
|
767
770
|
'notis tools exec LOCAL_NOTIS_DATABASE_QUERY --dry-run --arguments \'{"database_slug":"tasks","query":{}}\'',
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// GENERATED by scripts/generate_channel_hosts.py from server/lib/release_channels.py
|
|
2
|
+
// (CHANNEL_ORIGINS and _LEGACY_HOSTNAMES). Do not edit: change the server list, then run
|
|
3
|
+
// python3 scripts/generate_channel_hosts.py
|
|
4
|
+
|
|
5
|
+
/** Each channel's public origin per surface. */
|
|
6
|
+
export const CHANNEL_ORIGINS = {
|
|
7
|
+
stable: {
|
|
8
|
+
portal: 'https://app.notis.ai',
|
|
9
|
+
api: 'https://api.notis.ai',
|
|
10
|
+
mcp: 'https://mcp.notis.ai',
|
|
11
|
+
realtime: 'wss://realtime.notis.ai',
|
|
12
|
+
},
|
|
13
|
+
nightly: {
|
|
14
|
+
portal: 'https://app-nightly.notis.ai',
|
|
15
|
+
api: 'https://api-nightly.notis.ai',
|
|
16
|
+
mcp: 'https://mcp-nightly.notis.ai',
|
|
17
|
+
realtime: 'wss://realtime-nightly.notis.ai',
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** Each channel's hostnames per surface, the current name first, then the retired ones. */
|
|
22
|
+
export const CHANNEL_HOSTNAMES = {
|
|
23
|
+
stable: {
|
|
24
|
+
portal: ['app.notis.ai'],
|
|
25
|
+
api: ['api.notis.ai'],
|
|
26
|
+
mcp: ['mcp.notis.ai'],
|
|
27
|
+
realtime: ['realtime.notis.ai', 'websocket-prod.onrender.com'],
|
|
28
|
+
},
|
|
29
|
+
nightly: {
|
|
30
|
+
portal: ['app-nightly.notis.ai'],
|
|
31
|
+
api: ['api-nightly.notis.ai'],
|
|
32
|
+
mcp: ['mcp-nightly.notis.ai'],
|
|
33
|
+
realtime: ['realtime-nightly.notis.ai', 'notis-websocket.onrender.com'],
|
|
34
|
+
},
|
|
35
|
+
};
|
package/src/runtime/api-hosts.js
CHANGED
|
@@ -1,18 +1,35 @@
|
|
|
1
|
+
import { CHANNEL_HOSTNAMES, CHANNEL_ORIGINS } from './api-hosts.generated.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Retired API names the CLI keeps knowing after the server list drops them. A
|
|
5
|
+
* retired name stays listed after its domain is removed: profiles that stored
|
|
6
|
+
* it keep being recognised and renamed to the channel's current API (CLI-037),
|
|
7
|
+
* and sign-ins recorded on it are known to be spent (CLI-038, CLI-039).
|
|
8
|
+
*/
|
|
9
|
+
const CLI_RETIRED_API_HOSTS = {
|
|
10
|
+
nightly: ['api-beta.notis.ai'],
|
|
11
|
+
};
|
|
12
|
+
|
|
1
13
|
/**
|
|
2
14
|
* The live Notis APIs, one row per release channel: the API's current name,
|
|
3
15
|
* the names it answered on before (retired), and the channel's Portal.
|
|
4
16
|
*
|
|
5
|
-
* Every CLI list of live API hosts derives from this table.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* Mirrors server/lib/release_channels.py (CHANNEL_ORIGINS, _LEGACY_HOSTNAMES).
|
|
17
|
+
* Every CLI list of live API hosts derives from this table. The current and
|
|
18
|
+
* retired names come from api-hosts.generated.js, written by
|
|
19
|
+
* scripts/generate_channel_hosts.py from server/lib/release_channels.py
|
|
20
|
+
* (CHANNEL_ORIGINS, _LEGACY_HOSTNAMES): edit the server list and regenerate.
|
|
21
|
+
* CLI_RETIRED_API_HOSTS adds the retired names only the CLI still needs.
|
|
11
22
|
*/
|
|
12
|
-
const CHANNEL_APIS =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
23
|
+
const CHANNEL_APIS = channelApis(CHANNEL_HOSTNAMES, CHANNEL_ORIGINS);
|
|
24
|
+
|
|
25
|
+
/** The CHANNEL_APIS rows of a generated host table, with the CLI's own retired names added. */
|
|
26
|
+
export function channelApis(channelHostnames, channelOrigins) {
|
|
27
|
+
return Object.fromEntries(Object.entries(channelHostnames).map(([channel, surfaces]) => {
|
|
28
|
+
const [current, ...legacy] = surfaces.api;
|
|
29
|
+
const retired = [...new Set([...legacy, ...(CLI_RETIRED_API_HOSTS[channel] || [])])].filter(host => host !== current);
|
|
30
|
+
return [channel, { current, retired, portal: channelOrigins[channel].portal }];
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
16
33
|
|
|
17
34
|
const HOST_ROWS = Object.entries(CHANNEL_APIS).flatMap(([channel, row]) => [
|
|
18
35
|
{ host: row.current, channel, current: true },
|
|
@@ -3,7 +3,7 @@ import { dirname, extname, join, resolve } from 'node:path';
|
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
|
|
5
5
|
import { usageError } from './errors.js';
|
|
6
|
-
import { maskSerializedJsonData } from './app-data-literals.js';
|
|
6
|
+
import { maskSerializedJsonData, maskSerializedJsonDataOrNull } from './app-data-literals.js';
|
|
7
7
|
|
|
8
8
|
const moduleDir = dirname(fileURLToPath(import.meta.url));
|
|
9
9
|
|
|
@@ -341,7 +341,7 @@ export function loadDesignRules({ rulesPath = resolveDesignRulesPath(), profile
|
|
|
341
341
|
);
|
|
342
342
|
}
|
|
343
343
|
if (!payload) {
|
|
344
|
-
return { profile, include: [], exclude: [], extensions: DEFAULT_DESIGN_EXTENSIONS, rules: [], allowDirective: 'notis-design-allow', allowReasonMinLength: 12 };
|
|
344
|
+
return { profile, include: [], exclude: [], extensions: DEFAULT_DESIGN_EXTENSIONS, rules: [], icons: null, allowDirective: 'notis-design-allow', allowReasonMinLength: 12 };
|
|
345
345
|
}
|
|
346
346
|
const profiles = payload.profiles && typeof payload.profiles === 'object' && !Array.isArray(payload.profiles) ? payload.profiles : {};
|
|
347
347
|
const selected = profile !== 'app' && profiles[profile] && typeof profiles[profile] === 'object' ? profiles[profile] : null;
|
|
@@ -355,6 +355,7 @@ export function loadDesignRules({ rulesPath = resolveDesignRulesPath(), profile
|
|
|
355
355
|
extensions: Array.isArray(payload.extensions) ? payload.extensions : DEFAULT_DESIGN_EXTENSIONS,
|
|
356
356
|
allowDirective: typeof payload.allow_directive === 'string' ? payload.allow_directive : 'notis-design-allow',
|
|
357
357
|
allowReasonMinLength: Number.isInteger(payload.allow_reason_min_length) ? payload.allow_reason_min_length : 12,
|
|
358
|
+
icons: loadIconCheck(payload.icons, profile),
|
|
358
359
|
rules: (Array.isArray(payload.rules) ? payload.rules : [])
|
|
359
360
|
.filter((rule) => !Array.isArray(rule.profiles) || rule.profiles.includes(profile))
|
|
360
361
|
.map((rule) => ({
|
|
@@ -373,6 +374,243 @@ export function loadDesignRules({ rulesPath = resolveDesignRulesPath(), profile
|
|
|
373
374
|
};
|
|
374
375
|
}
|
|
375
376
|
|
|
377
|
+
// ---------------------------------------------------------------------------
|
|
378
|
+
// Icon names
|
|
379
|
+
//
|
|
380
|
+
// The toolkit's Icon draws a fixed set of names (`icons.names` in the rules
|
|
381
|
+
// file, kept equal to the SDK's ICON_NAMES by packages/sdk/src/ui/icons.test.tsx)
|
|
382
|
+
// and an unknown one draws nothing, so a guessed Phosphor name ships an empty
|
|
383
|
+
// button. Only toolkit inputs are checked, and only when the whole value is one
|
|
384
|
+
// kebab-case string literal:
|
|
385
|
+
// - `name` on the SDK's Icon and `icon` on any other SDK component, the tag
|
|
386
|
+
// resolved through the file's @notis/sdk imports (aliases and namespaces);
|
|
387
|
+
// - an `icon` field of an object that also has a `label` (reader actions,
|
|
388
|
+
// view menu items, tabs: the toolkit's labelled items).
|
|
389
|
+
// Text inside strings and comments is never read. Mirrored by
|
|
390
|
+
// _icon_candidates in server/lib/app_boundary_validator.py.
|
|
391
|
+
// ---------------------------------------------------------------------------
|
|
392
|
+
|
|
393
|
+
const ICON_NAME_SHAPE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
394
|
+
const SDK_IMPORTS = /(?<![\w$.])import\s+([\w$\s{},*]+?)\s+from\s*(["'])@notis\/sdk(?:\/[^"'\s]*)?\2/g;
|
|
395
|
+
const JSX_TAG = /<([A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)?)(?=[\s/>])/g;
|
|
396
|
+
const JSX_ATTRIBUTE = /(?<![\w$.-])(icon|name)\s*=\s*/g;
|
|
397
|
+
const ICON_FIELD = /(?<![\w$.-])icon\s*:\s*/g;
|
|
398
|
+
const LABEL_KEY = /(?<![\w$.-])label\s*[:,}]/g;
|
|
399
|
+
// What a JSX opening tag holds at its own level besides strings and braced values.
|
|
400
|
+
const TAG_TEXT = /[\w$\-:.=\t\n\v\f\r /]/;
|
|
401
|
+
|
|
402
|
+
/** Local component names bound to @notis/sdk (local -> exported) and namespace names. Type-only imports bind nothing. */
|
|
403
|
+
function sdkBindings(text) {
|
|
404
|
+
const components = new Map(), namespaces = new Set();
|
|
405
|
+
for (const match of text.matchAll(SDK_IMPORTS)) {
|
|
406
|
+
const clause = match[1].trim();
|
|
407
|
+
if (/^type\s/.test(clause)) continue;
|
|
408
|
+
const namespace = clause.match(/\*\s*as\s+([\w$]+)/);
|
|
409
|
+
if (namespace) namespaces.add(namespace[1]);
|
|
410
|
+
const named = clause.match(/\{([^}]*)\}/);
|
|
411
|
+
for (const part of named ? named[1].split(',') : []) {
|
|
412
|
+
const item = part.trim();
|
|
413
|
+
if (!item || /^type\s/.test(item)) continue;
|
|
414
|
+
const [exported, local = exported] = item.split(/\s+as\s+/).map((value) => value.trim());
|
|
415
|
+
components.set(local, exported);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return { components, namespaces };
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* One pass over comment-masked source: which characters sit inside a string, the innermost open
|
|
423
|
+
* brace around each character, and where each brace closes. A quote left open at the end of its
|
|
424
|
+
* line is JSX text (an apostrophe), not a string.
|
|
425
|
+
*/
|
|
426
|
+
function sourceShape(text) {
|
|
427
|
+
const length = text.length;
|
|
428
|
+
const inString = new Uint8Array(length), owner = new Int32Array(length).fill(-1), closes = new Map(), stack = [];
|
|
429
|
+
let index = 0;
|
|
430
|
+
while (index < length) {
|
|
431
|
+
const char = text[index];
|
|
432
|
+
const top = stack.length ? stack[stack.length - 1] : -1;
|
|
433
|
+
if (char === '"' || char === "'" || char === '`') {
|
|
434
|
+
let cursor = index + 1, closed = false;
|
|
435
|
+
while (cursor < length) {
|
|
436
|
+
const inner = text[cursor];
|
|
437
|
+
if (inner === '\\') { cursor += 2; continue; }
|
|
438
|
+
if (inner === char) { cursor += 1; closed = true; break; }
|
|
439
|
+
if (inner === '\n' && char !== '`') break;
|
|
440
|
+
cursor += 1;
|
|
441
|
+
}
|
|
442
|
+
if (closed) {
|
|
443
|
+
for (let at = index; at < cursor; at += 1) { inString[at] = 1; owner[at] = top; }
|
|
444
|
+
index = cursor;
|
|
445
|
+
continue;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
owner[index] = top;
|
|
449
|
+
if (char === '{') stack.push(index);
|
|
450
|
+
else if (char === '}' && stack.length) closes.set(stack.pop(), index);
|
|
451
|
+
index += 1;
|
|
452
|
+
}
|
|
453
|
+
return { inString, owner, closes };
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/** The literal at `at` when it is the whole value: 'x', "x", `x` (no ${}), or {'x'} in JSX. */
|
|
457
|
+
function literalAt(text, shape, at, { braced = false } = {}) {
|
|
458
|
+
let start = at;
|
|
459
|
+
if (braced && text[at] === '{' && shape.closes.has(at)) {
|
|
460
|
+
const inner = text.slice(at + 1, shape.closes.get(at));
|
|
461
|
+
const match = inner.match(/^\s*(["'`])([^"'`\n\\$]*)\1\s*$/);
|
|
462
|
+
if (!match) return null;
|
|
463
|
+
start = at + 1 + inner.indexOf(match[1]);
|
|
464
|
+
return { name: match[2], index: start + 1 };
|
|
465
|
+
}
|
|
466
|
+
const match = text.slice(start).match(/^(["'`])([^"'`\n\\$]*)\1/);
|
|
467
|
+
return match ? { name: match[2], index: start + 1, end: start + match[0].length } : null;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Where a JSX opening tag ends: its `>` at the tag's own brace level, outside strings, jumping over
|
|
472
|
+
* braced values. Any other character at that level means this is not a tag (`a <B && c`): stop there.
|
|
473
|
+
*/
|
|
474
|
+
function tagEnd(text, shape, from) {
|
|
475
|
+
const level = shape.owner[from];
|
|
476
|
+
let index = from + 1;
|
|
477
|
+
while (index < text.length) {
|
|
478
|
+
const char = text[index];
|
|
479
|
+
if (shape.inString[index]) { index += 1; continue; }
|
|
480
|
+
if (char === '>') return index;
|
|
481
|
+
if (char === '{') {
|
|
482
|
+
if (!shape.closes.has(index)) return index;
|
|
483
|
+
index = shape.closes.get(index) + 1;
|
|
484
|
+
continue;
|
|
485
|
+
}
|
|
486
|
+
if (shape.owner[index] !== level || !TAG_TEXT.test(char)) return index;
|
|
487
|
+
index += 1;
|
|
488
|
+
}
|
|
489
|
+
return text.length;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/** True when the key at `at` sits where an object key does: right after `{` or `,`, outside strings. */
|
|
493
|
+
function keyPosition(text, shape, at) {
|
|
494
|
+
let index = at - 1;
|
|
495
|
+
while (index >= 0 && ' \t\n\v\f\r'.includes(text[index])) index -= 1;
|
|
496
|
+
return index >= 0 && !shape.inString[index] && (text[index] === '{' || text[index] === ',');
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/** `{ index, name }` for every literal handed to a toolkit icon input in this comment-masked file. */
|
|
500
|
+
function iconCandidates(text) {
|
|
501
|
+
const { components, namespaces } = sdkBindings(text);
|
|
502
|
+
if (!components.size && !namespaces.size) return [];
|
|
503
|
+
const shape = sourceShape(text), found = [];
|
|
504
|
+
for (const match of text.matchAll(JSX_TAG)) {
|
|
505
|
+
if (shape.inString[match.index]) continue;
|
|
506
|
+
const [first, second] = match[1].split('.');
|
|
507
|
+
const exported = second === undefined ? components.get(first) : namespaces.has(first) ? second : undefined;
|
|
508
|
+
if (!exported) continue;
|
|
509
|
+
const wanted = exported === 'Icon' ? 'name' : 'icon';
|
|
510
|
+
const end = tagEnd(text, shape, match.index);
|
|
511
|
+
const level = shape.owner[match.index];
|
|
512
|
+
JSX_ATTRIBUTE.lastIndex = match.index + match[0].length;
|
|
513
|
+
let attribute;
|
|
514
|
+
while ((attribute = JSX_ATTRIBUTE.exec(text)) !== null && attribute.index < end) {
|
|
515
|
+
if (attribute[1] !== wanted || shape.inString[attribute.index] || shape.owner[attribute.index] !== level) continue;
|
|
516
|
+
const literal = literalAt(text, shape, attribute.index + attribute[0].length, { braced: true });
|
|
517
|
+
if (literal) found.push(literal);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
for (const match of text.matchAll(ICON_FIELD)) {
|
|
521
|
+
if (shape.inString[match.index] || !keyPosition(text, shape, match.index)) continue;
|
|
522
|
+
const literal = literalAt(text, shape, match.index + match[0].length);
|
|
523
|
+
if (!literal || !/^\s*[,}]/.test(text.slice(literal.end))) continue;
|
|
524
|
+
const object = shape.owner[match.index];
|
|
525
|
+
if (object < 0 || !shape.closes.has(object)) continue;
|
|
526
|
+
const body = text.slice(object, shape.closes.get(object) + 1);
|
|
527
|
+
const labelled = [...body.matchAll(LABEL_KEY)].some((key) => !shape.inString[object + key.index]
|
|
528
|
+
&& shape.owner[object + key.index] === object && keyPosition(text, shape, object + key.index));
|
|
529
|
+
if (labelled) found.push(literal);
|
|
530
|
+
}
|
|
531
|
+
return found;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
function loadIconCheck(icons, profile) {
|
|
535
|
+
if (!icons || typeof icons !== 'object' || !Array.isArray(icons.names) || icons.names.length === 0) return null;
|
|
536
|
+
if (Array.isArray(icons.profiles) && !icons.profiles.includes(profile)) return null;
|
|
537
|
+
const names = icons.names.filter((name) => typeof name === 'string');
|
|
538
|
+
return {
|
|
539
|
+
id: typeof icons.id === 'string' ? icons.id : 'space-unknown-icon',
|
|
540
|
+
message: typeof icons.message === 'string' ? icons.message : 'Unknown icon "{name}". Closest names: {suggestions}.',
|
|
541
|
+
suggestions: Number.isInteger(icons.suggestions) && icons.suggestions > 0 ? icons.suggestions : 3,
|
|
542
|
+
exclude: Array.isArray(icons.exclude) ? icons.exclude : [],
|
|
543
|
+
names,
|
|
544
|
+
known: new Set(names),
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
function editDistance(a, b) {
|
|
549
|
+
let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
|
|
550
|
+
for (let i = 1; i <= a.length; i += 1) {
|
|
551
|
+
const current = [i];
|
|
552
|
+
for (let j = 1; j <= b.length; j += 1) {
|
|
553
|
+
current[j] = Math.min(previous[j] + 1, current[j - 1] + 1, previous[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
554
|
+
}
|
|
555
|
+
previous = current;
|
|
556
|
+
}
|
|
557
|
+
return previous[b.length];
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* The names the refusal suggests: those sharing a word with the unknown name first ("funnel" finds
|
|
562
|
+
* funnel-simple), then by edit distance, ties by name.
|
|
563
|
+
*/
|
|
564
|
+
export function closestIconNames(name, names, count = 3) {
|
|
565
|
+
const words = new Set(name.split('-'));
|
|
566
|
+
return names
|
|
567
|
+
.map((candidate) => ({
|
|
568
|
+
candidate,
|
|
569
|
+
shared: candidate.split('-').some((word) => words.has(word)) ? 0 : 1,
|
|
570
|
+
distance: editDistance(name, candidate),
|
|
571
|
+
}))
|
|
572
|
+
.sort((left, right) => left.shared - right.shared || left.distance - right.distance
|
|
573
|
+
|| (left.candidate < right.candidate ? -1 : left.candidate > right.candidate ? 1 : 0))
|
|
574
|
+
.slice(0, count)
|
|
575
|
+
.map((entry) => entry.candidate);
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
function iconViolations(normalized, content, checked, lines, config) {
|
|
579
|
+
const icons = config.icons;
|
|
580
|
+
if (!icons || matchesAny(normalized, icons.exclude)) return [];
|
|
581
|
+
const found = new Map(), suggestions = new Map(), lineStarts = [0];
|
|
582
|
+
for (let cursor = 0; cursor < content.length; cursor += 1) if (content.charCodeAt(cursor) === 10) lineStarts.push(cursor + 1);
|
|
583
|
+
const lineAt = (index) => {
|
|
584
|
+
let low = 0, high = lineStarts.length - 1;
|
|
585
|
+
while (low < high) { const middle = (low + high + 1) >> 1; if (lineStarts[middle] <= index) low = middle; else high = middle - 1; }
|
|
586
|
+
return low + 1;
|
|
587
|
+
};
|
|
588
|
+
for (const { index, name } of iconCandidates(checked)) {
|
|
589
|
+
if (!ICON_NAME_SHAPE.test(name) || icons.known.has(name)) continue;
|
|
590
|
+
const line = lineAt(index);
|
|
591
|
+
const key = `${line}:${name}`;
|
|
592
|
+
if (!found.has(key)) found.set(key, { line, name });
|
|
593
|
+
}
|
|
594
|
+
return [...found.values()].sort((left, right) => left.line - right.line).map(({ line, name }) => {
|
|
595
|
+
const message = icons.message
|
|
596
|
+
.replace('{name}', name)
|
|
597
|
+
.replace('{suggestions}', suggestions.get(name) ?? suggestions.set(name, closestIconNames(name, icons.names, icons.suggestions).join(', ')).get(name));
|
|
598
|
+
const reason = findAllowDirective(lines, line, icons.id, config.allowDirective);
|
|
599
|
+
const allowed = reason !== null && reason.length >= config.allowReasonMinLength;
|
|
600
|
+
return {
|
|
601
|
+
file: normalized,
|
|
602
|
+
line,
|
|
603
|
+
ruleId: icons.id,
|
|
604
|
+
severity: allowed ? 'warn' : 'error',
|
|
605
|
+
message: reason !== null && !allowed
|
|
606
|
+
? `${message} (a notis-design-allow directive needs a reason of at least ${config.allowReasonMinLength} characters)`
|
|
607
|
+
: message,
|
|
608
|
+
allowed,
|
|
609
|
+
reason: allowed ? reason : null,
|
|
610
|
+
};
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
|
|
376
614
|
function getCompiledDesignRules(profile = 'app') {
|
|
377
615
|
if (!compiledDesignRules.has(profile)) {
|
|
378
616
|
compiledDesignRules.set(profile, loadDesignRules({ profile }));
|
|
@@ -411,7 +649,13 @@ export function collectDesignViolationsForFile(relPath, content, config = getCom
|
|
|
411
649
|
// directive; comments are masked after, for matching only, so a real
|
|
412
650
|
// directive comment is still read from `lines`.
|
|
413
651
|
const unserialized = ['.js', '.jsx', '.ts', '.tsx'].includes(extension)
|
|
414
|
-
?
|
|
652
|
+
? maskSerializedJsonDataOrNull(content, extension) : content;
|
|
653
|
+
// Too deep to parse here: checked unmasked, data deep in it would read as code. The server checks it when the
|
|
654
|
+
// Space is released, at any depth, so this file is left to it.
|
|
655
|
+
if (unserialized === null) {
|
|
656
|
+
return [{ file: normalized, line: 1, ruleId: 'too-deep', severity: 'info', allowed: false, reason: null,
|
|
657
|
+
message: 'nested too deep to check here; the server checks this file when you deploy' }];
|
|
658
|
+
}
|
|
415
659
|
const checked = maskComments(unserialized, extension);
|
|
416
660
|
const lines = unserialized.split('\n');
|
|
417
661
|
const violations = [];
|
|
@@ -452,6 +696,7 @@ export function collectDesignViolationsForFile(relPath, content, config = getCom
|
|
|
452
696
|
});
|
|
453
697
|
}
|
|
454
698
|
}
|
|
699
|
+
if (extension !== '.css') violations.push(...iconViolations(normalized, content, checked, lines, config));
|
|
455
700
|
return violations;
|
|
456
701
|
}
|
|
457
702
|
|