@jini-ai/cli 0.7.2 → 0.7.3-next.2
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 +1 -1
- package/README.md +3 -2
- package/dist/daemon-call-deps.d.ts +53 -0
- package/dist/daemon-call-deps.js +24 -0
- package/dist/daemon-command.d.ts +2 -39
- package/dist/daemon-command.js +6 -28
- package/dist/daemon-url.d.ts +3 -3
- package/dist/daemon-url.js +3 -3
- package/dist/flags.js +5 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/local-daemon-discovery.d.ts +1 -1
- package/dist/local-daemon-discovery.js +2 -2
- package/dist/main.js +3 -9
- package/dist/prompt.d.ts +9 -34
- package/dist/prompt.js +24 -16
- package/dist/quiet-line.d.ts +16 -0
- package/dist/quiet-line.js +31 -0
- package/dist/run-command.d.ts +2 -20
- package/dist/run-command.js +10 -32
- package/dist/stdin-line.d.ts +24 -0
- package/dist/stdin-line.js +50 -0
- package/dist/version-command.d.ts +2 -37
- package/dist/version-command.js +6 -30
- package/package.json +6 -8
package/CHANGELOG.md
CHANGED
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
|
|
82
82
|
### Patch Changes
|
|
83
83
|
|
|
84
|
-
-
|
|
84
|
+
- Host clean-up release (2026-10-08): code the first host moved into Jini, plus the Jini clean-up (see the commit log since 0.4.0).
|
|
85
85
|
|
|
86
86
|
## 0.4.0 — 2026-10-02
|
|
87
87
|
|
package/README.md
CHANGED
|
@@ -47,10 +47,11 @@ No peer dependencies. Depends on `@jini-ai/core` (for the `token()`-based transp
|
|
|
47
47
|
```ts
|
|
48
48
|
import { CommandRegistry, resolveDaemonUrl, registerRunCommands, exitWithStructuredError } from '@jini-ai/cli';
|
|
49
49
|
|
|
50
|
+
const env = process.env;
|
|
50
51
|
const registry = new CommandRegistry({});
|
|
51
52
|
|
|
52
53
|
registerRunCommands({ registry,
|
|
53
|
-
resolveBaseUrl: () => resolveDaemonUrl({}, { envVarName: 'JINI_DAEMON_URL', defaultUrl: 'http://127.0.0.1:4317' }),
|
|
54
|
+
resolveBaseUrl: () => resolveDaemonUrl({ env }, { envVarName: 'JINI_DAEMON_URL', defaultUrl: 'http://127.0.0.1:4317' }),
|
|
54
55
|
});
|
|
55
56
|
|
|
56
57
|
const result = await registry.dispatch({ argv: process.argv.slice(2) });
|
|
@@ -94,4 +95,4 @@ Text sanitization and terminal control stripping now live at `@jini-ai/core/text
|
|
|
94
95
|
bounded lowercase-marker output preserved. Former direct `redactSecretLike` callers use core
|
|
95
96
|
`redactSecrets({ input }, { policy: 'aggressive' })`; this explicit policy emits category markers
|
|
96
97
|
and also masks recognized PII. Core's default stays conservative for diagnostics. The CLI keeps
|
|
97
|
-
`sanitizeUnknownDeep` for bounded recursive JSON. Loopback warnings use `@jini-ai/
|
|
98
|
+
`sanitizeUnknownDeep` for bounded recursive JSON. Loopback warnings use `@jini-ai/core/net`.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ExitCodeTable } from './errors.js';
|
|
2
|
+
export interface DaemonCallDeps {
|
|
3
|
+
/** Resolves the daemon HTTP base URL once per command invocation (e.g. wraps `resolveDaemonUrl`). */
|
|
4
|
+
resolveBaseUrl: () => Promise<string> | string;
|
|
5
|
+
/** Defaults to `process.stdout.write`; inject for tests. Used for successful command output. */
|
|
6
|
+
write?: (requiredArgs: {
|
|
7
|
+
text: string;
|
|
8
|
+
}) => void;
|
|
9
|
+
/** Defaults to `process.stderr.write`; inject for tests. Used for usage/validation errors. */
|
|
10
|
+
writeErr?: (requiredArgs: {
|
|
11
|
+
text: string;
|
|
12
|
+
}) => void;
|
|
13
|
+
/** Defaults to the global `fetch`; inject for tests. */
|
|
14
|
+
fetchImpl?: typeof fetch;
|
|
15
|
+
/** Defaults to `process.exit`; inject for tests (must not return). */
|
|
16
|
+
exit?: (requiredArgs: {
|
|
17
|
+
code: number;
|
|
18
|
+
}) => never;
|
|
19
|
+
/** Extra/overriding `code -> exitCode` entries layered on the package default table. */
|
|
20
|
+
exitCodes?: ExitCodeTable;
|
|
21
|
+
}
|
|
22
|
+
export declare function defaultWrite({ text }: {
|
|
23
|
+
text: string;
|
|
24
|
+
}, _optional?: Record<string, never>): void;
|
|
25
|
+
export declare function defaultWriteErr({ text }: {
|
|
26
|
+
text: string;
|
|
27
|
+
}, _optional?: Record<string, never>): void;
|
|
28
|
+
/** Builds `{write, exit, exitCodes?}` for `errors.ts`'s structured-error helpers, never assigning `exitCodes` when unset (required under `exactOptionalPropertyTypes`). */
|
|
29
|
+
export declare function errorOptions({ deps }: {
|
|
30
|
+
deps: Omit<DaemonCallDeps, 'resolveBaseUrl'>;
|
|
31
|
+
}, _optional?: Record<string, never>): {
|
|
32
|
+
write: (requiredArgs: {
|
|
33
|
+
text: string;
|
|
34
|
+
}) => void;
|
|
35
|
+
exit: (requiredArgs: {
|
|
36
|
+
code: number;
|
|
37
|
+
}) => never;
|
|
38
|
+
exitCodes?: ExitCodeTable;
|
|
39
|
+
};
|
|
40
|
+
/** Builds the transport-call options object for `postJsonToDaemon`/`getJsonFromDaemon`, only ever including a key when its value is actually set. */
|
|
41
|
+
export declare function transportOptions({ deps }: {
|
|
42
|
+
deps: DaemonCallDeps;
|
|
43
|
+
}, _optional?: Record<string, never>): {
|
|
44
|
+
fetchImpl?: typeof fetch;
|
|
45
|
+
write?: (requiredArgs: {
|
|
46
|
+
text: string;
|
|
47
|
+
}) => void;
|
|
48
|
+
exit?: (requiredArgs: {
|
|
49
|
+
code: number;
|
|
50
|
+
}) => never;
|
|
51
|
+
exitCodes?: ExitCodeTable;
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=daemon-call-deps.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export function defaultWrite({ text }, _optional = {}) {
|
|
2
|
+
process.stdout.write(text);
|
|
3
|
+
}
|
|
4
|
+
export function defaultWriteErr({ text }, _optional = {}) {
|
|
5
|
+
process.stderr.write(text);
|
|
6
|
+
}
|
|
7
|
+
/** Builds `{write, exit, exitCodes?}` for `errors.ts`'s structured-error helpers, never assigning `exitCodes` when unset (required under `exactOptionalPropertyTypes`). */
|
|
8
|
+
export function errorOptions({ deps }, _optional = {}) {
|
|
9
|
+
return {
|
|
10
|
+
write: deps.writeErr ?? defaultWriteErr,
|
|
11
|
+
exit: deps.exit ?? (({ code }) => process.exit(code)),
|
|
12
|
+
...(deps.exitCodes !== undefined ? { exitCodes: deps.exitCodes } : {}),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/** Builds the transport-call options object for `postJsonToDaemon`/`getJsonFromDaemon`, only ever including a key when its value is actually set. */
|
|
16
|
+
export function transportOptions({ deps }, _optional = {}) {
|
|
17
|
+
return {
|
|
18
|
+
...(deps.fetchImpl !== undefined ? { fetchImpl: deps.fetchImpl } : {}),
|
|
19
|
+
...(deps.writeErr !== undefined ? { write: deps.writeErr } : {}),
|
|
20
|
+
...(deps.exit !== undefined ? { exit: deps.exit } : {}),
|
|
21
|
+
...(deps.exitCodes !== undefined ? { exitCodes: deps.exitCodes } : {}),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=daemon-call-deps.js.map
|
package/dist/daemon-command.d.ts
CHANGED
|
@@ -1,43 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module daemon-command
|
|
3
|
-
*
|
|
4
|
-
* `daemon status` / `daemon stop` — concrete commands over `@jini-ai/http-kit`'s
|
|
5
|
-
* `daemonStatusRoute`/`daemonShutdownRoute` (`packages/http/src/daemon-status.ts`).
|
|
6
|
-
* `packages/cli/archived provenance ledger`'s original UNCLEAR verdict on these two
|
|
7
|
-
* blocked on `@jini-ai/http-kit` being a stub with no `/status`/`/shutdown` route to
|
|
8
|
-
* call; that blocker no longer holds (both routes exist and are tested), and
|
|
9
|
-
* `run-command.ts` is now a real, established "first concrete command"
|
|
10
|
-
* precedent this file follows rather than pioneers.
|
|
11
|
-
*
|
|
12
|
-
* `daemon status` is a plain read (`GET`, no `requireSameOrigin`).
|
|
13
|
-
* `daemon stop` posts to a `requireSameOrigin: true` route — a bare CLI
|
|
14
|
-
* `fetch()` sends no `Origin` header, so `guardSameOrigin` falls through to
|
|
15
|
-
* its Host-header check (`isLocalSameOrigin`'s `origin == null` branch),
|
|
16
|
-
* which passes as long as the resolved daemon URL's host:port is one the
|
|
17
|
-
* daemon itself considers local. No special headers are added here for
|
|
18
|
-
* that — it is the same call shape `run-command.ts` already uses.
|
|
19
|
-
*/
|
|
20
|
-
import { type ExitCodeTable } from './errors.js';
|
|
21
1
|
import type { CommandRegistry } from './command-registry.js';
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
resolveBaseUrl: () => Promise<string> | string;
|
|
25
|
-
/** Defaults to `process.stdout.write`; inject for tests. Used for successful command output. */
|
|
26
|
-
write?: (requiredArgs: {
|
|
27
|
-
text: string;
|
|
28
|
-
}) => void;
|
|
29
|
-
/** Defaults to `process.stderr.write`; inject for tests. Used for usage/validation errors. */
|
|
30
|
-
writeErr?: (requiredArgs: {
|
|
31
|
-
text: string;
|
|
32
|
-
}) => void;
|
|
33
|
-
/** Defaults to the global `fetch`; inject for tests. */
|
|
34
|
-
fetchImpl?: typeof fetch;
|
|
35
|
-
/** Defaults to `process.exit`; inject for tests (must not return). */
|
|
36
|
-
exit?: (requiredArgs: {
|
|
37
|
-
code: number;
|
|
38
|
-
}) => never;
|
|
39
|
-
/** Extra/overriding `code -> exitCode` entries layered on the package default table. */
|
|
40
|
-
exitCodes?: ExitCodeTable;
|
|
2
|
+
import { type DaemonCallDeps } from './daemon-call-deps.js';
|
|
3
|
+
export interface DaemonCommandDeps extends DaemonCallDeps {
|
|
41
4
|
}
|
|
42
5
|
/** `daemon status` */
|
|
43
6
|
export declare function daemonStatusCommand({ args, resolveBaseUrl }: {
|
package/dist/daemon-command.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* @module daemon-command
|
|
3
3
|
*
|
|
4
4
|
* `daemon status` / `daemon stop` — concrete commands over `@jini-ai/http-kit`'s
|
|
5
|
-
* `daemonStatusRoute`/`daemonShutdownRoute` (`packages/
|
|
6
|
-
* `packages/cli/
|
|
5
|
+
* `daemonStatusRoute`/`daemonShutdownRoute` (`packages/daemon/src/http/daemon-status.ts`).
|
|
6
|
+
* `070311a07^:packages/cli/source-map.md`'s original UNCLEAR verdict on these two
|
|
7
7
|
* blocked on `@jini-ai/http-kit` being a stub with no `/status`/`/shutdown` route to
|
|
8
8
|
* call; that blocker no longer holds (both routes exist and are tested), and
|
|
9
9
|
* `run-command.ts` is now a real, established "first concrete command"
|
|
@@ -20,34 +20,12 @@
|
|
|
20
20
|
import { exitWithStructuredError } from './errors.js';
|
|
21
21
|
import { getJsonFromDaemon, postJsonToDaemon } from './http.js';
|
|
22
22
|
import { renderUsage } from './usage.js';
|
|
23
|
-
|
|
24
|
-
process.stdout.write(text);
|
|
25
|
-
}
|
|
26
|
-
function defaultWriteErr({ text }) {
|
|
27
|
-
process.stderr.write(text);
|
|
28
|
-
}
|
|
23
|
+
import { defaultWrite, errorOptions, transportOptions } from './daemon-call-deps.js';
|
|
29
24
|
const DAEMON_STATUS_USAGE = renderUsage({ usage: ['daemon status'] }, { description: 'Reports the running daemon\'s version/host/port/dataDir/shutdown state.' });
|
|
30
25
|
const DAEMON_STOP_USAGE = renderUsage({ usage: ['daemon stop'] }, { description: 'Schedules a graceful daemon shutdown. Responds once the shutdown is scheduled, not once the process has actually exited.' });
|
|
31
26
|
const DAEMON_USAGE = renderUsage({ usage: ['daemon <status|stop> ...'] }, { description: 'Inspect or control a running Jini daemon over HTTP.' });
|
|
32
|
-
/** Builds `{write, exit, exitCodes?}` for `errors.ts`'s structured-error helpers, never assigning `exitCodes` when unset (required under `exactOptionalPropertyTypes`). */
|
|
33
|
-
function errorOptions(deps) {
|
|
34
|
-
return {
|
|
35
|
-
write: deps.writeErr ?? defaultWriteErr,
|
|
36
|
-
exit: deps.exit ?? (({ code }) => process.exit(code)),
|
|
37
|
-
...(deps.exitCodes !== undefined ? { exitCodes: deps.exitCodes } : {}),
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
/** Builds the transport-call options object for `postJsonToDaemon`/`getJsonFromDaemon`, only ever including a key when its value is actually set. */
|
|
41
|
-
function transportOptions(deps) {
|
|
42
|
-
return {
|
|
43
|
-
...(deps.fetchImpl !== undefined ? { fetchImpl: deps.fetchImpl } : {}),
|
|
44
|
-
...(deps.writeErr !== undefined ? { write: deps.writeErr } : {}),
|
|
45
|
-
...(deps.exit !== undefined ? { exit: deps.exit } : {}),
|
|
46
|
-
...(deps.exitCodes !== undefined ? { exitCodes: deps.exitCodes } : {}),
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
27
|
function invalidFlag(deps, message) {
|
|
50
|
-
return exitWithStructuredError({ code: 'invalid-flag', message }, errorOptions(deps));
|
|
28
|
+
return exitWithStructuredError({ code: 'invalid-flag', message }, errorOptions({ deps }));
|
|
51
29
|
}
|
|
52
30
|
function printJsonResult(deps, value) {
|
|
53
31
|
(deps.write ?? defaultWrite)({ text: `${JSON.stringify(value)}\n` });
|
|
@@ -60,7 +38,7 @@ export async function daemonStatusCommand({ args, resolveBaseUrl }, optionalArgs
|
|
|
60
38
|
return;
|
|
61
39
|
}
|
|
62
40
|
const baseUrl = await deps.resolveBaseUrl();
|
|
63
|
-
const result = await getJsonFromDaemon({ base: baseUrl, route: '/api/daemon/status' }, transportOptions(deps));
|
|
41
|
+
const result = await getJsonFromDaemon({ base: baseUrl, route: '/api/daemon/status' }, transportOptions({ deps }));
|
|
64
42
|
printJsonResult(deps, result);
|
|
65
43
|
}
|
|
66
44
|
/** `daemon stop` */
|
|
@@ -71,7 +49,7 @@ export async function daemonStopCommand({ args, resolveBaseUrl }, optionalArgs =
|
|
|
71
49
|
return;
|
|
72
50
|
}
|
|
73
51
|
const baseUrl = await deps.resolveBaseUrl();
|
|
74
|
-
const result = await postJsonToDaemon({ base: baseUrl, route: '/api/daemon/shutdown', body: {} }, transportOptions(deps));
|
|
52
|
+
const result = await postJsonToDaemon({ base: baseUrl, route: '/api/daemon/shutdown', body: {} }, transportOptions({ deps }));
|
|
75
53
|
printJsonResult(deps, result);
|
|
76
54
|
}
|
|
77
55
|
/** Registers `daemon` (dispatching `status`/`stop` on the first remaining token) against `registry`. */
|
package/dist/daemon-url.d.ts
CHANGED
|
@@ -13,8 +13,6 @@
|
|
|
13
13
|
export interface ResolveDaemonUrlOptions {
|
|
14
14
|
/** Value passed via a `--daemon-url`-shaped flag. Empty string is treated as unset. */
|
|
15
15
|
flagUrl?: string | null;
|
|
16
|
-
/** Defaults to `process.env`; inject for tests. */
|
|
17
|
-
env?: NodeJS.ProcessEnv;
|
|
18
16
|
/**
|
|
19
17
|
* Name of the environment variable to check (e.g. `'JINI_DAEMON_URL'`).
|
|
20
18
|
* Omit to skip the env step entirely — this package has no baked-in
|
|
@@ -53,7 +51,9 @@ export interface ResolveDaemonUrlOptions {
|
|
|
53
51
|
* `http://127.0.0.1:0`-style fallback would be worse than a clear error,
|
|
54
52
|
* and this package has no locked default port to fall back to on its own.
|
|
55
53
|
*/
|
|
56
|
-
export declare function resolveDaemonUrl(
|
|
54
|
+
export declare function resolveDaemonUrl(required: {
|
|
55
|
+
env: NodeJS.ProcessEnv;
|
|
56
|
+
}, options?: ResolveDaemonUrlOptions): Promise<string>;
|
|
57
57
|
/**
|
|
58
58
|
* Return `url` with any embedded userinfo (`user:pass@host`) stripped, safe to include in a
|
|
59
59
|
* printed error message, log line, or structured-error envelope. Per SEC-RB-009
|
package/dist/daemon-url.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isLoopbackHostname } from '@jini-ai/
|
|
1
|
+
import { isLoopbackHostname } from '@jini-ai/core/net';
|
|
2
2
|
/**
|
|
3
3
|
* Resolve a daemon HTTP base URL for a CLI client command.
|
|
4
4
|
*
|
|
@@ -8,8 +8,8 @@ import { isLoopbackHostname } from '@jini-ai/platform/net';
|
|
|
8
8
|
* `http://127.0.0.1:0`-style fallback would be worse than a clear error,
|
|
9
9
|
* and this package has no locked default port to fall back to on its own.
|
|
10
10
|
*/
|
|
11
|
-
export async function resolveDaemonUrl(
|
|
12
|
-
const env =
|
|
11
|
+
export async function resolveDaemonUrl(required, options = {}) {
|
|
12
|
+
const { env } = required;
|
|
13
13
|
// `??` short-circuits, so discover() is only probed when flag and env both came up empty.
|
|
14
14
|
// defaultUrl is taken as-is (even `''`): only `undefined` skips it.
|
|
15
15
|
const url = nonEmpty(options.flagUrl ?? null) ??
|
package/dist/flags.js
CHANGED
|
@@ -85,13 +85,16 @@ export function positionalArgs({ argv }, opts = {}) {
|
|
|
85
85
|
out.push(a);
|
|
86
86
|
}
|
|
87
87
|
else {
|
|
88
|
-
|
|
89
|
-
if (inlineValue === undefined && stringFlags.has(key))
|
|
88
|
+
if (positionalFlagConsumesNext(a, stringFlags))
|
|
90
89
|
i++;
|
|
91
90
|
}
|
|
92
91
|
}
|
|
93
92
|
return out;
|
|
94
93
|
}
|
|
94
|
+
function positionalFlagConsumesNext(token, stringFlags) {
|
|
95
|
+
const { key, inlineValue } = splitFlagToken({ token });
|
|
96
|
+
return inlineValue === undefined && stringFlags.has(key);
|
|
97
|
+
}
|
|
95
98
|
const NUMERIC_LITERAL_RE = /^-?\d+(\.\d+)?$/;
|
|
96
99
|
/**
|
|
97
100
|
* Coerce a raw `--flag <value>` string into its likely native type:
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export * from './daemon-url.js';
|
|
|
13
13
|
export * from './errors.js';
|
|
14
14
|
export * from './http.js';
|
|
15
15
|
export * from './prompt.js';
|
|
16
|
+
export * from './quiet-line.js';
|
|
17
|
+
export * from './stdin-line.js';
|
|
16
18
|
export * from './redact.js';
|
|
17
19
|
export * from './usage.js';
|
|
18
20
|
export * from './command-registry.js';
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,8 @@ export * from './daemon-url.js';
|
|
|
13
13
|
export * from './errors.js';
|
|
14
14
|
export * from './http.js';
|
|
15
15
|
export * from './prompt.js';
|
|
16
|
+
export * from './quiet-line.js';
|
|
17
|
+
export * from './stdin-line.js';
|
|
16
18
|
export * from './redact.js';
|
|
17
19
|
export * from './usage.js';
|
|
18
20
|
export * from './command-registry.js';
|
|
@@ -6,7 +6,7 @@ export type LocalDaemonDiscoveryOptions = {
|
|
|
6
6
|
dataDir: string;
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
|
-
* Build a `resolveDaemonUrl({}, { discover })`-compatible probe backed by a local, on-disk daemon
|
|
9
|
+
* Build a `resolveDaemonUrl({ env }, { discover })`-compatible probe backed by a local, on-disk daemon
|
|
10
10
|
* registry record: reads the record at the resolved registry path, confirms the recording
|
|
11
11
|
* process's pid is still alive (a stale record left behind by a daemon that crashed rather than
|
|
12
12
|
* shut down cleanly is never trusted — see `readLiveDaemonRegistryRecord`), and returns its
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* `discoveryFile` config, backed by `@jini-ai/sidecar`'s `daemon-registry.ts`); this module is the
|
|
9
9
|
* matching CLI-side reader: `createLocalDaemonDiscovery(...)` builds a probe over that same
|
|
10
10
|
* on-disk record, verified live (not just present — see `readLiveDaemonRegistryRecord`'s own
|
|
11
|
-
* doc), that plugs directly into `resolveDaemonUrl({}, { discover })`.
|
|
11
|
+
* doc), that plugs directly into `resolveDaemonUrl({ env }, { discover })`.
|
|
12
12
|
*
|
|
13
13
|
* Deliberately not wired to a hardcoded default `dataDir`: exactly like `resolveDaemonUrl` itself
|
|
14
14
|
* has no baked-in env var name or default URL, this package has no opinion on where a given
|
|
@@ -30,7 +30,7 @@ function resolveRegistryPathFromOptions(options) {
|
|
|
30
30
|
throw new Error('createLocalDaemonDiscovery requires either dataDir or registryPath');
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
|
-
* Build a `resolveDaemonUrl({}, { discover })`-compatible probe backed by a local, on-disk daemon
|
|
33
|
+
* Build a `resolveDaemonUrl({ env }, { discover })`-compatible probe backed by a local, on-disk daemon
|
|
34
34
|
* registry record: reads the record at the resolved registry path, confirms the recording
|
|
35
35
|
* process's pid is still alive (a stale record left behind by a daemon that crashed rather than
|
|
36
36
|
* shut down cleanly is never trusted — see `readLiveDaemonRegistryRecord`), and returns its
|
package/dist/main.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* other module in this package is a library building block — `run-command.ts`,
|
|
7
7
|
* `daemon-command.ts`, and `version-command.ts` each export a `register*Commands(registry,
|
|
8
8
|
* deps)` function ready for a pack to call, but until this file, nothing actually parsed
|
|
9
|
-
* `process.argv` and called them: `packages/cli/
|
|
9
|
+
* `process.argv` and called them: `070311a07^:packages/cli/source-map.md`'s "Not built" note on
|
|
10
10
|
* `run-command.ts`'s original addition said as much — "no wiring of this file's commands into
|
|
11
11
|
* an actual bootable CLI entrypoint." This closes that gap.
|
|
12
12
|
*
|
|
@@ -78,18 +78,13 @@ import { existsSync, realpathSync } from 'node:fs';
|
|
|
78
78
|
import { fileURLToPath } from 'node:url';
|
|
79
79
|
import { CommandRegistry } from './command-registry.js';
|
|
80
80
|
import { registerDaemonCommands } from './daemon-command.js';
|
|
81
|
+
import { defaultWrite, defaultWriteErr } from './daemon-call-deps.js';
|
|
81
82
|
import { resolveDaemonUrl } from './daemon-url.js';
|
|
82
83
|
import { exitWithStructuredError } from './errors.js';
|
|
83
84
|
import { createLocalDaemonDiscovery } from './local-daemon-discovery.js';
|
|
84
85
|
import { registerRunCommands } from './run-command.js';
|
|
85
86
|
import { renderUsage } from './usage.js';
|
|
86
87
|
import { registerVersionCommand } from './version-command.js';
|
|
87
|
-
function defaultWrite({ text }) {
|
|
88
|
-
process.stdout.write(text);
|
|
89
|
-
}
|
|
90
|
-
function defaultWriteErr({ text }) {
|
|
91
|
-
process.stderr.write(text);
|
|
92
|
-
}
|
|
93
88
|
function defaultExit({ code }) {
|
|
94
89
|
return process.exit(code);
|
|
95
90
|
}
|
|
@@ -163,9 +158,8 @@ function buildResolveBaseUrl(globals, env, warn) {
|
|
|
163
158
|
discover = createLocalDaemonDiscovery({ dataDir });
|
|
164
159
|
else
|
|
165
160
|
discover = undefined;
|
|
166
|
-
return () => resolveDaemonUrl({}, {
|
|
161
|
+
return () => resolveDaemonUrl({ env }, {
|
|
167
162
|
flagUrl: daemonUrl ?? null,
|
|
168
|
-
env,
|
|
169
163
|
envVarName: DAEMON_URL_ENV_VAR,
|
|
170
164
|
...(discover !== undefined ? { discover } : {}),
|
|
171
165
|
warn,
|
package/dist/prompt.d.ts
CHANGED
|
@@ -1,43 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module prompt
|
|
3
|
-
*
|
|
4
|
-
* Long-form text intake shared across CLI domains: two sibling conventions
|
|
5
|
-
* for reading a large piece of text from an inline flag, a `--*-file <path>`
|
|
6
|
-
* flag, or stdin (`-`).
|
|
7
|
-
*
|
|
8
|
-
* `readPromptFromFlags` is the `--prompt <text>` / `--prompt-file <path>` /
|
|
9
|
-
* `--prompt-file -` convention, ported from OD's `apps/daemon/src/cli.ts`
|
|
10
|
-
* `readPromptFromFlags` (see `archived provenance ledger`). This exact pattern recurred
|
|
11
|
-
* verbatim across many of OD's product commands (`brand create`, `run
|
|
12
|
-
* start`, `files version-create`, `automation source ingest`, …) with zero
|
|
13
|
-
* product nouns in the reading logic itself, which is what makes it a
|
|
14
|
-
* genuine reusable primitive rather than a one-off helper worth leaving in
|
|
15
|
-
* each caller.
|
|
16
|
-
*
|
|
17
|
-
* `readBodyFromFlags` is the sibling `--body`/`--body-file` convention,
|
|
18
|
-
* ported from the `cli-capability-barrels` branch's `cli/core/io.ts`
|
|
19
|
-
* `readMemoryBodyFromFlags` (see `archived provenance ledger`'s "Barrel branch
|
|
20
|
-
* reconciliation" section). Despite the origin name, it has no memory-domain
|
|
21
|
-
* coupling — that module's own docblock confirms it is reused verbatim by
|
|
22
|
-
* both the memory and automation domains — so it is ported here under a
|
|
23
|
-
* de-branded name alongside its prompt sibling.
|
|
24
|
-
*
|
|
25
|
-
* Per CR-004/SEC-RB-009
|
|
26
|
-
* (`ADS-memory/reports/code-review/CR-remaining-backend-audit-2026-07-21.md`,
|
|
27
|
-
* `ADS-memory/reports/security/SEC-remaining-backend-audit-2026-07-21.md`),
|
|
28
|
-
* the default file/stdin readers below cap how many bytes they will read
|
|
29
|
-
* (rejecting past the cap rather than truncating silently or reading
|
|
30
|
-
* unbounded input into memory) and accept an optional `AbortSignal` so a
|
|
31
|
-
* caller can cancel an in-progress read. Both knobs only apply to the
|
|
32
|
-
* default `readFile`/`readStdin` implementations — they have no effect if a
|
|
33
|
-
* caller injects their own.
|
|
34
|
-
*/
|
|
35
1
|
/** Thrown by the default readers when a file or stdin stream exceeds its configured byte cap. */
|
|
36
2
|
export declare class PayloadTooLargeError extends Error {
|
|
37
3
|
constructor({ message }: {
|
|
38
4
|
message: string;
|
|
39
5
|
});
|
|
40
6
|
}
|
|
7
|
+
/** Default cap for the default file/stdin readers: generous for a prompt/body payload, small enough to bound worst-case memory. */
|
|
8
|
+
export declare const DEFAULT_MAX_READ_BYTES: number;
|
|
41
9
|
export interface PromptFlags {
|
|
42
10
|
prompt?: string;
|
|
43
11
|
'prompt-file'?: string;
|
|
@@ -62,6 +30,13 @@ export interface ReadPromptFromFlagsOptions {
|
|
|
62
30
|
export declare function readPromptFromFlags({ flags }: {
|
|
63
31
|
flags: PromptFlags;
|
|
64
32
|
}, options?: ReadPromptFromFlagsOptions): Promise<string | null>;
|
|
33
|
+
/** All of `input` as UTF-8, bounded to 10 MiB by default; rejects with PayloadTooLargeError past the cap or with the cancellation reason. */
|
|
34
|
+
export declare function readStreamText(required: {
|
|
35
|
+
input: NodeJS.ReadableStream;
|
|
36
|
+
}, optional?: {
|
|
37
|
+
maxBytes?: number;
|
|
38
|
+
signal?: AbortSignal;
|
|
39
|
+
}): Promise<string>;
|
|
65
40
|
export interface BodyFlags {
|
|
66
41
|
body?: string;
|
|
67
42
|
'body-file'?: string;
|
package/dist/prompt.js
CHANGED
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
* default `readFile`/`readStdin` implementations — they have no effect if a
|
|
33
33
|
* caller injects their own.
|
|
34
34
|
*/
|
|
35
|
+
import { createReadStream } from 'node:fs';
|
|
35
36
|
/** Thrown by the default readers when a file or stdin stream exceeds its configured byte cap. */
|
|
36
37
|
export class PayloadTooLargeError extends Error {
|
|
37
38
|
constructor({ message }) {
|
|
@@ -40,7 +41,7 @@ export class PayloadTooLargeError extends Error {
|
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
/** Default cap for the default file/stdin readers: generous for a prompt/body payload, small enough to bound worst-case memory. */
|
|
43
|
-
const DEFAULT_MAX_READ_BYTES = 10 * 1024 * 1024;
|
|
44
|
+
export const DEFAULT_MAX_READ_BYTES = 10 * 1024 * 1024;
|
|
44
45
|
/**
|
|
45
46
|
* Resolve prompt text from `--prompt`, or `--prompt-file <path>` /
|
|
46
47
|
* `--prompt-file -` (stdin). Returns `null` when neither flag is set so the
|
|
@@ -54,7 +55,7 @@ export async function readPromptFromFlags({ flags }, options = {}) {
|
|
|
54
55
|
if (typeof promptFile !== 'string' || promptFile.length === 0) {
|
|
55
56
|
return null;
|
|
56
57
|
}
|
|
57
|
-
return await readFlagSource({ source: promptFile
|
|
58
|
+
return await readFlagSource({ source: promptFile }, options);
|
|
58
59
|
}
|
|
59
60
|
/**
|
|
60
61
|
* Reads a `--*-file` flag's value: `-` means stdin (the injected `readStdin`, else
|
|
@@ -64,14 +65,14 @@ export async function readPromptFromFlags({ flags }, options = {}) {
|
|
|
64
65
|
async function readFlagSource({ source, readDefaultStdin }, options) {
|
|
65
66
|
const readLimits = { maxBytes: options.maxBytes ?? DEFAULT_MAX_READ_BYTES, ...(options.signal !== undefined ? { signal: options.signal } : {}) };
|
|
66
67
|
if (source === '-') {
|
|
67
|
-
const
|
|
68
|
+
const readDefault = readDefaultStdin ?? ((limits) => defaultReadStream({ input: process.stdin }, limits));
|
|
69
|
+
const readStdin = options.readStdin ?? (() => readDefault(readLimits));
|
|
68
70
|
return await readStdin();
|
|
69
71
|
}
|
|
70
72
|
const readFile = options.readFile ?? (({ path }) => defaultReadFile(path, readLimits));
|
|
71
73
|
return await readFile({ path: source });
|
|
72
74
|
}
|
|
73
75
|
async function defaultReadFile(path, limits) {
|
|
74
|
-
const { createReadStream } = await import('node:fs');
|
|
75
76
|
return await new Promise((resolve, reject) => {
|
|
76
77
|
const stream = createReadStream(path, limits.signal !== undefined ? { signal: limits.signal } : {});
|
|
77
78
|
const chunks = [];
|
|
@@ -115,7 +116,14 @@ async function defaultReadFile(path, limits) {
|
|
|
115
116
|
stream.on('end', () => finish(() => resolve(Buffer.concat(chunks).toString('utf8'))));
|
|
116
117
|
});
|
|
117
118
|
}
|
|
118
|
-
|
|
119
|
+
/** All of `input` as UTF-8, bounded to 10 MiB by default; rejects with PayloadTooLargeError past the cap or with the cancellation reason. */
|
|
120
|
+
export function readStreamText(required, optional = {}) {
|
|
121
|
+
return defaultReadStream(required, {
|
|
122
|
+
maxBytes: optional.maxBytes ?? DEFAULT_MAX_READ_BYTES,
|
|
123
|
+
...(optional.signal !== undefined ? { signal: optional.signal } : {}),
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
async function defaultReadStream({ input }, limits) {
|
|
119
127
|
return await new Promise((resolve, reject) => {
|
|
120
128
|
if (limits.signal?.aborted === true) {
|
|
121
129
|
reject(limits.signal.reason ?? new Error('stdin read aborted'));
|
|
@@ -123,21 +131,21 @@ async function defaultReadStdin(limits) {
|
|
|
123
131
|
}
|
|
124
132
|
let buffer = '';
|
|
125
133
|
let total = 0;
|
|
126
|
-
|
|
134
|
+
input.setEncoding('utf8');
|
|
127
135
|
const cleanup = () => {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
136
|
+
input.off('data', onData);
|
|
137
|
+
input.off('end', onEnd);
|
|
138
|
+
input.off('error', onError);
|
|
131
139
|
limits.signal?.removeEventListener('abort', onAbort);
|
|
132
140
|
};
|
|
133
|
-
const
|
|
134
|
-
|
|
141
|
+
const pauseInput = () => {
|
|
142
|
+
input.pause?.();
|
|
135
143
|
};
|
|
136
144
|
const onData = (chunk) => {
|
|
137
145
|
total += Buffer.byteLength(chunk, 'utf8');
|
|
138
146
|
if (total > limits.maxBytes) {
|
|
139
147
|
cleanup();
|
|
140
|
-
|
|
148
|
+
pauseInput();
|
|
141
149
|
reject(new PayloadTooLargeError({ message: `stdin exceeded the ${limits.maxBytes}-byte limit` }));
|
|
142
150
|
return;
|
|
143
151
|
}
|
|
@@ -147,12 +155,12 @@ async function defaultReadStdin(limits) {
|
|
|
147
155
|
const onError = (err) => { cleanup(); reject(err); };
|
|
148
156
|
const onAbort = () => {
|
|
149
157
|
cleanup();
|
|
150
|
-
|
|
158
|
+
pauseInput();
|
|
151
159
|
reject(limits.signal?.reason ?? new Error('stdin read aborted'));
|
|
152
160
|
};
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
161
|
+
input.on('data', onData);
|
|
162
|
+
input.on('end', onEnd);
|
|
163
|
+
input.on('error', onError);
|
|
156
164
|
limits.signal?.addEventListener('abort', onAbort, { once: true });
|
|
157
165
|
});
|
|
158
166
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One line from `input`: piped input is read to EOF under the byte cap, then its
|
|
3
|
+
* first CRLF/LF line is returned. A terminal receives `prompt`, reads without
|
|
4
|
+
* echo, and closes the prompt with a newline on `output`; EOF resolves empty.
|
|
5
|
+
* @throws {PayloadTooLargeError} when piped input exceeds maxBytes (default 10 MiB).
|
|
6
|
+
*/
|
|
7
|
+
export declare function readQuietLine({ input, output, prompt }: {
|
|
8
|
+
input: NodeJS.ReadableStream & {
|
|
9
|
+
isTTY?: boolean;
|
|
10
|
+
};
|
|
11
|
+
output: Pick<NodeJS.WritableStream, 'write'>;
|
|
12
|
+
prompt: string;
|
|
13
|
+
}, optional?: {
|
|
14
|
+
maxBytes?: number;
|
|
15
|
+
}): Promise<string>;
|
|
16
|
+
//# sourceMappingURL=quiet-line.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createInterface } from 'node:readline';
|
|
2
|
+
import { Writable } from 'node:stream';
|
|
3
|
+
import { readStreamText } from './prompt.js';
|
|
4
|
+
/**
|
|
5
|
+
* One line from `input`: piped input is read to EOF under the byte cap, then its
|
|
6
|
+
* first CRLF/LF line is returned. A terminal receives `prompt`, reads without
|
|
7
|
+
* echo, and closes the prompt with a newline on `output`; EOF resolves empty.
|
|
8
|
+
* @throws {PayloadTooLargeError} when piped input exceeds maxBytes (default 10 MiB).
|
|
9
|
+
*/
|
|
10
|
+
export async function readQuietLine({ input, output, prompt }, optional = {}) {
|
|
11
|
+
if (!input.isTTY) {
|
|
12
|
+
const text = await readStreamText({ input }, optional);
|
|
13
|
+
// Only the first line is returned; anything after it is ignored.
|
|
14
|
+
const lineEnd = text.search(/\r?\n/);
|
|
15
|
+
return lineEnd === -1 ? text : text.slice(0, lineEnd);
|
|
16
|
+
}
|
|
17
|
+
output.write(prompt);
|
|
18
|
+
const muted = new Writable({ write: (_chunk, _encoding, done) => done() });
|
|
19
|
+
const rl = createInterface({ input, output: muted, terminal: true });
|
|
20
|
+
try {
|
|
21
|
+
return await new Promise((resolve) => {
|
|
22
|
+
rl.once('line', resolve);
|
|
23
|
+
rl.once('close', () => resolve(''));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
finally {
|
|
27
|
+
rl.close();
|
|
28
|
+
output.write('\n');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=quiet-line.js.map
|
package/dist/run-command.d.ts
CHANGED
|
@@ -1,24 +1,6 @@
|
|
|
1
|
-
import { type ExitCodeTable } from './errors.js';
|
|
2
1
|
import type { CommandRegistry } from './command-registry.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
resolveBaseUrl: () => Promise<string> | string;
|
|
6
|
-
/** Defaults to `process.stdout.write`; inject for tests. Used for successful command output. */
|
|
7
|
-
write?: (requiredArgs: {
|
|
8
|
-
text: string;
|
|
9
|
-
}) => void;
|
|
10
|
-
/** Defaults to `process.stderr.write`; inject for tests. Used for usage/validation errors. */
|
|
11
|
-
writeErr?: (requiredArgs: {
|
|
12
|
-
text: string;
|
|
13
|
-
}) => void;
|
|
14
|
-
/** Defaults to the global `fetch`; inject for tests. */
|
|
15
|
-
fetchImpl?: typeof fetch;
|
|
16
|
-
/** Defaults to `process.exit`; inject for tests (must not return). */
|
|
17
|
-
exit?: (requiredArgs: {
|
|
18
|
-
code: number;
|
|
19
|
-
}) => never;
|
|
20
|
-
/** Extra/overriding `code -> exitCode` entries layered on the package default table. */
|
|
21
|
-
exitCodes?: ExitCodeTable;
|
|
2
|
+
import { type DaemonCallDeps } from './daemon-call-deps.js';
|
|
3
|
+
export interface RunCommandDeps extends DaemonCallDeps {
|
|
22
4
|
}
|
|
23
5
|
/** `run start --context-ref <ref> [--agent-id <id>] [--idempotency-key <key>]` */
|
|
24
6
|
export declare function runStartCommand({ args, resolveBaseUrl: resolveBaseUrlPort }: {
|
package/dist/run-command.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* first concrete commands registered against this package's
|
|
6
6
|
* `CommandRegistry` (`command-registry.ts`'s own docblock notes none existed
|
|
7
7
|
* yet because no HTTP-client-mode pack had landed to call). Built directly
|
|
8
|
-
* against `@jini-ai/http-kit`'s real run transport (`packages/
|
|
8
|
+
* against `@jini-ai/http-kit`'s real run transport (`packages/daemon/src/http/runs.ts`:
|
|
9
9
|
* `POST /api/runs`, `GET /api/runs`, `GET /api/runs/:runId`,
|
|
10
10
|
* `POST /api/runs/:runId/cancel`, `GET /api/runs/:runId/events` SSE) — a
|
|
11
11
|
* thin HTTP-transport-mode CLI over the kernel's own `Run` noun, with no
|
|
@@ -25,12 +25,7 @@ import { exitWithStructuredError, structuredHttpFailure } from './errors.js';
|
|
|
25
25
|
import { getJsonFromDaemon, postJsonToDaemon } from './http.js';
|
|
26
26
|
import { sanitizeUntrustedText, stripControlSequences } from '@jini-ai/core/text';
|
|
27
27
|
import { renderUsage } from './usage.js';
|
|
28
|
-
|
|
29
|
-
process.stdout.write(text);
|
|
30
|
-
}
|
|
31
|
-
function defaultWriteErr({ text }) {
|
|
32
|
-
process.stderr.write(text);
|
|
33
|
-
}
|
|
28
|
+
import { defaultWrite, errorOptions, transportOptions } from './daemon-call-deps.js';
|
|
34
29
|
const RUN_START_USAGE = renderUsage({ usage: ['run start --context-ref <ref> [--agent-id <id>] [--idempotency-key <key>]'] }, { description: 'Starts a new run for the given contextRef.', options: [
|
|
35
30
|
{ flag: '--context-ref', description: 'Opaque caller-supplied identity the run belongs to (required).' },
|
|
36
31
|
{ flag: '--agent-id', description: 'Which registered agent should drive this run.' },
|
|
@@ -41,28 +36,11 @@ const RUN_GET_USAGE = renderUsage({ usage: ['run get <runId>'] }, { description:
|
|
|
41
36
|
const RUN_CANCEL_USAGE = renderUsage({ usage: ['run cancel <runId> [--reason <text>]'] }, { description: 'Requests cancellation of an in-progress run. A no-op on an already-terminal run.', options: [{ flag: '--reason', description: 'Optional human-readable cancellation reason.' }] });
|
|
42
37
|
const RUN_WATCH_USAGE = renderUsage({ usage: ['run watch <runId> [--after-cursor <cursor>]'] }, { description: 'Streams a run\'s protocol events as one NDJSON line per event on stdout until a terminal event arrives.', options: [{ flag: '--after-cursor', description: 'Resume streaming after this event cursor (reconnect support).' }] });
|
|
43
38
|
const RUN_USAGE = renderUsage({ usage: ['run <start|list|get|cancel|watch> ...'] }, { description: 'Manage runs against a Jini daemon over HTTP.' });
|
|
44
|
-
/** Builds `{write, exit, exitCodes?}` for `errors.ts`'s structured-error helpers, never assigning `exitCodes` when unset (required under `exactOptionalPropertyTypes`). */
|
|
45
|
-
function errorOptions(deps) {
|
|
46
|
-
return {
|
|
47
|
-
write: deps.writeErr ?? defaultWriteErr,
|
|
48
|
-
exit: deps.exit ?? (({ code }) => process.exit(code)),
|
|
49
|
-
...(deps.exitCodes !== undefined ? { exitCodes: deps.exitCodes } : {}),
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
/** Builds the transport-call options object for `postJsonToDaemon`/`getJsonFromDaemon`, only ever including a key when its value is actually set. */
|
|
53
|
-
function transportOptions(deps) {
|
|
54
|
-
return {
|
|
55
|
-
...(deps.fetchImpl !== undefined ? { fetchImpl: deps.fetchImpl } : {}),
|
|
56
|
-
...(deps.writeErr !== undefined ? { write: deps.writeErr } : {}),
|
|
57
|
-
...(deps.exit !== undefined ? { exit: deps.exit } : {}),
|
|
58
|
-
...(deps.exitCodes !== undefined ? { exitCodes: deps.exitCodes } : {}),
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
39
|
function missingInput(deps, message) {
|
|
62
|
-
return exitWithStructuredError({ code: 'missing-input', message }, errorOptions(deps));
|
|
40
|
+
return exitWithStructuredError({ code: 'missing-input', message }, errorOptions({ deps }));
|
|
63
41
|
}
|
|
64
42
|
function invalidFlag(deps, message) {
|
|
65
|
-
return exitWithStructuredError({ code: 'invalid-flag', message }, errorOptions(deps));
|
|
43
|
+
return exitWithStructuredError({ code: 'invalid-flag', message }, errorOptions({ deps }));
|
|
66
44
|
}
|
|
67
45
|
function printJsonResult(deps, value) {
|
|
68
46
|
(deps.write ?? defaultWrite)({ text: `${JSON.stringify(value)}\n` });
|
|
@@ -90,7 +68,7 @@ export async function runStartCommand({ args, resolveBaseUrl: resolveBaseUrlPort
|
|
|
90
68
|
if (typeof flags['idempotency-key'] === 'string')
|
|
91
69
|
body.idempotencyKey = flags['idempotency-key'];
|
|
92
70
|
const baseUrl = await deps.resolveBaseUrl();
|
|
93
|
-
const result = await postJsonToDaemon({ base: baseUrl, route: '/api/runs', body }, transportOptions(deps));
|
|
71
|
+
const result = await postJsonToDaemon({ base: baseUrl, route: '/api/runs', body }, transportOptions({ deps }));
|
|
94
72
|
printJsonResult(deps, result);
|
|
95
73
|
}
|
|
96
74
|
/** `run list [--context-ref <ref>]` */
|
|
@@ -104,7 +82,7 @@ export async function runListCommand({ args, resolveBaseUrl: resolveBaseUrlPort
|
|
|
104
82
|
? `/api/runs?contextRef=${encodeURIComponent(contextRef)}`
|
|
105
83
|
: '/api/runs';
|
|
106
84
|
const baseUrl = await deps.resolveBaseUrl();
|
|
107
|
-
const result = await getJsonFromDaemon({ base: baseUrl, route }, transportOptions(deps));
|
|
85
|
+
const result = await getJsonFromDaemon({ base: baseUrl, route }, transportOptions({ deps }));
|
|
108
86
|
printJsonResult(deps, result);
|
|
109
87
|
}
|
|
110
88
|
/** `run get <runId>` */
|
|
@@ -117,7 +95,7 @@ export async function runGetCommand({ args, resolveBaseUrl: resolveBaseUrlPort }
|
|
|
117
95
|
missingInput(deps, 'runId is required: run get <runId>');
|
|
118
96
|
}
|
|
119
97
|
const baseUrl = await deps.resolveBaseUrl();
|
|
120
|
-
const result = await getJsonFromDaemon({ base: baseUrl, route: `/api/runs/${encodeURIComponent(runId)}` }, transportOptions(deps));
|
|
98
|
+
const result = await getJsonFromDaemon({ base: baseUrl, route: `/api/runs/${encodeURIComponent(runId)}` }, transportOptions({ deps }));
|
|
121
99
|
printJsonResult(deps, result);
|
|
122
100
|
}
|
|
123
101
|
/** `run cancel <runId> [--reason <text>]` */
|
|
@@ -134,7 +112,7 @@ export async function runCancelCommand({ args, resolveBaseUrl: resolveBaseUrlPor
|
|
|
134
112
|
if (typeof flags.reason === 'string')
|
|
135
113
|
body.reason = flags.reason;
|
|
136
114
|
const baseUrl = await deps.resolveBaseUrl();
|
|
137
|
-
const result = await postJsonToDaemon({ base: baseUrl, route: `/api/runs/${encodeURIComponent(runId)}/cancel`, body }, transportOptions(deps));
|
|
115
|
+
const result = await postJsonToDaemon({ base: baseUrl, route: `/api/runs/${encodeURIComponent(runId)}/cancel`, body }, transportOptions({ deps }));
|
|
138
116
|
printJsonResult(deps, result);
|
|
139
117
|
}
|
|
140
118
|
/** Cap on total buffered-but-not-yet-frame-terminated SSE text — a daemon that never sends a blank-line frame terminator must not grow this without bound (retains the historical 10 MiB-sized text cap; TextDecoder output is measured in UTF-16 units). */
|
|
@@ -190,7 +168,7 @@ export async function watchRunEvents({ baseUrl, runId, args }, deps = {}) {
|
|
|
190
168
|
const write = deps.write ?? defaultWrite;
|
|
191
169
|
const resp = await fetchImpl(`${baseUrl}/api/runs/${encodeURIComponent(runId)}/events`, { headers });
|
|
192
170
|
if (!resp.ok || resp.body === null) {
|
|
193
|
-
await structuredHttpFailure({ resp }, { fallbackCode: 'daemon-not-running', ...errorOptions(deps) });
|
|
171
|
+
await structuredHttpFailure({ resp }, { fallbackCode: 'daemon-not-running', ...errorOptions({ deps }) });
|
|
194
172
|
return;
|
|
195
173
|
}
|
|
196
174
|
try {
|
|
@@ -200,7 +178,7 @@ export async function watchRunEvents({ baseUrl, runId, args }, deps = {}) {
|
|
|
200
178
|
// A broken/hostile stream (e.g. the unbounded-buffer guard above) must exit through the same
|
|
201
179
|
// structured contract as every other failure here, not surface as an unhandled rejection.
|
|
202
180
|
const message = error instanceof Error ? error.message : String(error);
|
|
203
|
-
exitWithStructuredError({ code: 'daemon-not-running', message: sanitizeUntrustedText({ text: message }) }, errorOptions(deps));
|
|
181
|
+
exitWithStructuredError({ code: 'daemon-not-running', message: sanitizeUntrustedText({ text: message }) }, errorOptions({ deps }));
|
|
204
182
|
return;
|
|
205
183
|
}
|
|
206
184
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** What this reader needs of the stream. `unref` is absent when stdin is a file rather than a pipe. */
|
|
2
|
+
export type RequestLineStream = Pick<NodeJS.ReadableStream, 'on' | 'once'> & {
|
|
3
|
+
unref?: () => unknown;
|
|
4
|
+
};
|
|
5
|
+
export interface ReadStdinRequestLineOptions {
|
|
6
|
+
/** Longest accepted line in bytes, newline excluded. Default 16 KiB. */
|
|
7
|
+
maxBytes?: number;
|
|
8
|
+
/** The rejection when the line is over `maxBytes`. Default: a `PayloadTooLargeError`. */
|
|
9
|
+
tooLarge?: () => Error;
|
|
10
|
+
/** The abort reason set on `stop` when the stream ends after the line was read. */
|
|
11
|
+
stopped?: () => unknown;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The first line of `input`, then keeps watching: the stream ending after that line aborts `stop`.
|
|
15
|
+
* Input that ends with no newline is still a request, with nothing left to watch. Later bytes are dropped.
|
|
16
|
+
* `unref` lets the process exit once its work is done, with the stream still open.
|
|
17
|
+
* @throws {PayloadTooLargeError} (or the error `tooLarge` builds) when the line is over `maxBytes`.
|
|
18
|
+
* @complexity O(request bytes); holds at most one chunk past the cap.
|
|
19
|
+
*/
|
|
20
|
+
export declare function readStdinRequestLine({ input, stop }: {
|
|
21
|
+
input: RequestLineStream;
|
|
22
|
+
stop: AbortController;
|
|
23
|
+
}, optional?: ReadStdinRequestLineOptions): Promise<string>;
|
|
24
|
+
//# sourceMappingURL=stdin-line.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module stdin-line
|
|
3
|
+
*
|
|
4
|
+
* Reads a one-line request from a stream (normally stdin) and then keeps watching that stream.
|
|
5
|
+
* A secret sent this way (for example a link token) never becomes argv. A parent process that
|
|
6
|
+
* keeps the stream open after the line and closes it to cancel gets cancellation on every
|
|
7
|
+
* platform, and also when the parent crashes.
|
|
8
|
+
*/
|
|
9
|
+
import { PayloadTooLargeError } from './prompt.js';
|
|
10
|
+
const DEFAULT_MAX_BYTES = 16 * 1024;
|
|
11
|
+
/**
|
|
12
|
+
* The first line of `input`, then keeps watching: the stream ending after that line aborts `stop`.
|
|
13
|
+
* Input that ends with no newline is still a request, with nothing left to watch. Later bytes are dropped.
|
|
14
|
+
* `unref` lets the process exit once its work is done, with the stream still open.
|
|
15
|
+
* @throws {PayloadTooLargeError} (or the error `tooLarge` builds) when the line is over `maxBytes`.
|
|
16
|
+
* @complexity O(request bytes); holds at most one chunk past the cap.
|
|
17
|
+
*/
|
|
18
|
+
export function readStdinRequestLine({ input, stop }, optional = {}) {
|
|
19
|
+
const maxBytes = optional.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
20
|
+
const tooLarge = optional.tooLarge ?? (() => new PayloadTooLargeError({ message: 'The request line is too large.' }));
|
|
21
|
+
const stopped = optional.stopped ?? (() => new Error('The input ended, so the operation was stopped.'));
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
let received = Buffer.alloc(0), finishedReading = false, lineSeen = false;
|
|
24
|
+
input.on('data', (chunk) => {
|
|
25
|
+
if (finishedReading)
|
|
26
|
+
return;
|
|
27
|
+
received = Buffer.concat([received, Buffer.from(chunk)]);
|
|
28
|
+
const newline = received.indexOf(10);
|
|
29
|
+
if ((newline === -1 ? received.length : newline) > maxBytes) {
|
|
30
|
+
finishedReading = true;
|
|
31
|
+
reject(tooLarge());
|
|
32
|
+
}
|
|
33
|
+
else if (newline !== -1) {
|
|
34
|
+
finishedReading = lineSeen = true;
|
|
35
|
+
input.unref?.();
|
|
36
|
+
resolve(received.subarray(0, newline).toString('utf8'));
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
const ended = () => {
|
|
40
|
+
if (lineSeen)
|
|
41
|
+
stop.abort(stopped());
|
|
42
|
+
else
|
|
43
|
+
resolve(received.toString('utf8'));
|
|
44
|
+
};
|
|
45
|
+
input.once('end', ended);
|
|
46
|
+
input.once('close', ended);
|
|
47
|
+
input.once('error', ended);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=stdin-line.js.map
|
|
@@ -1,41 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module version-command
|
|
3
|
-
*
|
|
4
|
-
* `version` — prints just the running daemon's version string. Sourced from
|
|
5
|
-
* `GET /api/daemon/status`'s `version` field (`packages/http/src/daemon-status.ts`,
|
|
6
|
-
* `DaemonStatusResponse.version`) — the same route `daemon-command.ts`'s `daemon status`
|
|
7
|
-
* already calls. `packages/cli/archived provenance ledger`'s original UNCLEAR verdict on a standalone
|
|
8
|
-
* `version` command noted "@jini-ai/http-kit has no version route yet ... nothing to call"; that
|
|
9
|
-
* blocker never actually required a *separate* route — `daemonStatusRoute`'s response body
|
|
10
|
-
* already carries a `version` field, so no new HTTP route was added for this command. It just
|
|
11
|
-
* extracts and prints that one field instead of the full status envelope `daemon status` prints.
|
|
12
|
-
*
|
|
13
|
-
* Same DI/testing/`resolveBaseUrl` conventions as `daemon-command.ts`'s `daemon status`/`daemon
|
|
14
|
-
* stop` (this file duplicates rather than imports their small `errorOptions`/`transportOptions`
|
|
15
|
-
* helpers, matching that file's own precedent of each command module owning its own copy rather
|
|
16
|
-
* than sharing a not-otherwise-needed abstraction across files).
|
|
17
|
-
*/
|
|
18
|
-
import { type ExitCodeTable } from './errors.js';
|
|
19
1
|
import type { CommandRegistry } from './command-registry.js';
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
resolveBaseUrl: () => Promise<string> | string;
|
|
23
|
-
/** Defaults to `process.stdout.write`; inject for tests. Used for the printed version string. */
|
|
24
|
-
write?: (requiredArgs: {
|
|
25
|
-
text: string;
|
|
26
|
-
}) => void;
|
|
27
|
-
/** Defaults to `process.stderr.write`; inject for tests. Used for usage/validation errors. */
|
|
28
|
-
writeErr?: (requiredArgs: {
|
|
29
|
-
text: string;
|
|
30
|
-
}) => void;
|
|
31
|
-
/** Defaults to the global `fetch`; inject for tests. */
|
|
32
|
-
fetchImpl?: typeof fetch;
|
|
33
|
-
/** Defaults to `process.exit`; inject for tests (must not return). */
|
|
34
|
-
exit?: (requiredArgs: {
|
|
35
|
-
code: number;
|
|
36
|
-
}) => never;
|
|
37
|
-
/** Extra/overriding `code -> exitCode` entries layered on the package default table. */
|
|
38
|
-
exitCodes?: ExitCodeTable;
|
|
2
|
+
import { type DaemonCallDeps } from './daemon-call-deps.js';
|
|
3
|
+
export interface VersionCommandDeps extends DaemonCallDeps {
|
|
39
4
|
}
|
|
40
5
|
/** `version` */
|
|
41
6
|
export declare function versionCommand({ args, resolveBaseUrl }: {
|
package/dist/version-command.js
CHANGED
|
@@ -2,46 +2,22 @@
|
|
|
2
2
|
* @module version-command
|
|
3
3
|
*
|
|
4
4
|
* `version` — prints just the running daemon's version string. Sourced from
|
|
5
|
-
* `GET /api/daemon/status`'s `version` field (`packages/
|
|
5
|
+
* `GET /api/daemon/status`'s `version` field (`packages/daemon/src/http/daemon-status.ts`,
|
|
6
6
|
* `DaemonStatusResponse.version`) — the same route `daemon-command.ts`'s `daemon status`
|
|
7
|
-
* already calls. `packages/cli/
|
|
7
|
+
* already calls. `070311a07^:packages/cli/source-map.md`'s original UNCLEAR verdict on a standalone
|
|
8
8
|
* `version` command noted "@jini-ai/http-kit has no version route yet ... nothing to call"; that
|
|
9
9
|
* blocker never actually required a *separate* route — `daemonStatusRoute`'s response body
|
|
10
10
|
* already carries a `version` field, so no new HTTP route was added for this command. It just
|
|
11
11
|
* extracts and prints that one field instead of the full status envelope `daemon status` prints.
|
|
12
12
|
*
|
|
13
13
|
* Same DI/testing/`resolveBaseUrl` conventions as `daemon-command.ts`'s `daemon status`/`daemon
|
|
14
|
-
* stop
|
|
15
|
-
* helpers, matching that file's own precedent of each command module owning its own copy rather
|
|
16
|
-
* than sharing a not-otherwise-needed abstraction across files).
|
|
14
|
+
* stop`; this file shares `daemon-call-deps.ts` with the other daemon commands.
|
|
17
15
|
*/
|
|
18
16
|
import { exitWithStructuredError } from './errors.js';
|
|
19
17
|
import { getJsonFromDaemon } from './http.js';
|
|
20
18
|
import { renderUsage } from './usage.js';
|
|
21
|
-
|
|
22
|
-
process.stdout.write(text);
|
|
23
|
-
}
|
|
24
|
-
function defaultWriteErr({ text }) {
|
|
25
|
-
process.stderr.write(text);
|
|
26
|
-
}
|
|
19
|
+
import { defaultWrite, errorOptions, transportOptions } from './daemon-call-deps.js';
|
|
27
20
|
const VERSION_USAGE = renderUsage({ usage: ['version'] }, { description: 'Prints the running daemon\'s version string (nothing else — see "daemon status" for the full status envelope).' });
|
|
28
|
-
/** Builds `{write, exit, exitCodes?}` for `errors.ts`'s structured-error helpers, never assigning `exitCodes` when unset (required under `exactOptionalPropertyTypes`). */
|
|
29
|
-
function errorOptions(deps) {
|
|
30
|
-
return {
|
|
31
|
-
write: deps.writeErr ?? defaultWriteErr,
|
|
32
|
-
exit: deps.exit ?? (({ code }) => process.exit(code)),
|
|
33
|
-
...(deps.exitCodes !== undefined ? { exitCodes: deps.exitCodes } : {}),
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
/** Builds the transport-call options object for `getJsonFromDaemon`, only ever including a key when its value is actually set. */
|
|
37
|
-
function transportOptions(deps) {
|
|
38
|
-
return {
|
|
39
|
-
...(deps.fetchImpl !== undefined ? { fetchImpl: deps.fetchImpl } : {}),
|
|
40
|
-
...(deps.writeErr !== undefined ? { write: deps.writeErr } : {}),
|
|
41
|
-
...(deps.exit !== undefined ? { exit: deps.exit } : {}),
|
|
42
|
-
...(deps.exitCodes !== undefined ? { exitCodes: deps.exitCodes } : {}),
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
21
|
/**
|
|
46
22
|
* Extracts a non-empty `version` string out of `/api/daemon/status`'s parsed JSON body. A daemon
|
|
47
23
|
* that responds 2xx but omits (or mistypes) `version` is exactly as "not behaving like a Jini
|
|
@@ -55,7 +31,7 @@ function extractVersion(deps, body) {
|
|
|
55
31
|
if (typeof version === 'string' && version.length > 0)
|
|
56
32
|
return version;
|
|
57
33
|
}
|
|
58
|
-
return exitWithStructuredError({ code: 'daemon-not-running', message: '/api/daemon/status response did not include a version string' }, errorOptions(deps));
|
|
34
|
+
return exitWithStructuredError({ code: 'daemon-not-running', message: '/api/daemon/status response did not include a version string' }, errorOptions({ deps }));
|
|
59
35
|
}
|
|
60
36
|
/** `version` */
|
|
61
37
|
export async function versionCommand({ args, resolveBaseUrl }, optionalArgs = {}) {
|
|
@@ -65,7 +41,7 @@ export async function versionCommand({ args, resolveBaseUrl }, optionalArgs = {}
|
|
|
65
41
|
return;
|
|
66
42
|
}
|
|
67
43
|
const baseUrl = await deps.resolveBaseUrl();
|
|
68
|
-
const result = await getJsonFromDaemon({ base: baseUrl, route: '/api/daemon/status' }, transportOptions(deps));
|
|
44
|
+
const result = await getJsonFromDaemon({ base: baseUrl, route: '/api/daemon/status' }, transportOptions({ deps }));
|
|
69
45
|
const version = extractVersion(deps, result);
|
|
70
46
|
(deps.write ?? defaultWrite)({ text: `${version}\n` });
|
|
71
47
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jini-ai/cli",
|
|
3
|
-
"version": "0.7.2",
|
|
3
|
+
"version": "0.7.3-next.2",
|
|
4
4
|
"description": "CLI transport shell for driving a Jini daemon over HTTP: flag parsing, daemon-URL resolution, local daemon discovery, and a pluggable command registry.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"jini": {
|
|
12
12
|
"domain": "server",
|
|
13
|
-
"kind": "
|
|
13
|
+
"kind": "host-preset",
|
|
14
14
|
"entries": {
|
|
15
15
|
".": "node",
|
|
16
16
|
"./introspection": "universal"
|
|
@@ -54,14 +54,12 @@
|
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"commander": "^15.0.0",
|
|
57
|
-
"@jini-ai/
|
|
58
|
-
"@jini-ai/sidecar": "0.7.2"
|
|
59
|
-
"@jini-ai/core": "0.7.2"
|
|
57
|
+
"@jini-ai/core": "0.7.3-next.2",
|
|
58
|
+
"@jini-ai/sidecar": "0.7.3-next.2"
|
|
60
59
|
},
|
|
61
60
|
"dependencies": {
|
|
62
|
-
"@jini-ai/
|
|
63
|
-
"@jini-ai/
|
|
64
|
-
"@jini-ai/sidecar": "^0.7.2"
|
|
61
|
+
"@jini-ai/core": "^0.7.3-next.2",
|
|
62
|
+
"@jini-ai/sidecar": "^0.7.3-next.2"
|
|
65
63
|
},
|
|
66
64
|
"scripts": {
|
|
67
65
|
"build": "tsc -p tsconfig.json && chmod +x dist/main.js",
|