@synopackageland/cli 0.48.1 → 0.48.3
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 +16 -0
- package/README.md +10 -7
- package/dist/ctl/ai-tools.d.ts +1 -1
- package/dist/ctl/descriptor.d.ts +1 -1
- package/dist/ctl/descriptor.js +1 -1
- package/dist/ctl/flows.d.ts +2 -1
- package/dist/ctl/flows.js +19 -5
- package/dist/ctl/registry.d.ts +1 -1
- package/dist/ctl/service.d.ts +2 -0
- package/dist/ctl/service.js +9 -5
- package/dist/nas/transport.d.ts +2 -2
- package/dist/nas/transport.js +4 -3
- package/dist/runtime/operation-budget.d.ts +2 -0
- package/dist/runtime/operation-budget.js +5 -0
- package/dist/runtime/sdk-source.d.ts +1 -1
- package/dist/runtime/sdk-source.js +1 -1
- package/dist/runtime/sdk-timeouts.js +2 -1
- package/dist/standalone/daemon-nofile.d.ts +13 -0
- package/dist/standalone/daemon-nofile.js +96 -0
- package/dist/standalone/daemon.d.ts +2 -0
- package/dist/standalone/daemon.js +8 -0
- package/dist/standalone/inspect-spk.js +35 -7
- package/dist/standalone/lifecycle.js +2 -1
- package/dist/standalone/manifest.js +14 -1
- package/dist/standalone/spk.js +8 -1
- package/package.json +1 -1
- package/schema/bridge-manifest.v1.schema.json +1 -1
- package/schema/sdk-timeouts.json +24 -0
- package/schema/synopkgland-api-v1.schema.json +1 -2
- package/schema/synopkgland-api-v2.schema.json +3 -3
- package/skills/SKILL.md +1 -1
- package/skills/reference/create.md +1 -1
- package/skills/reference/ctl.md +7 -6
- package/skills/reference/lifecycle.md +33 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.48.3
|
|
4
|
+
|
|
5
|
+
- Make v2 job flow timeoutMs optional in commands and operations, matching v1: shared per-request budgets and no total polling deadline; retain explicit bounds and preserve omission through generation
|
|
6
|
+
|
|
7
|
+
- Add opt-in daemon.nofile (1024–1048576) through a fixed DSM-acquired package system unit with LimitNOFILE and package User/Group
|
|
8
|
+
- Preserve SDK-owned deadlines, non-root supervision, legacy omission and upgrade stop/uninstall routing; reject old or mismatched SDK sources
|
|
9
|
+
- Inspect the exact unit, metadata and controller config together; retain SDK 0.49.5 from 0.48.2
|
|
10
|
+
|
|
11
|
+
## 0.48.2
|
|
12
|
+
|
|
13
|
+
- Pin SDK 0.49.5 for CLI-owned controllers and planning so they inherit the shared operation policy
|
|
14
|
+
- Make job flow timeoutMs optional; use the SDK operation allowance for each query and keep live jobs polling until completion or cancellation
|
|
15
|
+
- Preserve job IDs and dispatch start once; abort pending JSON reads when local waiting is canceled
|
|
16
|
+
- Use the SDK timeout contract for ctl defaults and allow unconfigured root programs to share the parent request budget
|
|
17
|
+
- Build CLI-owned controllers against the published SDK 0.49.5 and its protected executor inventory; retain explicit App SDK pins and templates ~0.39.2
|
|
18
|
+
|
|
3
19
|
## 0.48.1
|
|
4
20
|
|
|
5
21
|
- Align Go requirement messages, native build guidance and fixtures with Go 1.26.10 (#130)
|
package/README.md
CHANGED
|
@@ -89,7 +89,7 @@ alongside npm lockfiles. Do not disable checksum verification for public SDK
|
|
|
89
89
|
packages. Private mirrors can use explicitly configured Go authentication and
|
|
90
90
|
checksum settings; a failed fetch reports `SDK_DOWNLOAD_FAILED`.
|
|
91
91
|
|
|
92
|
-
The CLI pins SDK 0.
|
|
92
|
+
The CLI pins SDK 0.49.5 for its daemon controllers, Compose planning and installer
|
|
93
93
|
context. Explicit App SDK declarations take precedence. Templates use ~0.39.2
|
|
94
94
|
and retain their own scaffold SDK pins; none declare daemon ingress.
|
|
95
95
|
Every App method is declared once in operations.json; ctl generate writes the
|
|
@@ -364,7 +364,7 @@ contract for the complete transport and CGI validation rules.
|
|
|
364
364
|
|
|
365
365
|
`webapi.call` request parameters are JSON-only; it has no request upload field.
|
|
366
366
|
Use streaming `files.write` for uploads, up to 100 MiB per file. Reads and URL
|
|
367
|
-
downloads retain their separate 64 MiB limit. Rebuild with SDK 0.
|
|
367
|
+
downloads retain their separate 64 MiB limit. Rebuild with SDK 0.49.5 and approve
|
|
368
368
|
the refreshed executor payload.
|
|
369
369
|
|
|
370
370
|
## App launch mode
|
|
@@ -570,11 +570,14 @@ such as `CTL_DESCRIPTOR_INVALID`, remain specific errors (exit 5).
|
|
|
570
570
|
`host list/show` can also succeed while reporting `authenticated:false` and
|
|
571
571
|
exit 0. Check discovery `apps`/`diagnostics` and session fields as well as the exit
|
|
572
572
|
code when deciding whether an App is ready.
|
|
573
|
-
`ctl --timeout <seconds>` applies to discovery, JSON calls
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
573
|
+
`ctl --timeout <seconds>` applies to discovery, JSON calls and transfer inactivity.
|
|
574
|
+
The default is the SDK's shared five-minute work allowance plus its two-second
|
|
575
|
+
response reserve. Synchronous flows consume one remaining allowance. Job flows
|
|
576
|
+
refresh that allowance for each status/result request and keep polling a live job
|
|
577
|
+
until a terminal state or cancellation. `flow.timeoutMs` is optional; an explicit
|
|
578
|
+
value changes per-request waiting, never the elapsed job lifetime. A failed status
|
|
579
|
+
read does not fail or restart the remote job: query its original ID before retrying.
|
|
580
|
+
|
|
578
581
|
|
|
579
582
|
Read `synopkgland skill show ctl` for the AI workflow, batch discovery approval,
|
|
580
583
|
cache refresh, host removal/revocation and `ctl.registry` authoring with `synopkgland.api` v2. Run `ctl generate`,
|
package/dist/ctl/ai-tools.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare function listAiTools(client: CtlClient, appName: string, options?
|
|
|
18
18
|
destructiveHint: boolean;
|
|
19
19
|
openWorldHint: boolean;
|
|
20
20
|
};
|
|
21
|
-
ai: "read" | "preview" | "draft" | "human-only"
|
|
21
|
+
ai: "hidden" | "read" | "preview" | "draft" | "human-only";
|
|
22
22
|
flow: import("./descriptor.js").Flow;
|
|
23
23
|
}[];
|
|
24
24
|
}>;
|
package/dist/ctl/descriptor.d.ts
CHANGED
package/dist/ctl/descriptor.js
CHANGED
|
@@ -113,7 +113,7 @@ export function validateFlow(op, bindings) {
|
|
|
113
113
|
throw Error('binding/effect');
|
|
114
114
|
}
|
|
115
115
|
if (flow.type === 'job') {
|
|
116
|
-
if (!flow.jobId || !flow.idParam || !flow.state || !Array.isArray(flow.done) || !flow.done.length || !Array.isArray(flow.failed) || !Number.isInteger(flow.intervalMs) || flow.intervalMs < 10 || flow.intervalMs > 60000 || !Number.isInteger(flow.timeoutMs) || flow.timeoutMs < flow.intervalMs || flow.timeoutMs > 3600000 || bindings[flow.poll].effect !== 'read' || flow.result && bindings[flow.result].effect !== 'read')
|
|
116
|
+
if (!flow.jobId || !flow.idParam || !flow.state || !Array.isArray(flow.done) || !flow.done.length || !Array.isArray(flow.failed) || !Number.isInteger(flow.intervalMs) || flow.intervalMs < 10 || flow.intervalMs > 60000 || flow.timeoutMs !== undefined && (!Number.isInteger(flow.timeoutMs) || flow.timeoutMs < flow.intervalMs || flow.timeoutMs > 3600000) || bindings[flow.poll].effect !== 'read' || flow.result && bindings[flow.result].effect !== 'read')
|
|
117
117
|
throw Error('job contract');
|
|
118
118
|
}
|
|
119
119
|
if (flow.type === 'paginate' && (!flow.items || !flow.offsetParam || !flow.limitParam || !Number.isInteger(flow.pageSize) || flow.pageSize < 1 || flow.pageSize > 1000 || !Number.isInteger(flow.maxPages) || flow.maxPages < 1 || flow.maxPages > 1000 || op.effect !== 'read'))
|
package/dist/ctl/flows.d.ts
CHANGED
|
@@ -3,9 +3,10 @@ export type Invoke = (method: string, params: Record<string, unknown>) => Promis
|
|
|
3
3
|
export interface FlowOptions {
|
|
4
4
|
wait?: boolean;
|
|
5
5
|
timeoutMs?: number;
|
|
6
|
+
signal?: AbortSignal;
|
|
6
7
|
upload?: (method: string, params: Record<string, unknown>, flow: Extract<Flow, {
|
|
7
8
|
type: 'upload';
|
|
8
9
|
}>) => Promise<unknown>;
|
|
9
10
|
ndjson?: (method: string, params: Record<string, unknown>) => Promise<unknown>;
|
|
10
11
|
}
|
|
11
|
-
export declare function runFlow(flow: Flow, params: Record<string, unknown>,
|
|
12
|
+
export declare function runFlow(flow: Flow, params: Record<string, unknown>, send: Invoke, options: FlowOptions): Promise<any>;
|
package/dist/ctl/flows.js
CHANGED
|
@@ -1,10 +1,24 @@
|
|
|
1
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
1
2
|
import { CtlError } from './errors.js';
|
|
3
|
+
function canceled() { return new CtlError('CTL_CANCELED', 'Stopped waiting for the job.', 'Query the original job; start was not repeated.', 130); }
|
|
4
|
+
function cancelable(work, signal) {
|
|
5
|
+
if (signal?.aborted)
|
|
6
|
+
return Promise.reject(canceled());
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
const abort = () => { signal?.removeEventListener('abort', abort); reject(canceled()); };
|
|
9
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
10
|
+
const finish = () => signal?.removeEventListener('abort', abort);
|
|
11
|
+
Promise.resolve().then(() => { if (signal?.aborted)
|
|
12
|
+
throw canceled(); return work(); }).then(value => { finish(); resolve(value); }, error => { finish(); reject(error); });
|
|
13
|
+
});
|
|
14
|
+
}
|
|
2
15
|
function field(value, path) { for (const key of path.split('.')) {
|
|
3
16
|
if (!value || typeof value !== 'object' || !Object.hasOwn(value, key))
|
|
4
17
|
return undefined;
|
|
5
18
|
value = value[key];
|
|
6
19
|
} return value; }
|
|
7
|
-
export async function runFlow(flow, params,
|
|
20
|
+
export async function runFlow(flow, params, send, options) {
|
|
21
|
+
const invoke = (method, input) => cancelable(() => send(method, input), options.signal);
|
|
8
22
|
if (flow.type === 'invoke')
|
|
9
23
|
return invoke(flow.method, params);
|
|
10
24
|
if (flow.type === 'upload') {
|
|
@@ -32,21 +46,21 @@ export async function runFlow(flow, params, invoke, options) {
|
|
|
32
46
|
}
|
|
33
47
|
throw new CtlError('CTL_FLOW_LIMIT', 'Pagination page limit reached; result is incomplete.', 'Narrow the query.', 5);
|
|
34
48
|
}
|
|
35
|
-
const until = performance.now() + Math.min(options.timeoutMs ?? flow.timeoutMs, 3600000);
|
|
36
49
|
const accepted = await invoke(flow.start, params);
|
|
37
50
|
if (options.wait === false)
|
|
38
51
|
return { accepted: true, job: accepted };
|
|
39
52
|
const id = field(accepted, flow.jobId);
|
|
40
53
|
if (!['string', 'number'].includes(typeof id))
|
|
41
54
|
throw new CtlError('CTL_FLOW_RESPONSE', 'Start response has no job ID.', 'Check command metadata; start is not retried.', 5);
|
|
42
|
-
while (
|
|
55
|
+
while (true) {
|
|
43
56
|
const poll = await invoke(flow.poll, { [flow.idParam]: id });
|
|
44
57
|
const state = field(poll, flow.state);
|
|
58
|
+
if (typeof state !== 'string')
|
|
59
|
+
throw new CtlError('CTL_FLOW_RESPONSE', 'Job status has no state.', 'Query the original job; start was not repeated.', 5);
|
|
45
60
|
if (flow.failed.includes(state))
|
|
46
61
|
throw new CtlError('CTL_JOB_FAILED', `Job ${id} failed (${state}).`, 'Inspect the job in the App; start was not retried.', 5);
|
|
47
62
|
if (flow.done.includes(state))
|
|
48
63
|
return flow.result ? invoke(flow.result, { [flow.idParam]: id }) : poll;
|
|
49
|
-
await
|
|
64
|
+
await delay(flow.intervalMs, undefined, { signal: options.signal }).catch(() => { throw canceled(); });
|
|
50
65
|
}
|
|
51
|
-
throw new CtlError('CTL_JOB_TIMEOUT', `Wait timed out; job ${id} may still be running.`, 'Query the job status; do not repeat the start blindly.', 6);
|
|
52
66
|
}
|
package/dist/ctl/registry.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ export declare function registryTools(registry: OperationRegistry): {
|
|
|
39
39
|
destructiveHint: boolean;
|
|
40
40
|
openWorldHint: boolean;
|
|
41
41
|
};
|
|
42
|
-
ai: "read" | "preview" | "draft" | "human-only"
|
|
42
|
+
ai: "hidden" | "read" | "preview" | "draft" | "human-only";
|
|
43
43
|
flow: import("./descriptor.js").Flow;
|
|
44
44
|
}[];
|
|
45
45
|
export declare function registryReference(registry: OperationRegistry): string;
|
package/dist/ctl/service.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export declare class CtlClient {
|
|
|
30
30
|
request: JsonRequest;
|
|
31
31
|
constructor(store: CtlStore, host: Host, request?: JsonRequest, timeoutMs?: number);
|
|
32
32
|
private until?;
|
|
33
|
+
private jobRequestBudget?;
|
|
33
34
|
private remaining;
|
|
34
35
|
valid(): Promise<boolean>;
|
|
35
36
|
inventory(session: DsmSession): Promise<{
|
|
@@ -46,6 +47,7 @@ export declare class CtlClient {
|
|
|
46
47
|
stdin?: string;
|
|
47
48
|
wait?: boolean;
|
|
48
49
|
timeoutMs?: number;
|
|
50
|
+
signal?: AbortSignal;
|
|
49
51
|
}): Promise<any>;
|
|
50
52
|
private executeWithin;
|
|
51
53
|
private appCookieSession;
|
package/dist/ctl/service.js
CHANGED
|
@@ -19,7 +19,8 @@ export class CtlClient {
|
|
|
19
19
|
this.request = request ?? createRequest(host.origin, () => this.remaining(timeoutMs), undefined, store.trust(host));
|
|
20
20
|
}
|
|
21
21
|
until;
|
|
22
|
-
|
|
22
|
+
jobRequestBudget;
|
|
23
|
+
remaining(fallback) { return this.jobRequestBudget ?? (this.until === undefined ? fallback : Math.max(0, this.until - performance.now())); }
|
|
23
24
|
async valid() { try {
|
|
24
25
|
await this.inventory(await this.store.session(this.host));
|
|
25
26
|
return true;
|
|
@@ -121,6 +122,7 @@ export class CtlClient {
|
|
|
121
122
|
}
|
|
122
123
|
finally {
|
|
123
124
|
this.until = undefined;
|
|
125
|
+
this.jobRequestBudget = undefined;
|
|
124
126
|
}
|
|
125
127
|
}
|
|
126
128
|
async executeWithin(name, path, args, options = {}) {
|
|
@@ -131,8 +133,10 @@ export class CtlClient {
|
|
|
131
133
|
const { id, operation } = selectOperation(app, path);
|
|
132
134
|
const params = operationInput(operation, args, options.stdin, `run: synopkgland ctl ${name} ${operation.cli.join(' ')} --host ${this.host.name} --help`);
|
|
133
135
|
const output = new SensitiveOutput(params, operation.paramsSchema);
|
|
134
|
-
if (
|
|
135
|
-
this.until =
|
|
136
|
+
if (operation.flow.type === 'job') {
|
|
137
|
+
this.until = undefined;
|
|
138
|
+
this.jobRequestBudget = options.timeoutMs ?? operation.flow.timeoutMs ?? CTL_TIMEOUT_MS;
|
|
139
|
+
}
|
|
136
140
|
try {
|
|
137
141
|
const plan = requestPlan(app, id, params);
|
|
138
142
|
if (operation.flow.type === 'upload')
|
|
@@ -153,14 +157,14 @@ export class CtlClient {
|
|
|
153
157
|
const invoke = async (method, input) => {
|
|
154
158
|
if (!app.payload.bindings[method])
|
|
155
159
|
throw new CtlError('CTL_METHOD_NOT_ALLOWED', 'Flow method is not allowlisted.', 'Refresh the API description.', 4);
|
|
156
|
-
const response = await this.request(app.payload.transport.path, { method, params: input }, appSession);
|
|
160
|
+
const response = await this.request(app.payload.transport.path, { method, params: input }, appSession, options.signal);
|
|
157
161
|
if (response?.success !== true) {
|
|
158
162
|
const code = String(response?.error?.code ?? 'invalid_response');
|
|
159
163
|
throw new CtlError(['admin_required', 'app_privilege_denied'].includes(code) ? 'CTL_PERMISSION_DENIED' : 'CTL_APP_ERROR', `App rejected operation (${code}).`, 'Check command permissions and App state.', ['admin_required', 'app_privilege_denied'].includes(code) ? 4 : 5);
|
|
160
164
|
}
|
|
161
165
|
return response.data;
|
|
162
166
|
};
|
|
163
|
-
const result = await runFlow(operation.flow, params, invoke, { wait: options.wait, timeoutMs: this.remaining(options.timeoutMs ?? CTL_TIMEOUT_MS),
|
|
167
|
+
const result = await runFlow(operation.flow, params, invoke, { wait: options.wait, signal: options.signal, timeoutMs: this.remaining(options.timeoutMs ?? CTL_TIMEOUT_MS),
|
|
164
168
|
ndjson: (method, input) => transferRequest(appSession, app.payload.transport.path, method, input, { trust: this.store.trust(this.host), timeoutMs: this.remaining(options.timeoutMs ?? CTL_TIMEOUT_MS) }),
|
|
165
169
|
upload: (method, input, flow) => transferRequest(appSession, app.payload.transport.path, method, {}, { trust: this.store.trust(this.host), timeoutMs: this.remaining(options.timeoutMs ?? CTL_TIMEOUT_MS), file: { path: String(input[flow.fileParam]), parent: String(input[flow.parentParam]), name: String(input[flow.nameParam]) } }) });
|
|
166
170
|
if (operation.resultSchema && !ajv.validate(operation.resultSchema, result))
|
package/dist/nas/transport.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type HostTls } from './tls.js';
|
|
2
2
|
import http from 'node:http';
|
|
3
|
-
export declare const CTL_TIMEOUT_MS
|
|
3
|
+
export declare const CTL_TIMEOUT_MS: number;
|
|
4
4
|
export declare const APP_COOKIE: unique symbol;
|
|
5
5
|
export interface DsmSession {
|
|
6
6
|
origin: string;
|
|
@@ -9,7 +9,7 @@ export interface DsmSession {
|
|
|
9
9
|
token: string;
|
|
10
10
|
deviceId?: string;
|
|
11
11
|
}
|
|
12
|
-
export type JsonRequest = (path: string, body: URLSearchParams | Record<string, unknown>, session?: DsmSession) => Promise<any>;
|
|
12
|
+
export type JsonRequest = (path: string, body: URLSearchParams | Record<string, unknown>, session?: DsmSession, signal?: AbortSignal) => Promise<any>;
|
|
13
13
|
export declare function canonicalOrigin(input: string, tunnel?: boolean): string;
|
|
14
14
|
export declare function createRequest(origin: string, timeoutMs?: number | (() => number) | undefined, ca?: string, trust?: HostTls): JsonRequest;
|
|
15
15
|
export declare function sessionFetch(url: string, init: RequestInit, session: DsmSession | undefined, ca?: string, trust?: HostTls, timeoutMs?: number): Promise<Response>;
|
package/dist/nas/transport.js
CHANGED
|
@@ -7,7 +7,8 @@ import { nasOptions } from './options.js';
|
|
|
7
7
|
import { readFileSync } from 'node:fs';
|
|
8
8
|
import { CtlError } from '../ctl/errors.js';
|
|
9
9
|
import { dsmRequestTimeoutMs, dsmApiTimeoutMs } from './timeouts.js';
|
|
10
|
-
|
|
10
|
+
import { DEFAULT_OPERATION_TIMEOUT_MS, RESPONSE_RESERVE_MS } from '../runtime/operation-budget.js';
|
|
11
|
+
export const CTL_TIMEOUT_MS = DEFAULT_OPERATION_TIMEOUT_MS + RESPONSE_RESERVE_MS;
|
|
11
12
|
export const APP_COOKIE = Symbol("ctlAppCookie");
|
|
12
13
|
export function canonicalOrigin(input, tunnel = false) {
|
|
13
14
|
let url;
|
|
@@ -22,7 +23,7 @@ export function canonicalOrigin(input, tunnel = false) {
|
|
|
22
23
|
return url.origin;
|
|
23
24
|
}
|
|
24
25
|
export function createRequest(origin, timeoutMs = undefined, ca, trust) {
|
|
25
|
-
return async (path, body, session) => {
|
|
26
|
+
return async (path, body, session, signal) => {
|
|
26
27
|
if (!path.startsWith('/') || path.startsWith('//') || path.includes('?') || path.includes('#') || path.includes('\\') || path.includes('%') || path.split('/').some(p => p === '.' || p === '..'))
|
|
27
28
|
throw new CtlError('CTL_PATH_INVALID', 'Unsafe request path.', 'run: synopkgland ctl list --refresh');
|
|
28
29
|
const params = body instanceof URLSearchParams ? body : undefined;
|
|
@@ -42,7 +43,7 @@ export function createRequest(origin, timeoutMs = undefined, ca, trust) {
|
|
|
42
43
|
headers.cookie = session.cookie;
|
|
43
44
|
headers['X-SYNO-TOKEN'] = session.token;
|
|
44
45
|
}
|
|
45
|
-
const req = nasHttpRequest(url, { method: 'POST', headers }, remaining, trustWithCa(trust, ca), res => {
|
|
46
|
+
const req = nasHttpRequest(url, { method: 'POST', headers, signal }, remaining, trustWithCa(trust, ca), res => {
|
|
46
47
|
if (!res.statusCode || res.statusCode < 200 || res.statusCode >= 300) {
|
|
47
48
|
res.resume();
|
|
48
49
|
reject(new CtlError('CTL_HTTP_ERROR', `HTTP ${res.statusCode}; redirects are never followed.`, 'Check the NAS URL and connection.', 6));
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
// Build-time snapshot of the SDK timeout contract, shipped in schema/.
|
|
3
|
+
const budget = JSON.parse(readFileSync(new URL('../../schema/sdk-timeouts.json', import.meta.url), 'utf8'));
|
|
4
|
+
export const DEFAULT_OPERATION_TIMEOUT_MS = budget.request.default_s * 1000;
|
|
5
|
+
export const RESPONSE_RESERVE_MS = budget.browser.margin_ms;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { goPrivateCovers } from './go-env.js';
|
|
2
2
|
import { type ExecutorManifest } from './sdk-executor-manifest.js';
|
|
3
3
|
/** Pinned SDK for CLI-owned controllers and Compose planning; App pins take precedence. */
|
|
4
|
-
export declare const DEFAULT_SDK_VERSION = "0.
|
|
4
|
+
export declare const DEFAULT_SDK_VERSION = "0.49.5";
|
|
5
5
|
export declare const SDK_PACKAGE = "@synopackageland/sdk";
|
|
6
6
|
export declare const SDK_MODULE = "github.com/synopackageland/syno-pkg-land-sdk";
|
|
7
7
|
export declare const EXECUTOR_MODULE = "github.com/synopackageland/syno-pkg-land-sdk/executor";
|
|
@@ -5,7 +5,7 @@ import { tmpdir } from 'node:os';
|
|
|
5
5
|
import { join } from 'node:path';
|
|
6
6
|
import { readExecutorManifest, predatesExecutorManifest } from './sdk-executor-manifest.js';
|
|
7
7
|
/** Pinned SDK for CLI-owned controllers and Compose planning; App pins take precedence. */
|
|
8
|
-
export const DEFAULT_SDK_VERSION = '0.
|
|
8
|
+
export const DEFAULT_SDK_VERSION = '0.49.5';
|
|
9
9
|
export const SDK_PACKAGE = '@synopackageland/sdk';
|
|
10
10
|
export const SDK_MODULE = 'github.com/synopackageland/syno-pkg-land-sdk';
|
|
11
11
|
export const EXECUTOR_MODULE = `${SDK_MODULE}/executor`;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { DEFAULT_OPERATION_TIMEOUT_MS } from './operation-budget.js';
|
|
1
2
|
import { readFileSync } from 'node:fs';
|
|
2
3
|
import { join } from 'node:path';
|
|
3
4
|
import { appSdkVersion, sdkBelowFloor, sdkSource } from './sdk-source.js';
|
|
4
5
|
/** The SDK's timeouts on the call chain to the executor (spec/protocol/v1, Timeouts). */
|
|
5
6
|
export const SDK_TIMEOUTS_FILE = join('spec', 'protocol', 'v1', 'timeouts.json');
|
|
6
7
|
/** What an App without the SDK waits. */
|
|
7
|
-
export const NO_SDK_TIMEOUTS = { requestDefaultSeconds:
|
|
8
|
+
export const NO_SDK_TIMEOUTS = { requestDefaultSeconds: DEFAULT_OPERATION_TIMEOUT_MS / 1000, browserMarginMs: 2000, rootRunDefaultSeconds: DEFAULT_OPERATION_TIMEOUT_MS / 1000, rootRunRequestMarginSeconds: 20 };
|
|
8
9
|
const read = new Map();
|
|
9
10
|
/** The timeouts of the SDK checkout or module at goDir. */
|
|
10
11
|
export function sdkTimeouts(goDir) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { StandaloneError, StandaloneManifest } from './manifest.js';
|
|
2
|
+
export declare const DAEMON_NOFILE_MIN_SDK = "0.49.5";
|
|
3
|
+
export declare const DAEMON_NOFILE_MIN_DSM = "7.0-40761";
|
|
4
|
+
export declare function daemonNoFileSdkProblem(sdk: string): string | undefined;
|
|
5
|
+
export declare function daemonNoFileIdentityProblem(pkg: string): string | undefined;
|
|
6
|
+
export declare function readNoFile(value: unknown, fail: (e: StandaloneError) => void): number | undefined;
|
|
7
|
+
export declare function daemonSystemUnitName(pkg: string): string;
|
|
8
|
+
export declare function renderDaemonSystemUnit(pkg: string, nofile: number): string;
|
|
9
|
+
/** One fixed dispatch layer covers every native lifecycle composition, including
|
|
10
|
+
* delegated jobs and rootOps. The unit itself calls the SDK directly. */
|
|
11
|
+
export declare function renderNoFileLifecycle(manifest: StandaloneManifest, script: string): string;
|
|
12
|
+
/** Refuse old pins or mismatched local SDK overrides before producing an SPK. */
|
|
13
|
+
export declare function requireDaemonNoFileSource(dir: string, sdk: string, nofile?: number): void;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { StandaloneBuildError } from './spk.js';
|
|
4
|
+
export const DAEMON_NOFILE_MIN_SDK = '0.49.5';
|
|
5
|
+
export const DAEMON_NOFILE_MIN_DSM = '7.0-40761';
|
|
6
|
+
export function daemonNoFileSdkProblem(sdk) {
|
|
7
|
+
const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(sdk);
|
|
8
|
+
if (match) {
|
|
9
|
+
const [major, minor, patch] = match.slice(1).map(Number);
|
|
10
|
+
if (major > 0 || minor > 49 || minor === 49 && patch >= 5)
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
return `daemon.nofile requires SDK ${DAEMON_NOFILE_MIN_SDK} or later; selected SDK ${sdk}`;
|
|
14
|
+
}
|
|
15
|
+
export function daemonNoFileIdentityProblem(pkg) {
|
|
16
|
+
if (!/^[A-Za-z][A-Za-z0-9]{1,63}$/.test(pkg) || pkg.toLowerCase() === 'root')
|
|
17
|
+
return 'daemon.nofile requires a valid non-root package account';
|
|
18
|
+
}
|
|
19
|
+
export function readNoFile(value, fail) {
|
|
20
|
+
if (value === undefined)
|
|
21
|
+
return;
|
|
22
|
+
if (typeof value === 'number' && Number.isSafeInteger(value) && value >= 1024 && value <= 1048576)
|
|
23
|
+
return value;
|
|
24
|
+
fail({ code: 'STANDALONE_DAEMON_NOFILE_INVALID', message: 'daemon.nofile must be an integer from 1024 to 1048576; the daemon always runs as the package account' });
|
|
25
|
+
}
|
|
26
|
+
export function daemonSystemUnitName(pkg) { return `pkg-${pkg}-daemon.service`; }
|
|
27
|
+
export function renderDaemonSystemUnit(pkg, nofile) {
|
|
28
|
+
const problem = daemonNoFileIdentityProblem(pkg);
|
|
29
|
+
if (problem)
|
|
30
|
+
throw new StandaloneBuildError('STANDALONE_DAEMON_NOFILE_INVALID', problem);
|
|
31
|
+
return `[Unit]
|
|
32
|
+
Description=${pkg} daemon
|
|
33
|
+
|
|
34
|
+
[Service]
|
|
35
|
+
Type=oneshot
|
|
36
|
+
RemainAfterExit=yes
|
|
37
|
+
User=${pkg}
|
|
38
|
+
Group=${pkg}
|
|
39
|
+
Slice=${pkg}.slice
|
|
40
|
+
LimitNOFILE=${nofile}
|
|
41
|
+
NoNewPrivileges=yes
|
|
42
|
+
UMask=0077
|
|
43
|
+
ExecStart=/var/packages/${pkg}/target/daemon/control start /var/packages/${pkg}/target /var/packages/${pkg}/var
|
|
44
|
+
ExecStop=/var/packages/${pkg}/target/daemon/control stop /var/packages/${pkg}/target /var/packages/${pkg}/var
|
|
45
|
+
KillMode=control-group
|
|
46
|
+
# The SDK controller owns the validated operation deadlines
|
|
47
|
+
TimeoutStartSec=0
|
|
48
|
+
TimeoutStopSec=0
|
|
49
|
+
`;
|
|
50
|
+
}
|
|
51
|
+
/** One fixed dispatch layer covers every native lifecycle composition, including
|
|
52
|
+
* delegated jobs and rootOps. The unit itself calls the SDK directly. */
|
|
53
|
+
export function renderNoFileLifecycle(manifest, script) {
|
|
54
|
+
if (manifest.daemon?.nofile === undefined)
|
|
55
|
+
return script;
|
|
56
|
+
const pkg = manifest.package, unit = daemonSystemUnitName(pkg);
|
|
57
|
+
const controls = [`"/var/packages/${pkg}/target/daemon/control"`, `"\${SYNOPKG_PKGDEST:-/var/packages/${pkg}/target}/daemon/control"`];
|
|
58
|
+
if (!controls.some(c => script.includes(c)))
|
|
59
|
+
return script;
|
|
60
|
+
for (const control of controls)
|
|
61
|
+
script = script.replaceAll(`exec ${control}`, 'synopkgland_daemon_control').replaceAll(control, 'synopkgland_daemon_control');
|
|
62
|
+
const dispatch = `synopkgland_daemon_control() {
|
|
63
|
+
synopkgland_daemon_action="$1"
|
|
64
|
+
shift
|
|
65
|
+
case "$synopkgland_daemon_action" in
|
|
66
|
+
start|restart) /usr/syno/bin/synosystemctl "$synopkgland_daemon_action" ${unit} ;;
|
|
67
|
+
stop)
|
|
68
|
+
if [ -f /usr/local/lib/systemd/system/${unit} ]; then
|
|
69
|
+
/usr/syno/bin/synosystemctl stop ${unit} || return $?
|
|
70
|
+
fi
|
|
71
|
+
"\${SYNOPKG_PKGDEST:-/var/packages/${pkg}/target}/daemon/control" stop "$@" ;;
|
|
72
|
+
uninstall)
|
|
73
|
+
if [ -f /usr/local/lib/systemd/system/${unit} ]; then
|
|
74
|
+
/usr/syno/bin/synosystemctl stop ${unit} || return $?
|
|
75
|
+
fi
|
|
76
|
+
"\${SYNOPKG_PKGDEST:-/var/packages/${pkg}/target}/daemon/control" uninstall "$@" ;;
|
|
77
|
+
*) "\${SYNOPKG_PKGDEST:-/var/packages/${pkg}/target}/daemon/control" "$synopkgland_daemon_action" "$@" ;;
|
|
78
|
+
esac
|
|
79
|
+
}
|
|
80
|
+
`;
|
|
81
|
+
return script.replace('#!/bin/sh\n', () => `#!/bin/sh\n${dispatch}`);
|
|
82
|
+
}
|
|
83
|
+
/** Refuse old pins or mismatched local SDK overrides before producing an SPK. */
|
|
84
|
+
export function requireDaemonNoFileSource(dir, sdk, nofile) {
|
|
85
|
+
if (nofile === undefined)
|
|
86
|
+
return;
|
|
87
|
+
let main = '', linux = '';
|
|
88
|
+
try {
|
|
89
|
+
main = readFileSync(join(dir, 'daemonctl/main.go'), 'utf8');
|
|
90
|
+
linux = readFileSync(join(dir, 'daemonctl/nofile_linux.go'), 'utf8');
|
|
91
|
+
}
|
|
92
|
+
catch { /* Fail closed below. */ }
|
|
93
|
+
const problem = daemonNoFileSdkProblem(sdk);
|
|
94
|
+
if (problem || !/\bNoFile\s+int\s+`json:"nofile,omitempty"`/.test(main) || !main.includes('validateNoFile(cfg.NoFile)') || !main.includes('applyNoFile(c.NoFile)') || !linux.includes('func applyNoFile('))
|
|
95
|
+
throw new StandaloneBuildError('STANDALONE_DAEMON_NOFILE_SDK_REQUIRED', problem ?? `daemon.nofile requires matching SDK ${DAEMON_NOFILE_MIN_SDK} source with validated non-root NOFILE inheritance; update the SDK pin or development override before building`);
|
|
96
|
+
}
|
|
@@ -5,6 +5,8 @@ import { type DaemonRestart } from "./daemon-restart.js";
|
|
|
5
5
|
import type { CommandRunner } from "./build.js";
|
|
6
6
|
import type { StandaloneError, StandaloneManifest } from "./manifest.js";
|
|
7
7
|
export interface Daemon {
|
|
8
|
+
/** Acquired system-unit file descriptor limit; all processes stay non-root. */
|
|
9
|
+
nofile?: number;
|
|
8
10
|
/** Optional bounded recovery; omission uses the SDK controller default. SDK 0.26.0 or later. */
|
|
9
11
|
restart?: DaemonRestart;
|
|
10
12
|
/** Fixed foreground executable relative to daemon/payload; empty for a backend daemon. */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readNoFile, requireDaemonNoFileSource } from "./daemon-nofile.js";
|
|
1
2
|
import { portDefaults } from "./install-ports.js";
|
|
2
3
|
import { operationBudgetSeconds, runtimeBudgetSdkSupported } from "../runtime/runtime-budgets.js";
|
|
3
4
|
import { goChildEnv } from "../runtime/go-env.js";
|
|
@@ -45,6 +46,7 @@ const fields = new Set([
|
|
|
45
46
|
"node",
|
|
46
47
|
"ingress",
|
|
47
48
|
"restart",
|
|
49
|
+
"nofile",
|
|
48
50
|
]);
|
|
49
51
|
const record = (v) => Boolean(v) && typeof v === "object" && !Array.isArray(v);
|
|
50
52
|
/** A fixed argv or env value: only the package's own directories expand. */
|
|
@@ -120,6 +122,9 @@ export function readDaemon(value, root, arches, fail, packageId) {
|
|
|
120
122
|
const timeouts = readLifecycleTimeouts(value.timeouts, fail);
|
|
121
123
|
if (!timeouts)
|
|
122
124
|
return undefined;
|
|
125
|
+
const nofile = readNoFile(value.nofile, fail);
|
|
126
|
+
if (value.nofile !== undefined && nofile === undefined)
|
|
127
|
+
return undefined;
|
|
123
128
|
const restart = readDaemonRestart(value.restart, fail);
|
|
124
129
|
if (value.restart !== undefined && !restart)
|
|
125
130
|
return undefined;
|
|
@@ -146,6 +151,7 @@ export function readDaemon(value, root, arches, fail, packageId) {
|
|
|
146
151
|
...(node ? { node } : {}),
|
|
147
152
|
...(ingress ? { ingress } : {}),
|
|
148
153
|
...(restart ? { restart } : {}),
|
|
154
|
+
...(nofile !== undefined ? { nofile } : {}),
|
|
149
155
|
};
|
|
150
156
|
}
|
|
151
157
|
function readDaemonNode(value, fail) {
|
|
@@ -182,6 +188,7 @@ export function daemonConfig(manifest) {
|
|
|
182
188
|
: runnableDaemon(manifest.package, manifest.daemon);
|
|
183
189
|
return (JSON.stringify({
|
|
184
190
|
package: manifest.package,
|
|
191
|
+
...(manifest.daemon?.nofile !== undefined ? { nofile: manifest.daemon.nofile } : {}),
|
|
185
192
|
...(!manifest.compose && manifest.daemon?.backend ? { backend: true } : { exec }),
|
|
186
193
|
args,
|
|
187
194
|
...(uninstall_args ? { uninstall_args } : {}),
|
|
@@ -231,6 +238,7 @@ export async function buildDaemonControl(manifest, arch, work, run) {
|
|
|
231
238
|
const sdk = daemonSdkVersion(manifest);
|
|
232
239
|
const source = runtimeBudgetSource(sdkSource(sdk).goDir, manifest);
|
|
233
240
|
requireDaemonRestartSource(source, sdk, manifest.daemon?.restart);
|
|
241
|
+
requireDaemonNoFileSource(source, sdk, manifest.daemon?.nofile);
|
|
234
242
|
requireBackendDaemonSource(source, manifest.daemon);
|
|
235
243
|
const result = await run("go", [
|
|
236
244
|
"build",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readNoFile, daemonSystemUnitName, renderDaemonSystemUnit, daemonNoFileSdkProblem, daemonNoFileIdentityProblem, DAEMON_NOFILE_MIN_DSM } from "./daemon-nofile.js";
|
|
1
2
|
import { gatewayIngressPathProblem, gatewayIngressOwnershipSupported } from './gateway-ingress.js';
|
|
2
3
|
import { renderGatewayIngressCheck } from './native-gateway.js';
|
|
3
4
|
import { portDefaults, portInstallSteps } from "./install-ports.js";
|
|
@@ -153,7 +154,15 @@ export async function inspectSpk(spkPath, expectedKind) {
|
|
|
153
154
|
}
|
|
154
155
|
}
|
|
155
156
|
const dependencies = inspectPackageDependencies(metadata.dependencies, findings);
|
|
156
|
-
const
|
|
157
|
+
const daemonNoFile = readNoFile(metadata.daemon_nofile, e => findings.push(e.message));
|
|
158
|
+
if (daemonNoFile !== undefined) {
|
|
159
|
+
const problem = daemonNoFileSdkProblem(typeof metadata.daemon_sdk === 'string' ? metadata.daemon_sdk : 'unknown');
|
|
160
|
+
if (problem)
|
|
161
|
+
findings.push(problem);
|
|
162
|
+
}
|
|
163
|
+
if (metadata.daemon_nofile !== undefined && (!paths.has("daemon/control") || metadata.compose !== undefined))
|
|
164
|
+
findings.push("daemon.nofile requires a native daemon controller");
|
|
165
|
+
const daemonRestart = recoverDaemonRestart(metadata.daemon_restart, metadata.daemon_restart === undefined && daemonNoFile !== undefined ? undefined : metadata.daemon_sdk, findings);
|
|
157
166
|
await inspectModuleUi(dir, paths, metadata.ui_module, findings);
|
|
158
167
|
if (metadata.daemon_restart !== undefined && (metadata.compose !== undefined || !paths.has("daemon/control")))
|
|
159
168
|
findings.push("DAEMON_RESTART_INVALID daemon restart requires a native daemon controller, without Compose supervision");
|
|
@@ -228,7 +237,7 @@ export async function inspectSpk(spkPath, expectedKind) {
|
|
|
228
237
|
!isDsmAtLeast(info.os_min_ver, PORTAL_MIN_DSM)) {
|
|
229
238
|
findings.push(`INFO os_min_ver "${info.os_min_ver}" is below the DSM ${PORTAL_MIN_DSM} a portal needs; ${PORTAL_MIN_DSM_REASON}`);
|
|
230
239
|
}
|
|
231
|
-
checkConf(dir, findings, kind, background, sharedFolder, info.package, portal, combined?.compose, nativeGateway, info.os_min_ver, daemonIngress, Boolean(metadata.installPorts));
|
|
240
|
+
checkConf(dir, findings, kind, background, sharedFolder, info.package, portal, combined?.compose, nativeGateway, info.os_min_ver, daemonIngress, Boolean(metadata.installPorts), daemonNoFile);
|
|
232
241
|
checkScripts(dir, findings);
|
|
233
242
|
checkUninstall(dir, findings);
|
|
234
243
|
if (kind === "container")
|
|
@@ -258,7 +267,7 @@ export async function inspectSpk(spkPath, expectedKind) {
|
|
|
258
267
|
if (standalone && portal)
|
|
259
268
|
findings.push(...inspectPortalInfo(info, hasExecutor));
|
|
260
269
|
const daemon = standalone
|
|
261
|
-
? await checkDaemon(dir, info, paths, payload, findings, hasExecutor, background, combined, nativeGateway, uninstallHook?.uninstall, { ingress: daemonIngress, node: daemonNode, restart: daemonRestart, installPorts: Boolean(metadata.installPorts) })
|
|
270
|
+
? await checkDaemon(dir, info, paths, payload, findings, hasExecutor, background, combined, nativeGateway, uninstallHook?.uninstall, { ingress: daemonIngress, node: daemonNode, restart: daemonRestart, nofile: daemonNoFile, installPorts: Boolean(metadata.installPorts) })
|
|
262
271
|
: undefined;
|
|
263
272
|
if (background)
|
|
264
273
|
checkBackground(dir, info, payload, findings, hasExecutor, daemon, kind !== "native-go", metadata.lifecycleTimeouts, nativeGateway, Boolean(metadata.installPorts));
|
|
@@ -990,9 +999,12 @@ async function checkDaemon(dir, info, paths, payload, findings, executor, backgr
|
|
|
990
999
|
"operation_seconds",
|
|
991
1000
|
"uninstall_args",
|
|
992
1001
|
"restart",
|
|
1002
|
+
"nofile",
|
|
993
1003
|
...(combined ? ["network"] : []),
|
|
994
1004
|
].includes(key)))
|
|
995
1005
|
throw new Error("package/config mismatch");
|
|
1006
|
+
if (config.nofile !== extras.nofile)
|
|
1007
|
+
throw new Error("daemon nofile differs from its build declaration");
|
|
996
1008
|
if (!isDeepStrictEqual(config.restart, extras.restart))
|
|
997
1009
|
throw new Error("daemon restart differs from its build declaration");
|
|
998
1010
|
const backend = config.backend === true;
|
|
@@ -1005,6 +1017,7 @@ async function checkDaemon(dir, info, paths, payload, findings, executor, backgr
|
|
|
1005
1017
|
env: config.env,
|
|
1006
1018
|
timeouts: config.timeouts,
|
|
1007
1019
|
restart: config.restart,
|
|
1020
|
+
nofile: config.nofile,
|
|
1008
1021
|
targets: { x86_64: "payload" },
|
|
1009
1022
|
}, dir, ["x86_64"], () => { }, info.package);
|
|
1010
1023
|
if (!daemon)
|
|
@@ -1334,7 +1347,7 @@ async function recoverDaemonIngress(dir, value, info, paths, findings) {
|
|
|
1334
1347
|
return undefined;
|
|
1335
1348
|
}
|
|
1336
1349
|
}
|
|
1337
|
-
function checkConf(dir, findings, kind, background, sharedFolder, pkg, portal, compose, nativeGateway, osMinVer, daemonIngress, installPorts = false) {
|
|
1350
|
+
function checkConf(dir, findings, kind, background, sharedFolder, pkg, portal, compose, nativeGateway, osMinVer, daemonIngress, installPorts = false, nofile) {
|
|
1338
1351
|
const confDir = join(dir, "conf");
|
|
1339
1352
|
const entries = existsSync(confDir) ? readdirSync(confDir) : [];
|
|
1340
1353
|
const nativeResource = kind !== "container"
|
|
@@ -1359,10 +1372,26 @@ function checkConf(dir, findings, kind, background, sharedFolder, pkg, portal, c
|
|
|
1359
1372
|
if (name !== "privilege" &&
|
|
1360
1373
|
!(kind === "container" && name === "resource") &&
|
|
1361
1374
|
!(nativeResource !== undefined && name === "resource") &&
|
|
1362
|
-
!(background && name === "systemd")) {
|
|
1375
|
+
!((background || nofile !== undefined) && name === "systemd")) {
|
|
1363
1376
|
findings.push(`conf/${name} registers an extra resource with DSM; a Standalone Package does not produce it`);
|
|
1364
1377
|
}
|
|
1365
1378
|
}
|
|
1379
|
+
if (nofile !== undefined && pkg) {
|
|
1380
|
+
if (!osMinVer || !isDsmAtLeast(osMinVer, DAEMON_NOFILE_MIN_DSM))
|
|
1381
|
+
findings.push(`daemon.nofile requires DSM ${DAEMON_NOFILE_MIN_DSM} or later`);
|
|
1382
|
+
const unit = daemonSystemUnitName(pkg);
|
|
1383
|
+
const identityProblem = daemonNoFileIdentityProblem(pkg);
|
|
1384
|
+
if (identityProblem)
|
|
1385
|
+
findings.push(identityProblem);
|
|
1386
|
+
else if (readOptional(join(confDir, "systemd", unit)) !== renderDaemonSystemUnit(pkg, nofile))
|
|
1387
|
+
findings.push("daemon NOFILE system unit must match the fixed package account, limit and lifecycle");
|
|
1388
|
+
}
|
|
1389
|
+
if (background || nofile !== undefined) {
|
|
1390
|
+
const expected = [...(background && pkg ? [backgroundUnitName(pkg)] : []), ...(nofile !== undefined && pkg ? [daemonSystemUnitName(pkg)] : [])].sort();
|
|
1391
|
+
const actual = existsSync(join(confDir, "systemd")) ? readdirSync(join(confDir, "systemd")).sort() : [];
|
|
1392
|
+
if (!isDeepStrictEqual(actual, expected))
|
|
1393
|
+
findings.push("conf/systemd contains missing or extra package units");
|
|
1394
|
+
}
|
|
1366
1395
|
if (kind === "container") {
|
|
1367
1396
|
try {
|
|
1368
1397
|
const resource = JSON.parse(readFileSync(join(confDir, "resource"), "utf8"));
|
|
@@ -1423,8 +1452,7 @@ function checkBackground(dir, info, payload, findings, executor, daemon, bridge
|
|
|
1423
1452
|
? readdirSync(join(dir, BACKGROUND_UNIT_DIR))
|
|
1424
1453
|
: [];
|
|
1425
1454
|
const unit = backgroundUnitName(pkg);
|
|
1426
|
-
if (units.
|
|
1427
|
-
units[0] !== unit ||
|
|
1455
|
+
if (!isDeepStrictEqual(units.sort(), [unit, ...(daemon?.nofile !== undefined ? [daemonSystemUnitName(pkg)] : [])].sort()) ||
|
|
1428
1456
|
read(`${BACKGROUND_UNIT_DIR}/${unit}`) !==
|
|
1429
1457
|
renderBackgroundUnit(pkg, bridge ? BRIDGE_WORKER_ARGS : [], daemon?.timeouts.stop ?? lifecycleTimeouts?.stop ?? 30)) {
|
|
1430
1458
|
findings.push(`${BACKGROUND_UNIT_DIR} must contain only the fixed ${unit} (runs as the package account, no User=, no root)`);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { renderNoFileLifecycle } from "./daemon-nofile.js";
|
|
1
2
|
import { renderGatewayIngressCheck } from './native-gateway.js';
|
|
2
3
|
import { renderSettingsHook } from './install-settings.js';
|
|
3
4
|
import { renderComposeRetainedData } from "../build-spk/compose-retained-data.js";
|
|
@@ -15,7 +16,7 @@ import { composeAppScript } from "./app-scripts.js";
|
|
|
15
16
|
const UNINSTALL_ONLY = '[ "${SYNOPKG_PKG_STATUS:-}" = UPGRADE ] || synopkgland_uninstall_hook\n';
|
|
16
17
|
/** Package-account lifecycle hooks for CGI, daemon and background packages. */
|
|
17
18
|
export function renderStandaloneScript(name, manifest) {
|
|
18
|
-
const script = renderStandaloneScriptInternal(name, manifest);
|
|
19
|
+
const script = renderNoFileLifecycle(manifest, renderStandaloneScriptInternal(name, manifest));
|
|
19
20
|
const prefix = renderStandaloneScriptPrefix(name, manifest);
|
|
20
21
|
const sdk = prefix ? script.replace('#!/bin/sh\n', () => '#!/bin/sh\n' + prefix) : script;
|
|
21
22
|
return manifest.appScripts?.some((app) => app === name)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { daemonNoFileSdkProblem, daemonNoFileIdentityProblem, DAEMON_NOFILE_MIN_DSM } from './daemon-nofile.js';
|
|
1
2
|
import { readRegistry, registryFile } from '../ctl/registry.js';
|
|
2
3
|
import { gatewayIngressPathProblem, gatewayIngressOwnershipSupported } from './gateway-ingress.js';
|
|
3
4
|
import { nativeGatewaySdk } from "./native-gateway.js";
|
|
@@ -226,7 +227,9 @@ function readManifest(raw, c) {
|
|
|
226
227
|
.filter(({ setting }) => !setting || setting.run)
|
|
227
228
|
.map(({ op, setting }) => ({
|
|
228
229
|
name: op.name,
|
|
229
|
-
timeoutSeconds: setting?.run?.timeout_s ?? timeouts.rootRunDefaultSeconds
|
|
230
|
+
timeoutSeconds: setting?.run?.timeout_s ?? (timeouts.rootRunDefaultSeconds === timeouts.requestDefaultSeconds
|
|
231
|
+
? Math.min(timeouts.rootRunDefaultSeconds, Math.max(1, requestTimeoutSeconds(backend) - timeouts.rootRunRequestMarginSeconds))
|
|
232
|
+
: timeouts.rootRunDefaultSeconds),
|
|
230
233
|
}));
|
|
231
234
|
const problem = rootRunDeadlineProblem(runnable, requestTimeoutSeconds(backend), timeouts.rootRunRequestMarginSeconds);
|
|
232
235
|
if (problem)
|
|
@@ -345,6 +348,16 @@ function readManifest(raw, c) {
|
|
|
345
348
|
if (problem)
|
|
346
349
|
c.fail("STANDALONE_DAEMON_INGRESS_MIN_DSM", problem);
|
|
347
350
|
}
|
|
351
|
+
if (daemon?.nofile !== undefined && backend) {
|
|
352
|
+
if (osMinVer && !isDsmAtLeast(osMinVer, DAEMON_NOFILE_MIN_DSM))
|
|
353
|
+
c.fail('STANDALONE_DAEMON_NOFILE_DSM_REQUIRED', `daemon.nofile requires DSM ${DAEMON_NOFILE_MIN_DSM} or later; the target is never raised automatically`);
|
|
354
|
+
const problem = daemonNoFileSdkProblem(daemonSdkVersion({ backend, identityGateway }));
|
|
355
|
+
if (problem)
|
|
356
|
+
c.fail('STANDALONE_DAEMON_NOFILE_SDK_REQUIRED', problem);
|
|
357
|
+
const identityProblem = daemonNoFileIdentityProblem(packageId ?? '');
|
|
358
|
+
if (identityProblem)
|
|
359
|
+
c.fail('STANDALONE_DAEMON_NOFILE_INVALID', identityProblem);
|
|
360
|
+
}
|
|
348
361
|
if (daemon?.restart && backend) {
|
|
349
362
|
const problem = daemonRestartSdkProblem(daemonSdkVersion({ backend, identityGateway }));
|
|
350
363
|
if (problem)
|
package/dist/standalone/spk.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { daemonSystemUnitName, renderDaemonSystemUnit } from "./daemon-nofile.js";
|
|
1
2
|
import { gatewayIngressOwnershipSupported } from './gateway-ingress.js';
|
|
2
3
|
import { portDefaults, portInstallSteps, writePortPayload } from "./install-ports.js";
|
|
3
4
|
import { packageDependencies, dependencyInfo } from "./package-dependencies.js";
|
|
@@ -272,7 +273,9 @@ export async function assembleStandaloneSpk(options) {
|
|
|
272
273
|
...(nativeGatewaySupported(manifest) ? { native_gateway: { sdk: manifest.identityGateway.sdk, listen: manifest.identityGateway.listen, ...(manifest.identityGateway.ingress ? { ingress: manifest.identityGateway.ingress } : {}) } } : {}),
|
|
273
274
|
...(manifest.daemon?.ingress ? { daemon_ingress: manifest.daemon.ingress } : {}),
|
|
274
275
|
...(manifest.daemon?.node ? { daemon_node: manifest.daemon.node } : {}),
|
|
275
|
-
...(manifest.daemon?.
|
|
276
|
+
...(manifest.daemon?.nofile !== undefined ? { daemon_nofile: manifest.daemon.nofile } : {}),
|
|
277
|
+
...(manifest.daemon?.restart ? { daemon_restart: manifest.daemon.restart } : {}),
|
|
278
|
+
...(manifest.daemon?.restart || manifest.daemon?.nofile !== undefined ? { daemon_sdk: daemonSdkVersion(manifest) } : {}),
|
|
276
279
|
launch: resolvedSdkLaunch(manifest),
|
|
277
280
|
capabilities: Object.keys(manifest.capabilities).sort(),
|
|
278
281
|
...(manifest.compose
|
|
@@ -299,6 +302,10 @@ export async function assembleStandaloneSpk(options) {
|
|
|
299
302
|
const resource = renderStandaloneResource(manifest, portal);
|
|
300
303
|
if (resource)
|
|
301
304
|
writeFile(join(staging, "conf", "resource"), resource);
|
|
305
|
+
if (manifest.daemon?.nofile !== undefined) {
|
|
306
|
+
mkdirSync(join(staging, "conf/systemd"), { recursive: true });
|
|
307
|
+
writeFile(join(staging, "conf/systemd", daemonSystemUnitName(manifest.package)), renderDaemonSystemUnit(manifest.package, manifest.daemon.nofile));
|
|
308
|
+
}
|
|
302
309
|
if (manifest.capabilities.jobs) {
|
|
303
310
|
mkdirSync(join(staging, BACKGROUND_UNIT_DIR), { recursive: true });
|
|
304
311
|
writeFile(join(staging, BACKGROUND_UNIT_DIR, backgroundUnitName(manifest.package)), renderBackgroundUnit(manifest.package, isBridgeBackend(manifest.backend) ? BRIDGE_WORKER_ARGS : [], manifest.daemon?.timeouts.stop ?? manifest.lifecycleTimeouts?.stop ?? 30));
|
package/package.json
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"$comment": "The App's methods. The App's hello MUST list exactly these. They MUST NOT be SDK methods (api/sdk-permissions.json)."
|
|
26
26
|
},
|
|
27
27
|
"access": { "enum": ["admin-only", "app-privilege"], "$comment": "Entry restriction (dsm.NewEntryGate). Absent: permissions.json alone decides." },
|
|
28
|
-
"timeout_seconds": { "type": "integer", "minimum": 1, "maximum": 3600, "$comment": "Request deadline. Absent: api.DefaultRequestTimeout (
|
|
28
|
+
"timeout_seconds": { "type": "integer", "minimum": 1, "maximum": 3600, "$comment": "Request deadline. Absent: api.DefaultRequestTimeout (300 s). The browser client must wait longer." },
|
|
29
29
|
"max_request_bytes": { "type": "integer", "minimum": 1, "maximum": 16777216, "$comment": "JSON request body limit. Absent: api.MaxRequestBytes." },
|
|
30
30
|
"env": {
|
|
31
31
|
"type": "object",
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$comment": "Timeouts on the call chain to the executor, in seconds unless the name says ms. Each layer waits margin_s longer than the layer it calls, so the inner answer arrives first; README.md, Timeouts.",
|
|
3
|
+
"margin_s": 10,
|
|
4
|
+
"executor": {
|
|
5
|
+
"op_s": 300,
|
|
6
|
+
"webapi_raw_execution_s": 300,
|
|
7
|
+
"webapi_raw_answer_s": 310,
|
|
8
|
+
"root_run_program_default_s": 300,
|
|
9
|
+
"root_run_program_max_s": 3600,
|
|
10
|
+
"root_run_answer_s": 3610,
|
|
11
|
+
"start_step_s": 300
|
|
12
|
+
},
|
|
13
|
+
"client": {
|
|
14
|
+
"op_s": 310,
|
|
15
|
+
"webapi_raw_s": 320,
|
|
16
|
+
"root_run_s": 3620
|
|
17
|
+
},
|
|
18
|
+
"request": {
|
|
19
|
+
"default_s": 300
|
|
20
|
+
},
|
|
21
|
+
"browser": {
|
|
22
|
+
"margin_ms": 2000
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -430,7 +430,8 @@
|
|
|
430
430
|
"timeoutMs": {
|
|
431
431
|
"type": "integer",
|
|
432
432
|
"minimum": 10,
|
|
433
|
-
"maximum": 3600000
|
|
433
|
+
"maximum": 3600000,
|
|
434
|
+
"description": "Optional per-request allowance; omission uses the shared operation budget, with polling until completion or cancellation and no total elapsed limit"
|
|
434
435
|
}
|
|
435
436
|
},
|
|
436
437
|
"required": [
|
|
@@ -442,8 +443,7 @@
|
|
|
442
443
|
"state",
|
|
443
444
|
"done",
|
|
444
445
|
"failed",
|
|
445
|
-
"intervalMs"
|
|
446
|
-
"timeoutMs"
|
|
446
|
+
"intervalMs"
|
|
447
447
|
]
|
|
448
448
|
}
|
|
449
449
|
]
|
package/skills/SKILL.md
CHANGED
|
@@ -53,7 +53,7 @@ progress and authorized status/result polling by the original ID. A timed-out
|
|
|
53
53
|
status read does not fail a queued/running job; reuse the same key/input after
|
|
54
54
|
a lost admission reply. Read [reference/create.md](reference/create.md) for
|
|
55
55
|
the deadline and background-job contract. The independent ctl transport keeps
|
|
56
|
-
|
|
56
|
+
the shared SDK operation default; use existing jobs for long work and poll until terminal state or cancellation.
|
|
57
57
|
|
|
58
58
|
Use `ipc.StartUnix(ctx, path, handler)` for multiple private data-plane sockets.
|
|
59
59
|
Each direct `.sock` child of the package `var/run` gets an independent handle
|
|
@@ -93,7 +93,7 @@ func deadline() api.DeadlineOption {
|
|
|
93
93
|
|
|
94
94
|
直接 File Station 瀏覽器讀取預設也為 302 秒;identity gateway 等候 upstream headers 預設 310 秒,自訂期限需對齊 gateway 與外部 proxy。這些預設不保證所有 DSM/proxy 都能完成五分鐘請求。executor batch 的 60 秒上限、已核准 root policy/program budget 與 credential lifetime 維持原契約;長 root 工作使用既有 `root.start` / `root.jobs.*`。
|
|
95
95
|
|
|
96
|
-
|
|
96
|
+
`ctl` transport 採 SDK 共用的五分鐘操作預算與回覆保留時間;job flow 不以累計時間中止存活工作。長工作必須映射既有 job flow,不以延長同步等待取代非同步 API;參考 [ctl](ctl.md)。完整契約見 SDK 的 [request deadlines](https://github.com/synopackageland/syno-pkg-land-sdk/blob/v0.47.1/docs/request-deadlines.md)。
|
|
97
97
|
|
|
98
98
|
DSM 視窗預設 960×640、最小 700×420;`ui.window` 只寫要改的欄位:
|
|
99
99
|
|
package/skills/reference/ctl.md
CHANGED
|
@@ -208,16 +208,17 @@ list, get, result, cancel, pause and resume capabilities. Only declare capabilit
|
|
|
208
208
|
that the selected SDK and enabled backend actually provide. Never fabricate ETA,
|
|
209
209
|
cancellation, deduplication or "return existing ID" behavior.
|
|
210
210
|
|
|
211
|
-
The
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
211
|
+
The ctl transport uses the shared five-minute SDK operation default plus response
|
|
212
|
+
reserve. Job flow `timeoutMs` is optional and sets a per-request allowance. Keep
|
|
213
|
+
polling while the App reports a live job; elapsed time never fails it. Cancellation
|
|
214
|
+
ends the local wait. Preserve the original ID after a failed status read or lost
|
|
215
|
+
admission reply, and never repeat a dispatched mutation merely because it was slow.
|
|
216
|
+
|
|
216
217
|
|
|
217
218
|
For AI tools, a draft always returns a non-mutating preview and plan. Obtain
|
|
218
219
|
human authorization before the normal ctl command executes with --yes. Report
|
|
219
220
|
acceptance separately from completion; preparation is not download or save
|
|
220
|
-
completion. If
|
|
221
|
+
completion. If a status request times out, return the original ID and the exact
|
|
221
222
|
existing status command. A timeout does not prove failure or cancellation.
|
|
222
223
|
Cancellation also requires its declared preview/confirmation policy and readback
|
|
223
224
|
until the existing API proves that work stopped.
|
|
@@ -133,3 +133,36 @@ continue. The executor helper's JSON state distinguishes `accepted`,
|
|
|
133
133
|
request and does not prove cleanup finished. Unconfirmed cleanup retains protected
|
|
134
134
|
state for a later retry. DSM's outer install/uninstall deadline is not established
|
|
135
135
|
by these settings.
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
## Daemon file descriptor budget
|
|
139
|
+
|
|
140
|
+
Native daemon Apps may opt in with `daemon.nofile: 32768`. The value must be an
|
|
141
|
+
integer from 1024 to 1048576; omission keeps the legacy controller path. This
|
|
142
|
+
requires DSM 7.0-40761 or later and SDK 0.49.5 or later, including an explicit Go App SDK pin or gateway
|
|
143
|
+
pin. CLI 0.48.3 retains the SDK 0.49.5 default introduced in 0.48.2. Check and
|
|
144
|
+
build reject older pins; build also verifies matching controller sources.
|
|
145
|
+
|
|
146
|
+
The CLI generates only `conf/systemd/pkg-<package>-daemon.service`. DSM acquires
|
|
147
|
+
this fixed system unit directly; it needs no `systemd-user-unit` resource
|
|
148
|
+
(that worker is for `pkguser-*` user units). See the
|
|
149
|
+
[official acquired-unit contract](https://help.synology.com/developer-guide/resource_acquisition/systemd_user_unit.html). `LimitNOFILE` sets its inherited soft/hard budget;
|
|
150
|
+
`User` and `Group` stay the package account, with `NoNewPrivileges=yes` and
|
|
151
|
+
`KillMode=control-group`. A root package identity is refused. Apps cannot supply
|
|
152
|
+
arbitrary units, identities, commands or root lifecycle work through this field.
|
|
153
|
+
The SDK daemon controller verifies the inherited hard limit and raises only the
|
|
154
|
+
soft limit before launching its non-root worker; insufficient inheritance fails
|
|
155
|
+
with `DAEMON_NOFILE_INSUFFICIENT`.
|
|
156
|
+
|
|
157
|
+
Generated start/restart uses the acquired unit; status stays on the SDK
|
|
158
|
+
controller. Stop also calls the idempotent SDK stop to cover an upgrade from a
|
|
159
|
+
legacy controller, including when a new unit file is already present. Uninstall
|
|
160
|
+
stops the unit then invokes the existing SDK uninstall path. The unit leaves
|
|
161
|
+
outer systemd start/stop timeouts disabled so the SDK's existing validated
|
|
162
|
+
`daemon.timeouts` remain the single work deadline. Inspect rejects a missing,
|
|
163
|
+
extra or changed unit and mismatched metadata/controller configuration.
|
|
164
|
+
|
|
165
|
+
After publishing and deploying an opted-in package, read the actual worker UID
|
|
166
|
+
and soft/hard limits after upgrade/restart. Generated files and local SPK tests
|
|
167
|
+
alone do not establish DSM acquisition, inherited worker limits or full lifecycle
|
|
168
|
+
acceptance on a NAS.
|