@synopackageland/cli 0.53.5 → 0.53.7

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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.53.7 (2026-11-11)
4
+
5
+ - The v2 operation registry accepts the SDK 0.53.33 AI semantics: `ai` classes `propose`, `local` and `one-click`, and optional `consent`, `targets`, `risk`, `tier`, `undo`, `audit`, `mcp`, `dynamicProvider` and `labels`. `ctl generate`, `check` and description validation refuse invalid values with the field named.
6
+ - `generated/tools.json` adds each field only when the operation declares it, with an `execution` for the new classes; `generated/operations.md` adds one line of declared semantics. Registries without the new fields generate byte-identical artifacts.
7
+ - `ctl tools <app> --mcp` lists the tools an external MCP client may see. `ctl tool` returns a dry-run plan for `propose`, `local` and `one-click` tools and never executes them.
8
+ - `ctl generate` and `check` warn when an AI tool summary has four words or fewer (`CTL_DESCRIPTION_QUALITY`); set `ctl.descriptions: error` to refuse them.
9
+ - Older CLI releases cannot read descriptions of Apps that use the new fields; update the CLI first.
10
+
11
+ ## 0.53.6 (2026-11-11)
12
+
13
+ - `ui_secret_ignores` entries can name a bundler-hashed chunk with one `[hash]` (`app/chunks/Dialog-[hash].js`), so an unrelated frontend change no longer breaks the build with `UI_SECRET_IGNORE_MISSING`. `[hash]` matches `[A-Za-z0-9_-]{6,64}` inside one path segment, with no other glob syntax, and must match exactly one file; more than one fails with `UI_SECRET_IGNORE_AMBIGUOUS`, listing them.
14
+ - New `match` (a string or a list): the exact flagged texts to exempt. It is required with `[hash]` and optional for exact paths. Other hits in the same file still fail `PUBLIC_UI_UNSAFE`, and a listed text that no longer occurs fails with `UI_SECRET_IGNORE_STALE`. Exact paths without `match` behave as before. Source maps are still never exempt.
15
+ - `build` and project `check` print each unexempted hit (truncated) with a ready-to-paste entry; known token signatures are never printed, and `check <spk>`/`inspect` still report patterns only. Project `check` scans JS/CSS minified as `build` packs it, so printed texts agree with `build`. `[UI_SECRET_IGNORED]` names the resolved file and the `[hash]` entry.
16
+ - SPKs record the resolved exact file and its `match` list in `sdk-package.json`/`native-layout.json`, never `[hash]`; inspection re-checks them. SPKs from earlier releases inspect unchanged. Earlier CLIs cannot read a recorded `match` and report the exceptions as invalid when inspecting a new SPK that uses it.
17
+
3
18
  ## 0.53.5 (2026-11-11)
4
19
 
5
20
  - Page `ctl external` describe so an App's MCP Catalog can grow far past 1 MiB while every message stays within it. Describe returns one page with the Catalog `revision` and, until the last page, a `nextCursor`; request the next page with `{"protocol","action":"describe","revision","cursor"}`. These map directly onto MCP `tools/list` `cursor`/`nextCursor`. A page from a changed revision refuses with `CTL_EXTERNAL_REVISION`; list again from the first page. A page holds at most 1024 tools, and a page with `nextCursor` holds at least one.
@@ -1,5 +1,7 @@
1
1
  import type { CtlClient, DiscoverOptions } from './service.js';
2
- export declare function listAiTools(client: CtlClient, appName: string, options?: DiscoverOptions): Promise<{
2
+ export declare function listAiTools(client: CtlClient, appName: string, options?: DiscoverOptions & {
3
+ mcp?: boolean;
4
+ }): Promise<{
3
5
  auth?: {
4
6
  state: import("./native-store.js").NativeStoreState;
5
7
  reason?: string;
@@ -17,6 +19,15 @@ export declare function listAiTools(client: CtlClient, appName: string, options?
17
19
  };
18
20
  sha256: string;
19
21
  tools: {
22
+ consent?: import("./operation-semantics.js").OperationConsent | undefined;
23
+ targets?: import("./operation-semantics.js").OperationTargets | undefined;
24
+ risk?: "low" | "medium" | "high" | undefined;
25
+ tier?: string | undefined;
26
+ undo?: import("./operation-semantics.js").OperationUndo | undefined;
27
+ audit?: "change" | "sensitive-read" | "read" | "none" | undefined;
28
+ mcp?: "exposed" | "hidden" | "human-only" | undefined;
29
+ labels?: Record<string, string> | undefined;
30
+ dynamicProvider?: boolean | undefined;
20
31
  execution: string;
21
32
  preview?: string | undefined;
22
33
  name: string;
@@ -28,12 +39,14 @@ export declare function listAiTools(client: CtlClient, appName: string, options?
28
39
  destructiveHint: boolean;
29
40
  openWorldHint: boolean;
30
41
  };
31
- ai: "read" | "preview" | "draft" | "human-only" | "hidden";
42
+ ai: "local" | "read" | "preview" | "draft" | "human-only" | "hidden" | "propose" | "one-click";
32
43
  flow: import("./descriptor.js").Flow;
33
44
  }[];
34
45
  }>;
35
46
  /** A draft is always a preview and plan. This API has no write-confirmation input.
36
47
  * Humans can execute the reviewed ctl plan separately with the normal --yes guard.
37
48
  * Read tools run a complete fixed flow, including job polling or pagination.
49
+ * propose, local and one-click need the App's per-turn Allow-changes or a
50
+ * person pressing a card; ctl has neither, so they return a dry-run plan only.
38
51
  */
39
52
  export declare function runAiTool(client: CtlClient, appName: string, method: string, params: Record<string, unknown>, options?: DiscoverOptions): Promise<any>;
@@ -1,19 +1,22 @@
1
1
  import { CtlError } from './errors.js';
2
2
  import { registryTools } from './registry.js';
3
+ import { isToolClass } from './operation-semantics.js';
3
4
  export async function listAiTools(client, appName, options = {}) {
4
5
  const app = client.selectApp(await client.discover(options), appName);
5
6
  if (app.version === 1 || app.version === 2 && !app.payload.operations)
6
7
  throw new CtlError('CTL_AI_REGISTRY_REQUIRED', 'AI tools require an operation registry.', 'Migrate the App operation registry.', 5);
7
- return { package: app.payload.package, sha256: app.sha256, tools: registryTools({ operations: app.version === 3 ? app.payload.commands : app.payload.operations }), ...(app.payload.execution ? { auth: await client.nativeState(app), credentialGuidance: 'Ask the user to run ctl auth in their own terminal. Never request credentials in chat.' } : {}) };
8
+ return { package: app.payload.package, sha256: app.sha256, tools: registryTools({ operations: app.version === 3 ? app.payload.commands : app.payload.operations }, { mcp: options.mcp }), ...(app.payload.execution ? { auth: await client.nativeState(app), credentialGuidance: 'Ask the user to run ctl auth in their own terminal. Never request credentials in chat.' } : {}) };
8
9
  }
9
10
  /** A draft is always a preview and plan. This API has no write-confirmation input.
10
11
  * Humans can execute the reviewed ctl plan separately with the normal --yes guard.
11
12
  * Read tools run a complete fixed flow, including job polling or pagination.
13
+ * propose, local and one-click need the App's per-turn Allow-changes or a
14
+ * person pressing a card; ctl has neither, so they return a dry-run plan only.
12
15
  */
13
16
  export async function runAiTool(client, appName, method, params, options = {}) {
14
17
  const app = client.selectApp(await client.discover(options), appName);
15
18
  const op = app.version !== 1 ? app.payload.commands[method] : undefined;
16
- if (!op || !['read', 'preview', 'draft'].includes(op.ai ?? ''))
19
+ if (!op || !isToolClass(op.ai))
17
20
  throw new CtlError('CTL_AI_NOT_EXPOSED', 'Operation is not an AI tool.', 'Use the generated tool list.', 4);
18
21
  const args = ['--input', '-'], stdin = JSON.stringify(params);
19
22
  if (op.ai === 'draft') {
@@ -24,5 +27,9 @@ export async function runAiTool(client, appName, method, params, options = {}) {
24
27
  const draft = await client.execute(appName, op.cli, args, { ...options, stdin, dryRun: true });
25
28
  return { confirmationRequired: true, preview: result, draft };
26
29
  }
30
+ if (['propose', 'local', 'one-click'].includes(op.ai ?? '')) {
31
+ const plan = await client.execute(appName, op.cli, args, { ...options, stdin, dryRun: true });
32
+ return { confirmationRequired: true, ai: op.ai, plan };
33
+ }
27
34
  return client.execute(appName, op.cli, args, { ...options, stdin });
28
35
  }
package/dist/ctl/cli.js CHANGED
@@ -144,9 +144,10 @@ async function runCtlWithin(argv, io = {}) {
144
144
  throw new CtlError('CTL_ARGUMENT_INVALID', 'Select one host and App.', 'Use --host <profile>.', 3);
145
145
  const { listAiTools, runAiTool } = await import('./ai-tools.js');
146
146
  if (args[0] === 'tools') {
147
- if (args.length !== 2)
148
- throw new CtlError('CTL_ARGUMENT_INVALID', 'Unexpected tool-list arguments.', 'Use ctl tools <app>.', 3);
149
- emit({ ok: true, data: await listAiTools(client(store.get(hosts[0])), args[1]) });
147
+ const mcp = args[2] === '--mcp';
148
+ if (args.length !== (mcp ? 3 : 2))
149
+ throw new CtlError('CTL_ARGUMENT_INVALID', 'Unexpected tool-list arguments.', 'Use ctl tools <app> [--mcp].', 3);
150
+ emit({ ok: true, data: await listAiTools(client(store.get(hosts[0])), args[1], { mcp }) });
150
151
  return;
151
152
  }
152
153
  if (args.length !== 5 || args[3] !== '--input' || !args[4])
@@ -12,5 +12,5 @@ export async function generateCommand(args) {
12
12
  const result = spawnSync(command, argv, { cwd: options?.cwd, env: options?.env, encoding: 'utf8' });
13
13
  return { status: result.status ?? 1, stdout: result.stdout ?? '', stderr: result.stderr ?? '' };
14
14
  }, check);
15
- return { checked: check, sha256: result.description.sha256 };
15
+ return { checked: check, sha256: result.description.sha256, ...('warnings' in result && result.warnings ? { warnings: result.warnings } : {}) };
16
16
  }
@@ -0,0 +1,51 @@
1
+ /** Optional v2 AI semantics. Every field is metadata for the App/SDK runtime;
2
+ * none grants authority. Omitted fields keep earlier v2 output unchanged. */
3
+ export declare const TOOL_CLASSES: readonly ["read", "preview", "draft", "propose", "local", "one-click"];
4
+ export type OperationConsent = {
5
+ category?: string;
6
+ param?: string;
7
+ };
8
+ export type OperationTargets = {
9
+ max: number;
10
+ traceable?: boolean;
11
+ };
12
+ export type OperationUndo = {
13
+ method: string;
14
+ from: string;
15
+ param: string;
16
+ };
17
+ export interface OperationSemantics {
18
+ consent?: OperationConsent;
19
+ targets?: OperationTargets;
20
+ risk?: 'low' | 'medium' | 'high';
21
+ tier?: string;
22
+ undo?: OperationUndo;
23
+ audit?: 'change' | 'sensitive-read' | 'read' | 'none';
24
+ mcp?: 'exposed' | 'hidden' | 'human-only';
25
+ labels?: Record<string, string>;
26
+ dynamicProvider?: boolean;
27
+ }
28
+ export declare const SEMANTIC_FIELDS: readonly ["consent", "targets", "risk", "tier", "undo", "audit", "mcp", "labels", "dynamicProvider"];
29
+ export declare const isToolClass: (ai: unknown) => boolean;
30
+ /** Effective defaults follow from ai and effect alone. */
31
+ export declare function auditClass(op: {
32
+ audit?: string;
33
+ effect: string;
34
+ }): string;
35
+ export declare function mcpExposure(op: {
36
+ mcp?: string;
37
+ ai?: string;
38
+ }): string;
39
+ /** Returns the first problem as `field: reason`, or undefined. Mirrors the SDK's Go validation. */
40
+ export declare function semanticsProblem(name: string, op: any, ops: Record<string, any>): string | undefined;
41
+ /** Declared semantics only, in a fixed order, for generated artifacts. */
42
+ export declare function declaredSemantics(op: OperationSemantics): Partial<OperationSemantics>;
43
+ export declare const TOOL_EXECUTION: Record<string, string>;
44
+ /** Summary quality for model-facing tools: say what it does and when to use it. */
45
+ export declare function descriptionFindings(operations: Record<string, {
46
+ summary: string;
47
+ ai?: string;
48
+ }>): {
49
+ method: string;
50
+ message: string;
51
+ }[];
@@ -0,0 +1,85 @@
1
+ /** Optional v2 AI semantics. Every field is metadata for the App/SDK runtime;
2
+ * none grants authority. Omitted fields keep earlier v2 output unchanged. */
3
+ export const TOOL_CLASSES = ['read', 'preview', 'draft', 'propose', 'local', 'one-click'];
4
+ export const SEMANTIC_FIELDS = ['consent', 'targets', 'risk', 'tier', 'undo', 'audit', 'mcp', 'labels', 'dynamicProvider'];
5
+ const TOKEN = /^[a-z][a-z0-9-]{0,31}$/, TIER = /^[A-Za-z0-9][A-Za-z0-9_-]{0,15}$/, PARAM = /^[A-Za-z_][A-Za-z0-9_]{0,63}$/;
6
+ export const isToolClass = (ai) => TOOL_CLASSES.includes(ai);
7
+ const record = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
8
+ const pointer = (v) => typeof v === 'string' && v.length > 1 && v.length <= 128 && v[0] === '/' && !/[\r\n]/.test(v);
9
+ const exactKeys = (v, allowed) => Object.keys(v).every(k => allowed.includes(k));
10
+ const head = (p) => p.slice(1).split('/')[0].replaceAll('~1', '/').replaceAll('~0', '~');
11
+ const hasParam = (schema, name) => !record(schema?.properties) || Object.hasOwn(schema.properties, name);
12
+ /** Effective defaults follow from ai and effect alone. */
13
+ export function auditClass(op) { return op.audit ?? (op.effect === 'read' ? 'read' : 'change'); }
14
+ export function mcpExposure(op) { return op.mcp ?? (isToolClass(op.ai) ? 'exposed' : op.ai === 'human-only' ? 'human-only' : 'hidden'); }
15
+ /** Returns the first problem as `field: reason`, or undefined. Mirrors the SDK's Go validation. */
16
+ export function semanticsProblem(name, op, ops) {
17
+ if (op.ai === 'propose' && op.effect !== 'write')
18
+ return 'propose stores a proposal and requires effect write';
19
+ if (op.ai === 'local' && op.effect !== 'write')
20
+ return 'local is a reversible App-local change and requires effect write';
21
+ const c = op.consent;
22
+ if (c !== undefined) {
23
+ if (!isToolClass(op.ai))
24
+ return 'consent applies only to AI tool classes';
25
+ if (!record(c) || !exactKeys(c, ['category', 'param']) || (c.category === undefined) === (c.param === undefined))
26
+ return 'consent requires exactly one of category or param';
27
+ if (c.category !== undefined && (typeof c.category !== 'string' || !TOKEN.test(c.category)))
28
+ return 'consent category must be a lowercase token';
29
+ if (c.param !== undefined && (!pointer(c.param) || !hasParam(op.paramsSchema, head(c.param))))
30
+ return 'consent param must be a JSON pointer to a declared parameter';
31
+ }
32
+ const t = op.targets;
33
+ if (t !== undefined && (!record(t) || !exactKeys(t, ['max', 'traceable']) || !Number.isInteger(t.max) || t.max < 0 || t.max > 1000 || t.traceable !== undefined && typeof t.traceable !== 'boolean'))
34
+ return 'targets requires integer max 0..1000 and optional boolean traceable';
35
+ if (op.risk !== undefined && !['low', 'medium', 'high'].includes(op.risk))
36
+ return 'risk must be low, medium or high';
37
+ if (op.tier !== undefined && (typeof op.tier !== 'string' || !TIER.test(op.tier)))
38
+ return 'tier must be a short token';
39
+ const u = op.undo;
40
+ if (u !== undefined) {
41
+ const target = record(u) ? ops[u.method] : undefined;
42
+ if (!record(u) || !exactKeys(u, ['method', 'from', 'param']))
43
+ return 'undo requires method, from and param';
44
+ if (op.effect === 'read')
45
+ return 'undo applies only to a change';
46
+ if (u.method === name || !target || target.effect === 'read' || target.ai === 'hidden')
47
+ return 'undo method must be another visible change operation';
48
+ if (!pointer(u.from))
49
+ return 'undo from must be a JSON pointer into the result';
50
+ if (typeof u.param !== 'string' || !PARAM.test(u.param) || !hasParam(target.paramsSchema, u.param))
51
+ return `undo param must be a parameter of ${u.method}`;
52
+ }
53
+ if (op.audit !== undefined) {
54
+ if (!['change', 'sensitive-read', 'read', 'none'].includes(op.audit))
55
+ return 'audit must be change, sensitive-read, read or none';
56
+ if (op.audit !== 'change' && op.effect !== 'read')
57
+ return 'audit of a change must be change';
58
+ }
59
+ if (op.mcp !== undefined) {
60
+ if (!['exposed', 'hidden', 'human-only'].includes(op.mcp))
61
+ return 'mcp must be exposed, hidden or human-only';
62
+ if (op.mcp === 'exposed' && !isToolClass(op.ai))
63
+ return 'mcp exposed requires an AI tool class';
64
+ if (op.mcp === 'human-only' && op.ai === 'hidden')
65
+ return 'mcp cannot expose a hidden operation';
66
+ }
67
+ if (op.dynamicProvider !== undefined && (typeof op.dynamicProvider !== 'boolean' || op.dynamicProvider && !isToolClass(op.ai)))
68
+ return 'dynamicProvider requires an AI tool class';
69
+ const l = op.labels;
70
+ if (l !== undefined && (!record(l) || Object.keys(l).length > 16 || Object.entries(l).some(([k, v]) => !TOKEN.test(k) || typeof v !== 'string' || v.length > 128 || /[\r\n]/.test(v))))
71
+ return 'labels need at most 16 lowercase keys with one-line values up to 128 characters';
72
+ return undefined;
73
+ }
74
+ /** Declared semantics only, in a fixed order, for generated artifacts. */
75
+ export function declaredSemantics(op) {
76
+ return Object.fromEntries(SEMANTIC_FIELDS.filter(k => op[k] !== undefined).map(k => [k, op[k]]));
77
+ }
78
+ export const TOOL_EXECUTION = { read: 'flow', preview: 'flow', draft: 'preview-and-human-confirmation', propose: 'proposal-with-allow-changes', local: 'allow-changes-or-human-card', "one-click": 'human-card' };
79
+ /** Summary quality for model-facing tools: say what it does and when to use it. */
80
+ export function descriptionFindings(operations) {
81
+ return Object.entries(operations).sort(([a], [b]) => a.localeCompare(b)).filter(([, op]) => isToolClass(op.ai)).flatMap(([method, op]) => {
82
+ const words = op.summary.trim().split(/\s+/).filter(Boolean).length;
83
+ return words <= 4 ? [{ method, message: `${method}: summary has ${words} word${words === 1 ? '' : 's'}; say what the tool does and when to use it (at least 5 words).` }] : [];
84
+ });
85
+ }
@@ -1,7 +1,8 @@
1
1
  import { type Operation } from './descriptor.js';
2
- export declare const AI_CLASSES: readonly ["read", "preview", "draft", "human-only", "hidden"];
2
+ import { type OperationSemantics } from './operation-semantics.js';
3
+ export declare const AI_CLASSES: readonly ["read", "preview", "draft", "propose", "local", "one-click", "human-only", "hidden"];
3
4
  export type AIClass = typeof AI_CLASSES[number];
4
- export type RegisteredOperation = Operation & {
5
+ export type RegisteredOperation = Operation & OperationSemantics & {
5
6
  ai: AIClass;
6
7
  paramsSchema: Record<string, any>;
7
8
  resultSchema: Record<string, any>;
@@ -28,7 +29,21 @@ export declare function checkRouteEquality(registry: OperationRegistry, routes:
28
29
  permission: string;
29
30
  }[]): void;
30
31
  export declare function registryPermissions(registry: OperationRegistry): string;
31
- export declare function registryTools(registry: Pick<OperationRegistry, 'operations'>): {
32
+ /** Model-facing tools. Semantic fields appear only when declared, so earlier
33
+ * registries generate byte-identical tools.json. With mcp, only tools an
34
+ * external MCP client may list (exposed, or human-only as a card) remain. */
35
+ export declare function registryTools(registry: Pick<OperationRegistry, 'operations'>, options?: {
36
+ mcp?: boolean;
37
+ }): {
38
+ consent?: import("./operation-semantics.js").OperationConsent | undefined;
39
+ targets?: import("./operation-semantics.js").OperationTargets | undefined;
40
+ risk?: "low" | "medium" | "high" | undefined;
41
+ tier?: string | undefined;
42
+ undo?: import("./operation-semantics.js").OperationUndo | undefined;
43
+ audit?: "change" | "sensitive-read" | "read" | "none" | undefined;
44
+ mcp?: "exposed" | "hidden" | "human-only" | undefined;
45
+ labels?: Record<string, string> | undefined;
46
+ dynamicProvider?: boolean | undefined;
32
47
  execution: string;
33
48
  preview?: string | undefined;
34
49
  name: string;
@@ -40,7 +55,7 @@ export declare function registryTools(registry: Pick<OperationRegistry, 'operati
40
55
  destructiveHint: boolean;
41
56
  openWorldHint: boolean;
42
57
  };
43
- ai: "read" | "preview" | "draft" | "human-only" | "hidden";
58
+ ai: "local" | "read" | "preview" | "draft" | "human-only" | "hidden" | "propose" | "one-click";
44
59
  flow: import("./descriptor.js").Flow;
45
60
  }[];
46
61
  export declare function registryReference(registry: OperationRegistry): string;
@@ -3,7 +3,8 @@ import { dirname, join, resolve, relative, isAbsolute } from 'node:path';
3
3
  import { strictJson } from './json.js';
4
4
  import { ajv, safeSchema, validateFlow } from './descriptor.js';
5
5
  import { validateNativeRegistry } from './native-registry.js';
6
- export const AI_CLASSES = ['read', 'preview', 'draft', 'human-only', 'hidden'];
6
+ import { semanticsProblem, declaredSemantics, isToolClass, mcpExposure, TOOL_EXECUTION } from './operation-semantics.js';
7
+ export const AI_CLASSES = ['read', 'preview', 'draft', 'propose', 'local', 'one-click', 'human-only', 'hidden'];
7
8
  export const INFRASTRUCTURE_METHODS = new Set(['synopkgland.describe', 'identity.status', 'identity.login', 'identity.session', 'identity.logout']);
8
9
  const METHOD = /^[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)+$/;
9
10
  export function registryFile(root, file) {
@@ -82,6 +83,9 @@ export function validateRegistry(value) {
82
83
  if (!preview || preview.ai !== 'preview' || preview.effect !== 'read')
83
84
  fail(`${name}: preview must name a non-mutating preview operation.`);
84
85
  }
86
+ const problem = semanticsProblem(name, op, value.operations);
87
+ if (problem)
88
+ fail(`${name}: ${problem}.`);
85
89
  }
86
90
  }
87
91
  export function checkRouteEquality(registry, routes) {
@@ -109,11 +113,36 @@ function toolResultSchema(op) {
109
113
  const items = op.resultSchema.type === 'array' ? op.resultSchema : { type: 'array', items: op.resultSchema };
110
114
  return { type: 'object', required: op.flow.type === 'paginate-http' ? ['items', 'incomplete'] : ['items'], properties: { items, ...(op.flow.type === 'paginate-http' ? { incomplete: { type: 'boolean' }, reason: { type: 'string' }, continuation: { type: 'object' } } : {}) }, additionalProperties: false };
111
115
  }
112
- export function registryTools(registry) {
113
- return Object.entries(registry.operations).sort(([a], [b]) => a.localeCompare(b)).filter(([, op]) => ['read', 'preview', 'draft'].includes(op.ai)).map(([name, op]) => ({ name, description: op.summary, inputSchema: op.paramsSchema, outputSchema: toolResultSchema(op), annotations: { readOnlyHint: op.effect === 'read', destructiveHint: op.effect === 'destructive', openWorldHint: false }, ai: op.ai, flow: op.flow, ...(op.preview ? { preview: op.preview } : {}), execution: op.ai === 'draft' ? 'preview-and-human-confirmation' : 'flow' }));
116
+ /** Model-facing tools. Semantic fields appear only when declared, so earlier
117
+ * registries generate byte-identical tools.json. With mcp, only tools an
118
+ * external MCP client may list (exposed, or human-only as a card) remain. */
119
+ export function registryTools(registry, options = {}) {
120
+ return Object.entries(registry.operations).sort(([a], [b]) => a.localeCompare(b)).filter(([, op]) => isToolClass(op.ai) && (!options.mcp || mcpExposure(op) !== 'hidden')).map(([name, op]) => ({ name, description: op.summary, inputSchema: op.paramsSchema, outputSchema: toolResultSchema(op), annotations: { readOnlyHint: op.effect === 'read', destructiveHint: op.effect === 'destructive', openWorldHint: false }, ai: op.ai, flow: op.flow, ...(op.preview ? { preview: op.preview } : {}), execution: TOOL_EXECUTION[op.ai], ...declaredSemantics(op) }));
121
+ }
122
+ function semanticsLine(op) {
123
+ const parts = [];
124
+ if (op.consent)
125
+ parts.push(op.consent.category ? `consent: ${op.consent.category}` : `consent: from \`${op.consent.param}\``);
126
+ if (op.targets)
127
+ parts.push(`targets: at most ${op.targets.max}${op.targets.traceable ? ', traceable' : ''}`);
128
+ if (op.risk)
129
+ parts.push(`risk: ${op.risk}`);
130
+ if (op.tier)
131
+ parts.push(`tier: ${op.tier}`);
132
+ if (op.undo)
133
+ parts.push(`undo: \`${op.undo.method}\` with ${op.undo.param} from result \`${op.undo.from}\``);
134
+ if (op.audit)
135
+ parts.push(`audit: ${op.audit}`);
136
+ if (op.mcp)
137
+ parts.push(`MCP: ${op.mcp}`);
138
+ if (op.dynamicProvider)
139
+ parts.push('runtime tools: the App adds tools that call this operation at runtime');
140
+ if (op.labels)
141
+ parts.push('labels: ' + Object.entries(op.labels).sort(([a], [b]) => a.localeCompare(b)).map(([k, v]) => `${k}=${v}`).join(', '));
142
+ return parts.length ? `${parts.join('; ').replaceAll('<', '&lt;')}\n\n` : '';
114
143
  }
115
144
  export function registryReference(registry) {
116
- return '<!-- Generated by synopkgland ctl generate; edit the operation registry. -->\n# App operations\n\n' + Object.entries(registry.operations).sort(([a], [b]) => a.localeCompare(b)).map(([name, op]) => `## ${name}\n\n${op.summary.replaceAll('<', '&lt;')}\n\nAI: ${op.ai}; effect: ${op.effect}; permission: ${op.permission}; flow: ${op.flow.type}\n\n${op.ai === 'hidden' ? 'No ctl or AI exposure.' : `ctl: \`${op.cli.join(' ')}\``}\n${op.preview ? `\nPreview: \`${op.preview}\`; obtain human confirmation before execution.\n` : ''}`).join('\n');
145
+ return '<!-- Generated by synopkgland ctl generate; edit the operation registry. -->\n# App operations\n\n' + Object.entries(registry.operations).sort(([a], [b]) => a.localeCompare(b)).map(([name, op]) => `## ${name}\n\n${op.summary.replaceAll('<', '&lt;')}\n\nAI: ${op.ai}; effect: ${op.effect}; permission: ${op.permission}; flow: ${op.flow.type}\n\n${semanticsLine(op)}${op.ai === 'hidden' ? 'No ctl or AI exposure.' : `ctl: \`${op.cli.join(' ')}\``}\n${op.preview ? `\nPreview: \`${op.preview}\`; obtain human confirmation before execution.\n` : ''}`).join('\n');
117
146
  }
118
147
  export function writeGenerated(path, contents, check) {
119
148
  if (check) {
@@ -68,6 +68,7 @@ export const ERROR_REGISTRY = {
68
68
  COMPOSE_HEALTH_REQUIRED: { code: "COMPOSE_HEALTH_REQUIRED", description: "Compose web readiness was not selected.", suggestion: "Set compose.web.health.path and expected 2xx status for the actual App; redirects are not followed." },
69
69
  CTL_LEGACY_COMMANDS_DEPRECATED: { code: 'CTL_LEGACY_COMMANDS_DEPRECATED', description: 'The App uses the supported legacy ctl.commands declaration.', suggestion: 'Plan migration to ctl.registry when ready; check and build continue to support v1.' },
70
70
  CTL_REGISTRY_REQUIRED: { code: 'CTL_REGISTRY_REQUIRED', description: 'The App needs a single operation registry.', suggestion: 'Replace ctl.commands with ctl.registry and run synopkgland ctl generate.' },
71
+ CTL_DESCRIPTION_QUALITY: { code: 'CTL_DESCRIPTION_QUALITY', description: 'An AI tool summary is too short to choose the tool.', suggestion: 'Write one English sentence of at least five words: what the tool does and when to use it.' },
71
72
  CTL_REGISTRY_INVALID: { code: 'CTL_REGISTRY_INVALID', description: 'The operation registry is invalid.', suggestion: 'Declare every method with its required ai class, schemas, effect, permission and fixed flow.' },
72
73
  CTL_ROUTE_MISMATCH: { code: 'CTL_ROUTE_MISMATCH', description: 'Operation specs and registered handlers differ.', suggestion: 'Match all method names and permissions in both directions, including hidden methods.' },
73
74
  CTL_GENERATED_DRIFT: { code: 'CTL_GENERATED_DRIFT', description: 'Generated operation artifacts differ from the registry.', suggestion: 'Run synopkgland ctl generate, then synopkgland ctl generate --check.' },
@@ -3,7 +3,7 @@ import { posix } from "node:path";
3
3
  import * as tar from "tar";
4
4
  import { ARCH_ELF_MACHINE } from "./dsm-spec.js";
5
5
  import { archiveInventory, formatArchiveIssue } from './archive-inventory.js';
6
- import { applyUiIgnores, publicUiReport, uiFileProblems } from "../standalone/public-ui.js";
6
+ import { applyUiIgnores, logicalUiFile, publicUiReport, resolveUiSecretIgnores, staleUiIgnores, uiFileProblems } from "../standalone/public-ui.js";
7
7
  const XZ_MAGIC = Buffer.from([0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00]);
8
8
  const ELF_MAGIC = Buffer.from("\x7fELF", "latin1");
9
9
  const MAX_TEXT = 1024 * 1024;
@@ -164,17 +164,31 @@ export async function checkPayload(payloadPath, info, findings, policy = {}) {
164
164
  checkUiConfig(file, sections, findings);
165
165
  checkElf(files, info.arch, findings);
166
166
  const ui = files.filter(file => file.path.startsWith("ui/"));
167
+ let ignores = [];
168
+ try {
169
+ // New builds record exact files; older or hand-made metadata may still hold [hash].
170
+ ignores = resolveUiSecretIgnores(ui.map(file => logicalUiFile(file.path.slice(3), policy.moduleVersion)), policy.ignores ?? [], false);
171
+ }
172
+ catch (error) {
173
+ findings.add("SPK_UI_UNSAFE", error.message, "ui/");
174
+ }
175
+ const scanned = [];
167
176
  for (const file of ui) {
168
177
  if (file.content === undefined) {
169
178
  findings.add("SPK_UI_UNSAFE", "Public UI file exceeds the 64 MiB scan limit.", at(file.path));
170
179
  continue;
171
180
  }
172
- const problems = applyUiIgnores(uiFileProblems(file.path.slice(3), file.content), policy.ignores ?? [], policy.moduleVersion);
181
+ const raw = uiFileProblems(file.path.slice(3), file.content);
182
+ scanned.push(...raw);
183
+ // Inspection may run on SPKs from others: report patterns, never the flagged text.
184
+ const problems = applyUiIgnores(raw, ignores, policy.moduleVersion);
173
185
  for (const problem of problems) {
174
186
  if (policy.sourceMaps === false && ["source-map-file", "sourceMappingURL"].includes(problem.pattern))
175
187
  continue;
176
- findings.add(problem.ignored ? "SPK_UI_SECRET_IGNORED" : "SPK_UI_UNSAFE", `Public UI pattern: ${problem.pattern}${problem.ignored ? `; reason: ${problem.ignored}` : "; remove it before packaging"}.`, at(file.path));
188
+ findings.add(problem.ignored ? "SPK_UI_SECRET_IGNORED" : "SPK_UI_UNSAFE", `Public UI pattern: ${problem.pattern}${problem.ignored ? `; ${problem.ignoredBy ? `matched ui/${problem.ignoredBy}; ` : ""}reason: ${problem.ignored}` : "; remove it before packaging"}.`, at(file.path));
177
189
  }
178
190
  }
191
+ for (const stale of staleUiIgnores(scanned, ignores, policy.moduleVersion))
192
+ findings.add("SPK_UI_UNSAFE", "A recorded ui_secret_ignores match no longer occurs in this file; rebuild the SPK.", at(`ui/${stale.file}`));
179
193
  return publicUiReport(ui.filter(file => file.content !== undefined).map(file => ({ file: file.path, content: file.content.toString("utf8") })));
180
194
  }
@@ -18,7 +18,7 @@ export declare const SPK_RULES: {
18
18
  };
19
19
  readonly SPK_UI_SECRET_IGNORED: {
20
20
  readonly severity: "warning";
21
- readonly description: "An exact public UI file has a secret-scan exception with a reason.";
21
+ readonly description: "A public UI file has a secret-scan exception with a reason (and, when listed, only its matched texts).";
22
22
  readonly source: "Public UI policy";
23
23
  };
24
24
  readonly SPK_ARCHIVE_INVALID: {
package/dist/spk/rules.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const GUIDE = "DSM 7 Developer Guide";
2
2
  export const SPK_RULES = {
3
3
  SPK_UI_UNSAFE: { severity: "error", description: "Public UI contains source maps or secret-looking content.", source: "Public UI policy" },
4
- SPK_UI_SECRET_IGNORED: { severity: "warning", description: "An exact public UI file has a secret-scan exception with a reason.", source: "Public UI policy" },
4
+ SPK_UI_SECRET_IGNORED: { severity: "warning", description: "A public UI file has a secret-scan exception with a reason (and, when listed, only its matched texts).", source: "Public UI policy" },
5
5
  SPK_ARCHIVE_INVALID: { severity: "error", description: "An archive has noncanonical or colliding names, repeated entries, or unsupported entry types.", source: "Archive inventory" },
6
6
  SPK_NOT_TAR: { severity: "error", description: "The file is not a readable tar archive; an SPK is an uncompressed tar.", source: `${GUIDE}: Package Structure` },
7
7
  SPK_ENTRY_UNSAFE: { severity: "error", description: "A path inside the SPK escapes the archive root (an absolute path or ..), or is a link.", source: `${GUIDE}: Package Structure` },
@@ -59,6 +59,7 @@ export interface StandaloneManifest {
59
59
  enabled: boolean;
60
60
  transport?: 'native-http';
61
61
  registry?: string;
62
+ descriptions?: 'warn' | 'error';
62
63
  aliases?: string[];
63
64
  developedBy?: string;
64
65
  commands: Record<string, import("../ctl/descriptor.js").Operation>;
@@ -651,6 +651,10 @@ function readManifest(raw, c) {
651
651
  return undefined;
652
652
  }
653
653
  }
654
+ if (isRecord(raw.ctl) && raw.ctl.descriptions !== undefined && (!['warn', 'error'].includes(raw.ctl.descriptions) || typeof raw.ctl.registry !== 'string')) {
655
+ c.fail('CTL_DECLARATION_INVALID', 'ctl.descriptions must be warn or error and requires ctl.registry.');
656
+ return undefined;
657
+ }
654
658
  const manifest = {
655
659
  ...(raw.ctl ? { ctl: raw.ctl } : {}),
656
660
  ...(allowSecretFiles ? { allowSecretFiles } : {}),
@@ -5,7 +5,7 @@ import { validateMetadata, metadataInfoFields } from "../package-metadata.js";
5
5
  import { createHash } from 'node:crypto';
6
6
  import { chmodSync, copyFileSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
7
7
  import { enforceRepositorySecrets, readAllowedSecretFiles } from '../secret-files.js';
8
- import { enforcePublicUi, minifyUiTree, readUiSecretIgnores, uiFiles } from './public-ui.js';
8
+ import { enforcePublicUi, minifyUiTree, readUiSecretIgnores, storedUiSecretIgnores, uiFiles } from './public-ui.js';
9
9
  import { tmpdir } from 'node:os';
10
10
  import { dirname, isAbsolute, join, relative, resolve } from 'node:path';
11
11
  import { parse } from 'yaml';
@@ -355,9 +355,9 @@ export async function buildNativeLayout(options) {
355
355
  mkdirSync(target);
356
356
  copyTree(payload, target);
357
357
  minifyUiTree(join(target, 'ui'));
358
- enforcePublicUi(join(target, 'ui'), m.uiSecretIgnores);
358
+ const uiIgnores = enforcePublicUi(join(target, 'ui'), m.uiSecretIgnores);
359
359
  const files = layoutFiles(target);
360
- const ignoredUi = uiFiles(join(target, 'ui')).filter(file => m.uiSecretIgnores?.some(ignore => ignore.file === file)).map(file => `ui/${file}`);
360
+ const ignoredUi = uiFiles(join(target, 'ui')).filter(file => uiIgnores.some(ignore => ignore.file === file)).map(file => `ui/${file}`);
361
361
  await createReproducibleTar(target, join(stage, 'package.tgz'), { gzip: true, rejectSecrets: true, allowSecretFiles: [...new Set([...(m.allowSecretFiles ?? []), ...ignoredUi])] });
362
362
  rmSync(target, { recursive: true });
363
363
  const fields = { package: m.package, version, arch: layoutInfoArch(arch), os_min_ver: m.os_min_ver, displayname: m.displayname, description: m.description, maintainer: m.maintainer, dsmuidir: 'ui', dsmappname: `SYNO.SDS.${m.package}.Instance`, startable: 'yes', thirdparty: 'yes', checksum: createHash('md5').update(readFileSync(join(stage, 'package.tgz'))).digest('hex') };
@@ -366,7 +366,7 @@ export async function buildNativeLayout(options) {
366
366
  if (new Set(info.map(([k]) => k)).size !== info.length)
367
367
  fail('INFO anchor collides with an INFO field');
368
368
  writeFileSync(join(stage, 'INFO'), info.map(([k, v]) => `${k}="${v.replace(/([\\"$`])/g, '\\$1')}"\n`).join(''));
369
- writeFileSync(join(stage, 'native-layout.json'), JSON.stringify({ format: 1, arch, dependencies: m.dependencies ?? { packages: [] }, ...(m.uiSecretIgnores?.length ? { ui_secret_ignores: m.uiSecretIgnores } : {}), binaries: binaries.map(({ path, linkage }) => ({ path, linkage })), files, ...(m.layout.anchors ? { anchors: m.layout.anchors } : {}), ...(m.portal ? { portal: m.portal } : {}) }));
369
+ writeFileSync(join(stage, 'native-layout.json'), JSON.stringify({ format: 1, arch, dependencies: m.dependencies ?? { packages: [] }, ...(uiIgnores.length ? { ui_secret_ignores: storedUiSecretIgnores(uiIgnores) } : {}), binaries: binaries.map(({ path, linkage }) => ({ path, linkage })), files, ...(m.layout.anchors ? { anchors: m.layout.anchors } : {}), ...(m.portal ? { portal: m.portal } : {}) }));
370
370
  for (const name of ['INFO', 'native-layout.json'])
371
371
  chmodSync(join(stage, name), 0o644);
372
372
  const output = join(outDir, `${m.package}-${version}-${arch}.spk`);
@@ -2,7 +2,14 @@ import { type Descriptor } from '../ctl/descriptor.js';
2
2
  import { type StandaloneManifest } from './manifest.js';
3
3
  import type { CommandRunner } from './build.js';
4
4
  import { type NativeArtifacts } from './native-http.js';
5
+ /** Tool summary lint. Warnings by default; ctl.descriptions: error refuses generation. */
6
+ export declare function descriptionWarnings(m: StandaloneManifest, operations: Record<string, {
7
+ summary: string;
8
+ ai?: string;
9
+ }>): string[];
5
10
  export declare function operationRegistry(m: StandaloneManifest): import("../ctl/registry.js").OperationRegistry;
6
11
  export declare function registryDescriptor(m: StandaloneManifest, registry?: import("../ctl/registry.js").OperationRegistry): Descriptor;
7
12
  /** Generation writes metadata only. The exporter constructs routes without running handlers. */
8
- export declare function generateOperations(m: StandaloneManifest, run: CommandRunner, check?: boolean, bridgeMethods?: string[]): Promise<NativeArtifacts>;
13
+ export declare function generateOperations(m: StandaloneManifest, run: CommandRunner, check?: boolean, bridgeMethods?: string[]): Promise<NativeArtifacts & {
14
+ warnings?: string[];
15
+ }>;
@@ -7,6 +7,14 @@ import { readApiPermissions, API_PERMISSIONS_FILE } from './api-permissions.js';
7
7
  import { sdkBackend } from './manifest.js';
8
8
  import { describeApiRoutes } from './api-description.js';
9
9
  import { generateNativeOperations } from './native-http.js';
10
+ import { descriptionFindings } from '../ctl/operation-semantics.js';
11
+ /** Tool summary lint. Warnings by default; ctl.descriptions: error refuses generation. */
12
+ export function descriptionWarnings(m, operations) {
13
+ const findings = descriptionFindings(operations).map(f => f.message);
14
+ if (findings.length && m.ctl?.descriptions === 'error')
15
+ throw Error('CTL_DESCRIPTION_QUALITY: ' + findings.join(' '));
16
+ return findings;
17
+ }
10
18
  export function operationRegistry(m) {
11
19
  if (!m.ctl?.registry)
12
20
  throw Error('CTL_REGISTRY_REQUIRED: declare ctl.registry with a synopkgland.api v2 spec.');
@@ -34,6 +42,7 @@ export async function generateOperations(m, run, check = false, bridgeMethods) {
34
42
  if (m.ctl?.transport === 'native-http')
35
43
  return generateNativeOperations(m, run, check);
36
44
  const source = operationRegistry(m);
45
+ const warnings = descriptionWarnings(m, source.operations);
37
46
  const registry = structuredClone(source);
38
47
  if (m.backend.kind === 'binary' || m.compose)
39
48
  throw Error('CTL_UNSUPPORTED_BACKEND: operation registry requires the SDK native runtime.');
@@ -82,5 +91,5 @@ export async function generateOperations(m, run, check = false, bridgeMethods) {
82
91
  registryArtifacts(m.root, registry, check, routes);
83
92
  writeGenerated(join(m.root, 'generated', 'synopkgland-api.json'), JSON.stringify(description, null, 2) + '\n', check);
84
93
  writeGenerated(join(m.root, 'generated', 'ctl.json'), JSON.stringify({ commands: description.payload.commands }, null, 2) + '\n', check);
85
- return { description, registry: { ...Object.fromEntries(routes.map(r => [r.method, r.permission])), ...(m.capabilities.identity ? { 'identity.session': 'public', 'identity.logout': 'public' } : {}) } };
94
+ return { ...(warnings.length ? { warnings } : {}), description, registry: { ...Object.fromEntries(routes.map(r => [r.method, r.permission])), ...(m.capabilities.identity ? { 'identity.session': 'public', 'identity.logout': 'public' } : {}) } };
86
95
  }