Expose App commands to ctl
An App is controllable when its package contains a valid, authenticated API description (synopkgland-api.json). For a native SDK App the build writes it from ctl.commands in dsm-package.yaml, so nothing is exposed that you did not declare. How a caller uses the result is in Run ctl commands; what is checked and trusted is in ctl security.
Prerequisites
Section titled “Prerequisites”| Need | Detail |
|---|---|
| Backend | Native SDK backend: Go, Node.js, Python or Rust. A binary or Compose App fails the build with CTL_UNSUPPORTED_BACKEND if ctl.enabled is set; implement the contract yourself instead. |
| Versions | The latest public CLI and templates with their pinned SDK. |
| Go backend | main.go must support the build-only --describe flag, as the templates do, or the build fails with CTL_DESCRIBE_REQUIRED. |
| Methods | Each command binds to methods the backend registers. An unregistered method fails with CTL_COMMAND_UNREGISTERED. |
Add a command
Section titled “Add a command”- Start from a native template. Every one declares three commands in the
ctlblock ofdsm-package.yaml:
synopkgland init -t native-go --package MyApp my-appctl: enabled: true commands: status.show: cli: [status] summary: Show this App's status and verified caller effect: read flow: {type: invoke, method: app.status} paramsSchema: {type: object, additionalProperties: false} examples: [{}] greeting.get: cli: [greeting, get] summary: Read the greeting effect: read flow: {type: invoke, method: greeting.get} paramsSchema: {type: object, additionalProperties: false} examples: [{}] greeting.set: cli: [greeting, set] summary: Set the greeting effect: write flow: {type: invoke, method: greeting.set} paramsSchema: type: object required: [text] additionalProperties: false properties: text: {type: string, minLength: 1, maxLength: 200, description: Greeting text, examples: [Hello]} examples: [{text: Hello}]The map key is the command ID, cli is what the caller types after the App’s alias, and flow.method is the backend method the command calls.
- Add a backend method and a permission. This Go handler is registered in
backend/internal/app/routes.go:
api.Handle("notes.add", cfg.addNote),func (cfg Config) addNote(_ context.Context, caller api.Caller, params json.RawMessage) (any, error) { var in struct { Text string `json:"text"` } if err := decodeParams(params, &in); err != nil { return nil, err } if n := utf8.RuneCountInString(in.Text); n < 1 || n > 200 { return nil, api.BadRequest("text must be 1 to 200 characters") } return cfg.saveNote(caller.User(), in.Text) // your storage code}Set who may call it in backend/internal/api/permissions.json. An unlisted method is administrators:
{ "schema": 1, "default": "administrators", "methods": { "notes.add": "authenticated" } }| Runtime | Register | Permission file |
|---|---|---|
| Go | api.Handle("notes.add", fn) | backend/internal/api/permissions.json |
| Node.js | app.method('notes.add', (ctx, params) => ...) | backend/app/permissions.json |
| Python | app.method("notes.add")(lambda ctx, params: ...) | backend/app/permissions.json |
| Rust | app.method("notes.add", move |ctx, params| ...) | backend/permissions.json |
- Declare the command under
ctl.commands:
notes.add: cli: [notes, add] summary: Add a note for the signed-in user effect: write flow: {type: invoke, method: notes.add} paramsSchema: type: object required: [text] additionalProperties: false properties: text: {type: string, minLength: 1, maxLength: 200, description: Note text} examples: [{text: Buy milk}]- Build and validate.
checkvalidates the declaration,buildcompares each command with the real route registry and permissions and writessynopkgland-api.json, andinspectverifies the description inside the SPK:
synopkgland checksynopkgland build --arch x86_64synopkgland inspect dist/MyApp-0.1.0-0001-x86_64.spk- Try it as a caller. Install the SPK first;
--dry-runsends nothing:
synopkgland ctl list --host nas --app MyApp --jsonsynopkgland ctl myapp notes add --text "Buy milk" --host nas --dry-runsynopkgland ctl myapp notes add --text "Buy milk" --host nas --yesDeclaration reference
Section titled “Declaration reference”ctl in dsm-package.yaml:
| Field | Required | Rule |
|---|---|---|
enabled | Yes | true builds the description. Without ctl, the App is not listed. |
commands | With enabled | Map of command ID to command, 1 to 1024 entries. |
aliases | No | Up to 8 short names, pattern ^[a-zA-Z][a-zA-Z0-9-]{0,63}$. Default: the package ID in lower case. Do not use host, list or help. Two Apps with one alias give CTL_APP_AMBIGUOUS; callers then use the package ID. |
developedBy | No | synopkgland, third-party or unknown (default). Shown to callers as self-declared. |
Each command:
| Field | Required | Rule |
|---|---|---|
| ID (map key) | Yes | Lower case words joined by dots, such as notes.add, at most 128 characters. |
cli | Yes | 1 to 8 words, pattern ^[a-z][a-z0-9-]*$. Unique within the App; the caller types them after the alias. |
summary | Yes | What the command does, up to 1024 characters. |
effect | Yes | read, write or destructive. Never inferred from the name. |
flow | Yes | One of the five flows below. |
paramsSchema | No | JSON Schema 2020-12 object. Without it only --input is accepted and parameters show as undescribed. |
resultSchema | No | The result is validated against it; a mismatch is CTL_RESPONSE_INVALID. |
examples | No | Up to 16 parameter objects, which become the runnable examples in ctl list. |
permission | Never set | The build derives it and overwrites any value. |
| Flow | Use | Fields | Limits |
|---|---|---|---|
invoke | One method call. | method | Request and response at most 1 MiB. |
job | Start a long task, poll, return the result. | start, poll, optional result, jobId, idParam, state, done, failed, intervalMs, timeoutMs | start runs once. poll and result must be reads. intervalMs 10 to 60000; timeoutMs from intervalMs to 3600000. |
paginate | Collect a list. | method, items, offsetParam, limitParam, pageSize, maxPages | Reads only. pageSize and maxPages 1 to 1000. At most 100000 items; a reached page limit is an error, not a partial result. |
ndjson | Collect a line stream. | method | The response is application/x-ndjson. At most 8 MiB and 10000 lines, returned as {items}. |
upload | Send one local file. | method, fileParam, parentParam, nameParam | Not a read. A regular file of at most 16 GiB, streamed once. No resume, chunking or retry. |
jobId, state and items are dotted field paths in the response. A job example:
scan.start: cli: [scan, start] summary: Run a scan and return its result effect: write flow: type: job start: scan.start poll: scan.status result: scan.result jobId: job_id idParam: job_id state: state done: [completed] failed: [failed, cancelled] intervalMs: 1000 timeoutMs: 60000 paramsSchema: type: object required: [target] additionalProperties: false properties: target: {type: string}Flows cannot hold scripts, URLs, expressions or step graphs. Sequencing that belongs to your App goes into one backend method.
How permission and effect are derived
Section titled “How permission and effect are derived”- Each bound method’s permission comes from the real registry:
permissions.json, or the fixed policy of an SDK capability method. Your declaration cannot change it. - A command’s
permissionis the strongest of its methods (administratorsoverauthenticatedoverpublic). Withentry: admin-onlyevery command isadministrators. - The
effectyou declare is applied to the bound methods; ajob’spollandresultmethods are reads. A command’s effect is never weaker than the effect of a method it binds. - A method used by two commands takes the stronger effect. Methods that no command binds are not callable through ctl.
Parameters
Section titled “Parameters”string,integer,numberandbooleanproperties become typed flags:textis--text,maxItemsandmax_itemsare--max-items. Arrays and objects need--input.- Only top-level property defaults are filled in before validation. A
defaultinside a nested object is not applied: the caller must send that value, or validation fails. Invalid input is rejected before any business request. - A property whose flag name equals a ctl flag cannot be typed; the caller must use
--input. The reserved names are listed in Run ctl commands. - Mark secrets, tokens, private URLs and upload content with
writeOnly: true, including nested properties, array items and$reftargets. Do the same inresultSchema. See ctl security. - Schemas may use
$refonly to#fragments, the 2020-12 dialect and nesting up to 32. Do not put real secrets in defaults or examples.
Design rules
Section titled “Design rules”- One command per complete task. Do not expose raw
*.request-style proxies or internal steps. - Declare the honest effect; use
destructivefor deletes and anything irreversible. --yesis the only built-in confirmation and coverswriteanddestructivealike. A confirmation that needs a plan identity, freshness or a second approval belongs in your backend method.- Accepted is not completed. For work that continues after the call returns, use a
jobflow or return a job ID that a read command can query. - Keep results small and complete. A response over 1 MiB fails; paginate or use
ndjson. - Prefer
<resource> <verb>:list,get,exportfor reads;create,update,import,runfor writes;deletefor destructive. Use one synonym per task; domain verbs such aspauseare fine. - Return stable, documented fields. An agent builds on them.
Build errors
Section titled “Build errors”| Code | Cause |
|---|---|
CTL_DECLARATION_INVALID | ctl lacks enabled, or enabled: true lacks commands. |
CTL_COMMAND_UNREGISTERED | A flow names a method the backend does not register. |
CTL_DESCRIBE_REQUIRED | The Go main.go has no --describe support. Update it from the template. |
CTL_DESCRIBE_FAILED | The Go route export failed or returned invalid JSON. |
CTL_DESCRIPTOR_INVALID | The generated description breaks the contract: duplicate cli path, bad flow fields, unsafe schema. |
CTL_UNSUPPORTED_BACKEND | binary or Compose backend. |
Meanings and fixes for every code are in Error codes; the ctl field is in the manifest reference.
How the App serves it
Section titled “How the App serves it”The private description sits at the package root as synopkgland-api.json, outside every static UI path. The SDK serves it from the package CGI only for the fixed method synopkgland.describe, after DSM session, SynoToken and App entry checks; anonymous requests get an error and no description. The envelope is {format:"synopkgland.api", version:1, payload, sha256}, where the hash covers the canonical JSON of everything but sha256. It identifies content; it is not an author signature.