@zaowu-labs/cli 1.0.1

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 (102) hide show
  1. package/README.md +16 -0
  2. package/dist/args.d.ts +11 -0
  3. package/dist/args.d.ts.map +1 -0
  4. package/dist/args.js +65 -0
  5. package/dist/args.js.map +1 -0
  6. package/dist/command-contracts.d.ts +11 -0
  7. package/dist/command-contracts.d.ts.map +1 -0
  8. package/dist/command-contracts.js +74 -0
  9. package/dist/command-contracts.js.map +1 -0
  10. package/dist/domain-handlers.d.ts +4 -0
  11. package/dist/domain-handlers.d.ts.map +1 -0
  12. package/dist/domain-handlers.js +65 -0
  13. package/dist/domain-handlers.js.map +1 -0
  14. package/dist/domains.d.ts +4 -0
  15. package/dist/domains.d.ts.map +1 -0
  16. package/dist/domains.js +22 -0
  17. package/dist/domains.js.map +1 -0
  18. package/dist/handler-utils.d.ts +59 -0
  19. package/dist/handler-utils.d.ts.map +1 -0
  20. package/dist/handler-utils.js +113 -0
  21. package/dist/handler-utils.js.map +1 -0
  22. package/dist/handlers/ai-handlers.d.ts +4 -0
  23. package/dist/handlers/ai-handlers.d.ts.map +1 -0
  24. package/dist/handlers/ai-handlers.js +159 -0
  25. package/dist/handlers/ai-handlers.js.map +1 -0
  26. package/dist/handlers/auto-handlers.d.ts +5 -0
  27. package/dist/handlers/auto-handlers.d.ts.map +1 -0
  28. package/dist/handlers/auto-handlers.js +132 -0
  29. package/dist/handlers/auto-handlers.js.map +1 -0
  30. package/dist/handlers/config-handlers.d.ts +8 -0
  31. package/dist/handlers/config-handlers.d.ts.map +1 -0
  32. package/dist/handlers/config-handlers.js +140 -0
  33. package/dist/handlers/config-handlers.js.map +1 -0
  34. package/dist/handlers/data-handlers.d.ts +8 -0
  35. package/dist/handlers/data-handlers.d.ts.map +1 -0
  36. package/dist/handlers/data-handlers.js +135 -0
  37. package/dist/handlers/data-handlers.js.map +1 -0
  38. package/dist/handlers/dev-handlers.d.ts +6 -0
  39. package/dist/handlers/dev-handlers.d.ts.map +1 -0
  40. package/dist/handlers/dev-handlers.js +322 -0
  41. package/dist/handlers/dev-handlers.js.map +1 -0
  42. package/dist/handlers/doc-handlers.d.ts +7 -0
  43. package/dist/handlers/doc-handlers.d.ts.map +1 -0
  44. package/dist/handlers/doc-handlers.js +133 -0
  45. package/dist/handlers/doc-handlers.js.map +1 -0
  46. package/dist/handlers/plugin-handlers.d.ts +6 -0
  47. package/dist/handlers/plugin-handlers.d.ts.map +1 -0
  48. package/dist/handlers/plugin-handlers.js +149 -0
  49. package/dist/handlers/plugin-handlers.js.map +1 -0
  50. package/dist/handlers/teach-handlers.d.ts +4 -0
  51. package/dist/handlers/teach-handlers.d.ts.map +1 -0
  52. package/dist/handlers/teach-handlers.js +30 -0
  53. package/dist/handlers/teach-handlers.js.map +1 -0
  54. package/dist/handlers/web-handlers.d.ts +4 -0
  55. package/dist/handlers/web-handlers.d.ts.map +1 -0
  56. package/dist/handlers/web-handlers.js +90 -0
  57. package/dist/handlers/web-handlers.js.map +1 -0
  58. package/dist/help-text.d.ts +2 -0
  59. package/dist/help-text.d.ts.map +1 -0
  60. package/dist/help-text.js +439 -0
  61. package/dist/help-text.js.map +1 -0
  62. package/dist/index.d.ts +3 -0
  63. package/dist/index.d.ts.map +1 -0
  64. package/dist/index.js +5 -0
  65. package/dist/index.js.map +1 -0
  66. package/dist/option-validation.d.ts +5 -0
  67. package/dist/option-validation.d.ts.map +1 -0
  68. package/dist/option-validation.js +111 -0
  69. package/dist/option-validation.js.map +1 -0
  70. package/dist/output.d.ts +5 -0
  71. package/dist/output.d.ts.map +1 -0
  72. package/dist/output.js +11 -0
  73. package/dist/output.js.map +1 -0
  74. package/dist/root-doctor.d.ts +22 -0
  75. package/dist/root-doctor.d.ts.map +1 -0
  76. package/dist/root-doctor.js +231 -0
  77. package/dist/root-doctor.js.map +1 -0
  78. package/dist/root-help.d.ts +8 -0
  79. package/dist/root-help.d.ts.map +1 -0
  80. package/dist/root-help.js +130 -0
  81. package/dist/root-help.js.map +1 -0
  82. package/dist/root-init.d.ts +4 -0
  83. package/dist/root-init.d.ts.map +1 -0
  84. package/dist/root-init.js +87 -0
  85. package/dist/root-init.js.map +1 -0
  86. package/dist/run.d.ts +8 -0
  87. package/dist/run.d.ts.map +1 -0
  88. package/dist/run.js +152 -0
  89. package/dist/run.js.map +1 -0
  90. package/dist/system-command.d.ts +3 -0
  91. package/dist/system-command.d.ts.map +1 -0
  92. package/dist/system-command.js +27 -0
  93. package/dist/system-command.js.map +1 -0
  94. package/dist/types.d.ts +16 -0
  95. package/dist/types.d.ts.map +1 -0
  96. package/dist/types.js +2 -0
  97. package/dist/types.js.map +1 -0
  98. package/dist/version.d.ts +2 -0
  99. package/dist/version.d.ts.map +1 -0
  100. package/dist/version.js +14 -0
  101. package/dist/version.js.map +1 -0
  102. package/package.json +54 -0
@@ -0,0 +1,231 @@
1
+ import path from 'node:path';
2
+ import { validateAIProviderConfig } from '@zaowu-labs/ai';
3
+ import { findConfigFile, loadResolvedConfig } from '@zaowu-labs/config';
4
+ import { createOperationPlan, isZaoWuError } from '@zaowu-labs/core';
5
+ import { COMMAND_CONTRACTS } from './command-contracts.js';
6
+ import { runSystemCommand } from './system-command.js';
7
+ const MINIMUM_NODE_VERSION = '20.19.0';
8
+ const MINIMUM_PNPM_VERSION = '10.34.1';
9
+ const MAXIMUM_PNPM_MAJOR = 11;
10
+ const ADDITIONAL_ROOT_SURFACES_IN_CAPABILITY_MATRIX = 3;
11
+ const PNPM_MISSING_FIX = 'Run `corepack enable` or install pnpm.';
12
+ const PNPM_VERSION_FIX = `Use pnpm ${MINIMUM_PNPM_VERSION} through Corepack: ` +
13
+ `corepack prepare pnpm@${MINIMUM_PNPM_VERSION} --activate.`;
14
+ const satisfiesMinimumVersion = (version, minimum) => {
15
+ const parse = (value) => value
16
+ .replace(/^v/, '')
17
+ .split('.')
18
+ .map((part) => Number.parseInt(part, 10) || 0);
19
+ const actual = parse(version);
20
+ const required = parse(minimum);
21
+ const length = Math.max(actual.length, required.length);
22
+ for (let index = 0; index < length; index += 1) {
23
+ const actualPart = actual[index] ?? 0;
24
+ const requiredPart = required[index] ?? 0;
25
+ if (actualPart > requiredPart) {
26
+ return true;
27
+ }
28
+ if (actualPart < requiredPart) {
29
+ return false;
30
+ }
31
+ }
32
+ return true;
33
+ };
34
+ const extractVersion = (output) => {
35
+ const match = output.match(/v?\d+(?:\.\d+)+(?:[-.\w]*)?/);
36
+ return match?.[0];
37
+ };
38
+ const getMajorVersion = (version) => Number.parseInt(version.replace(/^v/, '').split('.')[0] ?? '', 10) || 0;
39
+ const satisfiesPnpmVersion = (version) => Boolean(version &&
40
+ satisfiesMinimumVersion(version, MINIMUM_PNPM_VERSION) &&
41
+ getMajorVersion(version) < MAXIMUM_PNPM_MAJOR);
42
+ const checkCommand = (name, command, args, fix, commandRunner, details) => {
43
+ try {
44
+ const output = commandRunner(command, args);
45
+ return {
46
+ name,
47
+ status: 'ok',
48
+ version: extractVersion(output),
49
+ details,
50
+ };
51
+ }
52
+ catch {
53
+ return {
54
+ name,
55
+ status: 'missing',
56
+ fix,
57
+ };
58
+ }
59
+ };
60
+ const checkPnpmCommand = (command, args, commandRunner, details) => {
61
+ try {
62
+ const output = commandRunner(command, args);
63
+ const version = extractVersion(output);
64
+ const isSupported = satisfiesPnpmVersion(version);
65
+ return {
66
+ name: 'pnpm',
67
+ status: isSupported ? 'ok' : 'warning',
68
+ version,
69
+ details,
70
+ fix: isSupported ? undefined : PNPM_VERSION_FIX,
71
+ };
72
+ }
73
+ catch {
74
+ return {
75
+ name: 'pnpm',
76
+ status: 'missing',
77
+ fix: PNPM_MISSING_FIX,
78
+ };
79
+ }
80
+ };
81
+ const checkPnpm = (commandRunner) => {
82
+ const pnpmCheck = checkPnpmCommand('pnpm', ['--version'], commandRunner);
83
+ if (pnpmCheck.status === 'ok') {
84
+ return pnpmCheck;
85
+ }
86
+ const corepackPnpmCheck = checkPnpmCommand('corepack', ['pnpm', '--version'], commandRunner, 'via corepack');
87
+ if (corepackPnpmCheck.status === 'ok') {
88
+ return corepackPnpmCheck;
89
+ }
90
+ if (pnpmCheck.status !== 'missing') {
91
+ return pnpmCheck;
92
+ }
93
+ return corepackPnpmCheck.status !== 'missing' ? corepackPnpmCheck : pnpmCheck;
94
+ };
95
+ const getConfigCheck = async (cwd) => {
96
+ const configFile = await findConfigFile({ cwd });
97
+ if (!configFile) {
98
+ return {
99
+ check: {
100
+ name: 'Config',
101
+ status: 'missing',
102
+ fix: 'Run `zw init` to preview config creation, then `zw init --yes` to create it.',
103
+ },
104
+ checkedInvalidConfig: false,
105
+ };
106
+ }
107
+ try {
108
+ const resolvedConfig = await loadResolvedConfig(cwd);
109
+ return {
110
+ check: {
111
+ name: 'Config',
112
+ status: 'ok',
113
+ details: path.relative(cwd, resolvedConfig.filePath) || 'zw.yml',
114
+ },
115
+ resolvedConfig,
116
+ checkedInvalidConfig: false,
117
+ };
118
+ }
119
+ catch (error) {
120
+ return {
121
+ check: {
122
+ name: 'Config',
123
+ status: 'warning',
124
+ details: path.relative(cwd, configFile) || 'zw.yml',
125
+ fix: isZaoWuError(error)
126
+ ? error.fix
127
+ : 'Run `zw config validate` to inspect and repair the config file.',
128
+ },
129
+ checkedInvalidConfig: true,
130
+ };
131
+ }
132
+ };
133
+ const checkAIProvider = (resolvedConfig, checkedInvalidConfig) => {
134
+ if (!resolvedConfig && checkedInvalidConfig) {
135
+ return {
136
+ name: 'AI provider',
137
+ status: 'warning',
138
+ details: 'not checked because config is invalid',
139
+ fix: 'Run `zw config validate` before enabling provider-backed AI commands.',
140
+ };
141
+ }
142
+ try {
143
+ const validation = validateAIProviderConfig(resolvedConfig?.config.ai.provider);
144
+ const provider = validation.provider;
145
+ const location = provider.network ? 'network' : 'local';
146
+ const configStatus = provider.configured ? 'configured' : 'missing config';
147
+ return {
148
+ name: 'AI provider',
149
+ status: validation.status,
150
+ details: `${provider.id} (${location}, ${configStatus})`,
151
+ fix: validation.warnings[0],
152
+ };
153
+ }
154
+ catch (error) {
155
+ return {
156
+ name: 'AI provider',
157
+ status: 'warning',
158
+ details: String(resolvedConfig?.config.ai.provider ?? 'default'),
159
+ fix: isZaoWuError(error)
160
+ ? error.fix
161
+ : 'Run `zw ai providers --json` to inspect supported AI providers.',
162
+ };
163
+ }
164
+ };
165
+ const checkCommandMatrix = () => ({
166
+ name: 'Command matrix',
167
+ status: 'ok',
168
+ details: `${COMMAND_CONTRACTS.length + ADDITIONAL_ROOT_SURFACES_IN_CAPABILITY_MATRIX} command surface(s) tracked`,
169
+ });
170
+ export const buildDoctorResult = async (options = {}) => {
171
+ const cwd = options.cwd ?? process.cwd();
172
+ const nodeVersion = options.nodeVersion ?? process.versions.node;
173
+ const commandRunner = options.commandRunner ?? runSystemCommand;
174
+ const checks = [];
175
+ checks.push({
176
+ name: 'Node.js',
177
+ status: satisfiesMinimumVersion(nodeVersion, MINIMUM_NODE_VERSION) ? 'ok' : 'warning',
178
+ version: `v${nodeVersion.replace(/^v/, '')}`,
179
+ fix: satisfiesMinimumVersion(nodeVersion, MINIMUM_NODE_VERSION)
180
+ ? undefined
181
+ : `Install Node.js ${MINIMUM_NODE_VERSION} or newer.`,
182
+ });
183
+ checks.push(checkCommand('Git', 'git', ['--version'], 'Install Git and make sure it is on PATH.', commandRunner));
184
+ checks.push(checkPnpm(commandRunner));
185
+ const config = await getConfigCheck(cwd);
186
+ checks.push(config.check);
187
+ checks.push(checkAIProvider(config.resolvedConfig, config.checkedInvalidConfig ?? false));
188
+ checks.push(checkCommandMatrix());
189
+ const nextSteps = checks
190
+ .filter((check) => check.status !== 'ok' && check.fix)
191
+ .map((check) => check.fix);
192
+ return {
193
+ schemaVersion: 1,
194
+ status: checks.some((check) => check.status !== 'ok') ? 'warning' : 'ok',
195
+ checks,
196
+ nextSteps,
197
+ operationPlan: createOperationPlan({
198
+ risk: 'low',
199
+ reads: [
200
+ 'nearest ZaoWu config path',
201
+ 'resolved ZaoWu config',
202
+ 'AI provider environment variable presence',
203
+ 'command contract registry',
204
+ ],
205
+ executes: ['git --version', 'pnpm --version', 'corepack pnpm --version'],
206
+ notes: ['Doctor runs fixed local diagnostics and does not write files.'],
207
+ }),
208
+ };
209
+ };
210
+ export const formatDoctorHuman = (doctor) => {
211
+ const lines = [
212
+ 'ZaoWu Doctor',
213
+ '',
214
+ `Status: ${doctor.status === 'ok' ? 'OK' : 'Warning'}`,
215
+ '',
216
+ 'Checks:',
217
+ ];
218
+ for (const check of doctor.checks) {
219
+ const parts = [check.status, check.version, check.details].filter(Boolean);
220
+ const suffix = parts.join(' ');
221
+ lines.push(`- ${check.name}: ${suffix}`);
222
+ }
223
+ if (doctor.nextSteps.length > 0) {
224
+ lines.push('', 'Next steps:');
225
+ doctor.nextSteps.forEach((step, index) => {
226
+ lines.push(`${index + 1}. ${step}`);
227
+ });
228
+ }
229
+ return lines.join('\n');
230
+ };
231
+ //# sourceMappingURL=root-doctor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"root-doctor.js","sourceRoot":"","sources":["../src/root-doctor.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAuB,MAAM,oBAAoB,CAAC;AAC7F,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAsB,MAAM,kBAAkB,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAsBvD,MAAM,oBAAoB,GAAG,SAAS,CAAC;AACvC,MAAM,oBAAoB,GAAG,SAAS,CAAC;AACvC,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAM,6CAA6C,GAAG,CAAC,CAAC;AACxD,MAAM,gBAAgB,GAAG,wCAAwC,CAAC;AAClE,MAAM,gB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AAI,CAAC,CAAC;AAC1B,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { DomainDefinition, OperationPlan } from '@zaowu-labs/core';
2
+ export declare const formatHelp: () => string;
3
+ export declare const formatDomainHelp: (domain: DomainDefinition) => string;
4
+ export declare const formatActionHelp: (domain: DomainDefinition, action: string) => string;
5
+ export declare const formatInitHelp: () => string;
6
+ export declare const formatDoctorHelp: () => string;
7
+ export declare const formatInlineOperationPlan: (plan: OperationPlan) => string;
8
+ //# sourceMappingURL=root-help.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"root-help.d.ts","sourceRoot":"","sources":["../src/root-help.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAOxE,eAAO,MAAM,UAAU,QAAO,MAoC7B,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,QAAQ,gBAAgB,KAAG,MAoC3D,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,QAAQ,gBAAgB,EAAE,QAAQ,MAAM,KAAG,MAS1B,CAAC;AAEnD,eAAO,MAAM,cAAc,QAAO,MAqBjB,CAAC;AAElB,eAAO,MAAM,gBAAgB,QAAO,MAcjB,CAAC;AAEpB,eAAO,MAAM,yBAAyB,GAAI,MAAM,aAAa,KAAG,MAYlD,CAAC"}
@@ -0,0 +1,130 @@
1
+ import { DOMAIN_DEFINITIONS } from './domains.js';
2
+ import { ACTION_HELP } from './help-text.js';
3
+ import { formatRows } from './output.js';
4
+ const toTitleCase = (value) => `${value.charAt(0).toUpperCase()}${value.slice(1)}`;
5
+ export const formatHelp = () => {
6
+ const commands = formatRows([
7
+ ['zw init', 'Preview or create a ZaoWu config file'],
8
+ ['zw doctor', 'Check local environment health'],
9
+ ['zw help', 'Show this help'],
10
+ ]);
11
+ const domains = formatRows(DOMAIN_DEFINITIONS.map((domain) => [`zw ${domain.name}`, domain.summary]));
12
+ return `ZaoWu / 造物
13
+
14
+ Usage:
15
+ zw <command> [options]
16
+
17
+ Commands:
18
+ ${commands}
19
+
20
+ Domains:
21
+ ${domains}
22
+
23
+ Global options:
24
+ --help Show help
25
+ --version Show version
26
+ --json Output machine-readable JSON
27
+ --dry-run Preview without applying changes
28
+ --yes Apply a safe confirmed action
29
+ --plan-fingerprint <hash>
30
+ Require confirmed actions to match a previewed plan
31
+
32
+ Examples:
33
+ zw doctor
34
+ zw doctor --json
35
+ zw init --dry-run
36
+ zw init --yes
37
+ zw dev --help`;
38
+ };
39
+ export const formatDomainHelp = (domain) => {
40
+ const commands = formatRows(domain.commands.map((command) => {
41
+ const flags = [command.status, command.sensitive ? 'sensitive' : undefined]
42
+ .filter(Boolean)
43
+ .join(', ');
44
+ return [`zw ${domain.name} ${command.name}`, `${flags} - ${command.summary}`];
45
+ }));
46
+ const capabilities = domain.capabilities
47
+ ? Object.entries(domain.capabilities)
48
+ .filter(([, enabled]) => enabled)
49
+ .map(([name]) => `- ${name}`)
50
+ .join('\n') || '- none'
51
+ : '- none';
52
+ return `ZaoWu ${toTitleCase(domain.name)} Domain
53
+
54
+ Usage:
55
+ zw ${domain.name} <action> [target] [options]
56
+
57
+ Description:
58
+ ${domain.summary}
59
+
60
+ Commands:
61
+ ${commands}
62
+
63
+ Capabilities:
64
+ ${capabilities}
65
+
66
+ Global options:
67
+ --help Show help
68
+ --json Output machine-readable JSON
69
+ --dry-run Preview without applying changes
70
+ --yes Apply a safe confirmed action`;
71
+ };
72
+ export const formatActionHelp = (domain, action) => ACTION_HELP[domain.name]?.[action] ??
73
+ `ZaoWu ${toTitleCase(domain.name)} ${toTitleCase(action)}
74
+
75
+ Usage:
76
+ zw ${domain.name} ${action} [target] [options]
77
+
78
+ Options:
79
+ --help Show help
80
+ --json Output machine-readable JSON`;
81
+ export const formatInitHelp = () => `ZaoWu Init
82
+
83
+ Usage:
84
+ zw init [options]
85
+
86
+ Description:
87
+ Preview or create a starter ZaoWu config file.
88
+
89
+ Options:
90
+ --dry-run Preview without writing files
91
+ --yes Create zw.yml
92
+ --plan-fingerprint <hash>
93
+ Require confirmed creation to match a preview
94
+ --json Output machine-readable JSON
95
+ --help Show this help
96
+
97
+ Examples:
98
+ zw init
99
+ zw init --dry-run
100
+ zw init --yes
101
+ zw init --yes --plan-fingerprint <hash>
102
+ zw init --json`;
103
+ export const formatDoctorHelp = () => `ZaoWu Doctor
104
+
105
+ Usage:
106
+ zw doctor [options]
107
+
108
+ Description:
109
+ Check local environment health.
110
+
111
+ Options:
112
+ --json Output machine-readable JSON
113
+ --help Show this help
114
+
115
+ Examples:
116
+ zw doctor
117
+ zw doctor --json`;
118
+ export const formatInlineOperationPlan = (plan) => [
119
+ 'Operation plan:',
120
+ `Risk: ${plan.risk}`,
121
+ `Confirmation required: ${plan.confirmationRequired ? 'yes' : 'no'}`,
122
+ `Fingerprint: ${plan.fingerprint}`,
123
+ ...(plan.confirmationRequired
124
+ ? [`Base confirmation flags: --yes --plan-fingerprint ${plan.fingerprint}`]
125
+ : []),
126
+ `Subjects: ${plan.subjects.length > 0 ? plan.subjects.join(', ') : 'none'}`,
127
+ `Writes: ${plan.writes.length > 0 ? plan.writes.join(', ') : 'none'}`,
128
+ `Deletes: ${plan.deletes.length > 0 ? plan.deletes.join(', ') : 'none'}`,
129
+ ].join('\n');
130
+ //# sourceMappingURL=root-help.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"root-help.js","sourceRoot":"","sources":["../src/root-help.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,WAAW,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE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CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE;IAC3E,WAAW,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE;IACrE,YAAY,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE;CACzE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { CliExecutionOptions, CliResult } from './types.js';
2
+ export declare const DEFAULT_CONFIG_FILE_NAME = "zw.yml";
3
+ export declare const handleInit: (args: readonly string[], options: CliExecutionOptions, json: boolean) => Promise<CliResult>;
4
+ //# sourceMappingURL=root-init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"root-init.d.ts","sourceRoot":"","sources":["../src/root-init.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEjE,eAAO,MAAM,wBAAwB,WAAW,CAAC;AA2BjD,eAAO,MAAM,UAAU,GACrB,MAAM,SAAS,MAAM,EAAE,EACvB,SAAS,mBAAmB,EAC5B,MAAM,OAAO,KACZ,OAAO,CAAC,SAAS,CA2EnB,CAAC"}
@@ -0,0 +1,87 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { writeFile } from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import { getDefaultConfigContent } from '@zaowu-labs/config';
5
+ import { assertOperationPlanFingerprint, createContentOperationSubjects, createOperationPlan, ZaoWuError, } from '@zaowu-labs/core';
6
+ import { getValue, parseArgs } from './args.js';
7
+ import { createResult } from './output.js';
8
+ import { formatInlineOperationPlan } from './root-help.js';
9
+ export const DEFAULT_CONFIG_FILE_NAME = 'zw.yml';
10
+ const hasFlag = (args, flag) => args.includes(flag);
11
+ const formatInitPreview = (configPath, content, operationPlan) => `ZaoWu Init
12
+
13
+ No files were written.
14
+
15
+ Would create:
16
+ ${path.basename(configPath)}
17
+
18
+ ${formatInlineOperationPlan(operationPlan)}
19
+
20
+ Preview:
21
+ ${content
22
+ .trimEnd()
23
+ .split('\n')
24
+ .map((line) => (line ? ` ${line}` : ''))
25
+ .join('\n')}
26
+
27
+ To create exactly this file, run:
28
+ zw init --yes --plan-fingerprint ${operationPlan.fingerprint}`;
29
+ export const handleInit = async (args, options, json) => {
30
+ const cwd = options.cwd ?? process.cwd();
31
+ const dryRun = hasFlag(args, '--dry-run');
32
+ const yes = hasFlag(args, '--yes');
33
+ const configPath = path.join(cwd, DEFAULT_CONFIG_FILE_NAME);
34
+ const content = getDefaultConfigContent(configPath);
35
+ const operationPlan = createOperationPlan({
36
+ risk: 'medium',
37
+ confirmationRequired: !yes || dryRun,
38
+ subjects: [`init:${configPath}`, ...createContentOperationSubjects(content)],
39
+ writes: [configPath],
40
+ notes: ['Init creates a config file only when --yes is provided and --dry-run is absent.'],
41
+ });
42
+ if (existsSync(configPath)) {
43
+ throw new ZaoWuError({
44
+ code: 'CONFIG_ALREADY_EXISTS',
45
+ message: 'ZaoWu config already exists.',
46
+ why: `${DEFAULT_CONFIG_FILE_NAME} already exists in the current directory.`,
47
+ fix: 'Open the existing config file or run `zw doctor` to check it.',
48
+ });
49
+ }
50
+ if (dryRun || !yes) {
51
+ const payload = {
52
+ schemaVersion: 1,
53
+ status: 'ok',
54
+ dryRun: true,
55
+ wouldCreate: configPath,
56
+ content,
57
+ operationPlan,
58
+ };
59
+ return createResult(0, json ? JSON.stringify(payload) : formatInitPreview(configPath, content, operationPlan));
60
+ }
61
+ assertOperationPlanFingerprint(getValue(parseArgs(args), '--plan-fingerprint'), operationPlan, yes && !dryRun, ZaoWuError);
62
+ try {
63
+ await writeFile(configPath, content, { encoding: 'utf8', flag: 'wx' });
64
+ }
65
+ catch {
66
+ throw new ZaoWuError({
67
+ code: 'CONFIG_WRITE_FAILED',
68
+ message: 'Could not write ZaoWu config.',
69
+ why: `ZaoWu tried to create ${DEFAULT_CONFIG_FILE_NAME} in the current directory, ` +
70
+ 'but the file system rejected the write.',
71
+ fix: 'Check directory permissions and make sure the config file does not already exist.',
72
+ });
73
+ }
74
+ const payload = {
75
+ schemaVersion: 1,
76
+ status: 'ok',
77
+ created: configPath,
78
+ operationPlan: {
79
+ ...operationPlan,
80
+ confirmationRequired: false,
81
+ },
82
+ };
83
+ return createResult(0, json
84
+ ? JSON.stringify(payload)
85
+ : `ZaoWu Init\n\nCreated:\n ${path.basename(configPath)}\n\nNext step:\n zw doctor`);
86
+ };
87
+ //# sourceMappingURL=root-init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"root-init.js","sourceRoot":"","sources":["../src/root-init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EACL,8BAA8B,EAC9B,8BAA8B,EAC9B,mBAAmB,EACnB,UAAU,GACX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAG3D,MAAM,CAAC,MAAM,wBAAwB,GAAG,QAAQ,CAAC;AAEjD,MAAM,OAAO,GAAG,CAAC,IAAuB,EAAE,IAAY,EAAW,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAExF,MAAM,iBAAiB,GAAG,C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ACD,IAAI;QACF,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;QACzB,CAAC,CAAC,6BAA6B,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,6BAA6B,CACxF,CAAC;AACJ,CAAC,CAAC"}
package/dist/run.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { DOMAIN_DEFINITIONS } from './domains.js';
2
+ import { DEFAULT_CONFIG_FILE_NAME } from './root-init.js';
3
+ import type { CliExecutionOptions, CliResult } from './types.js';
4
+ export declare const ZAOWU_CLI_VERSION: string;
5
+ export { DEFAULT_CONFIG_FILE_NAME, DOMAIN_DEFINITIONS };
6
+ export declare const executeCli: (args: readonly string[], options?: CliExecutionOptions) => Promise<CliResult>;
7
+ export declare const runCli: (args: readonly string[]) => Promise<number>;
8
+ //# sourceMappingURL=run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAc,MAAM,cAAc,CAAC;AAe9D,OAAO,EAAE,wBAAwB,EAAc,MAAM,gBAAgB,CAAC;AAEtE,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGjE,eAAO,MAAM,iBAAiB,QAAkB,CAAC;AACjD,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,CAAC;AAyBxD,eAAO,MAAM,UAAU,GACrB,MAAM,SAAS,MAAM,EAAE,EACvB,UAAS,mBAAwB,KAChC,OAAO,CAAC,SAAS,CAyInB,CAAC;AAEF,eAAO,MAAM,MAAM,GAAU,MAAM,SAAS,MAAM,EAAE,KAAG,OAAO,CAAC,MAAM,CAgBpE,CAAC"}
package/dist/run.js ADDED
@@ -0,0 +1,152 @@
1
+ import { findDomainCommand, isZaoWuError, ZaoWuError } from '@zaowu-labs/core';
2
+ import { getValue, hasFlag, parseArgs } from './args.js';
3
+ import { getDomainActionHandler } from './domain-handlers.js';
4
+ import { DOMAIN_DEFINITIONS, findDomain } from './domains.js';
5
+ import { assertNoMissingOptionValues, assertSupportedOptions, assertValidOptionValues, } from './option-validation.js';
6
+ import { createResult } from './output.js';
7
+ import { buildDoctorResult, formatDoctorHuman } from './root-doctor.js';
8
+ import { formatActionHelp, formatDoctorHelp, formatDomainHelp, formatHelp, formatInitHelp, } from './root-help.js';
9
+ import { DEFAULT_CONFIG_FILE_NAME, handleInit } from './root-init.js';
10
+ import { runSystemCommand } from './system-command.js';
11
+ import { getCliVersion } from './version.js';
12
+ export const ZAOWU_CLI_VERSION = getCliVersion();
13
+ export { DEFAULT_CONFIG_FILE_NAME, DOMAIN_DEFINITIONS };
14
+ const handleError = (error, json) => {
15
+ const zaowuError = isZaoWuError(error)
16
+ ? error
17
+ : new ZaoWuError({
18
+ code: 'INTERNAL_ERROR',
19
+ message: 'Unexpected internal error.',
20
+ why: 'ZaoWu hit an error that is not yet handled as a user-facing case.',
21
+ fix: 'Report this issue at https://github.com/zaowu-labs/zaowu/issues with the command you ran.',
22
+ });
23
+ return createResult(zaowuError.exitCode, '', json ? zaowuError.formatJSON() : zaowuError.formatHuman());
24
+ };
25
+ const createHelpResult = (help, json, details = {}) => createResult(0, json ? JSON.stringify({ schemaVersion: 1, status: 'ok', ...details, help }) : help);
26
+ export const executeCli = async (args, options = {}) => {
27
+ const parsed = parseArgs(args);
28
+ const json = hasFlag(parsed, '--json');
29
+ const wantsHelp = hasFlag(parsed, '--help');
30
+ const wantsVersion = hasFlag(parsed, '--version');
31
+ const commandArgs = parsed.positionals;
32
+ const command = commandArgs[0];
33
+ const domain = command ? findDomain(command) : undefined;
34
+ const cwd = options.cwd ?? process.cwd();
35
+ const commandRunner = options.commandRunner ?? runSystemCommand;
36
+ try {
37
+ if (wantsVersion || command === 'version') {
38
+ return createResult(0, json
39
+ ? JSON.stringify({ schemaVersion: 1, status: 'ok', version: ZAOWU_CLI_VERSION })
40
+ : ZAOWU_CLI_VERSION);
41
+ }
42
+ if (!command || command === 'help') {
43
+ return createHelpResult(formatHelp(), json);
44
+ }
45
+ if (wantsHelp) {
46
+ if (command === 'init') {
47
+ return createHelpResult(formatInitHelp(), json);
48
+ }
49
+ if (command === 'doctor') {
50
+ return createHelpResult(formatDoctorHelp(), json);
51
+ }
52
+ if (domain) {
53
+ const action = commandArgs[1];
54
+ if (action) {
55
+ const domainCommand = findDomainCommand(domain, action);
56
+ if (!domainCommand) {
57
+ throw new ZaoWuError({
58
+ code: 'UNKNOWN_DOMAIN_ACTION',
59
+ message: `Unknown command: zw ${domain.name} ${action}.`,
60
+ why: `ZaoWu has the \`${domain.name}\` domain, but it does not have an action named \`${action}\`.`,
61
+ fix: `Run \`zw ${domain.name} --help\` to see commands for this domain.`,
62
+ });
63
+ }
64
+ return createHelpResult(formatActionHelp(domain, action), json, {
65
+ domain: domain.name,
66
+ action,
67
+ });
68
+ }
69
+ return createHelpResult(formatDomainHelp(domain), json, { domain });
70
+ }
71
+ }
72
+ assertNoMissingOptionValues(parsed.missingValues);
73
+ assertSupportedOptions(parsed, commandArgs);
74
+ assertValidOptionValues(parsed, commandArgs);
75
+ if (command === 'doctor') {
76
+ const doctor = await buildDoctorResult(options);
77
+ return createResult(0, json ? JSON.stringify(doctor) : formatDoctorHuman(doctor));
78
+ }
79
+ if (command === 'init') {
80
+ return await handleInit(args, options, json);
81
+ }
82
+ if (domain) {
83
+ const action = commandArgs[1];
84
+ if (!action) {
85
+ return createHelpResult(formatDomainHelp(domain), json, { domain });
86
+ }
87
+ const domainCommand = findDomainCommand(domain, action);
88
+ if (!domainCommand) {
89
+ throw new ZaoWuError({
90
+ code: 'UNKNOWN_DOMAIN_ACTION',
91
+ message: `Unknown command: zw ${domain.name} ${action}.`,
92
+ why: `ZaoWu has the \`${domain.name}\` domain, but it does not have an action named \`${action}\`.`,
93
+ fix: `Run \`zw ${domain.name} --help\` to see commands for this domain.`,
94
+ });
95
+ }
96
+ if (domainCommand.status === 'planned') {
97
+ throw new ZaoWuError({
98
+ code: 'COMMAND_NOT_IMPLEMENTED',
99
+ message: `Command not implemented yet: zw ${domain.name} ${domainCommand.name}.`,
100
+ why: `The \`${domain.name}\` domain is scaffolded, but \`${domainCommand.name}\` ` +
101
+ 'is still planned and has no implementation yet.',
102
+ fix: 'Create or update the related experience spec under `docs/experience/`, ' +
103
+ `then implement it inside the \`packages/${domain.name}\` package.`,
104
+ });
105
+ }
106
+ const handler = getDomainActionHandler(domain.name, domainCommand.name);
107
+ if (handler) {
108
+ return await handler(commandArgs.slice(2), {
109
+ commandRunner,
110
+ cwd,
111
+ dryRun: hasFlag(parsed, '--dry-run'),
112
+ expectedPlanFingerprint: getValue(parsed, '--plan-fingerprint'),
113
+ json,
114
+ parsed,
115
+ yes: hasFlag(parsed, '--yes') && !hasFlag(parsed, '--dry-run'),
116
+ onChunk: options.onChunk,
117
+ });
118
+ }
119
+ throw new ZaoWuError({
120
+ code: 'COMMAND_HANDLER_MISSING',
121
+ message: `Command handler missing: zw ${domain.name} ${domainCommand.name}.`,
122
+ why: `The \`${domain.name}\` domain marks \`${domainCommand.name}\` as available, ` +
123
+ 'but the CLI has no handler wired for it.',
124
+ fix: 'Wire the command handler through `packages/cli` without moving domain logic into CLI.',
125
+ });
126
+ }
127
+ throw new ZaoWuError({
128
+ code: 'UNKNOWN_COMMAND',
129
+ message: `Unknown command: ${command}.`,
130
+ why: `ZaoWu does not have a command named \`zw ${command}\`.`,
131
+ fix: 'Run `zw --help` to see available commands.',
132
+ });
133
+ }
134
+ catch (error) {
135
+ return handleError(error, json);
136
+ }
137
+ };
138
+ export const runCli = async (args) => {
139
+ const result = await executeCli(args, {
140
+ onChunk: (chunk) => {
141
+ process.stdout.write(chunk);
142
+ },
143
+ });
144
+ if (result.stdout) {
145
+ process.stdout.write(`${result.stdout}\n`);
146
+ }
147
+ if (result.stderr) {
148
+ process.stderr.write(`${result.stderr}\n`);
149
+ }
150
+ return result.exitCode;
151
+ };
152
+ //# sourceMappingURL=run.js.map