Skip to content
Syno Package Land
Language: English

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.

NeedDetail
BackendNative 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.
VersionsThe latest public CLI and templates with their pinned SDK.
Go backendmain.go must support the build-only --describe flag, as the templates do, or the build fails with CTL_DESCRIBE_REQUIRED.
MethodsEach command binds to methods the backend registers. An unregistered method fails with CTL_COMMAND_UNREGISTERED.
  1. Start from a native template. Every one declares three commands in the ctl block of dsm-package.yaml:
Terminal window
synopkgland init -t native-go --package MyApp my-app
ctl:
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.

  1. 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" } }
RuntimeRegisterPermission file
Goapi.Handle("notes.add", fn)backend/internal/api/permissions.json
Node.jsapp.method('notes.add', (ctx, params) => ...)backend/app/permissions.json
Pythonapp.method("notes.add")(lambda ctx, params: ...)backend/app/permissions.json
Rustapp.method("notes.add", move |ctx, params| ...)backend/permissions.json
  1. 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}]
  1. Build and validate. check validates the declaration, build compares each command with the real route registry and permissions and writes synopkgland-api.json, and inspect verifies the description inside the SPK:
Terminal window
synopkgland check
synopkgland build --arch x86_64
synopkgland inspect dist/MyApp-0.1.0-0001-x86_64.spk
  1. Try it as a caller. Install the SPK first; --dry-run sends nothing:
Terminal window
synopkgland ctl list --host nas --app MyApp --json
synopkgland ctl myapp notes add --text "Buy milk" --host nas --dry-run
synopkgland ctl myapp notes add --text "Buy milk" --host nas --yes

ctl in dsm-package.yaml:

FieldRequiredRule
enabledYestrue builds the description. Without ctl, the App is not listed.
commandsWith enabledMap of command ID to command, 1 to 1024 entries.
aliasesNoUp 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.
developedByNosynopkgland, third-party or unknown (default). Shown to callers as self-declared.

Each command:

FieldRequiredRule
ID (map key)YesLower case words joined by dots, such as notes.add, at most 128 characters.
cliYes1 to 8 words, pattern ^[a-z][a-z0-9-]*$. Unique within the App; the caller types them after the alias.
summaryYesWhat the command does, up to 1024 characters.
effectYesread, write or destructive. Never inferred from the name.
flowYesOne of the five flows below.
paramsSchemaNoJSON Schema 2020-12 object. Without it only --input is accepted and parameters show as undescribed.
resultSchemaNoThe result is validated against it; a mismatch is CTL_RESPONSE_INVALID.
examplesNoUp to 16 parameter objects, which become the runnable examples in ctl list.
permissionNever setThe build derives it and overwrites any value.
FlowUseFieldsLimits
invokeOne method call.methodRequest and response at most 1 MiB.
jobStart a long task, poll, return the result.start, poll, optional result, jobId, idParam, state, done, failed, intervalMs, timeoutMsstart runs once. poll and result must be reads. intervalMs 10 to 60000; timeoutMs from intervalMs to 3600000.
paginateCollect a list.method, items, offsetParam, limitParam, pageSize, maxPagesReads only. pageSize and maxPages 1 to 1000. At most 100000 items; a reached page limit is an error, not a partial result.
ndjsonCollect a line stream.methodThe response is application/x-ndjson. At most 8 MiB and 10000 lines, returned as {items}.
uploadSend one local file.method, fileParam, parentParam, nameParamNot 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.

  • 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 permission is the strongest of its methods (administrators over authenticated over public). With entry: admin-only every command is administrators.
  • The effect you declare is applied to the bound methods; a job’s poll and result methods 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.
  • string, integer, number and boolean properties become typed flags: text is --text, maxItems and max_items are --max-items. Arrays and objects need --input.
  • Only top-level property defaults are filled in before validation. A default inside 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 $ref targets. Do the same in resultSchema. See ctl security.
  • Schemas may use $ref only to # fragments, the 2020-12 dialect and nesting up to 32. Do not put real secrets in defaults or examples.
  • One command per complete task. Do not expose raw *.request-style proxies or internal steps.
  • Declare the honest effect; use destructive for deletes and anything irreversible.
  • --yes is the only built-in confirmation and covers write and destructive alike. 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 job flow 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, export for reads; create, update, import, run for writes; delete for destructive. Use one synonym per task; domain verbs such as pause are fine.
  • Return stable, documented fields. An agent builds on them.
CodeCause
CTL_DECLARATION_INVALIDctl lacks enabled, or enabled: true lacks commands.
CTL_COMMAND_UNREGISTEREDA flow names a method the backend does not register.
CTL_DESCRIBE_REQUIREDThe Go main.go has no --describe support. Update it from the template.
CTL_DESCRIBE_FAILEDThe Go route export failed or returned invalid JSON.
CTL_DESCRIPTOR_INVALIDThe generated description breaks the contract: duplicate cli path, bad flow fields, unsafe schema.
CTL_UNSUPPORTED_BACKENDbinary or Compose backend.

Meanings and fixes for every code are in Error codes; the ctl field is in the manifest reference.

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.