@eyeauras/cli-factory 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +36 -0
  3. package/dist/src/app-arguments.d.ts +59 -0
  4. package/dist/src/app-arguments.d.ts.map +1 -0
  5. package/dist/src/app-arguments.js +102 -0
  6. package/dist/src/app-arguments.js.map +1 -0
  7. package/dist/src/auth.d.ts +14 -0
  8. package/dist/src/auth.d.ts.map +1 -0
  9. package/dist/src/auth.js +184 -0
  10. package/dist/src/auth.js.map +1 -0
  11. package/dist/src/bounded-lines.d.ts +4 -0
  12. package/dist/src/bounded-lines.d.ts.map +1 -0
  13. package/dist/src/bounded-lines.js +68 -0
  14. package/dist/src/bounded-lines.js.map +1 -0
  15. package/dist/src/cli.d.ts +3 -0
  16. package/dist/src/cli.d.ts.map +1 -0
  17. package/dist/src/cli.js +364 -0
  18. package/dist/src/cli.js.map +1 -0
  19. package/dist/src/command-gate.d.ts +9 -0
  20. package/dist/src/command-gate.d.ts.map +1 -0
  21. package/dist/src/command-gate.js +64 -0
  22. package/dist/src/command-gate.js.map +1 -0
  23. package/dist/src/command-input.d.ts +14 -0
  24. package/dist/src/command-input.d.ts.map +1 -0
  25. package/dist/src/command-input.js +2 -0
  26. package/dist/src/command-input.js.map +1 -0
  27. package/dist/src/command.d.ts +5 -0
  28. package/dist/src/command.d.ts.map +1 -0
  29. package/dist/src/command.js +14 -0
  30. package/dist/src/command.js.map +1 -0
  31. package/dist/src/index.d.ts +21 -0
  32. package/dist/src/index.d.ts.map +1 -0
  33. package/dist/src/index.js +16 -0
  34. package/dist/src/index.js.map +1 -0
  35. package/dist/src/input-limits.d.ts +9 -0
  36. package/dist/src/input-limits.d.ts.map +1 -0
  37. package/dist/src/input-limits.js +21 -0
  38. package/dist/src/input-limits.js.map +1 -0
  39. package/dist/src/json-rpc.d.ts +8 -0
  40. package/dist/src/json-rpc.d.ts.map +1 -0
  41. package/dist/src/json-rpc.js +99 -0
  42. package/dist/src/json-rpc.js.map +1 -0
  43. package/dist/src/option-parsers.d.ts +10 -0
  44. package/dist/src/option-parsers.d.ts.map +1 -0
  45. package/dist/src/option-parsers.js +26 -0
  46. package/dist/src/option-parsers.js.map +1 -0
  47. package/dist/src/output.d.ts +4 -0
  48. package/dist/src/output.d.ts.map +1 -0
  49. package/dist/src/output.js +54 -0
  50. package/dist/src/output.js.map +1 -0
  51. package/dist/src/permissions.d.ts +11 -0
  52. package/dist/src/permissions.d.ts.map +1 -0
  53. package/dist/src/permissions.js +95 -0
  54. package/dist/src/permissions.js.map +1 -0
  55. package/dist/src/private-storage.d.ts +5 -0
  56. package/dist/src/private-storage.d.ts.map +1 -0
  57. package/dist/src/private-storage.js +68 -0
  58. package/dist/src/private-storage.js.map +1 -0
  59. package/dist/src/profile-commands.d.ts +29 -0
  60. package/dist/src/profile-commands.d.ts.map +1 -0
  61. package/dist/src/profile-commands.js +265 -0
  62. package/dist/src/profile-commands.js.map +1 -0
  63. package/dist/src/profile-file.d.ts +26 -0
  64. package/dist/src/profile-file.d.ts.map +1 -0
  65. package/dist/src/profile-file.js +325 -0
  66. package/dist/src/profile-file.js.map +1 -0
  67. package/dist/src/profile-store.d.ts +32 -0
  68. package/dist/src/profile-store.d.ts.map +1 -0
  69. package/dist/src/profile-store.js +223 -0
  70. package/dist/src/profile-store.js.map +1 -0
  71. package/dist/src/proof.d.ts +18 -0
  72. package/dist/src/proof.d.ts.map +1 -0
  73. package/dist/src/proof.js +98 -0
  74. package/dist/src/proof.js.map +1 -0
  75. package/dist/src/resources.d.ts +4 -0
  76. package/dist/src/resources.d.ts.map +1 -0
  77. package/dist/src/resources.js +17 -0
  78. package/dist/src/resources.js.map +1 -0
  79. package/dist/src/response-body.d.ts +12 -0
  80. package/dist/src/response-body.d.ts.map +1 -0
  81. package/dist/src/response-body.js +70 -0
  82. package/dist/src/response-body.js.map +1 -0
  83. package/dist/src/secret-store.d.ts +21 -0
  84. package/dist/src/secret-store.d.ts.map +1 -0
  85. package/dist/src/secret-store.js +73 -0
  86. package/dist/src/secret-store.js.map +1 -0
  87. package/dist/src/target-commands.d.ts +19 -0
  88. package/dist/src/target-commands.d.ts.map +1 -0
  89. package/dist/src/target-commands.js +17 -0
  90. package/dist/src/target-commands.js.map +1 -0
  91. package/dist/src/testing-contracts.d.ts +31 -0
  92. package/dist/src/testing-contracts.d.ts.map +1 -0
  93. package/dist/src/testing-contracts.js +72 -0
  94. package/dist/src/testing-contracts.js.map +1 -0
  95. package/dist/src/testing.d.ts +51 -0
  96. package/dist/src/testing.d.ts.map +1 -0
  97. package/dist/src/testing.js +126 -0
  98. package/dist/src/testing.js.map +1 -0
  99. package/dist/src/types.d.ts +174 -0
  100. package/dist/src/types.d.ts.map +1 -0
  101. package/dist/src/types.js +2 -0
  102. package/dist/src/types.js.map +1 -0
  103. package/package.json +51 -0
@@ -0,0 +1,8 @@
1
+ import type { Readable, Writable } from "node:stream";
2
+ export declare function runJsonRpc(options: {
3
+ input: Readable;
4
+ output: Writable;
5
+ execute: (argv: readonly string[]) => Promise<unknown>;
6
+ signal?: AbortSignal;
7
+ }): Promise<void>;
8
+ //# sourceMappingURL=json-rpc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-rpc.d.ts","sourceRoot":"","sources":["../../src/json-rpc.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AA2EtD,wBAAsB,UAAU,CAAC,OAAO,EAAE;IACxC,KAAK,EAAE,QAAQ,CAAC;IAChB,MAAM,EAAE,QAAQ,CAAC;IACjB,OAAO,EAAE,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACvD,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,GAAG,OAAO,CAAC,IAAI,CAAC,CA0FhB"}
@@ -0,0 +1,99 @@
1
+ import { once } from "node:events";
2
+ import { boundedLines } from "./bounded-lines.js";
3
+ import { inputLimits, validateArgv } from "./input-limits.js";
4
+ function isRequest(value) {
5
+ if (typeof value !== "object" || value === null) {
6
+ return false;
7
+ }
8
+ const candidate = value;
9
+ return candidate.jsonrpc === "2.0" && typeof candidate.method === "string";
10
+ }
11
+ function executeParams(value) {
12
+ if (typeof value !== "object" || value === null) {
13
+ return undefined;
14
+ }
15
+ const argv = value.argv;
16
+ try {
17
+ validateArgv(argv);
18
+ return { argv: [...argv] };
19
+ }
20
+ catch {
21
+ return undefined;
22
+ }
23
+ }
24
+ async function response(output, value, signal) {
25
+ if (output.destroyed || output.writableEnded)
26
+ throw new Error("JSON-RPC output is closed.");
27
+ const closed = new AbortController();
28
+ const onClose = () => closed.abort(new Error("JSON-RPC output closed while writing."));
29
+ output.once("close", onClose);
30
+ try {
31
+ if (!output.write(`${JSON.stringify(value)}\n`))
32
+ await once(output, "drain", {
33
+ signal: signal
34
+ ? AbortSignal.any([signal, closed.signal])
35
+ : closed.signal,
36
+ });
37
+ }
38
+ finally {
39
+ output.off("close", onClose);
40
+ }
41
+ }
42
+ function errorResponse(output, id, code, message, signal) {
43
+ return response(output, {
44
+ jsonrpc: "2.0",
45
+ id: id ?? null,
46
+ error: { code, message },
47
+ }, signal);
48
+ }
49
+ export async function runJsonRpc(options) {
50
+ options.signal?.throwIfAborted();
51
+ for await (const line of boundedLines(options.input, inputLimits.rpcLineBytes, options.signal)) {
52
+ options.signal?.throwIfAborted();
53
+ if (!line.trim()) {
54
+ continue;
55
+ }
56
+ let request;
57
+ try {
58
+ request = JSON.parse(line);
59
+ }
60
+ catch {
61
+ await errorResponse(options.output, null, -32700, "Parse error", options.signal);
62
+ continue;
63
+ }
64
+ if (!isRequest(request)) {
65
+ await errorResponse(options.output, null, -32600, "Invalid Request", options.signal);
66
+ continue;
67
+ }
68
+ const expectsResponse = request.id !== undefined;
69
+ if (request.method !== "cli.execute") {
70
+ if (expectsResponse) {
71
+ await errorResponse(options.output, request.id, -32601, "Method not found", options.signal);
72
+ }
73
+ continue;
74
+ }
75
+ const params = executeParams(request.params);
76
+ if (!params) {
77
+ if (expectsResponse) {
78
+ await errorResponse(options.output, request.id, -32602, "Expected params.argv within the command argument count and byte limits", options.signal);
79
+ }
80
+ continue;
81
+ }
82
+ let result;
83
+ try {
84
+ result = await options.execute(params.argv);
85
+ }
86
+ catch (error) {
87
+ if (expectsResponse)
88
+ await errorResponse(options.output, request.id, -32000, error instanceof Error ? error.message : String(error), options.signal);
89
+ continue;
90
+ }
91
+ if (expectsResponse)
92
+ await response(options.output, {
93
+ jsonrpc: "2.0",
94
+ id: request.id ?? null,
95
+ result: result ?? null,
96
+ }, options.signal);
97
+ }
98
+ }
99
+ //# sourceMappingURL=json-rpc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-rpc.js","sourceRoot":"","sources":["../../src/json-rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAc9D,SAAS,SAAS,CAAC,KAAc;IAC/B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,SAAS,GAAG,KAAgC,CAAC;IACnD,OAAO,SAAS,CAAC,OAAO,KAAK,KAAK,IAAI,OAAO,SAAS,CAAC,MAAM,KAAK,QAAQ,CAAC;AAC7E,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,IAAI,GAAI,KAAgC,CAAC,IAAI,CAAC;IACpD,IAAI,CAAC;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C,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,IAAI,eAAe,EAAE,CAAC;gBACpB,MAAM,aAAa,CACjB,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,EAAE,EACV,CAAC,KAAK,EACN,wEAAwE,EACxE,OAAO,CAAC,MAAM,CACf,CAAC;YACJ,CAAC;YACD,SAAS;QACX,CAAC;QAED,IAAI,MAAe,CAAC;QACpB,IAAI,CAAC;YACH,MAAM,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,eAAe;gBACjB,MAAM,aAAa,CACjB,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,EAAE,EACV,CAAC,KAAK,EACN,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EACtD,OAAO,CAAC,MAAM,CACf,CAAC;YACJ,SAAS;QACX,CAAC;QACD,IAAI,eAAe;YACjB,MAAM,QAAQ,CACZ,OAAO,CAAC,MAAM,EACd;gBACE,OAAO,EAAE,KAAK;gBACd,EAAE,EAAE,OAAO,CAAC,EAAE,IAAI,IAAI;gBACtB,MAAM,EAAE,MAAM,IAAI,IAAI;aACvB,EACD,OAAO,CAAC,MAAM,CACf,CAAC;IACN,CAAC;AACH,CAAC"}
@@ -0,0 +1,10 @@
1
+ /** Decimal integer syntax and bounds only; callers supply a static, non-secret error message. */
2
+ export declare function integerParser({ min, max, signed, errorMessage }: {
3
+ min: number;
4
+ max: number;
5
+ signed: boolean;
6
+ errorMessage: string;
7
+ }): (value: string) => number;
8
+ /** Parse JSON to unknown, without exposing the input or the native parser's error/cause. */
9
+ export declare function jsonParser(errorMessage: string): (value: string) => unknown;
10
+ //# sourceMappingURL=option-parsers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"option-parsers.d.ts","sourceRoot":"","sources":["../../src/option-parsers.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,wBAAgB,aAAa,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE;IAChE,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAY5B;AAED,4FAA4F;AAC5F,wBAAgB,UAAU,CAAC,YAAY,EAAE,MAAM,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAQ3E"}
@@ -0,0 +1,26 @@
1
+ /** Decimal integer syntax and bounds only; callers supply a static, non-secret error message. */
2
+ export function integerParser({ min, max, signed, errorMessage }) {
3
+ if (!Number.isSafeInteger(min) || !Number.isSafeInteger(max) || min > max) {
4
+ throw new Error("Integer parser bounds must be ordered safe integers.");
5
+ }
6
+ const syntax = signed ? /^-?\d+$/ : /^\d+$/;
7
+ return value => {
8
+ const number = Number(value);
9
+ if (!syntax.test(value) || !Number.isSafeInteger(number) || number < min || number > max) {
10
+ throw new Error(errorMessage);
11
+ }
12
+ return number;
13
+ };
14
+ }
15
+ /** Parse JSON to unknown, without exposing the input or the native parser's error/cause. */
16
+ export function jsonParser(errorMessage) {
17
+ return value => {
18
+ try {
19
+ return JSON.parse(value);
20
+ }
21
+ catch {
22
+ throw new Error(errorMessage);
23
+ }
24
+ };
25
+ }
26
+ //# sourceMappingURL=option-parsers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"option-parsers.js","sourceRoot":"","sources":["../../src/option-parsers.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,MAAM,UAAU,aAAa,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,EAK7D;IACC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,GAAG,EAAE,CAAC;QAC1E,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IAC1E,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;IAC5C,OAAO,KAAK,CAAC,EAAE;QACb,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAC7B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,GAAG,IAAI,MAAM,GAAG,GAAG,EAAE,CAAC;YACzF,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;QAChC,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,UAAU,CAAC,YAAoB;IAC7C,OAAO,KAAK,CAAC,EAAE;QACb,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAY,CAAC;QACtC,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;QAChC,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { Writable } from "node:stream";
2
+ export declare function formatHuman(value: unknown): string;
3
+ export declare function writeResult(output: Writable, value: unknown, json: boolean): void;
4
+ //# sourceMappingURL=output.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/output.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAoC5C,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAmBlD;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAKjF"}
@@ -0,0 +1,54 @@
1
+ import { inspect } from "node:util";
2
+ function isRecord(value) {
3
+ return typeof value === "object" && value !== null && !Array.isArray(value);
4
+ }
5
+ function displayCell(value) {
6
+ if (value === null || value === undefined) {
7
+ return "";
8
+ }
9
+ if (typeof value === "object") {
10
+ return JSON.stringify(value);
11
+ }
12
+ return String(value);
13
+ }
14
+ function table(values) {
15
+ const columns = [...new Set(values.flatMap((value) => Object.keys(value)))];
16
+ if (columns.length === 0) {
17
+ return "";
18
+ }
19
+ const rows = values.map((value) => columns.map((column) => displayCell(value[column])));
20
+ const widths = columns.map((column, index) => Math.max(column.length, ...rows.map((row) => row[index]?.length ?? 0)));
21
+ const formatRow = (row) => row.map((cell, index) => cell.padEnd(widths[index] ?? 0)).join(" ").trimEnd();
22
+ return [
23
+ formatRow(columns),
24
+ formatRow(widths.map((width) => "-".repeat(width))),
25
+ ...rows.map(formatRow),
26
+ ].join("\n");
27
+ }
28
+ export function formatHuman(value) {
29
+ if (value === undefined || value === null) {
30
+ return "";
31
+ }
32
+ if (typeof value === "string") {
33
+ return value;
34
+ }
35
+ if (Array.isArray(value) && value.every(isRecord)) {
36
+ if (value.length === 0) {
37
+ return "No results.";
38
+ }
39
+ return table(value);
40
+ }
41
+ if (isRecord(value)) {
42
+ return Object.entries(value)
43
+ .map(([key, entry]) => `${key}: ${displayCell(entry)}`)
44
+ .join("\n");
45
+ }
46
+ return inspect(value, { colors: false, depth: 6, compact: false });
47
+ }
48
+ export function writeResult(output, value, json) {
49
+ const rendered = json ? JSON.stringify(value ?? null) : formatHuman(value);
50
+ if (rendered.length > 0) {
51
+ output.write(`${rendered}\n`);
52
+ }
53
+ }
54
+ //# sourceMappingURL=output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OA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IAAI,CAAC,CAAC;IAChB,CAAC;IACD,OAAO,OAAO,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;AACrE,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAAgB,EAAE,KAAc,EAAE,IAAa;IACzE,MAAM,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAC3E,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,CAAC,KAAK,CAAC,GAAG,QAAQ,IAAI,CAAC,CAAC;IAChC,CAAC;AACH,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { CommandDefinition, PermissionCategory, PermissionGateDefinition, ProfileStoreContract } from "./types.js";
2
+ /** Core-only declarations; admission policy stays in the shared command adapter. */
3
+ export declare function createPermissionCommand(categories: readonly PermissionCategory[], store: ProfileStoreContract, enabledPermissions: (profile: string) => Promise<Set<string>>): CommandDefinition;
4
+ export declare const Permission: Readonly<{
5
+ readonly ReadOnly: "ReadOnly";
6
+ readonly Update: "Update";
7
+ }>;
8
+ export declare function resolvePermissionCategories(definition: PermissionGateDefinition): readonly PermissionCategory[];
9
+ export declare function validateCommandPermissions(commands: readonly CommandDefinition[], categories: readonly PermissionCategory[]): void;
10
+ export declare function validatePermissionsDisabled(commands: readonly CommandDefinition[]): void;
11
+ //# sourceMappingURL=permissions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../../src/permissions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACxB,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAGpB,oFAAoF;AACpF,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,SAAS,kBAAkB,EAAE,EACzC,KAAK,EAAE,oBAAoB,EAC3B,kBAAkB,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAC5D,iBAAiB,CAyCnB;AAED,eAAO,MAAM,UAAU;uBACX,UAAU;qBACZ,QAAQ;EACP,CAAC;AAiBZ,wBAAgB,2BAA2B,CACzC,UAAU,EAAE,wBAAwB,GACnC,SAAS,kBAAkB,EAAE,CAiB/B;AAED,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,SAAS,iBAAiB,EAAE,EACtC,UAAU,EAAE,SAAS,kBAAkB,EAAE,GACxC,IAAI,CAsBN;AAED,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,SAAS,iBAAiB,EAAE,GACrC,IAAI,CAcN"}
@@ -0,0 +1,95 @@
1
+ import { command } from "./command.js";
2
+ /** Core-only declarations; admission policy stays in the shared command adapter. */
3
+ export function createPermissionCommand(categories, store, enabledPermissions) {
4
+ const names = categories.map((category) => category.name);
5
+ return command("permissions", "Manage profile-specific safety permissions", [
6
+ command("list", "List permissions for the selected profile", async (_input, context) => {
7
+ const enabled = await enabledPermissions(context.profile.name);
8
+ return categories.map((category) => ({
9
+ name: category.name,
10
+ enabled: enabled.has(category.name),
11
+ description: category.description,
12
+ }));
13
+ }),
14
+ ...["grant", "revoke"].map((action) => command(`${action} <permission>`, `${action === "grant" ? "Enable" : "Disable"} a permission for the selected profile`, async ({ args }, context) => {
15
+ const permission = String(args.permission);
16
+ if (!names.includes(permission))
17
+ throw new Error(`Unknown permission '${permission}'. Available permissions: ${names.join(", ")}.`);
18
+ const enabled = await enabledPermissions(context.profile.name);
19
+ if (action === "grant")
20
+ enabled.add(permission);
21
+ else
22
+ enabled.delete(permission);
23
+ await store.setPermissions(context.profile.name, names.filter((name) => enabled.has(name)));
24
+ return {
25
+ profile: context.profile.name,
26
+ permission,
27
+ enabled: action === "grant",
28
+ };
29
+ })),
30
+ ]);
31
+ }
32
+ export const Permission = Object.freeze({
33
+ ReadOnly: "ReadOnly",
34
+ Update: "Update",
35
+ });
36
+ const builtInCategories = [
37
+ {
38
+ name: Permission.ReadOnly,
39
+ description: "Read remote state without changing it",
40
+ enabledByDefault: true,
41
+ },
42
+ {
43
+ name: Permission.Update,
44
+ description: "Perform operations that may change remote state",
45
+ enabledByDefault: false,
46
+ },
47
+ ];
48
+ const categoryNamePattern = /^[A-Za-z][A-Za-z0-9._-]{0,63}$/;
49
+ export function resolvePermissionCategories(definition) {
50
+ const categories = [...builtInCategories, ...(definition.categories ?? [])];
51
+ const names = new Set();
52
+ for (const category of categories) {
53
+ if (!categoryNamePattern.test(category.name)) {
54
+ throw new Error(`Permission category '${category.name}' must start with a letter and contain at most 64 letters, numbers, dots, dashes, or underscores.`);
55
+ }
56
+ if (names.has(category.name)) {
57
+ throw new Error(`Permission category '${category.name}' is declared more than once.`);
58
+ }
59
+ names.add(category.name);
60
+ }
61
+ return categories;
62
+ }
63
+ export function validateCommandPermissions(commands, categories) {
64
+ const known = new Set(categories.map((category) => category.name));
65
+ const visit = (command, parentPath) => {
66
+ const commandName = command.name.trim().split(/\s+/, 1)[0] ?? command.name;
67
+ const path = parentPath ? `${parentPath} ${commandName}` : commandName;
68
+ if (command.run && !command.permission) {
69
+ throw new Error(`Command '${path}' must declare a permission because the permission gate is enabled.`);
70
+ }
71
+ if (command.permission && !known.has(command.permission)) {
72
+ throw new Error(`Command '${path}' requires unknown permission '${command.permission}'.`);
73
+ }
74
+ for (const child of command.children ?? []) {
75
+ visit(child, path);
76
+ }
77
+ };
78
+ for (const command of commands) {
79
+ visit(command, "");
80
+ }
81
+ }
82
+ export function validatePermissionsDisabled(commands) {
83
+ const visit = (command) => {
84
+ if (command.permission) {
85
+ throw new Error(`Command '${command.name}' declares permission '${command.permission}', but the CLI permission gate is not enabled.`);
86
+ }
87
+ for (const child of command.children ?? []) {
88
+ visit(child);
89
+ }
90
+ };
91
+ for (const command of commands) {
92
+ visit(command);
93
+ }
94
+ }
95
+ //# sourceMappingURL=permissions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permissions.js","sourceRoot":"","sources":["../../src/permissions.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,oFAAoF;AACpF,MAAM,UAAU,uBAAuB,CACrC,UAAyC,EACzC,KAA2B,EAC3B,kBAA6D;IAE7D,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC1D,OAAO,OAAO,CAAC,aAAa,EAAE,4CAA4C,EAAE;QAC1E,OAAO,CACL,MAAM,EACN,2CAA2C,EAC3C,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE;YACxB,MAAM,OAAO,GAAG,MAAM,kBAAkB,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC/D,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;gBACnC,IAAI,EAAE,QAAQ,CAAC,IAAI;gBACnB,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;gBACnC,WAAW,EAAE,QAAQ,CAAC,WAAW;aAClC,CAAC,CAAC,CAAC;QACN,CAAC,CACF;QACD,GAAI,CAAC,OAAO,EAAE,QAAQ,CAAW,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAC/C,OAAO,CACL,GAAG,MAAM,eAAe,EACxB,GAAG,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,wCAAwC,EACpF,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,EAAE;YAC1B,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAC3C,IAAI,CAA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AC;QACJ,CAAC;QACD,IAAI,OAAO,CAAC,UAAU,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;YACzD,MAAM,IAAI,KAAK,CACb,YAAY,IAAI,kCAAkC,OAAO,CAAC,UAAU,IAAI,CACzE,CAAC;QACJ,CAAC;QACD,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,QAAQ,IAAI,EAAE,EAAE,CAAC;YAC3C,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QACrB,CAAC;IACH,CAAC,CAAC;IACF,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IACrB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,2BAA2B,CACzC,QAAsC;IAEtC,MAAM,KAAK,GAAG,CAAC,OAA0B,EAAQ,EAAE;QACjD,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CACb,YAAY,OAAO,CAAC,IAAI,0BAA0B,OAAO,CAAC,UAAU,gDAAgD,CACrH,CAAC;QACJ,CAAC;QACD,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,QAAQ,IAAI,EAAE,EAAE,CAAC;YAC3C,KAAK,CAAC,KAAK,CAAC,CAAC;QACf,CAAC;IACH,CAAC,CAAC;IACF,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;AACH,CAAC"}
@@ -0,0 +1,5 @@
1
+ /** Only call for a dedicated application-owned directory, never a user-selected parent. */
2
+ export declare function privateDirectory(path: string): Promise<void>;
3
+ /** grpc-js owns the pipe; this only restricts the OS object's ACL before readiness. */
4
+ export declare function privateEndpoint(path: string): Promise<void>;
5
+ //# sourceMappingURL=private-storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"private-storage.d.ts","sourceRoot":"","sources":["../../src/private-storage.ts"],"names":[],"mappings":"AA4BA,2FAA2F;AAC3F,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAelE;AAED,uFAAuF;AACvF,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA8BjE"}
@@ -0,0 +1,68 @@
1
+ import { mkdir, chmod } from "node:fs/promises";
2
+ import { execFile } from "node:child_process";
3
+ import { promisify } from "node:util";
4
+ const execute = promisify(execFile);
5
+ const quote = (value) => "'" + value.replaceAll("'", "''") + "'";
6
+ async function windows(script) {
7
+ try {
8
+ await execute("powershell.exe", [
9
+ "-NoProfile",
10
+ "-NonInteractive",
11
+ "-EncodedCommand",
12
+ Buffer.from("$ErrorActionPreference='Stop'; " + script, "utf16le").toString("base64"),
13
+ ], { windowsHide: true, timeout: 15_000, maxBuffer: 8192 });
14
+ }
15
+ catch {
16
+ throw new Error("Cannot restrict runtime storage to the current Windows user.");
17
+ }
18
+ }
19
+ /** Only call for a dedicated application-owned directory, never a user-selected parent. */
20
+ export async function privateDirectory(path) {
21
+ await mkdir(path, { recursive: true, mode: 0o700 });
22
+ if (process.platform !== "win32") {
23
+ await chmod(path, 0o700);
24
+ return;
25
+ }
26
+ await windows(`
27
+ $taskSid=[Security.Principal.WindowsIdentity]::GetCurrent().User;
28
+ $taskAcl=New-Object Security.AccessControl.DirectorySecurity;
29
+ $taskAcl.SetOwner($taskSid);
30
+ $taskAcl.SetAccessRuleProtection($true,$false);
31
+ $taskRule=New-Object Security.AccessControl.FileSystemAccessRule($taskSid,'FullControl','ContainerInherit,ObjectInherit','None','Allow');
32
+ $taskAcl.AddAccessRule($taskRule);
33
+ [IO.Directory]::SetAccessControl(${quote(path)},$taskAcl);
34
+ `);
35
+ }
36
+ /** grpc-js owns the pipe; this only restricts the OS object's ACL before readiness. */
37
+ export async function privateEndpoint(path) {
38
+ if (process.platform !== "win32") {
39
+ await chmod(path, 0o600);
40
+ return;
41
+ }
42
+ await windows(`
43
+ Add-Type -TypeDefinition @'
44
+ using System;
45
+ using System.Runtime.InteropServices;
46
+ public static class PipePermissions {
47
+ [DllImport("advapi32.dll",CharSet=CharSet.Unicode,SetLastError=true)]
48
+ static extern bool ConvertStringSecurityDescriptorToSecurityDescriptor(string s,uint v,out IntPtr sd,out uint n);
49
+ [DllImport("advapi32.dll",SetLastError=true)]
50
+ static extern bool GetSecurityDescriptorDacl(IntPtr sd,out bool present,out IntPtr dacl,out bool defaulted);
51
+ [DllImport("advapi32.dll",CharSet=CharSet.Unicode)]
52
+ static extern uint SetNamedSecurityInfo(string name,int type,uint flags,IntPtr owner,IntPtr group,IntPtr dacl,IntPtr sacl);
53
+ [DllImport("kernel32.dll")] static extern IntPtr LocalFree(IntPtr p);
54
+ public static void Restrict(string path,string sid) {
55
+ IntPtr sd;uint n;if(!ConvertStringSecurityDescriptorToSecurityDescriptor("D:P(A;;GA;;;"+sid+")",1,out sd,out n))throw new Exception("Invalid descriptor");
56
+ try {
57
+ bool present,def;IntPtr dacl;
58
+ if(!GetSecurityDescriptorDacl(sd,out present,out dacl,out def))throw new Exception("Invalid DACL");
59
+ uint result=SetNamedSecurityInfo(path,1,0x80000004,IntPtr.Zero,IntPtr.Zero,dacl,IntPtr.Zero);
60
+ if(result!=0)throw new Exception("Pipe access protection failed: "+result);
61
+ }finally{LocalFree(sd);}
62
+ }
63
+ }
64
+ '@
65
+ [PipePermissions]::Restrict(${quote(path)},[Security.Principal.WindowsIdentity]::GetCurrent().User.Value);
66
+ `);
67
+ }
68
+ //# sourceMappingURL=private-storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"private-storage.js","sourceRoot":"","sources":["../../src/private-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OA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AAO;IACT,CAAC;IACD,MAAM,OAAO,CAAC;;;;;;;;;;;;;;;;;;;;;;;kCAuBkB,KAAK,CAAC,IAAI,CAAC;GAC1C,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,29 @@
1
+ import type { CliDefinition, CommandContext, Profile, ProfileField, ProfileStoreContract } from "./types.js";
2
+ interface ConfigurationState {
3
+ missingFields: readonly ProfileField[];
4
+ authenticationMissing: boolean;
5
+ }
6
+ interface ConfigureProfileOptions {
7
+ values: Record<string, unknown>;
8
+ authOptions: Record<string, unknown>;
9
+ interactive: boolean;
10
+ }
11
+ interface ProfileInvocation {
12
+ contextFor(profile: Profile): CommandContext;
13
+ stdinAvailable: boolean;
14
+ interactive(): boolean;
15
+ }
16
+ /** Profile/auth declarations and onboarding share the same operations, not a second parser. */
17
+ export declare function createProfileCommands(definition: Pick<CliDefinition, "name" | "profile" | "auth">, profileStore: ProfileStoreContract, invocation: ProfileInvocation, invalidateProfile: (profile: Profile) => Promise<void>): {
18
+ commands: import("./types.js").CommandDefinition[];
19
+ configureProfile: (profileName: string, options: ConfigureProfileOptions) => Promise<{
20
+ configured: true;
21
+ profile: string;
22
+ authenticated: true;
23
+ identity: unknown;
24
+ }>;
25
+ configurationState: (profile: Profile) => Promise<ConfigurationState>;
26
+ configurationError: (profile: Profile, state: ConfigurationState) => Error;
27
+ };
28
+ export {};
29
+ //# sourceMappingURL=profile-commands.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profile-commands.d.ts","sourceRoot":"","sources":["../../src/profile-commands.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAEV,aAAa,EACb,cAAc,EACd,OAAO,EACP,YAAY,EACZ,oBAAoB,EAErB,MAAM,YAAY,CAAC;AAEpB,UAAU,kBAAkB;IAC1B,aAAa,EAAE,SAAS,YAAY,EAAE,CAAC;IACvC,qBAAqB,EAAE,OAAO,CAAC;CAChC;AAED,UAAU,uBAAuB;IAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,UAAU,iBAAiB;IACzB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,cAAc,CAAC;IAC7C,cAAc,EAAE,OAAO,CAAC;IACxB,WAAW,IAAI,OAAO,CAAC;CACxB;AA4DD,+FAA+F;AAC/F,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,IAAI,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC,EAC5D,YAAY,EAAE,oBAAoB,EAClC,UAAU,EAAE,iBAAiB,EAC7B,iBAAiB,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC;;oCAgEvC,MAAM,WACV,uBAAuB,KAC/B,OAAO,CAAC;QACT,UAAU,EAAE,IAAI,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,aAAa,EAAE,IAAI,CAAC;QACpB,QAAQ,EAAE,OAAO,CAAC;KACnB,CAAC;kCA3DS,OAAO,KACf,OAAO,CAAC,kBAAkB,CAAC;kCAsBnB,OAAO,SACT,kBAAkB,KACxB,KAAK;EA6QT"}