@executioncontrolprotocol/plugin-sdk 0.0.0-stage → 0.51.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 (83) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +28 -2
  3. package/dist/build/build-plugin.d.ts +7 -0
  4. package/dist/build/build-plugin.d.ts.map +1 -0
  5. package/dist/build/build-plugin.js +90 -0
  6. package/dist/build/build-plugin.js.map +1 -0
  7. package/dist/build/check-plugin.d.ts +7 -0
  8. package/dist/build/check-plugin.d.ts.map +1 -0
  9. package/dist/build/check-plugin.js +98 -0
  10. package/dist/build/check-plugin.js.map +1 -0
  11. package/dist/build/generated-pjson.d.ts +23 -0
  12. package/dist/build/generated-pjson.d.ts.map +1 -0
  13. package/dist/build/generated-pjson.js +72 -0
  14. package/dist/build/generated-pjson.js.map +1 -0
  15. package/dist/build/scaffold-plugin.d.ts +6 -0
  16. package/dist/build/scaffold-plugin.d.ts.map +1 -0
  17. package/dist/build/scaffold-plugin.js +103 -0
  18. package/dist/build/scaffold-plugin.js.map +1 -0
  19. package/dist/build/types.d.ts +37 -0
  20. package/dist/build/types.d.ts.map +1 -0
  21. package/dist/build/types.js +2 -0
  22. package/dist/build/types.js.map +1 -0
  23. package/dist/codes.d.ts +12 -0
  24. package/dist/codes.d.ts.map +1 -0
  25. package/dist/codes.js +12 -0
  26. package/dist/codes.js.map +1 -0
  27. package/dist/define-operation.d.ts +79 -0
  28. package/dist/define-operation.d.ts.map +1 -0
  29. package/dist/define-operation.js +47 -0
  30. package/dist/define-operation.js.map +1 -0
  31. package/dist/ecp-command.d.ts +40 -0
  32. package/dist/ecp-command.d.ts.map +1 -0
  33. package/dist/ecp-command.js +109 -0
  34. package/dist/ecp-command.js.map +1 -0
  35. package/dist/envelope.d.ts +52 -0
  36. package/dist/envelope.d.ts.map +1 -0
  37. package/dist/envelope.js +15 -0
  38. package/dist/envelope.js.map +1 -0
  39. package/dist/errors.d.ts +30 -0
  40. package/dist/errors.d.ts.map +1 -0
  41. package/dist/errors.js +41 -0
  42. package/dist/errors.js.map +1 -0
  43. package/dist/flags-from-schema.d.ts +17 -0
  44. package/dist/flags-from-schema.d.ts.map +1 -0
  45. package/dist/flags-from-schema.js +129 -0
  46. package/dist/flags-from-schema.js.map +1 -0
  47. package/dist/format-execution.d.ts +23 -0
  48. package/dist/format-execution.d.ts.map +1 -0
  49. package/dist/format-execution.js +76 -0
  50. package/dist/format-execution.js.map +1 -0
  51. package/dist/help-text.d.ts +13 -0
  52. package/dist/help-text.d.ts.map +1 -0
  53. package/dist/help-text.js +38 -0
  54. package/dist/help-text.js.map +1 -0
  55. package/dist/host.d.ts +53 -0
  56. package/dist/host.d.ts.map +1 -0
  57. package/dist/host.js +30 -0
  58. package/dist/host.js.map +1 -0
  59. package/dist/index.d.ts +17 -0
  60. package/dist/index.d.ts.map +1 -0
  61. package/dist/index.js +16 -0
  62. package/dist/index.js.map +1 -0
  63. package/dist/input-merge.d.ts +12 -0
  64. package/dist/input-merge.d.ts.map +1 -0
  65. package/dist/input-merge.js +76 -0
  66. package/dist/input-merge.js.map +1 -0
  67. package/dist/kebab.d.ts +6 -0
  68. package/dist/kebab.d.ts.map +1 -0
  69. package/dist/kebab.js +12 -0
  70. package/dist/kebab.js.map +1 -0
  71. package/dist/reserved-names.d.ts +16 -0
  72. package/dist/reserved-names.d.ts.map +1 -0
  73. package/dist/reserved-names.js +29 -0
  74. package/dist/reserved-names.js.map +1 -0
  75. package/dist/schema-fields.d.ts +7 -0
  76. package/dist/schema-fields.d.ts.map +1 -0
  77. package/dist/schema-fields.js +11 -0
  78. package/dist/schema-fields.js.map +1 -0
  79. package/dist/to-commands.d.ts +9 -0
  80. package/dist/to-commands.d.ts.map +1 -0
  81. package/dist/to-commands.js +173 -0
  82. package/dist/to-commands.js.map +1 -0
  83. package/package.json +31 -3
@@ -0,0 +1,103 @@
1
+ import { mkdir, writeFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { toKebabCase } from "../kebab.js";
4
+ function pluginPackageName(name) {
5
+ if (name.startsWith("@"))
6
+ return name;
7
+ const slug = toKebabCase(name.replace(/^plugin-/, ""));
8
+ return `@executioncontrolprotocol/plugin-${slug}`;
9
+ }
10
+ function extensionName(name) {
11
+ if (name.startsWith("@")) {
12
+ const rest = name.split("/")[1] ?? name;
13
+ return rest.replace(/^plugin-/, "");
14
+ }
15
+ return toKebabCase(name.replace(/^plugin-/, ""));
16
+ }
17
+ /**
18
+ * Scaffold a plugin directory with `src/index.ts` and a minimal `package.json`.
19
+ * @category CLI
20
+ */
21
+ export async function scaffoldPlugin(dir, name) {
22
+ const pkgName = pluginPackageName(name);
23
+ const extName = extensionName(name);
24
+ await mkdir(join(dir, "src"), { recursive: true });
25
+ const packageJson = {
26
+ name: pkgName,
27
+ version: "0.51.0",
28
+ description: `ECP plugin ${extName}`,
29
+ license: "Apache-2.0",
30
+ type: "module",
31
+ main: "./dist/index.js",
32
+ types: "./dist/index.d.ts",
33
+ exports: {
34
+ ".": {
35
+ types: "./dist/index.d.ts",
36
+ import: "./dist/index.js",
37
+ },
38
+ },
39
+ files: ["dist", "README.md"],
40
+ scripts: {
41
+ build: "tsc -b && ecp plugins build",
42
+ },
43
+ peerDependencies: {
44
+ "@executioncontrolprotocol/core": "workspace:^",
45
+ zod: "catalog:",
46
+ },
47
+ dependencies: {
48
+ "@executioncontrolprotocol/plugin-sdk": "workspace:^",
49
+ },
50
+ devDependencies: {
51
+ "@executioncontrolprotocol/cli": "workspace:^",
52
+ "@executioncontrolprotocol/core": "workspace:^",
53
+ typescript: "catalog:",
54
+ zod: "catalog:",
55
+ },
56
+ };
57
+ await writeFile(join(dir, "package.json"), `${JSON.stringify(packageJson, null, 2)}\n`, "utf8");
58
+ const source = `import { defineExtension, capabilityFor } from "@executioncontrolprotocol/core"
59
+ import { z } from "zod"
60
+
61
+ const ${camel(extName)}Extension = defineExtension("@executioncontrolprotocol", ${JSON.stringify(extName)})
62
+ .withMetadata({
63
+ summary: "${extName} plugin",
64
+ description: "Replace this summary with product prose.",
65
+ useCases: ["Call this plugin when the workflow needs ${extName}"],
66
+ })
67
+ .withCapabilities([
68
+ capabilityFor("@executioncontrolprotocol/${extName}", "run")
69
+ .withInput(z.object({ value: z.string() }))
70
+ .withOutput(z.object({ result: z.string() }))
71
+ .withMetadata({
72
+ summary: "Echo value",
73
+ description: "Returns the input value. Replace with a real handler.",
74
+ useCases: ["Smoke-test a newly scaffolded plugin"],
75
+ projections: [
76
+ {
77
+ summary: "Take the result string",
78
+ description: "Use result as the echoed value.",
79
+ },
80
+ ],
81
+ })
82
+ .withHandler(async (input) => ({ result: input.value })),
83
+ ])
84
+ .build()
85
+
86
+ export default ${camel(extName)}Extension
87
+ `;
88
+ await writeFile(join(dir, "src", "index.ts"), source, "utf8");
89
+ const tsconfig = {
90
+ extends: "../../tsconfig.base.json",
91
+ compilerOptions: { outDir: "dist", rootDir: "src", composite: true },
92
+ include: ["src/**/*.ts"],
93
+ references: [{ path: "../../packages/core" }],
94
+ };
95
+ await writeFile(join(dir, "tsconfig.json"), `${JSON.stringify(tsconfig, null, 2)}\n`, "utf8");
96
+ }
97
+ function camel(value) {
98
+ const parts = value.split(/[-_]/g).filter(Boolean);
99
+ const [first = "plugin", ...rest] = parts;
100
+ return (first.replace(/[^a-zA-Z0-9]/g, "") +
101
+ rest.map((p) => p.charAt(0).toUpperCase() + p.slice(1)).join(""));
102
+ }
103
+ //# sourceMappingURL=scaffold-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scaffold-plugin.js","sourceRoot":"","sources":["../../src/build/scaffold-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzC,SAAS,iBAAiB,CAAC,IAAY;IACrC,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AAS,KAAK,CAAC,KAAa;IAC1B,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IAClD,MAAM,CAAC,KAAK,GAAG,QAAQ,EAAE,GAAG,IAAI,CAAC,GAAG,KAAK,CAAA;IACzC,OAAO,CACL,KAAK,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC;QAClC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CACjE,CAAA;AACH,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Report from {@link buildPlugin}.
3
+ * @category CLI
4
+ */
5
+ export interface BuildReport {
6
+ /** Plugin directory. */
7
+ dir: string;
8
+ /** Written files (relative to dir). */
9
+ written: string[];
10
+ /** Extension or policy id loaded from dist. */
11
+ definitionId: string;
12
+ /** Generated command ids. */
13
+ commandIds: string[];
14
+ }
15
+ /**
16
+ * Stale-file issue from {@link checkPlugin}.
17
+ * @category CLI
18
+ */
19
+ export interface CheckIssue {
20
+ /** File or field that is stale. */
21
+ path: string;
22
+ /** What is wrong. */
23
+ message: string;
24
+ }
25
+ /**
26
+ * Report from {@link checkPlugin}.
27
+ * @category CLI
28
+ */
29
+ export interface CheckReport {
30
+ /** Plugin directory. */
31
+ dir: string;
32
+ /** True when generated files match the definition. */
33
+ ok: boolean;
34
+ /** Stale or missing generated artifacts. */
35
+ issues: CheckIssue[];
36
+ }
37
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/build/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,wBAAwB;IACxB,GAAG,EAAE,MAAM,CAAA;IACX,uCAAuC;IACvC,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,+CAA+C;IAC/C,YAAY,EAAE,MAAM,CAAA;IACpB,6BAA6B;IAC7B,UAAU,EAAE,MAAM,EAAE,CAAA;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,mCAAmC;IACnC,IAAI,EAAE,MAAM,CAAA;IACZ,qBAAqB;IACrB,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,wBAAwB;IACxB,GAAG,EAAE,MAAM,CAAA;IACX,sDAAsD;IACtD,EAAE,EAAE,OAAO,CAAA;IACX,4CAA4C;IAC5C,MAAM,EAAE,UAAU,EAAE,CAAA;CACrB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/build/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ export { ECP_BINDING_INVALID, ECP_CAPABILITY_UNKNOWN, ECP_ENVIRONMENT_UNSUPPORTED, ECP_INPUT_INVALID, ECP_PLUGIN_DENIED, ECP_PLUGINS_MISSING, ECP_POLICY_DENIED, ECP_RUN_PAUSED, ECP_SECRET_MISSING, ECP_STEP_FAILED, ECP_WORKFLOW_LOAD, ECP_RERUN_INCOMPATIBLE, } from "@executioncontrolprotocol/core/types";
2
+ /** Process exit code for success. @category CLI */
3
+ export declare const EXIT_OK = 0;
4
+ /** Process exit code when a capability or run failed. @category CLI */
5
+ export declare const EXIT_FAILED = 1;
6
+ /** Process exit code for invalid input or usage. @category CLI */
7
+ export declare const EXIT_USAGE = 2;
8
+ /** Process exit code when a required plugin is missing. @category CLI */
9
+ export declare const EXIT_PLUGINS_MISSING = 3;
10
+ /** Process exit code when a policy paused execution. @category CLI */
11
+ export declare const EXIT_PAUSED = 4;
12
+ //# sourceMappingURL=codes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codes.d.ts","sourceRoot":"","sources":["../src/codes.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,2BAA2B,EAC3B,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,sCAAsC,CAAA;AAE7C,mDAAmD;AACnD,eAAO,MAAM,OAAO,IAAI,CAAA;AAExB,uEAAuE;AACvE,eAAO,MAAM,WAAW,IAAI,CAAA;AAE5B,kEAAkE;AAClE,eAAO,MAAM,UAAU,IAAI,CAAA;AAE3B,yEAAyE;AACzE,eAAO,MAAM,oBAAoB,IAAI,CAAA;AAErC,sEAAsE;AACtE,eAAO,MAAM,WAAW,IAAI,CAAA"}
package/dist/codes.js ADDED
@@ -0,0 +1,12 @@
1
+ export { ECP_BINDING_INVALID, ECP_CAPABILITY_UNKNOWN, ECP_ENVIRONMENT_UNSUPPORTED, ECP_INPUT_INVALID, ECP_PLUGIN_DENIED, ECP_PLUGINS_MISSING, ECP_POLICY_DENIED, ECP_RUN_PAUSED, ECP_SECRET_MISSING, ECP_STEP_FAILED, ECP_WORKFLOW_LOAD, ECP_RERUN_INCOMPATIBLE, } from "@executioncontrolprotocol/core/types";
2
+ /** Process exit code for success. @category CLI */
3
+ export const EXIT_OK = 0;
4
+ /** Process exit code when a capability or run failed. @category CLI */
5
+ export const EXIT_FAILED = 1;
6
+ /** Process exit code for invalid input or usage. @category CLI */
7
+ export const EXIT_USAGE = 2;
8
+ /** Process exit code when a required plugin is missing. @category CLI */
9
+ export const EXIT_PLUGINS_MISSING = 3;
10
+ /** Process exit code when a policy paused execution. @category CLI */
11
+ export const EXIT_PAUSED = 4;
12
+ //# sourceMappingURL=codes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codes.js","sourceRoot":"","sources":["../src/codes.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,2BAA2B,EAC3B,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,sCAAsC,CAAA;AAE7C,mDAAmD;AACnD,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAA;AAExB,uEAAuE;AACvE,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAA;AAE5B,kEAAkE;AAClE,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAA;AAE3B,yEAAyE;AACzE,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAA;AAErC,sEAAsE;AACtE,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAA"}
@@ -0,0 +1,79 @@
1
+ import type { Interfaces } from "@oclif/core";
2
+ import type { z } from "zod";
3
+ import type { EcpHost } from "./host.js";
4
+ /**
5
+ * Optional CLI hint on an operation: positional argument field names.
6
+ * @category CLI
7
+ */
8
+ export interface OperationCliHint {
9
+ /** Input-schema field names that become positional args, in order. */
10
+ args?: string[];
11
+ }
12
+ /**
13
+ * Agent-facing metadata for a host operation.
14
+ * @category CLI
15
+ */
16
+ export interface OperationMetadata {
17
+ /** One-line summary. */
18
+ summary: string;
19
+ /** Longer description. */
20
+ description?: string;
21
+ /** When to use this command. */
22
+ useCases?: string[];
23
+ /** Example invocations. */
24
+ examples?: string[];
25
+ /** oclif command aliases (for example `run` for `workflows:run`). */
26
+ aliases?: string[];
27
+ /** Positional argument mapping. */
28
+ cli?: OperationCliHint;
29
+ }
30
+ /**
31
+ * Context passed to an operation handler.
32
+ * @category CLI
33
+ */
34
+ export interface OperationContext {
35
+ /** Process host, when the init hook has run. */
36
+ host: EcpHost | undefined;
37
+ /** oclif config. */
38
+ config: Interfaces.Config;
39
+ /** Parsed argv after the command id. */
40
+ argv: string[];
41
+ /** True when `--json` was passed. */
42
+ json: boolean;
43
+ }
44
+ /**
45
+ * Host command definition (CLI's own commands). Not usable as a workflow step.
46
+ * @category CLI
47
+ */
48
+ export interface OperationDefinition {
49
+ /** Command id (`workflows:run`, `plugins:new`, `config:secrets:add`). */
50
+ name: string;
51
+ /** Zod schema for merged flags and args. */
52
+ inputSchema: z.ZodType;
53
+ /** Agent-facing docs. */
54
+ metadata: OperationMetadata;
55
+ /** Run the operation; return value becomes envelope `data`. */
56
+ handler: (input: Record<string, unknown>, ctx: OperationContext) => Promise<unknown>;
57
+ }
58
+ declare class OperationBuilder {
59
+ private readonly name;
60
+ private inputSchema?;
61
+ private metadata?;
62
+ private handler?;
63
+ constructor(name: string);
64
+ /** Set the input schema. */
65
+ withInput(schema: z.ZodType): this;
66
+ /** Set command metadata. */
67
+ withMetadata(metadata: OperationMetadata): this;
68
+ /** Set the handler. */
69
+ withHandler(handler: OperationDefinition["handler"]): this;
70
+ /** Build a plain operation definition. */
71
+ build(): OperationDefinition;
72
+ }
73
+ /**
74
+ * Start a host-operation builder. The CLI's own commands are operations.
75
+ * @category CLI
76
+ */
77
+ export declare function defineOperation(name: string): OperationBuilder;
78
+ export {};
79
+ //# sourceMappingURL=define-operation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-operation.d.ts","sourceRoot":"","sources":["../src/define-operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAC5B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAExC;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,sEAAsE;IACtE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,wBAAwB;IACxB,OAAO,EAAE,MAAM,CAAA;IACf,0BAA0B;IAC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W,CAAC,OAAO,EAAE,mBAAmB,CAAC,SAAS,CAAC,GAAG,IAAI;IAK1D,0CAA0C;IAC1C,KAAK,IAAI,mBAAmB;CAW7B;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAE9D"}
@@ -0,0 +1,47 @@
1
+ class OperationBuilder {
2
+ name;
3
+ inputSchema;
4
+ metadata;
5
+ handler;
6
+ constructor(name) {
7
+ this.name = name;
8
+ }
9
+ /** Set the input schema. */
10
+ withInput(schema) {
11
+ this.inputSchema = schema;
12
+ return this;
13
+ }
14
+ /** Set command metadata. */
15
+ withMetadata(metadata) {
16
+ this.metadata = metadata;
17
+ return this;
18
+ }
19
+ /** Set the handler. */
20
+ withHandler(handler) {
21
+ this.handler = handler;
22
+ return this;
23
+ }
24
+ /** Build a plain operation definition. */
25
+ build() {
26
+ if (!this.inputSchema)
27
+ throw new Error(`Operation ${this.name} is missing withInput`);
28
+ if (!this.metadata?.summary)
29
+ throw new Error(`Operation ${this.name} is missing metadata.summary`);
30
+ if (!this.handler)
31
+ throw new Error(`Operation ${this.name} is missing withHandler`);
32
+ return {
33
+ name: this.name,
34
+ inputSchema: this.inputSchema,
35
+ metadata: this.metadata,
36
+ handler: this.handler,
37
+ };
38
+ }
39
+ }
40
+ /**
41
+ * Start a host-operation builder. The CLI's own commands are operations.
42
+ * @category CLI
43
+ */
44
+ export function defineOperation(name) {
45
+ return new OperationBuilder(name);
46
+ }
47
+ //# sourceMappingURL=define-operation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-operation.js","sourceRoot":"","sources":["../src/define-operation.ts"],"names":[],"mappings":"AA8DA,MAAM,gBAAgB;IAKS;IAJrB,WAAW,CAAY;IACvB,QAAQ,CAAoB;IAC5B,OAAO,CAAiC;IAEhD,YAA6B,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;IAAG,CAAC;IAE7C,4BAA4B;IAC5B,SAAS,CAAC,MAAiB;QACzB,IAAI,CAAC,WAAW,GAAG,MAAM,CAAA;QACzB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,4BAA4B;IAC5B,YAAY,CAAC,QAA2B;QACtC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,uBAAuB;IACvB,WAAW,CAAC,OAAuC;QACjD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,0CAA0C;IAC1C,KAAK;QACH,IAAI,CAAC,IAAI,CAAC,WAAW;YAAE,MAAM,IAAI,KAAK,CAAC,aAAa,IAAI,CAAC,IAAI,uBAAuB,CAAC,CAAA;QACrF,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,aAAa,IAAI,CAAC,IAAI,8BAA8B,CAAC,CAAA;QAClG,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,aAAa,IAAI,CAAC,IAAI,yBAAyB,CAAC,CAAA;QACnF,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAA;IACH,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,OAAO,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAA;AACnC,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { Command } from "@oclif/core";
2
+ /**
3
+ * Base class for generated capability and operation commands.
4
+ * Owns the JSON envelope, error codes and exit codes.
5
+ * @category CLI
6
+ */
7
+ export declare abstract class EcpCommand extends Command {
8
+ static enableJsonFlag: boolean;
9
+ /**
10
+ * True when the caller passed `--json`. Non-TTY spawn clients keep pretty JSON
11
+ * until they opt in with `--json` (existing CLI tests).
12
+ * @category CLI
13
+ */
14
+ protected wantsEnvelope(): boolean;
15
+ /**
16
+ * Pretty-print `data` when not using `--json`. With `--json`, oclif prints
17
+ * {@link toSuccessJson} from the `run()` return value.
18
+ * @category CLI
19
+ */
20
+ protected writeSuccess(data: unknown): void;
21
+ /**
22
+ * oclif `--json` success wrapper. Returns the ECP envelope, not the raw result.
23
+ * @category CLI
24
+ */
25
+ toSuccessJson(result: unknown): unknown;
26
+ /**
27
+ * oclif `--json` error wrapper. Keeps the `ECP_*` code instead of oclif's
28
+ * `{ error: { oclif: { exit } } }` payload.
29
+ * @category CLI
30
+ */
31
+ toErrorJson(error: unknown): unknown;
32
+ /**
33
+ * Print the ECP error envelope (or pretty message) and exit.
34
+ * @category CLI
35
+ */
36
+ catch(error: Error & {
37
+ exitCode?: number;
38
+ }): Promise<void>;
39
+ }
40
+ //# sourceMappingURL=ecp-command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ecp-command.d.ts","sourceRoot":"","sources":["../src/ecp-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAMrC;;;;GAIG;AACH,8BAAsB,UAAW,SAAQ,OAAO;IAC9C,MAAM,CAAC,cAAc,UAAO;IAE5B;;;;OAIG;IACH,SAAS,CAAC,aAAa,IAAI,OAAO;IAIlC;;;;OAIG;IACH,SAAS,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI;IAW3C;;;OAGG;IACH,aAAa,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO;IAKvC;;;;OAIG;IACH,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;IAKpC;;;OAGG;IACG,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAiBjE"}
@@ -0,0 +1,109 @@
1
+ import { Command } from "@oclif/core";
2
+ import { ECP_INPUT_INVALID, EXIT_FAILED, EXIT_USAGE } from "./codes.js";
3
+ import { EcpCliError } from "./errors.js";
4
+ import { failureEnvelope } from "./envelope.js";
5
+ import { formatExecutionReport } from "./format-execution.js";
6
+ /**
7
+ * Base class for generated capability and operation commands.
8
+ * Owns the JSON envelope, error codes and exit codes.
9
+ * @category CLI
10
+ */
11
+ export class EcpCommand extends Command {
12
+ static enableJsonFlag = true;
13
+ /**
14
+ * True when the caller passed `--json`. Non-TTY spawn clients keep pretty JSON
15
+ * until they opt in with `--json` (existing CLI tests).
16
+ * @category CLI
17
+ */
18
+ wantsEnvelope() {
19
+ return this.jsonEnabled();
20
+ }
21
+ /**
22
+ * Pretty-print `data` when not using `--json`. With `--json`, oclif prints
23
+ * {@link toSuccessJson} from the `run()` return value.
24
+ * @category CLI
25
+ */
26
+ writeSuccess(data) {
27
+ if (this.jsonEnabled())
28
+ return;
29
+ if (data === undefined)
30
+ return;
31
+ if (typeof data === "string") {
32
+ this.log(data);
33
+ return;
34
+ }
35
+ const report = formatExecutionReport(data);
36
+ this.log(report ?? JSON.stringify(data, null, 2));
37
+ }
38
+ /**
39
+ * oclif `--json` success wrapper. Returns the ECP envelope, not the raw result.
40
+ * @category CLI
41
+ */
42
+ toSuccessJson(result) {
43
+ if (this.argv?.includes("--events"))
44
+ return undefined;
45
+ return { ok: true, data: result };
46
+ }
47
+ /**
48
+ * oclif `--json` error wrapper. Keeps the `ECP_*` code instead of oclif's
49
+ * `{ error: { oclif: { exit } } }` payload.
50
+ * @category CLI
51
+ */
52
+ toErrorJson(error) {
53
+ const data = error instanceof EcpCliError ? error.data : undefined;
54
+ return failureEnvelope(errorBody(error), data);
55
+ }
56
+ /**
57
+ * Print the ECP error envelope (or pretty message) and exit.
58
+ * @category CLI
59
+ */
60
+ async catch(error) {
61
+ const body = errorBody(error);
62
+ const exitCode = exitCodeOf(error);
63
+ const json = this.jsonEnabled() || (this.argv ?? []).includes("--json");
64
+ const data = error instanceof EcpCliError ? error.data : undefined;
65
+ if (json) {
66
+ // `this.log` is a no-op when jsonEnabled() is true; `logJson` always writes.
67
+ this.logJson(this.toErrorJson(error));
68
+ this.exit(exitCode);
69
+ }
70
+ if (data !== undefined) {
71
+ const report = formatExecutionReport(data) ?? JSON.stringify(data, null, 2);
72
+ this.log(report);
73
+ this.exit(exitCode);
74
+ }
75
+ this.error(body.message, { exit: exitCode });
76
+ }
77
+ }
78
+ function errorBody(error) {
79
+ if (error instanceof EcpCliError)
80
+ return error.toBody();
81
+ if (error && typeof error === "object" && "oclif" in error) {
82
+ const err = error;
83
+ const exit = err.oclif?.exit;
84
+ return {
85
+ code: exit === EXIT_USAGE ? ECP_INPUT_INVALID : "ECP_CLI_ERROR",
86
+ message: err.message,
87
+ };
88
+ }
89
+ if (error instanceof Error) {
90
+ return { code: "ECP_CLI_ERROR", message: error.message };
91
+ }
92
+ return { code: "ECP_CLI_ERROR", message: String(error) };
93
+ }
94
+ function exitCodeOf(error) {
95
+ if (error instanceof EcpCliError)
96
+ return error.exitCode;
97
+ if (error && typeof error === "object" && "oclif" in error) {
98
+ const exit = error.oclif?.exit;
99
+ if (typeof exit === "number")
100
+ return exit;
101
+ }
102
+ if (error && typeof error === "object" && "exitCode" in error) {
103
+ const exit = error.exitCode;
104
+ if (typeof exit === "number")
105
+ return exit;
106
+ }
107
+ return EXIT_FAILED;
108
+ }
109
+ //# sourceMappingURL=ecp-command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ecp-command.js","sourceRoot":"","sources":["../src/ecp-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,eAAe,EAAqB,MAAM,eAAe,CAAA;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,C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;IACH,CAAC;IACD,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAA;IAC1D,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAA;AAC1D,CAAC;AAED,SAAS,UAAU,CAAC,KAAc;IAChC,IAAI,KAAK,YAAY,WAAW;QAAE,OAAO,KAAK,CAAC,QAAQ,CAAA;IACvD,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,IAAI,KAAK,EAAE,CAAC;QAC3D,MAAM,IAAI,GAAI,KAAuC,CAAC,KAAK,EAAE,IAAI,CAAA;QACjE,IAAI,OAAO,IAAI,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAA;IAC3C,CAAC;IACD,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,UAAU,IAAI,KAAK,EAAE,CAAC;QAC9D,MAAM,IAAI,GAAI,KAA+B,CAAC,QAAQ,CAAA;QACtD,IAAI,OAAO,IAAI,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAA;IAC3C,CAAC;IACD,OAAO,WAAW,CAAA;AACpB,CAAC"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Structured error body used in the CLI `--json` envelope.
3
+ * @category CLI
4
+ */
5
+ export interface EcpErrorBody {
6
+ /** Stable `ECP_*` (or invoke) code. */
7
+ code: string;
8
+ /** Human-readable message. */
9
+ message: string;
10
+ /** Optional JSON-pointer or flag path. */
11
+ path?: string;
12
+ /** Optional recovery hints. */
13
+ suggestions?: string[];
14
+ /** Structured extras (for example missing-plugin rows). */
15
+ details?: unknown;
16
+ }
17
+ /**
18
+ * Success envelope printed with `--json` or when stdout is not a TTY.
19
+ * @category CLI
20
+ */
21
+ export interface EcpSuccessEnvelope {
22
+ ok: true;
23
+ data: unknown;
24
+ }
25
+ /**
26
+ * Failure envelope printed with `--json` or when stdout is not a TTY.
27
+ * Execution failures (`ecp run`, invoke) include `data` with the same record
28
+ * a successful run would print.
29
+ * @category CLI
30
+ */
31
+ export interface EcpFailureEnvelope {
32
+ ok: false;
33
+ error: EcpErrorBody;
34
+ /** Execution record (`RunResult` or invoke document) when the command ran. */
35
+ data?: unknown;
36
+ }
37
+ /**
38
+ * CLI JSON envelope.
39
+ * @category CLI
40
+ */
41
+ export type EcpEnvelope = EcpSuccessEnvelope | EcpFailureEnvelope;
42
+ /**
43
+ * Build a success envelope.
44
+ * @category CLI
45
+ */
46
+ export declare function successEnvelope(data: unknown): EcpSuccessEnvelope;
47
+ /**
48
+ * Build a failure envelope.
49
+ * @category CLI
50
+ */
51
+ export declare function failureEnvelope(error: EcpErrorBody, data?: unknown): EcpFailureEnvelope;
52
+ //# sourceMappingURL=envelope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../src/envelope.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAA;IACZ,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAA;IACf,0CAA0C;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,+BAA+B;IAC/B,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;IACtB,2DAA2D;IAC3D,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,IAAI,CAAA;IACR,IAAI,EAAE,OAAO,CAAA;CACd;AAED;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,KAAK,CAAA;IACT,KAAK,EAAE,YAAY,CAAA;IACnB,8EAA8E;IAC9E,IAAI,CAAC,EAAE,OAAO,CAAA;CACf;AAED;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,kBAAkB,GAAG,kBAAkB,CAAA;AAEjE;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,GAAG,kBAAkB,CAEjE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,kBAAkB,CAEvF"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Build a success envelope.
3
+ * @category CLI
4
+ */
5
+ export function successEnvelope(data) {
6
+ return { ok: true, data };
7
+ }
8
+ /**
9
+ * Build a failure envelope.
10
+ * @category CLI
11
+ */
12
+ export function failureEnvelope(error, data) {
13
+ return data !== undefined ? { ok: false, error, data } : { ok: false, error };
14
+ }
15
+ //# sourceMappingURL=envelope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envelope.js","sourceRoot":"","sources":["../src/envelope.ts"],"names":[],"mappings":"AA6CA;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,IAAa;IAC3C,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;AAC3B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,KAAmB,EAAE,IAAc;IACjE,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;AAC/E,CAAC"}
@@ -0,0 +1,30 @@
1
+ import type { EcpErrorBody } from "./envelope.js";
2
+ /**
3
+ * Thrown by generated commands and operations so {@link EcpCommand} can print
4
+ * the ECP envelope and set the process exit code.
5
+ * @category CLI
6
+ */
7
+ export declare class EcpCliError extends Error {
8
+ /** Stable `ECP_*` (or invoke) code. */
9
+ readonly code: string;
10
+ /** Optional JSON-pointer or flag path. */
11
+ readonly path?: string;
12
+ /** Optional recovery hints. */
13
+ readonly suggestions?: string[];
14
+ /** Structured extras (for example missing-plugin rows). */
15
+ readonly details?: unknown;
16
+ /** Execution record printed alongside the error (`RunResult` or invoke document). */
17
+ readonly data?: unknown;
18
+ /** Process exit code. */
19
+ readonly exitCode: number;
20
+ constructor(code: string, message: string, options?: {
21
+ path?: string;
22
+ suggestions?: string[];
23
+ exitCode?: number;
24
+ details?: unknown;
25
+ data?: unknown;
26
+ });
27
+ /** Convert to the envelope error body. */
28
+ toBody(): EcpErrorBody;
29
+ }
30
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAEjD;;;;GAIG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC,uCAAuC;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;IACtB,+BAA+B;IAC/B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;IAC/B,2DAA2D;IAC3D,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;IAC1B,qFAAqF;IACrF,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAA;IACvB,yBAAyB;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;gBAGvB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;QACP,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;QACtB,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,OAAO,CAAC,EAAE,OAAO,CAAA;QACjB,IAAI,CAAC,EAAE,OAAO,CAAA;KACV;IAYR,0CAA0C;IAC1C,MAAM,IAAI,YAAY;CASvB"}
package/dist/errors.js ADDED
@@ -0,0 +1,41 @@
1
+ import { EXIT_FAILED } from "./codes.js";
2
+ /**
3
+ * Thrown by generated commands and operations so {@link EcpCommand} can print
4
+ * the ECP envelope and set the process exit code.
5
+ * @category CLI
6
+ */
7
+ export class EcpCliError extends Error {
8
+ /** Stable `ECP_*` (or invoke) code. */
9
+ code;
10
+ /** Optional JSON-pointer or flag path. */
11
+ path;
12
+ /** Optional recovery hints. */
13
+ suggestions;
14
+ /** Structured extras (for example missing-plugin rows). */
15
+ details;
16
+ /** Execution record printed alongside the error (`RunResult` or invoke document). */
17
+ data;
18
+ /** Process exit code. */
19
+ exitCode;
20
+ constructor(code, message, options = {}) {
21
+ super(message);
22
+ this.name = "EcpCliError";
23
+ this.code = code;
24
+ this.path = options.path;
25
+ this.suggestions = options.suggestions;
26
+ this.details = options.details;
27
+ this.data = options.data;
28
+ this.exitCode = options.exitCode ?? EXIT_FAILED;
29
+ }
30
+ /** Convert to the envelope error body. */
31
+ toBody() {
32
+ return {
33
+ code: this.code,
34
+ message: this.message,
35
+ ...(this.path !== undefined ? { path: this.path } : {}),
36
+ ...(this.suggestions !== undefined ? { suggestions: this.suggestions } : {}),
37
+ ...(this.details !== undefined ? { details: this.details } : {}),
38
+ };
39
+ }
40
+ }
41
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAGxC;;;;GAIG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC,uCAAuC;IAC9B,IAAI,CAAQ;IACrB,0CAA0C;IACjC,IAAI,CAAS;IACtB,+BAA+B;IACtB,WAAW,CAAW;IAC/B,2DAA2D;IAClD,OAAO,CAAU;IAC1B,qFAAqF;IAC5E,IAAI,CAAU;IACvB,yBAAyB;IAChB,QAAQ,CAAQ;IAEzB,YACE,IAAY,EACZ,OAAe,EACf,UAMI,EAAE;QAEN,K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