@procedures/mark 0.0.0-stage → 0.2.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 (91) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/LICENSE +21 -0
  3. package/README.md +799 -2
  4. package/dist/.tsbuildinfo +1 -0
  5. package/dist/args.d.ts +77 -0
  6. package/dist/args.d.ts.map +1 -0
  7. package/dist/args.js +351 -0
  8. package/dist/args.js.map +1 -0
  9. package/dist/ask.d.ts +48 -0
  10. package/dist/ask.d.ts.map +1 -0
  11. package/dist/ask.js +91 -0
  12. package/dist/ask.js.map +1 -0
  13. package/dist/bin.d.ts +9 -0
  14. package/dist/bin.d.ts.map +1 -0
  15. package/dist/bin.js +10 -0
  16. package/dist/bin.js.map +1 -0
  17. package/dist/cli.d.ts +61 -0
  18. package/dist/cli.d.ts.map +1 -0
  19. package/dist/cli.js +535 -0
  20. package/dist/cli.js.map +1 -0
  21. package/dist/client-mode.d.ts +21 -0
  22. package/dist/client-mode.d.ts.map +1 -0
  23. package/dist/client-mode.js +75 -0
  24. package/dist/client-mode.js.map +1 -0
  25. package/dist/ecosystem.d.ts +67 -0
  26. package/dist/ecosystem.d.ts.map +1 -0
  27. package/dist/ecosystem.js +212 -0
  28. package/dist/ecosystem.js.map +1 -0
  29. package/dist/failure.d.ts +16 -0
  30. package/dist/failure.d.ts.map +1 -0
  31. package/dist/failure.js +47 -0
  32. package/dist/failure.js.map +1 -0
  33. package/dist/format.d.ts +30 -0
  34. package/dist/format.d.ts.map +1 -0
  35. package/dist/format.js +125 -0
  36. package/dist/format.js.map +1 -0
  37. package/dist/index.d.ts +13 -0
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +13 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/lockfile.d.ts +26 -0
  42. package/dist/lockfile.d.ts.map +1 -0
  43. package/dist/lockfile.js +68 -0
  44. package/dist/lockfile.js.map +1 -0
  45. package/dist/manifest-build.d.ts +7 -0
  46. package/dist/manifest-build.d.ts.map +1 -0
  47. package/dist/manifest-build.js +11 -0
  48. package/dist/manifest-build.js.map +1 -0
  49. package/dist/manifest.d.ts +57 -0
  50. package/dist/manifest.d.ts.map +1 -0
  51. package/dist/manifest.js +140 -0
  52. package/dist/manifest.js.map +1 -0
  53. package/dist/manifest.json +20960 -0
  54. package/dist/parse.d.ts +143 -0
  55. package/dist/parse.d.ts.map +1 -0
  56. package/dist/parse.js +509 -0
  57. package/dist/parse.js.map +1 -0
  58. package/dist/print.d.ts +42 -0
  59. package/dist/print.d.ts.map +1 -0
  60. package/dist/print.js +80 -0
  61. package/dist/print.js.map +1 -0
  62. package/dist/prompts.d.ts +58 -0
  63. package/dist/prompts.d.ts.map +1 -0
  64. package/dist/prompts.js +124 -0
  65. package/dist/prompts.js.map +1 -0
  66. package/dist/repl.d.ts +34 -0
  67. package/dist/repl.d.ts.map +1 -0
  68. package/dist/repl.js +101 -0
  69. package/dist/repl.js.map +1 -0
  70. package/dist/server-mode.d.ts +37 -0
  71. package/dist/server-mode.d.ts.map +1 -0
  72. package/dist/server-mode.js +167 -0
  73. package/dist/server-mode.js.map +1 -0
  74. package/package.json +97 -3
  75. package/src/args.ts +440 -0
  76. package/src/ask.ts +119 -0
  77. package/src/bin.ts +11 -0
  78. package/src/cli.ts +600 -0
  79. package/src/client-mode.ts +90 -0
  80. package/src/ecosystem.ts +260 -0
  81. package/src/failure.ts +47 -0
  82. package/src/format.ts +177 -0
  83. package/src/index.ts +31 -0
  84. package/src/lockfile.ts +85 -0
  85. package/src/manifest-build.ts +12 -0
  86. package/src/manifest.ts +162 -0
  87. package/src/parse.ts +670 -0
  88. package/src/print.ts +108 -0
  89. package/src/prompts.ts +181 -0
  90. package/src/repl.ts +121 -0
  91. package/src/server-mode.ts +205 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-mode.js","sourceRoot":"","sources":["../src/client-mode.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA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AE,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAE,EAAE,CAAC;IACvF,CAAC;IAAC,MAAM,CAAC;QACP,oEAAoE;QACpE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,sFAAsF;IACtF,sFAAsF;IACtF,IAAI,CAAC;QACH,yFAAyF;QACzF,oBAAoB;QACpB,IAAI,IAAoC,CAAC;QACzC,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC;YACtD,IAAI,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;YACvB,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC;QACjB,CAAC;QACD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;QAC9D,CAAC;QACD,OAAO;YACL,OAAO,EAAE,IAAI;YACb,MAAM,EAAE,IAAI,CAAC,KAAK;YAClB,OAAO,EAAE,MAAM,KAAK,SAAS;SAC9B,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;SAC9D,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Workspace-based Procedure Discovery
3
+ *
4
+ * Dynamically discovers and loads procedures from the packages of the
5
+ * monorepo this CLI lives in. This enables the CLI to automatically find
6
+ * all available procedures without hardcoding imports.
7
+ *
8
+ * Discovery flow:
9
+ * 1. Walk up from this module to the folder that holds pnpm-workspace.yaml
10
+ * 2. For each packages/* folder, read its package.json
11
+ * 3. If it has client.procedures, dynamically import it
12
+ * 4. The register.js entry of each package registers its procedures in PROCEDURE_REGISTRY
13
+ */
14
+ import { type ProcedureRegistry } from "@procedures/client";
15
+ interface DiscoveredPackage {
16
+ name: string;
17
+ path: string;
18
+ proceduresPath: string;
19
+ /** The file of the side-effect-free `./module` entry, when the package has one (roadmap 3.1) */
20
+ modulePath?: string | undefined;
21
+ }
22
+ /**
23
+ * Find the workspace root: the nearest folder above this module that holds pnpm-workspace.yaml
24
+ */
25
+ export declare function findWorkspaceRoot(): string | null;
26
+ /**
27
+ * Discover workspace packages that declare client.procedures
28
+ */
29
+ export declare function discoverFromEcosystem(root?: string | null): DiscoveredPackage[];
30
+ /**
31
+ * This function registers all core procedures of `@procedures/client` in the global registry: the
32
+ * control flow and `procedure.*` of `clientModule`, and the math, string, array, object, comparison
33
+ * and type procedures (`client.add` and the others). An import registers none of them
34
+ * (ARCHITECTURE-PROPOSALS-2026-10, P9). (Docs review DOC-6: before, `mark client add` was an
35
+ * unknown command.) A procedure that is registered already stays.
36
+ */
37
+ export declare function registerCoreProcedures(): number;
38
+ /**
39
+ * Dynamically load procedures from discovered packages.
40
+ *
41
+ * A package that fails to load gives one warning line on stderr, also without `verbose`: before,
42
+ * its commands were missing with no message (deep dive CLI-18). A package that is not built yet
43
+ * (no procedures file) is reported only with `verbose`. `warn: false` turns the warnings off (the
44
+ * build of mark writes the manifest while other packages can still be in their build).
45
+ */
46
+ export declare function loadEcosystemProcedures(verbose?: boolean, warn?: boolean): Promise<string[]>;
47
+ /**
48
+ * Get list of ecosystem packages that have procedures
49
+ */
50
+ export declare function listEcosystemProcedurePackages(): Array<{
51
+ name: string;
52
+ path: string;
53
+ }>;
54
+ /** The registry of `mark` and the names of the packages that it holds. */
55
+ export interface EcosystemRegistry {
56
+ registry: ProcedureRegistry;
57
+ loaded: string[];
58
+ }
59
+ /**
60
+ * The registry of `mark` (roadmap 3.1): a registry of its own, built from the module of each
61
+ * workspace package that declares `client.procedures`, with all the core procedures. The global
62
+ * registry does not change for a package with a module entry. A package that fails to load gives
63
+ * one warning line on stderr, as with `loadEcosystemProcedures()`.
64
+ */
65
+ export declare function loadEcosystemRegistry(verbose?: boolean, warn?: boolean): Promise<EcosystemRegistry>;
66
+ export {};
67
+ //# sourceMappingURL=ecosystem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ecosystem.d.ts","sourceRoot":"","sources":["../src/ecosystem.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,EAUL,KAAK,iBAAiB,EACvB,MAAM,oBAAoB,CAAC;AAc5B,UAAU,iBAAiB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,gGAAgG;IAChG,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACjC;AA6BD;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,GAAG,IAAI,CAYjD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,GAAE,MAAM,GAAG,IAA0B,GAAG,iBAAiB,EAAE,CA4BpG;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,IAAI,MAAM,CAS/C;AAED;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CAAC,OAAO,UAAQ,EAAE,IAAI,UAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAuC7F;AAED;;GAEG;AACH,wBAAgB,8BAA8B,IAAI,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAKtF;AAKD,0EAA0E;AAC1E,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAsBD;;;;;GAKG;AACH,wBAAsB,qBAAqB,CAAC,OAAO,UAAQ,EAAE,IAAI,UAAO,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAoBpG"}
@@ -0,0 +1,212 @@
1
+ /**
2
+ * Workspace-based Procedure Discovery
3
+ *
4
+ * Dynamically discovers and loads procedures from the packages of the
5
+ * monorepo this CLI lives in. This enables the CLI to automatically find
6
+ * all available procedures without hardcoding imports.
7
+ *
8
+ * Discovery flow:
9
+ * 1. Walk up from this module to the folder that holds pnpm-workspace.yaml
10
+ * 2. For each packages/* folder, read its package.json
11
+ * 3. If it has client.procedures, dynamically import it
12
+ * 4. The register.js entry of each package registers its procedures in PROCEDURE_REGISTRY
13
+ */
14
+ import * as fs from "node:fs";
15
+ import * as path from "node:path";
16
+ import { fileURLToPath, pathToFileURL } from "node:url";
17
+ import { PROCEDURE_REGISTRY, allCoreProcedures, clientModule, createRegistry, defineModule, pathToKey, registerModules, } from "@procedures/client";
18
+ /** The file of the `./module` export of a package, relative to the package folder. */
19
+ function moduleEntryOf(packageJson) {
20
+ const entry = packageJson.exports?.["./module"];
21
+ if (typeof entry === "string")
22
+ return entry;
23
+ if (entry && typeof entry === "object") {
24
+ const target = entry.import ?? entry.default;
25
+ return typeof target === "string" ? target : undefined;
26
+ }
27
+ return undefined;
28
+ }
29
+ // =============================================================================
30
+ // Discovery
31
+ // =============================================================================
32
+ /**
33
+ * Read and parse JSON file
34
+ */
35
+ function readJson(filePath) {
36
+ try {
37
+ const content = fs.readFileSync(filePath, "utf-8");
38
+ return JSON.parse(content);
39
+ }
40
+ catch {
41
+ return null;
42
+ }
43
+ }
44
+ /**
45
+ * Find the workspace root: the nearest folder above this module that holds pnpm-workspace.yaml
46
+ */
47
+ export function findWorkspaceRoot() {
48
+ let dir = path.dirname(fileURLToPath(import.meta.url));
49
+ for (;;) {
50
+ if (fs.existsSync(path.join(dir, "pnpm-workspace.yaml"))) {
51
+ return dir;
52
+ }
53
+ const parent = path.dirname(dir);
54
+ if (parent === dir) {
55
+ return null;
56
+ }
57
+ dir = parent;
58
+ }
59
+ }
60
+ /**
61
+ * Discover workspace packages that declare client.procedures
62
+ */
63
+ export function discoverFromEcosystem(root = findWorkspaceRoot()) {
64
+ const discovered = [];
65
+ if (!root) {
66
+ // Not running from inside the monorepo, nothing to discover
67
+ return discovered;
68
+ }
69
+ const packagesDir = path.join(root, "packages");
70
+ const entries = fs.readdirSync(packagesDir, { withFileTypes: true });
71
+ for (const entry of entries) {
72
+ if (!entry.isDirectory()) {
73
+ continue;
74
+ }
75
+ const packageDir = path.join(packagesDir, entry.name);
76
+ const packageJson = readJson(path.join(packageDir, "package.json"));
77
+ if (packageJson?.client?.procedures) {
78
+ discovered.push({
79
+ name: packageJson.name,
80
+ path: packageDir,
81
+ proceduresPath: packageJson.client.procedures,
82
+ modulePath: moduleEntryOf(packageJson),
83
+ });
84
+ }
85
+ }
86
+ return discovered;
87
+ }
88
+ /**
89
+ * This function registers all core procedures of `@procedures/client` in the global registry: the
90
+ * control flow and `procedure.*` of `clientModule`, and the math, string, array, object, comparison
91
+ * and type procedures (`client.add` and the others). An import registers none of them
92
+ * (ARCHITECTURE-PROPOSALS-2026-10, P9). (Docs review DOC-6: before, `mark client add` was an
93
+ * unknown command.) A procedure that is registered already stays.
94
+ */
95
+ export function registerCoreProcedures() {
96
+ let added = 0;
97
+ for (const procedure of [...clientModule.procedures, ...allCoreProcedures]) {
98
+ if (!PROCEDURE_REGISTRY.has(procedure.path)) {
99
+ PROCEDURE_REGISTRY.register(procedure);
100
+ added++;
101
+ }
102
+ }
103
+ return added;
104
+ }
105
+ /**
106
+ * Dynamically load procedures from discovered packages.
107
+ *
108
+ * A package that fails to load gives one warning line on stderr, also without `verbose`: before,
109
+ * its commands were missing with no message (deep dive CLI-18). A package that is not built yet
110
+ * (no procedures file) is reported only with `verbose`. `warn: false` turns the warnings off (the
111
+ * build of mark writes the manifest while other packages can still be in their build).
112
+ */
113
+ export async function loadEcosystemProcedures(verbose = false, warn = true) {
114
+ registerCoreProcedures();
115
+ const discovered = discoverFromEcosystem();
116
+ const loaded = [];
117
+ for (const pkg of discovered) {
118
+ // Build the full path to the procedures file
119
+ const proceduresFullPath = path.join(pkg.path, pkg.proceduresPath);
120
+ // Check if file exists
121
+ if (!fs.existsSync(proceduresFullPath)) {
122
+ if (verbose) {
123
+ console.warn(`Procedures file not found (build the package): ${proceduresFullPath}`);
124
+ }
125
+ continue;
126
+ }
127
+ try {
128
+ // Dynamic import - the module will self-register procedures. pathToFileURL escapes
129
+ // "#", "%" and spaces in the path (before, a string join broke such paths).
130
+ await import(pathToFileURL(proceduresFullPath).href);
131
+ loaded.push(pkg.name);
132
+ if (verbose) {
133
+ console.log(`Loaded procedures from: ${pkg.name}`);
134
+ }
135
+ }
136
+ catch (error) {
137
+ const message = error instanceof Error ? error.message.split("\n")[0] : String(error);
138
+ if (warn) {
139
+ console.warn(`mark: the procedures of ${pkg.name} did not load: ${message}`);
140
+ }
141
+ if (verbose && error instanceof Error && error.stack) {
142
+ console.warn(error.stack);
143
+ }
144
+ }
145
+ }
146
+ return loaded;
147
+ }
148
+ /**
149
+ * Get list of ecosystem packages that have procedures
150
+ */
151
+ export function listEcosystemProcedurePackages() {
152
+ return discoverFromEcosystem().map((pkg) => ({
153
+ name: pkg.name,
154
+ path: pkg.path,
155
+ }));
156
+ }
157
+ /** The core procedures that `mark` serves: all of them, also the ones that the core import does not register. */
158
+ const allCoreModule = defineModule("@procedures/client (all core procedures)", allCoreProcedures);
159
+ /**
160
+ * The module of a package: its `./module` entry (it registers nothing), or else the procedures
161
+ * that importing its procedures file adds to the global registry (a package of the old kind).
162
+ */
163
+ async function moduleOfPackage(pkg) {
164
+ if (pkg.modulePath) {
165
+ const file = path.join(pkg.path, pkg.modulePath);
166
+ if (fs.existsSync(file)) {
167
+ const exports = (await import(pathToFileURL(file).href));
168
+ if (exports.default && Array.isArray(exports.default.procedures))
169
+ return exports.default;
170
+ }
171
+ }
172
+ const proceduresFile = path.join(pkg.path, pkg.proceduresPath);
173
+ if (!fs.existsSync(proceduresFile))
174
+ return undefined;
175
+ const before = new Set(PROCEDURE_REGISTRY.getAll().map((procedure) => pathToKey(procedure.path)));
176
+ await import(pathToFileURL(proceduresFile).href);
177
+ const added = PROCEDURE_REGISTRY.getAll().filter((procedure) => !before.has(pathToKey(procedure.path)));
178
+ return { name: pkg.name, procedures: added };
179
+ }
180
+ /**
181
+ * The registry of `mark` (roadmap 3.1): a registry of its own, built from the module of each
182
+ * workspace package that declares `client.procedures`, with all the core procedures. The global
183
+ * registry does not change for a package with a module entry. A package that fails to load gives
184
+ * one warning line on stderr, as with `loadEcosystemProcedures()`.
185
+ */
186
+ export async function loadEcosystemRegistry(verbose = false, warn = true) {
187
+ const registry = createRegistry(allCoreModule);
188
+ const loaded = [];
189
+ for (const pkg of discoverFromEcosystem()) {
190
+ try {
191
+ const module = await moduleOfPackage(pkg);
192
+ if (!module) {
193
+ if (verbose)
194
+ console.warn(`Procedures file not found (build the package): ${path.join(pkg.path, pkg.proceduresPath)}`);
195
+ continue;
196
+ }
197
+ registerModules(registry, [module]);
198
+ loaded.push(pkg.name);
199
+ if (verbose)
200
+ console.log(`Loaded procedures from: ${pkg.name}`);
201
+ }
202
+ catch (error) {
203
+ const message = error instanceof Error ? error.message.split("\n")[0] : String(error);
204
+ if (warn)
205
+ console.warn(`mark: the procedures of ${pkg.name} did not load: ${message}`);
206
+ if (verbose && error instanceof Error && error.stack)
207
+ console.warn(error.stack);
208
+ }
209
+ }
210
+ return { registry, loaded };
211
+ }
212
+ //# sourceMappingURL=ecosystem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ecosystem.js","sourceRoot":"","sources":["../src/ecosystem.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,SAAS,EACT,eAAe,GAIhB,MAAM,oBAAoB,CAAC;AAsB5B,sFAAsF;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;YACD,eAAe,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;YACpC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACtB,IAAI,OAAO;gBAAE,OAAO,CAAC,GAAG,CAAC,2BAA2B,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;QAClE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACtF,IAAI,IAAI;gBAAE,OAAO,CAAC,IAAI,CAAC,2BAA2B,GAAG,CAAC,IAAI,kBAAkB,OAAO,EAAE,CAAC,CAAC;YACvF,IAAI,OAAO,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,KAAK;gBAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAClF,CAAC;IACH,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Procedure-level failure
3
+ *
4
+ * A procedure reports a failure in one of three ways, and `mark` exits with code 1 for each:
5
+ *
6
+ * 1. It throws an error. This is the usual way.
7
+ * 2. It returns an object with `success: false`. Use this when the result has more to show,
8
+ * for example the list of problems of `lib audit`.
9
+ * 3. It returns an object with a numeric `exitCode` that is not 0. Use this for a procedure that
10
+ * runs an external command (`vitest run`, `shell run`), so the caller sees the command's result.
11
+ *
12
+ * For a streaming procedure, each item is examined: one failed item makes the command fail.
13
+ */
14
+ /** A short description of the failure that a result reports, or undefined when it reports none */
15
+ export declare function failureOf(result: unknown): string | undefined;
16
+ //# sourceMappingURL=failure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"failure.d.ts","sourceRoot":"","sources":["../src/failure.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,kGAAkG;AAClG,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAa7D"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Procedure-level failure
3
+ *
4
+ * A procedure reports a failure in one of three ways, and `mark` exits with code 1 for each:
5
+ *
6
+ * 1. It throws an error. This is the usual way.
7
+ * 2. It returns an object with `success: false`. Use this when the result has more to show,
8
+ * for example the list of problems of `lib audit`.
9
+ * 3. It returns an object with a numeric `exitCode` that is not 0. Use this for a procedure that
10
+ * runs an external command (`vitest run`, `shell run`), so the caller sees the command's result.
11
+ *
12
+ * For a streaming procedure, each item is examined: one failed item makes the command fail.
13
+ */
14
+ /** A short description of the failure that a result reports, or undefined when it reports none */
15
+ export function failureOf(result) {
16
+ if (!result || typeof result !== "object" || Array.isArray(result)) {
17
+ return undefined;
18
+ }
19
+ const record = result;
20
+ const exitCode = record["exitCode"];
21
+ if (typeof exitCode === "number" && exitCode !== 0) {
22
+ return `exit code ${exitCode}`;
23
+ }
24
+ if (record["success"] === false) {
25
+ return firstText(record["error"]) ?? firstText(record["errors"]) ?? firstText(record["message"]) ?? "success: false";
26
+ }
27
+ return undefined;
28
+ }
29
+ /** The first text of a value: a string, the message of an error object, or the first of a list */
30
+ function firstText(value) {
31
+ if (typeof value === "string" && value.length > 0) {
32
+ return value;
33
+ }
34
+ if (Array.isArray(value)) {
35
+ for (const item of value) {
36
+ const text = firstText(item);
37
+ if (text)
38
+ return text;
39
+ }
40
+ return undefined;
41
+ }
42
+ if (value && typeof value === "object" && typeof value.message === "string") {
43
+ return value.message;
44
+ }
45
+ return undefined;
46
+ }
47
+ //# sourceMappingURL=failure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"failure.js","sourceRoot":"","sources":["../src/failure.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,kGAAk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O,CAAC;IAChD,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Output Formatting
3
+ *
4
+ * Formats procedure results for CLI output based on metadata hints.
5
+ */
6
+ export type OutputFormat = "text" | "json" | "table" | "streaming";
7
+ /**
8
+ * Print interface (used by formatOutput)
9
+ */
10
+ export interface Print {
11
+ info: (message: string) => void;
12
+ error: (message: string) => void;
13
+ success: (message: string) => void;
14
+ warning: (message: string) => void;
15
+ table: (data: string[][], options?: {
16
+ format?: string;
17
+ }) => void;
18
+ spin: (message: string) => Spinner;
19
+ }
20
+ export interface Spinner {
21
+ stop: () => void;
22
+ succeed: (message?: string) => void;
23
+ fail: (message?: string) => void;
24
+ text: string;
25
+ }
26
+ /**
27
+ * Format and print the result based on output format hint
28
+ */
29
+ export declare function formatOutput(print: Print, result: unknown, format?: OutputFormat): void;
30
+ //# sourceMappingURL=format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,WAAW,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,KAAK;IACpB,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACjE,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;CACpC;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,OAAO,EAAE,CAAC,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,IAAI,EAAE,CAAC,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,OAAO,EACf,MAAM,GAAE,YAAqB,GAC5B,IAAI,CAoBN"}
package/dist/format.js ADDED
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Output Formatting
3
+ *
4
+ * Formats procedure results for CLI output based on metadata hints.
5
+ */
6
+ /**
7
+ * Format and print the result based on output format hint
8
+ */
9
+ export function formatOutput(print, result, format = "text") {
10
+ if (result === undefined || result === null) {
11
+ return;
12
+ }
13
+ switch (format) {
14
+ case "json":
15
+ print.info(JSON.stringify(result, null, 2));
16
+ break;
17
+ case "table":
18
+ formatTable(print, result);
19
+ break;
20
+ case "text":
21
+ case "streaming":
22
+ default:
23
+ formatText(print, result);
24
+ break;
25
+ }
26
+ }
27
+ /**
28
+ * Format as text - handles common result shapes
29
+ */
30
+ function formatText(print, result) {
31
+ // String output
32
+ if (typeof result === "string") {
33
+ print.info(result);
34
+ return;
35
+ }
36
+ // Result with output field (common pattern)
37
+ if (isObjectWithOutput(result)) {
38
+ print.info(result.output);
39
+ return;
40
+ }
41
+ // Result with message field
42
+ if (isObjectWithMessage(result)) {
43
+ if (result.success === false) {
44
+ print.error(result.message);
45
+ }
46
+ else {
47
+ print.success(result.message);
48
+ }
49
+ return;
50
+ }
51
+ // Result with error field
52
+ if (isObjectWithError(result)) {
53
+ print.error(result.error);
54
+ return;
55
+ }
56
+ // Array of items
57
+ if (Array.isArray(result)) {
58
+ for (const item of result) {
59
+ formatText(print, item);
60
+ }
61
+ return;
62
+ }
63
+ // Fallback to JSON
64
+ print.info(JSON.stringify(result, null, 2));
65
+ }
66
+ /**
67
+ * Format as table - handles arrays of objects
68
+ */
69
+ function formatTable(print, result) {
70
+ // Result with rows/headers
71
+ if (isTableResult(result)) {
72
+ const headers = result.headers ?? Object.keys(result.rows[0] ?? {});
73
+ const data = [headers];
74
+ for (const row of result.rows) {
75
+ if (Array.isArray(row)) {
76
+ data.push(row.map(String));
77
+ }
78
+ else if (typeof row === "object" && row !== null) {
79
+ data.push(headers.map((h) => String(row[h] ?? "")));
80
+ }
81
+ }
82
+ print.table(data);
83
+ return;
84
+ }
85
+ // Plain array of objects
86
+ if (Array.isArray(result) && result.length > 0 && typeof result[0] === "object") {
87
+ const headers = Object.keys(result[0]);
88
+ const data = [headers];
89
+ for (const row of result) {
90
+ if (typeof row === "object" && row !== null) {
91
+ data.push(headers.map((h) => String(row[h] ?? "")));
92
+ }
93
+ }
94
+ print.table(data);
95
+ return;
96
+ }
97
+ // Fallback to text
98
+ formatText(print, result);
99
+ }
100
+ // Type guards
101
+ function isObjectWithOutput(val) {
102
+ return (typeof val === "object" &&
103
+ val !== null &&
104
+ "output" in val &&
105
+ typeof val.output === "string");
106
+ }
107
+ function isObjectWithMessage(val) {
108
+ return (typeof val === "object" &&
109
+ val !== null &&
110
+ "message" in val &&
111
+ typeof val.message === "string");
112
+ }
113
+ function isObjectWithError(val) {
114
+ return (typeof val === "object" &&
115
+ val !== null &&
116
+ "error" in val &&
117
+ typeof val.error === "string");
118
+ }
119
+ function isTableResult(val) {
120
+ return (typeof val === "object" &&
121
+ val !== null &&
122
+ "rows" in val &&
123
+ Array.isArray(val.rows));
124
+ }
125
+ //# sourceMappingURL=format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.js","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAuBH;;GAEG;AACH,MAAM,UAAU,YAAY,CAC1B,KAAY,EACZ,MAAe,EACf,MAAM,GAAiB,MAAM;IAE7B,IAAI,MAAM,KAA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KAAK,QAAQ,CACtD,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,GAAY;IACjC,OAAO,CACL,OAAO,GAAG,KAAK,QAAQ;QACvB,GAAG,KAAK,IAAI;QACZ,MAAM,IAAI,GAAG;QACb,KAAK,CAAC,OAAO,CAAE,GAAyB,CAAC,IAAI,CAAC,CAC/C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Mark CLI
3
+ *
4
+ * A generic CLI that reflects registered procedures from client packages.
5
+ * Importing this module runs nothing: the `mark` bin (`dist/bin.js`) runs the CLI.
6
+ */
7
+ export { run, main, executeArgs, initCli, type CliContext } from "./cli.js";
8
+ export { parseCommandLine, parseLeadingGlobals, type ParsedCommandLine, type Globals } from "./args.js";
9
+ export { failureOf } from "./failure.js";
10
+ export { parseFromSchema, generateHelp, extractSchemaFields, convertValue, type CLIMeta, type FieldType, type SchemaFieldInfo, } from "./parse.js";
11
+ export { formatOutput, type OutputFormat } from "./format.js";
12
+ export { readLockfile, writeLockfile, removeLockfile, isServerAlive, getLockfilePath, getLockfileDir, getLogPath, rotateLogFile, type LockfileData, } from "./lockfile.js";
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,KAAK,iBAAiB,EAAE,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AACxG,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EACL,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,YAAY,EACZ,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,eAAe,GACrB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EACL,YAAY,EACZ,aAAa,EACb,cAAc,EACd,aAAa,EACb,eAAe,EACf,cAAc,EACd,UAAU,EACV,aAAa,EACb,KAAK,YAAY,GAClB,MAAM,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Mark CLI
3
+ *
4
+ * A generic CLI that reflects registered procedures from client packages.
5
+ * Importing this module runs nothing: the `mark` bin (`dist/bin.js`) runs the CLI.
6
+ */
7
+ export { run, main, executeArgs, initCli } from "./cli.js";
8
+ export { parseCommandLine, parseLeadingGlobals } from "./args.js";
9
+ export { failureOf } from "./failure.js";
10
+ export { parseFromSchema, generateHelp, extractSchemaFields, convertValue, } from "./parse.js";
11
+ export { formatOutput } from "./format.js";
12
+ export { readLockfile, writeLockfile, removeLockfile, isServerAlive, getLockfilePath, getLockfileDir, getLogPath, rotateLogFile, } from "./lockfile.js";
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAmB,MAAM,UAAU,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAwC,MAAM,WAAW,CAAC;AACxG,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EACL,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,YAAY,GAIb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAqB,MAAM,aAAa,CAAC;AAC9D,OAAO,EACL,YAAY,EACZ,aAAa,EACb,cAAc,EACd,aAAa,EACb,eAAe,EACf,cAAc,EACd,UAAU,EACV,aAAa,GAEd,MAAM,eAAe,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Lockfiles of the CLI server: `mark` uses the shared module of `client-server`, so `mark` and the
3
+ * `server.*` procedures read and write the same files the same way (deep dive CLI-4). This module
4
+ * adds what only `mark` needs: the log file and the build id.
5
+ */
6
+ import { checkServer, findServer, readAllLockfiles, readLockfileForPort, removeLockfileForPort, type LockfileData } from "@procedures/peer/lockfile";
7
+ export type { LockfileData };
8
+ export { checkServer, findServer, readAllLockfiles, readLockfileForPort, removeLockfileForPort };
9
+ /**
10
+ * The build of this `mark`: its file and the time of its last build. A warm server runs only the
11
+ * commands of the same build (deep dive CLI-14): after `pnpm build`, or from another checkout,
12
+ * the CLI runs the command itself.
13
+ */
14
+ export declare function currentBuild(): string;
15
+ export declare function writeLockfile(data: LockfileData): Promise<void>;
16
+ /** The first lockfile whose server answers as its peer (any folder, any build). */
17
+ export declare function readLockfile(): Promise<LockfileData | null>;
18
+ /** True when the lockfile's server answers as its peer. A dead server's lockfile is removed. */
19
+ export declare function isServerAlive(lockfile: LockfileData): Promise<boolean>;
20
+ /** This function removes the lockfile of the default port (3000). */
21
+ export declare function removeLockfile(): Promise<void>;
22
+ export declare function getLockfileDir(): string;
23
+ export declare function getLockfilePath(): string;
24
+ export declare function getLogPath(): string;
25
+ export declare function rotateLogFile(): Promise<void>;
26
+ //# sourceMappingURL=lockfile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lockfile.d.ts","sourceRoot":"","sources":["../src/lockfile.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,EACL,WAAW,EACX,UAAU,EAGV,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EAErB,KAAK,YAAY,EAClB,MAAM,2BAA2B,CAAC;AAEnC,YAAY,EAAE,YAAY,EAAE,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,CAAC;AAKjG;;;;GAIG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAOrC;AAED,wBAAsB,aAAa,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAErE;AAED,mFAAmF;AACnF,wBAAsB,YAAY,IAAI,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAKjE;AAED,gGAAgG;AAChG,wBAAsB,aAAa,CAAC,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAI5E;AAED,qEAAqE;AACrE,wBAAsB,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAEpD;AAED,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED,wBAAsB,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAOnD"}