@synopackageland/cli 0.49.1 → 0.50.0

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.
Files changed (75) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +10 -0
  3. package/dist/ctl/ai-tools.d.ts +9 -1
  4. package/dist/ctl/ai-tools.js +4 -4
  5. package/dist/ctl/cli.d.ts +8 -1
  6. package/dist/ctl/cli.js +40 -5
  7. package/dist/ctl/descriptor.d.ts +15 -2
  8. package/dist/ctl/descriptor.js +9 -4
  9. package/dist/ctl/flows.js +2 -0
  10. package/dist/ctl/input.d.ts +5 -3
  11. package/dist/ctl/input.js +3 -3
  12. package/dist/ctl/native-auth-command.d.ts +9 -0
  13. package/dist/ctl/native-auth-command.js +98 -0
  14. package/dist/ctl/native-executor.d.ts +16 -0
  15. package/dist/ctl/native-executor.js +187 -0
  16. package/dist/ctl/native-file-types.d.ts +16 -0
  17. package/dist/ctl/native-file-types.js +57 -0
  18. package/dist/ctl/native-files.d.ts +13 -0
  19. package/dist/ctl/native-files.js +115 -0
  20. package/dist/ctl/native-metadata.d.ts +10 -0
  21. package/dist/ctl/native-metadata.js +50 -0
  22. package/dist/ctl/native-paths.d.ts +4 -0
  23. package/dist/ctl/native-paths.js +54 -0
  24. package/dist/ctl/native-protocol.d.ts +21 -0
  25. package/dist/ctl/native-protocol.js +150 -0
  26. package/dist/ctl/native-registry.d.ts +8 -0
  27. package/dist/ctl/native-registry.js +182 -0
  28. package/dist/ctl/native-schemas.d.ts +7 -0
  29. package/dist/ctl/native-schemas.js +25 -0
  30. package/dist/ctl/native-store.d.ts +61 -0
  31. package/dist/ctl/native-store.js +348 -0
  32. package/dist/ctl/native-transfers.d.ts +13 -0
  33. package/dist/ctl/native-transfers.js +331 -0
  34. package/dist/ctl/native-transport.d.ts +30 -0
  35. package/dist/ctl/native-transport.js +148 -0
  36. package/dist/ctl/native-types.d.ts +15 -0
  37. package/dist/ctl/native-types.js +1 -0
  38. package/dist/ctl/registry.d.ts +5 -4
  39. package/dist/ctl/registry.js +12 -1
  40. package/dist/ctl/service.d.ts +32 -1
  41. package/dist/ctl/service.js +122 -1
  42. package/dist/error-registry.js +15 -0
  43. package/dist/generated/native-http.d.ts +189 -0
  44. package/dist/generated/native-http.js +1 -0
  45. package/dist/nas/store.d.ts +3 -1
  46. package/dist/nas/store.js +6 -3
  47. package/dist/nas/transport.d.ts +1 -0
  48. package/dist/native-http-schema/descriptor.schema.json +242 -0
  49. package/dist/native-http-schema/inventory.schema.json +121 -0
  50. package/dist/native-http-schema/registry.schema.json +872 -0
  51. package/dist/native-http-schema/source.json +1 -0
  52. package/dist/runtime/sdk-source.d.ts +1 -1
  53. package/dist/runtime/sdk-source.js +1 -1
  54. package/dist/standalone/api-description.d.ts +2 -5
  55. package/dist/standalone/build.js +5 -1
  56. package/dist/standalone/compose-errors.js +5 -0
  57. package/dist/standalone/inspect-spk.js +2 -17
  58. package/dist/standalone/lifecycle.js +9 -2
  59. package/dist/standalone/manifest.d.ts +1 -0
  60. package/dist/standalone/manifest.js +22 -5
  61. package/dist/standalone/native-http-inspect.d.ts +9 -0
  62. package/dist/standalone/native-http-inspect.js +43 -0
  63. package/dist/standalone/native-http.d.ts +31 -0
  64. package/dist/standalone/native-http.js +120 -0
  65. package/dist/standalone/operation-registry.d.ts +2 -7
  66. package/dist/standalone/operation-registry.js +3 -0
  67. package/dist/standalone/spk.d.ts +1 -0
  68. package/dist/standalone/spk.js +15 -1
  69. package/package.json +2 -2
  70. package/schema/dsm-api-contract.json +8 -7
  71. package/skills/SKILL.md +2 -2
  72. package/skills/reference/compose.md +21 -0
  73. package/skills/reference/ctl.md +198 -0
  74. package/skills/reference/daemon-mode.md +1 -1
  75. package/skills/reference/upstream-fork.md +5 -2
@@ -40,6 +40,18 @@ No backend, dummy CGI, UI directory or helper payload is required. Omit `web`,
40
40
  architecture-specific native payloads for token/account adapters. All lifecycle
41
41
  scripts run as the package account; containers are managed by Container Manager.
42
42
 
43
+ START preflight checks Container Manager availability, share authorization and
44
+ package-owned runtime settings. It does not require Container Manager profiles:
45
+ the official STOP worker can remove them and START recreates them. Waiting for
46
+ those files before START would prevent the worker from running.
47
+
48
+ Headless STOP preserves local service cleanup failures and reports
49
+ `COMPOSE_STOP_UNCONFIRMED` for actual local teardown failure. Missing profiles
50
+ after STOP are normal and are not an error. Restart stops first and never
51
+ continues to START after a failed STOP. INSTALL and UPGRADE keep their existing
52
+ worker sequence. SDK and CLI hooks do not read or modify private profiles, and
53
+ local cleanup success does not attest that DSM later stopped actual containers.
54
+
43
55
  For external access, pin both `compose.sdk` and `identity_gateway.sdk` to
44
56
  the same release with external access support and use the gateway's
45
57
  [`external_access` policy and DSM settings entry](identity-gateway.md#external-access).
@@ -513,3 +525,12 @@ verifies planner/lock agreement and `inspect --json` reports `compose.hostUdp`.
513
525
  Rebuild with a CLI and SDK that support the declaration; older planners reject
514
526
  it. Discovery and multicast coexistence need real LAN verification; this guard
515
527
  is not a firewall and does not reserve ports or configure reuse.
528
+
529
+ ## Native HTTP ctl
530
+
531
+ Compose Apps may explicitly declare `ctl.transport: native-http` with a matching
532
+ SDK v3 registry and same-origin ingress. The SDK serves DSM-protected metadata;
533
+ the CLI calls the existing native API with a client-held App token. Legacy
534
+ Compose SDK RPC ctl stays refused. Follow [native credentials](ctl.md#native-app-credentials)
535
+ for human enrollment, per-API exposure review, scope, lifecycle and bounded flows.
536
+ Do not add a gateway business dispatcher or store user credentials on the NAS.
@@ -36,6 +36,109 @@ known alias matches. `ctl list` reports pending approvals in `data.diagnostics`.
36
36
 
37
37
  Use `host show nas` to inspect approvals/pins, `host revoke nas PackageID` to remove an App approval, `host logout nas` to retain registration, and `host remove nas --yes` to delete sessions, device token, approvals and cache. A failed NAS logout is reported independently from successful local removal.
38
38
 
39
+ ## Native App credentials
40
+
41
+ Apps may opt into `ctl.transport: native-http` with a matching SDK v3 registry.
42
+ This transport works with Compose or native backends and the App's existing
43
+ same-origin ingress. Legacy Compose SDK RPC ctl stays refused. The registry is
44
+ the only operation source; declarations cannot supply arbitrary URLs, scripts,
45
+ credential headers or browser login recipes. Keep `ctl.external` separate;
46
+ native credentials do not extend external MCP or local file authority.
47
+
48
+ The official client still requires the approved installed package/version/hash
49
+ and a fresh DSM-authenticated metadata description before native execution.
50
+ Native business HTTP uses only the App's own token. It sends no DSM cookie,
51
+ SynoToken, SDK session, Origin or trusted identity headers. Resource permissions,
52
+ expiry and revocation belong to the upstream App. DSM logout, disabled users or
53
+ revoked App entry do not revoke a raw native token used by other HTTP clients.
54
+ An App account selected by the user is not proof that it represents the DSM user.
55
+
56
+ Have the human run this in their own terminal:
57
+
58
+ ```sh
59
+ synopkgland ctl auth --host <profile> --app <package>
60
+ ```
61
+
62
+ The command shows the declared credential page and UI instructions, offers to
63
+ open that page in a browser, hides secret input, verifies the native identity and
64
+ asks before saving it in the OS keychain. The SDK never logs into the App for the
65
+ user. For header auth, copy an existing API token from the native UI. For
66
+ greader-client-login, supply the native account name and existing API password;
67
+ the client performs the fixed ClientLogin/user-info protocol and saves only the
68
+ exchanged Auth token. It never saves the API password or mints, rotates or revokes
69
+ upstream credentials. Fixed action T is obtained only for the current mutation.
70
+ That fixed action-token response alone accepts text/plain or PHP's text/html;
71
+ it must be a UTF-8 single-line token within 4 KiB (one terminal newline is allowed),
72
+ without markup (`<`), embedded whitespace or additional lines. This exception
73
+ never relaxes ClientLogin or ordinary business-response MIME checks.
74
+
75
+ Trusted human automation can use `--secret-stdin`: one token line for header
76
+ auth, or one strict JSON object with only `username` and `apiPassword` for
77
+ greader. Input is bounded and never echoed. No token/password argv or environment
78
+ option exists. **AI agents must ask the user to run ctl auth. Never ask for a token
79
+ in chat, read a secret file or run auth on the user's behalf.** Auth/reset are not
80
+ AI tools. Credential acquisition is never an ordinary operation binding.
81
+
82
+ Keychain records use service `synopkgland.ctl.native`, separate from DSM sessions.
83
+ Keys bind the registered profile name, canonical origin, DSM username, package and
84
+ auth contract digest. Same-origin profiles never fall back to each other or to an
85
+ administrator. Descriptor/version updates retain credentials only when the auth
86
+ contract is unchanged. Two DSM profiles under one OS login are not a security
87
+ boundary; use separate OS accounts for that isolation.
88
+
89
+ When the keychain is unavailable, unlock it or explicitly choose
90
+ `ctl auth --app <package> --store encrypted-file`. There is no silent fallback.
91
+ The independent passphrase is hidden, process-local and never derived from DSM
92
+ credentials. The vault uses scrypt and AES-256-GCM, bounded authenticated metadata,
93
+ private file permissions (user-only ACL on Windows), exclusive locking and atomic
94
+ replacement. Wrong passphrase, tamper, symlinks or unsafe permissions refuse
95
+ access. Headless encrypted-file unlock is unsupported; automation requires an OS
96
+ secret service. Actual OS availability must be verified on the target platform.
97
+ Changing storage backends requires explicit `--reset` and enrollment, which
98
+ prevents a failed migration from leaving an unindexed old secret behind.
99
+
100
+ `ctl list` reports native auth scheme, instructions, credential URL and state.
101
+ `stored` means a record was enrolled, not that it is unlocked or still valid.
102
+ After a 401, listing shows `invalid` until a verified replacement or local reset.
103
+ Listing never unlocks or probes native credentials. Help, tools and dry-run work
104
+ without a native token. Missing/locked auth in JSON, non-TTY or AI execution gives
105
+ instructions without prompting. An interactive first call can enroll, then asks
106
+ the user to rerun the original command; it never replays the original operation.
107
+ A 401 shows the cause, credential URL and App instructions before offering
108
+ "Enter a new token now? [y/N]". Declining preserves the invalid record. FreshRSS
109
+ renewal asks for the native account and API password again, exchanges and verifies
110
+ it, and stores only the exchanged token. A 403 remains a permission error.
111
+
112
+ `ctl auth --app <package>` updates an existing record without reset, retaining its
113
+ storage backend unless explicitly selected. Replacement verifies first; a failed
114
+ verification preserves the previous record. `ctl auth --reset` only deletes the
115
+ current local scope; run auth again to enroll.
116
+ `host remove` deletes all native keychain/vault records for that profile, including
117
+ old auth digests. `host logout` retains them but requires restored DSM metadata
118
+ admission. `host revoke` retains them and blocks official use until reapproval.
119
+ None of these commands revoke an upstream token. Rotate it intentionally in the
120
+ native App when upstream revocation is wanted.
121
+
122
+ | Native result | Client behavior |
123
+ | --- | --- |
124
+ | 401 | `CTL_NATIVE_AUTH_INVALID` (2); mark invalid; offer interactive renewal; never replay the request |
125
+ | 403 | `CTL_NATIVE_ACCESS_DENIED` (4); preserve credential and check native permissions |
126
+ | 503 | `CTL_NATIVE_UNAVAILABLE` (5); check API enablement/configuration |
127
+ | 3xx or login HTML | Refuse; no redirect, browser fallback or cookie reuse |
128
+ | Lost mutation request/receipt | `CTL_NATIVE_OUTCOME_UNKNOWN` (6); inspect the App before retrying |
129
+
130
+ All native requests use the shared profile TLS policy and never automatically
131
+ retry. Plans respect schema writeOnly fields and contain no auth carriers. Auth
132
+ exchange replies are private protocol input; diagnostics never echo them or raw
133
+ exception bodies. Business responses preserve their declared values without
134
+ content redaction. JSON/NDJSON/schema/projection bounds reject invalid results.
135
+ Page pagination never follows `next` URLs; cursor pagination uses only the fixed
136
+ bounded continuation token. Bound exhaustion or repeated cursor/no progress
137
+ returns `incomplete:true` and explicit continuation rather than claiming a full
138
+ result. Pagination is not an upstream snapshot guarantee. A dry-run is a request
139
+ plan; it is not a native preview. Draft AI mutations require a real read-only
140
+ preview, and writes still require human execution with `--yes`.
141
+
39
142
  Stdout defaults to JSON without a TTY. Success is {ok:true,data}; failure is {ok:false,error:{code,message,hint,allowed?}}. Multi-host output uses {ok,results:[{host,ok,data|error}]}. Follow the concrete hint and complete allowed list; do not guess another method or bypass ctl with raw HTTP. Exit codes: 2 authentication, 3 parameters/names, 4 permissions/trust, 5 App/contract, 6 network, 7 confirmation, 8 partial failure.
40
143
 
41
144
  ## Local MCP external callers
@@ -264,3 +367,98 @@ Request previews (plans, dry-run and missing-yes plans) mask schema-marked input
264
367
  Prefer `<resource> <verb>`. Common verbs are `list`, `get`, `export` (often reads), `create`, `update`, `import`, `run` (often writes), and `delete` (often destructive). Pick one synonym within an App; avoid mixing show/get/status for the same task. These are recommendations only: Apps may use domain verbs such as `pause` and `resume`.
265
368
 
266
369
  Every command must explicitly declare its required `effect`. CLI/build never infer or overwrite effect from the verb. The existing check that command effect must not be less restrictive than its bindings remains. There is no verb allowlist or new verb rejection rule.
370
+
371
+ ### Native HTTP metadata and builds
372
+
373
+ Native HTTP packaging requires a matching SDK containing native HTTP v3. The
374
+ CLI uses the SDK's `api/nativehttp/schema` resources and build-time exporter;
375
+ it has no independent schema grammar. `ctl generate` writes private
376
+ `generated/synopkgland-api.json` and
377
+ `generated/synopkgland-http-inventory.json`, plus command/tool/reference output.
378
+ `ctl generate --check` and `check` compare every generated artifact. Build compiles
379
+ a metadata-only CGI with the SDK DSM authenticator and matching entry gate;
380
+ no Go business handlers, second listener, per-user NAS store or HTTP relay is
381
+ required. The CGI serves only the fixed authenticated describe request.
382
+
383
+ The registry's full operation map, including hidden specs, participates in the
384
+ registry hash and HTTP inventory. Hidden operations stay absent from human
385
+ command selection and AI tools. The inventory includes required
386
+ `upstreamAuthPaths`; build/inspect compare them and the existing unscoped gateway
387
+ entry-policy digest to the resolved gateway config. Auth scope uses the SDK's
388
+ `authSha256`, including basePath, the entire auth declaration and entry policy.
389
+ Every artifact uses the SDK's JCS rules; explicit empty optional maps survive.
390
+ Exact features are required; unknown features never fall back to SDK RPC.
391
+
392
+ The frozen describe wire carries the descriptor. Its SDK handler validates the
393
+ private inventory before serving it. The client independently validates the
394
+ registry/auth/descriptor hashes and binding equality, and sends native requests
395
+ only to the exact declared path templates and auth endpoints. Original upstream
396
+ prefix containment and inventory hashing are additionally checked by the SDK
397
+ handler and SPK inspect. Business effects are explicitly authored: POST can be a
398
+ read and a confirmed GET can be an action. Never infer effect from the HTTP verb.
399
+
400
+ For CLI development, set `SYNOPKGLAND_SDK_DIR` to an authorized matching SDK
401
+ checkout before `npm run build` and focused native tests. The build generates
402
+ contract types and packaged schema assets directly from that checkout. Release
403
+ builds must use a published matching SDK selected by
404
+ `SYNOPKGLAND_NATIVE_HTTP_SDK_VERSION`; development checkouts are test inputs,
405
+ not release pins. Keep the release dependency open until that SDK exists.
406
+
407
+ ### Native HTTP local file flows (unreleased)
408
+
409
+ The human CLI installs `upload-http` and `download-file` through the authenticated
410
+ native transport. Both require `ai: human-only`; neither becomes an AI tool or an
411
+ external MCP file capability. Local `fileParam` / `outputParam` values never enter
412
+ the native query/body. Existing dry-run, write confirmation and fresh DSM metadata
413
+ admission still apply. These flows require the matching SDK v3 sources described
414
+ above; these changes are not included in the latest published CLI.
415
+
416
+ Multipart uploads send the declared part, optional bounded form fields and a safe
417
+ basename. PDF/PNG/JPEG require a matching signature and declared MIME. Raw uploads
418
+ accept UTF-8 OPML XML only, with a 1 MiB cap, an OPML root, and no DTD/entity
419
+ declarations. There is no XML entity resolver. The effective file limit is the
420
+ minimum of package, flow, response (downloads) and CLI hard 16 GiB limits. Form
421
+ fields are limited to 16 parts / 64 KiB and upload receipts to 64 KiB. Uploads
422
+ retain the upstream receipt/task ID; acceptance does not mean OCR completion.
423
+
424
+ Files stream with backpressure and bounded buffers. Connection/header/idle budgets
425
+ apply without a productive-stream total deadline. Interactive progress goes to
426
+ stderr; JSON stdout contains only the final receipt or error. One transfer runs
427
+ per process. Ctrl-C stops local IO and returns failure. An interrupted mutation
428
+ has `outcome_unknown`; inspect the original native task/resource before retrying.
429
+ There is no retry, resume, redirect following or implicit upstream cancellation.
430
+
431
+ Local sources require a no-follow regular-file descriptor and unchanged file
432
+ metadata through completion. Downloads use an exclusive 0600 partial on the same
433
+ filesystem, validate status/MIME/identity encoding, length and actual bytes, then
434
+ publish with an atomic no-replace hard link. Existing destinations are refused,
435
+ including symlinks; response filenames never choose the destination. Failed
436
+ transfers remove their partial. Completion returns `{bytes, sha256}` for the
437
+ received bytes, without claiming upstream authenticity. Filesystems without hard
438
+ links fail closed. A process crash can leave a hidden `.ctl-partial-*` file; it
439
+ never becomes the requested output automatically.
440
+
441
+ Ancestors are resolved once to the longest existing canonical directory before
442
+ file traversal is anchored to held descriptors. Root/current-user owned symlinks
443
+ are allowed only through safe directories: no group/world writes unless a public
444
+ directory has sticky-bit entry protection. Link targets follow the same checks.
445
+ Source/output leaves still refuse symlinks. Native credential state uses the same
446
+ ancestor policy, while the ctl and native directories themselves remain no-follow,
447
+ current-user owned and 0700, with the existing private-file checks retained.
448
+ This implementation uses Linux descriptor-relative filesystem aliases; macOS has
449
+ an equivalent implementation path pending platform verification. Unsupported
450
+ platforms, including Windows, fail closed before native IO rather than falling
451
+ back to unsafe path-based writes. Linux fixtures cover source changes, publication
452
+ races, truncated streams, disk-full, cancellation and slow sparse transfers.
453
+
454
+
455
+ ### Empty native mutation acknowledgements (unreleased)
456
+
457
+ An explicitly authored write/destructive operation can accept an empty declared
458
+ 204, or an empty declared 200 with Content-Length 0, without Content-Type. The
459
+ client verifies that the body really is empty, requires identity encoding and
460
+ returns `{ok: true, status}`. The receipt must satisfy the declared result schema;
461
+ there is no representation to project. Nonempty replies still require their
462
+ declared MIME and decoder. Read operations receive no such exception. This is an
463
+ HTTP acknowledgement, not proof of the final App state: run the App's declared
464
+ readback command as usual. No mutation is replayed or synthetic readback added.
@@ -41,7 +41,7 @@ cache an upper bound and measure it filled.
41
41
  These numbers come from Studio Office. Use them as an example of what
42
42
  to measure, not as a budget.
43
43
 
44
- - **CGI cost per request.** On a DS SA3400 with 25 Apps, every Studio call
44
+ - **CGI cost per request.** On a measured NAS with 25 Apps, every Studio call
45
45
  spent 100–140 ms before the handler did any work: process start, the DSM
46
46
  sign-in check (`authenticate.cgi`), the App Privileges check and schema
47
47
  checks. Recompiling App definitions on each request took about 70% of
@@ -61,7 +61,9 @@ Cover common reads and writes through existing native APIs, including the main
61
61
  UI tasks; `status` and `service status` alone are incomplete. Keep upstream code
62
62
  unchanged and run adapters as the package account. Report unsupported transports
63
63
  or synchronous-only long operations for discussion; do not invent App features
64
- or bypass the current Compose ctl restriction.
64
+ or bypass the legacy Compose RPC restriction. For an existing native API, opt into
65
+ matching v3 native-http metadata and client-side credentials; read the native
66
+ credential contract in [ctl.md](ctl.md#native-app-credentials).
65
67
 
66
68
  ## Container: official image and a matching source tag
67
69
 
@@ -257,7 +259,8 @@ with both init flags, or fill `compose.web.health` before check/build. No guesse
257
259
  `/` + 200. Readiness **does not follow redirects**: a 302 to a dashboard/login is
258
260
  unhealthy even if its destination is 200. A favicon/robots probe proves HTTP
259
261
  availability only; verify database setup and full readiness separately. `check`
260
- is static, not an HTTP or UID/storage probe. Compose ctl is rejected at check;
262
+ is static, not an HTTP or UID/storage probe. Legacy Compose RPC ctl is rejected;
263
+ native-http requires a matching v3 declaration and same-origin ingress;
261
264
  dedicated origin `/` is supported, automatic subpath rewriting is not.
262
265
 
263
266
  Public npm availability does not grant anonymous Go SDK access. Obtain authorised