@procedures/procedure 0.0.0-stage → 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 (40) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/LICENSE +21 -0
  3. package/README.md +405 -2
  4. package/dist/.tsbuildinfo +1 -0
  5. package/dist/index.d.ts +9 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +12 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/module.d.ts +17 -0
  10. package/dist/module.d.ts.map +1 -0
  11. package/dist/module.js +41 -0
  12. package/dist/module.js.map +1 -0
  13. package/dist/procedures/procedure/index.d.ts +5 -0
  14. package/dist/procedures/procedure/index.d.ts.map +1 -0
  15. package/dist/procedures/procedure/index.js +5 -0
  16. package/dist/procedures/procedure/index.js.map +1 -0
  17. package/dist/procedures/procedure/new.d.ts +54 -0
  18. package/dist/procedures/procedure/new.d.ts.map +1 -0
  19. package/dist/procedures/procedure/new.js +442 -0
  20. package/dist/procedures/procedure/new.js.map +1 -0
  21. package/dist/procedures/procedure/registry.d.ts +10 -0
  22. package/dist/procedures/procedure/registry.d.ts.map +1 -0
  23. package/dist/procedures/procedure/registry.js +67 -0
  24. package/dist/procedures/procedure/registry.js.map +1 -0
  25. package/dist/register.d.ts +8 -0
  26. package/dist/register.d.ts.map +1 -0
  27. package/dist/register.js +16 -0
  28. package/dist/register.js.map +1 -0
  29. package/dist/types.d.ts +29 -0
  30. package/dist/types.d.ts.map +1 -0
  31. package/dist/types.js +34 -0
  32. package/dist/types.js.map +1 -0
  33. package/package.json +72 -3
  34. package/src/index.ts +14 -0
  35. package/src/module.ts +50 -0
  36. package/src/procedures/procedure/index.ts +5 -0
  37. package/src/procedures/procedure/new.ts +493 -0
  38. package/src/procedures/procedure/registry.ts +92 -0
  39. package/src/register.ts +19 -0
  40. package/src/types.ts +63 -0
@@ -0,0 +1,92 @@
1
+ /**
2
+ * procedure.* Registry Procedures
3
+ *
4
+ * Procedures for managing the procedure registry dynamically.
5
+ * Enables procedure-as-data patterns, remote registration, and persistence.
6
+ */
7
+
8
+ import { defineProcedure, PROCEDURE_REGISTRY, pathToKey, keyToPath } from "@procedures/client";
9
+ import type { AnyProcedure, ProcedurePath } from "@procedures/client";
10
+ import { z } from "zod";
11
+
12
+ // procedure.list and procedure.get are core procedures (`@procedures/client`, in
13
+ // define-procedure.ts). This package gave its own versions for the whole registry and replaced
14
+ // the core ones, so the results depended on the imports of the host (docs review DOC-6). The core
15
+ // versions now list and describe the whole registry of the caller, with a `runtime` flag.
16
+
17
+ // =============================================================================
18
+ // procedure.export - Export procedure as JSON
19
+ // =============================================================================
20
+
21
+ const ProcedureExportInputSchema = z.object({
22
+ /** Procedure path (array or dot-separated) */
23
+ path: z.union([z.array(z.string()), z.string()]).describe("Procedure path (array or dot-separated)"),
24
+ });
25
+
26
+ type ProcedureExportInput = z.infer<typeof ProcedureExportInputSchema>;
27
+
28
+ interface ProcedureExportOutput {
29
+ /** Whether export succeeded */
30
+ success: boolean;
31
+ /** Exported procedure definition */
32
+ definition?: {
33
+ $proc: ProcedurePath;
34
+ metadata?: Record<string, unknown> | undefined;
35
+ };
36
+ /** Error if failed */
37
+ error?: string;
38
+ }
39
+
40
+ /** The output of `procedure.export` (roadmap 2.1: before, a pass-through schema) */
41
+ const ProcedureExportOutputSchema = z.looseObject({
42
+ success: z.boolean().describe("True when the registry has the procedure"),
43
+ definition: z
44
+ .looseObject({
45
+ $proc: z.array(z.string()).describe("The path of the procedure"),
46
+ metadata: z.record(z.string(), z.unknown()).optional().describe("The metadata of the procedure"),
47
+ })
48
+ .optional()
49
+ .describe("The procedure as a procedure reference, when it exists"),
50
+ error: z.string().optional().describe("The error message when the registry has no such procedure"),
51
+ }) as z.ZodType<ProcedureExportOutput>;
52
+
53
+ export const procedureExportProcedure: AnyProcedure = defineProcedure({
54
+ path: ["procedure", "export"],
55
+ input: ProcedureExportInputSchema,
56
+ output: ProcedureExportOutputSchema,
57
+ metadata: {
58
+ description: "Export a procedure definition as JSON",
59
+ tags: ["procedure", "registry"],
60
+ args: ["path"],
61
+ shorts: {},
62
+ output: "json",
63
+ },
64
+ handler: async (input: ProcedureExportInput): Promise<ProcedureExportOutput> => {
65
+ const path = typeof input.path === "string"
66
+ ? keyToPath(input.path)
67
+ : input.path;
68
+
69
+ const proc = PROCEDURE_REGISTRY.get(path);
70
+
71
+ if (!proc) {
72
+ return {
73
+ success: false,
74
+ error: `Procedure not found: ${pathToKey(path)}`,
75
+ };
76
+ }
77
+
78
+ return {
79
+ success: true,
80
+ definition: {
81
+ $proc: proc.path,
82
+ metadata: proc.metadata as Record<string, unknown> | undefined,
83
+ },
84
+ };
85
+ },
86
+ });
87
+
88
+ // =============================================================================
89
+ // Export all procedure.* procedures
90
+ // =============================================================================
91
+
92
+ export const procedureRegistryProcedures: AnyProcedure[] = [procedureExportProcedure];
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Importing this file registers the procedures of @procedures/procedure in the global
3
+ * registry (DECISIONS-2026-10, "Every package root registers its procedures"). The procedures as
4
+ * data are in `module.ts`, which registers nothing: a host with its own registry uses that one.
5
+ */
6
+
7
+ import { PROCEDURE_REGISTRY } from "@procedures/client";
8
+ import { procedureModule } from "./module.js";
9
+
10
+ export * from "./module.js";
11
+
12
+ export function registerProcedureProcedures(): void {
13
+ // Override makes the registration idempotent. procedure.list and procedure.get are the core
14
+ // ones: this package does not replace them (docs review DOC-6).
15
+ PROCEDURE_REGISTRY.registerAll(procedureModule.procedures, { override: true });
16
+ }
17
+
18
+ // Auto-register
19
+ registerProcedureProcedures();
package/src/types.ts ADDED
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Type definitions for client-procedure
3
+ */
4
+
5
+ import { z } from "zod";
6
+
7
+ // =============================================================================
8
+ // procedure.new Types
9
+ // =============================================================================
10
+
11
+ export const ProcedureNewInputSchema: z.ZodObject<{
12
+ name: z.ZodString;
13
+ namespace: z.ZodOptional<z.ZodString>;
14
+ description: z.ZodOptional<z.ZodString>;
15
+ path: z.ZodOptional<z.ZodString>;
16
+ dryRun: z.ZodDefault<z.ZodBoolean>;
17
+ }> = z.object({
18
+ /** Procedure name (e.g., "greet", "user.create" or "fs.readJson") */
19
+ name: z
20
+ .string()
21
+ .regex(
22
+ /^[a-z][a-zA-Z0-9]*(\.[a-z][a-zA-Z0-9]*)*$/,
23
+ "Name must be dot-separated segments, each starting with a lowercase letter (camelCase is allowed)"
24
+ ).describe("Procedure name (e.g., \"greet\", \"user.create\" or \"fs.readJson\")"),
25
+ /** Namespace override (defaults to first segment of name): the folder under src/procedures */
26
+ namespace: z
27
+ .string()
28
+ .regex(/^[a-z][a-zA-Z0-9]*$/, "Namespace must be one segment that starts with a lowercase letter")
29
+ .optional().describe("Namespace override (defaults to first segment of name): the folder under src/procedures"),
30
+ /** Procedure description for CLI help */
31
+ description: z.string().optional().describe("Procedure description for CLI help"),
32
+ /** Project path (defaults to cwd) */
33
+ path: z.string().optional().describe("Project path (defaults to cwd)"),
34
+ /** Preview changes without creating */
35
+ dryRun: z.boolean().default(false).describe("Preview changes without creating"),
36
+ });
37
+
38
+ export type ProcedureNewInput = z.infer<typeof ProcedureNewInputSchema>;
39
+
40
+ export interface ProcedureNewOutput {
41
+ /** Whether creation succeeded */
42
+ success: boolean;
43
+ /** Full procedure path (e.g., ["user", "create"]) */
44
+ procedurePath: string[];
45
+ /** Files created */
46
+ created: string[];
47
+ /** Files modified */
48
+ modified: string[];
49
+ /** Operations performed */
50
+ operations: string[];
51
+ /** Any errors encountered */
52
+ errors: string[];
53
+ }
54
+
55
+ /** The output schema of procedure.new (roadmap 2.1). Loose: a field that it does not name stays. */
56
+ export const ProcedureNewOutputSchema: z.ZodType<ProcedureNewOutput> = z.looseObject({
57
+ success: z.boolean().describe("True when the procedure was made"),
58
+ procedurePath: z.array(z.string()).describe('The path of the new procedure, for example ["user", "create"]'),
59
+ created: z.array(z.string()).describe("The files that the call made"),
60
+ modified: z.array(z.string()).describe("The files that the call changed (types.ts, register.ts)"),
61
+ operations: z.array(z.string()).describe("The steps that the call ran"),
62
+ errors: z.array(z.string()).describe("The errors"),
63
+ });