@hagicode/hagitask 0.1.0-dev.10

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 (38) hide show
  1. package/README.md +260 -0
  2. package/dist/cli.d.ts +4 -0
  3. package/dist/cli.js +50 -0
  4. package/dist/cli.js.map +1 -0
  5. package/dist/commands/new-command.d.ts +14 -0
  6. package/dist/commands/new-command.js +78 -0
  7. package/dist/commands/new-command.js.map +1 -0
  8. package/dist/commands/validate-command.d.ts +4 -0
  9. package/dist/commands/validate-command.js +14 -0
  10. package/dist/commands/validate-command.js.map +1 -0
  11. package/dist/index.d.ts +15 -0
  12. package/dist/index.js +42 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/templates/new-package.d.ts +9 -0
  15. package/dist/templates/new-package.js +281 -0
  16. package/dist/templates/new-package.js.map +1 -0
  17. package/dist/validation/diagnostics.d.ts +13 -0
  18. package/dist/validation/diagnostics.js +16 -0
  19. package/dist/validation/diagnostics.js.map +1 -0
  20. package/dist/validation/package-discovery.d.ts +10 -0
  21. package/dist/validation/package-discovery.js +45 -0
  22. package/dist/validation/package-discovery.js.map +1 -0
  23. package/dist/validation/package-validator.d.ts +4 -0
  24. package/dist/validation/package-validator.js +374 -0
  25. package/dist/validation/package-validator.js.map +1 -0
  26. package/dist/validation/schema-loader.d.ts +8 -0
  27. package/dist/validation/schema-loader.js +50 -0
  28. package/dist/validation/schema-loader.js.map +1 -0
  29. package/package.json +52 -0
  30. package/schemas/community-index-v1.schema.json +159 -0
  31. package/schemas/community-task-detail-v1.schema.json +182 -0
  32. package/schemas/task-preset-plugin/commands.schema.json +122 -0
  33. package/schemas/task-preset-plugin/locales.schema.json +24 -0
  34. package/schemas/task-preset-plugin/manifest.schema.json +225 -0
  35. package/schemas/task-preset-plugin/panel.schema.json +190 -0
  36. package/schemas/task-preset-plugin/prompt-package.schema.json +262 -0
  37. package/schemas/task-preset-plugin/store-page-frontmatter.schema.json +73 -0
  38. package/schemas/task-preset-plugin/task-preset.schema.json +153 -0
package/README.md ADDED
@@ -0,0 +1,260 @@
1
+ # hagitask
2
+
3
+ HagiTask is the canonical repository for preset-task contribution assets inside the
4
+ HagiCode monorepo. It is the maintained source of truth for shipped preset-task
5
+ schemas and preset packages.
6
+
7
+ ## npm CLI
8
+
9
+ The repository is also published as `@hagicode/hagitask` (Node.js 20 or newer).
10
+ Install it with `npm install --save-dev @hagicode/hagitask`, then validate a
11
+ repository or one package:
12
+
13
+ ```bash
14
+ npx hagitask validate .
15
+ npx hagitask validate ./data/my-task --json
16
+ ```
17
+
18
+ Create a new package scaffold without network access:
19
+
20
+ ```bash
21
+ npx hagitask new my-task
22
+ npx hagitask new my-task --target ./data/my-task --repository repos/web repos/hagicode-core
23
+ ```
24
+
25
+ The target directory must be empty (or absent), and package names use lowercase
26
+ letters, numbers, and hyphens. `--target` selects the exact package directory (its final directory name must match the package name);
27
+ `--destination` and `--output` are aliases. `--repository` may be repeated or
28
+ followed by multiple identifiers and only populates the repository selector
29
+ options; commands still require an explicit `targetRepositories` selection.
30
+
31
+ Generated packages contain `manifest.json`, `frontend/`, `backend/`, bilingual
32
+ `locales/`, `store-page/`, and `commands/README.md`. The baseline commands
33
+ `what is this` explain a selected repository, while `what is next` recommends
34
+ improvements. Add command definitions in `frontend/commands.json` and matching
35
+ localized prompt files in `backend/templates/<locale>/commands/`.
36
+
37
+ `validate` discovers packages directly under `presets/` and `data/`, or validates
38
+ a directory containing `manifest.json`. It returns exit code `0` only when all
39
+ discovered packages pass. Human-readable diagnostics are printed by default;
40
+ `--json` prints the stable `{ packages, errors, valid }` result on stdout for CI.
41
+ Validation reads `schemas/` shipped inside the npm package (and never requires a
42
+ network connection). The CLI is the new reusable validator; Contrib and Community
43
+ Packages retain their existing workflows until a separate migration.
44
+
45
+ > Authoring location: contributors add and update preset-task packages **here**, in
46
+ > `repos/hagitask`, not in `repos/hagicode-core/src/PCode.Web/plugins/task-presets/`.
47
+ > The `hagicode-core` copy is a transitional asset that is kept only until the backend
48
+ > loading cutover lands.
49
+
50
+ ## Repository Layout
51
+
52
+ ```text
53
+ repos/hagitask/
54
+ schemas/
55
+ task-preset-plugin/
56
+ manifest.schema.json # Preset package manifest contract
57
+ panel.schema.json # Frontend panel definition contract
58
+ commands.schema.json # Frontend command catalog contract
59
+ locales.schema.json # Locale bundle contract
60
+ task-preset.schema.json # Backend task-preset contract
61
+ prompt-package.schema.json # Backend prompt package contract
62
+ store-page-frontmatter.schema.json # Store-page frontmatter contract
63
+ community-index-v1.schema.json # Published /index.json contract
64
+ community-task-detail-v1.schema.json # Published /tasks/<taskId>.json contract
65
+ presets/
66
+ <presetTaskId>/
67
+ manifest.json
68
+ frontend/
69
+ panel.json
70
+ commands.json # Optional, only when the preset ships commands
71
+ backend/
72
+ task-preset.json
73
+ prompts.json
74
+ templates/<locale>/...
75
+ locales/
76
+ en-US.json
77
+ zh-CN.json
78
+ store-page/
79
+ index.en-US.md
80
+ index.zh-CN.md
81
+ ```
82
+
83
+ ## Schema Layers
84
+
85
+ `schemas/` holds three schema layers. They validate different documents, at different
86
+ points in the pipeline, and are owned by different producers.
87
+
88
+ | Layer | Schemas | Validates | Produced by |
89
+ | --- | --- | --- | --- |
90
+ | Package schemas | `schemas/task-preset-plugin/*.schema.json` | the JSON files inside a preset or community package (`manifest.json`, `frontend/*`, `backend/*`, `locales/*`) | contributors, by hand |
91
+ | Community discovery schema | `schemas/community-index-v1.schema.json` | the published `/index.json` catalog | `hagitask-site` build |
92
+ | Community detail schema | `schemas/community-task-detail-v1.schema.json` | each published `/tasks/<taskId>.json` document | `hagitask-site` build |
93
+
94
+ Package schemas describe **authored source**. The community schemas describe
95
+ **generated publication output** and carry fields that do not exist in any package file
96
+ (`generatedAt`, `detailUrl`, `packageUrl`, `integrity.sha256`, and so on). Choosing the
97
+ wrong layer is the most common source of confusion: if you are editing a file inside a
98
+ package directory, the matching contract is always under `schemas/task-preset-plugin/`.
99
+
100
+ Community packages live in
101
+ [`hagitask-community-packages`](https://github.com/HagiCode-org/hagitask-community-packages).
102
+ That repository mounts HagiTask as a **nested submodule** and consumes these schemas
103
+ directly from `hagitask/schemas/task-preset-plugin/` — it no longer vendors its own copy.
104
+ [`hagitask-site`](https://github.com/HagiCode-org/hagitask-site) in turn mounts the
105
+ community repository as its `community-packages/` submodule, reads task packages from
106
+ `community-packages/data/`, and loads the publication schemas from
107
+ `community-packages/hagitask/schemas`. Shipped presets live in `presets/` in this
108
+ repository. All three — HagiTask presets, community packages, and the site build — use the
109
+ same package schemas from this directory.
110
+
111
+ ## Package `$schema` Reference
112
+
113
+ `schemas/task-preset-plugin/` is the authoritative home for the JSON schemas that
114
+ validate preset packages. Every shipped and community preset package resolves its
115
+ `$schema` references against this directory, so contributors never need files from
116
+ `repos/hagicode-core` to validate a package.
117
+
118
+ The shipped preset packages use these relative `$schema` paths from inside
119
+ `presets/<presetTaskId>/`:
120
+
121
+ | Package file | `$schema` path |
122
+ |------------------------------------|-------------------------------------------------------------------------|
123
+ | `manifest.json` | `../../schemas/task-preset-plugin/manifest.schema.json` |
124
+ | `frontend/panel.json` | `../../../schemas/task-preset-plugin/panel.schema.json` |
125
+ | `frontend/commands.json` | `../../../schemas/task-preset-plugin/commands.schema.json` |
126
+ | `backend/task-preset.json` | `../../../schemas/task-preset-plugin/task-preset.schema.json` |
127
+ | `backend/prompts.json` | `../../../schemas/task-preset-plugin/prompt-package.schema.json` |
128
+ | `locales/<locale>.json` | `../../../schemas/task-preset-plugin/locales.schema.json` |
129
+
130
+ Prompt packages may optionally declare `commandSystemPrompts`, mapping a command id
131
+ to locale-specific system-template paths:
132
+
133
+ ```json
134
+ {
135
+ "commandSystemPrompts": {
136
+ "initialize": {
137
+ "en-US": "./templates/en-US/commands/initialize.md",
138
+ "zh-CN": "./templates/zh-CN/commands/initialize.md"
139
+ }
140
+ }
141
+ }
142
+ ```
143
+
144
+ The selected command template is rendered with the same context as the user and
145
+ base system templates. Locale resolution uses an exact match, then the language
146
+ portion, then the package default locale. Missing mappings, blank commands, and
147
+ legacy packages simply omit the additional system section. Final prompt order is
148
+ user prompt, command-specific system prompt, then base system prompt; existing
149
+ command preludes remain supported.
150
+
151
+ Community packages use the identical values, so a package can move between
152
+ `presets/<presetTaskId>/` and the community repository without rewriting references.
153
+
154
+ ## Publication Data Flow
155
+
156
+ ```mermaid
157
+ flowchart LR
158
+ SRC["Community package source<br/>data/&lt;taskId&gt;/manifest.json, frontend/, backend/, locales/, store-page/"]
159
+ PKG["Package schemas<br/>hagitask/schemas/task-preset-plugin/*.schema.json"]
160
+ SUB["hagitask-site community-packages/ submodule (nested hagitask)"]
161
+ NORM["Site build: normalize + digest"]
162
+ IDX["/index.json"]
163
+ DET["/tasks/&lt;taskId&gt;.json"]
164
+ ZIP["/packages/&lt;taskId&gt;.zip"]
165
+ CIDX["community-index-v1.schema.json"]
166
+ CDET["community-task-detail-v1.schema.json"]
167
+
168
+ PKG -.validates.-> SRC
169
+ SRC --> SUB --> NORM
170
+ NORM --> IDX
171
+ NORM --> DET
172
+ NORM --> ZIP
173
+ CIDX -.validates.-> IDX
174
+ CDET -.validates.-> DET
175
+ ```
176
+
177
+ How source edits reach the published documents:
178
+
179
+ | Source change | Affected published fields |
180
+ | --- | --- |
181
+ | `manifest.json` → `version` | `version` in index and detail |
182
+ | `manifest.json` → `owner` | `publisher` in index and detail |
183
+ | `backend/task-preset.json` → `requirements` | `requirements` in detail, and the derived `compatibility.agent` / `.skills` / `.cli` in both documents |
184
+ | `store-page/index.<locale>.md` → `title` / `summary` | `name`, `summary`, `description`, and `localization.supportedLocales` |
185
+ | `store-page/index.en-US.md` → `catalog` / `tags` | `category` and `tags` |
186
+ | any file in the package directory | the zip contents, plus `integrity.sha256` in the index and `installation.size` / `installation.sha256` in the detail |
187
+
188
+ ## Generated Output Is Not Editable
189
+
190
+ `/index.json`, `/tasks/<taskId>.json`, and `/packages/<taskId>.zip` are produced from
191
+ scratch on every site build. They are not stored in any repository as editable source and
192
+ hand edits are discarded on the next publish. The only way to change a published field is
193
+ to change the package file it is derived from.
194
+
195
+ When schema validation fails:
196
+
197
+ 1. Read which document failed. A `task-preset-plugin` failure points at a package file you
198
+ authored; a `community-index-v1` or `community-task-detail-v1` failure means the site
199
+ build normalized your source into something that violates the publication contract.
200
+ 2. Fix the source package file. Do not relax `$schema`, delete the `$schema` reference,
201
+ skip validation, or patch the generated output.
202
+ 3. Re-run the site build to confirm the fix.
203
+ 4. If the package data is genuinely correct and the schema is wrong, change the schema
204
+ **here**, in this repository, as a deliberate contract change.
205
+
206
+ ## Preset Package Directory
207
+
208
+ `presets/` is the root for preset-task packages. Each package lives in its own
209
+ `presets/<presetTaskId>/` directory and preserves the loader-compatible plugin
210
+ package shape (`manifest.json`, `frontend/`, `backend/`, `locales/`, and
211
+ `store-page/`). This means the backend can load migrated packages without a
212
+ HagiTask-specific adapter.
213
+
214
+ Currently shipped packages:
215
+
216
+ - `normal-session`
217
+ - `research-investigation`
218
+
219
+ `agents-md-update`, `goal`, `last30days`, `openspec-spec-compress`, `ponytail`, and
220
+ `ui-master` are published as community tasks and live in
221
+ [`hagitask-community-packages`](https://github.com/HagiCode-org/hagitask-community-packages),
222
+ not in `presets/`.
223
+
224
+ ## Source-of-Truth Ownership
225
+
226
+ HagiTask owns preset-task schemas and shipped preset packages. When you add a new
227
+ preset, update an existing one, or change a schema, do it here.
228
+
229
+ The legacy copies under `repos/hagicode-core/src/PCode.Web/plugins/task-presets/`
230
+ are kept unchanged during the copy-first transition phase. After the later backend
231
+ loading cutover (see `openspec/changes/migrate-preset-task-to-hagitask-repo`),
232
+ `hagicode-core` will load shipped presets from `repos/hagitask/presets` through the
233
+ `TaskPresetPlugins.PresetGroups` configuration and the backend-owned copy will no
234
+ longer be the shipped source of truth.
235
+
236
+ Until that cutover lands, every shipped preset update — including `openspec-spec-compress` —
237
+ must keep the `hagicode-core` runtime copy synchronized with the canonical HagiTask package.
238
+
239
+ ## Contributing a Preset Package
240
+
241
+ HagiTask owns the Schema and shipped preset source. Preset packages use the loader-compatible
242
+ layout described above and must keep their JSON resources aligned with
243
+ `schemas/task-preset-plugin/`. Validate authored files against those schemas before submitting:
244
+
245
+ ```bash
246
+ npm run validate
247
+ ```
248
+
249
+ The validator checks every shipped preset, all manifest resource references, package
250
+ JSON schemas, prompt template references, and compatibility binding aliases. It is
251
+ intentionally package-local so the same command can run in a clean checkout without
252
+ depending on Core or site-generated output.
253
+
254
+ For the user-facing walkthrough covering package creation, locale and store-page resources,
255
+ validation, semantic versioning, and Pull Requests, see the
256
+ [HagiTask community guide](https://docs.hagicode.com/guides/hagitask/community/). A community
257
+ task belongs in
258
+ [`hagitask-community-packages`](https://github.com/HagiCode-org/hagitask-community-packages),
259
+ not in this repository. This README remains the technical reference for Schema ownership,
260
+ preset source data, and the transitional runtime copy.
package/dist/cli.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ export declare function createCli(): Command;
4
+ export declare function main(argv?: string[]): void;
package/dist/cli.js ADDED
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import { readFileSync } from 'node:fs';
4
+ import { dirname, resolve } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { runNewCommand } from './commands/new-command.js';
7
+ import { runValidateCommand } from './commands/validate-command.js';
8
+ function packageVersion() {
9
+ try {
10
+ const packagePath = resolve(dirname(fileURLToPath(import.meta.url)), '..', 'package.json');
11
+ return JSON.parse(readFileSync(packagePath, 'utf8')).version;
12
+ }
13
+ catch {
14
+ return '0.1.0';
15
+ }
16
+ }
17
+ export function createCli() {
18
+ const program = new Command();
19
+ program
20
+ .name('hagitask')
21
+ .description('Validate HagiTask preset and community packages offline.')
22
+ .version(packageVersion());
23
+ program
24
+ .command('new <packageName>')
25
+ .description('create a new HagiTask package scaffold')
26
+ .option('-d, --target <path>', 'target package directory')
27
+ .option('--destination <path>', 'alias for --target')
28
+ .option('--output <path>', 'alias for --target')
29
+ .option('-r, --repository <repositories...>', 'repository identifier(s) to offer in the selector')
30
+ .action((packageName, options) => {
31
+ const result = runNewCommand(packageName, options);
32
+ if (result.error)
33
+ console.error(result.error);
34
+ process.exitCode = result.code;
35
+ });
36
+ program
37
+ .command('validate [path]')
38
+ .description('validate packages under presets/, data/, or a single package directory')
39
+ .option('--json', 'print machine-readable JSON diagnostics')
40
+ .action((path, options) => {
41
+ process.exitCode = runValidateCommand(path ?? process.cwd(), options);
42
+ });
43
+ return program;
44
+ }
45
+ export function main(argv = process.argv) {
46
+ createCli().parse(argv);
47
+ }
48
+ if (import.meta.url === `file://${process.argv[1]}`)
49
+ main();
50
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,aAAa,EAA0B,MAAM,2BAA2B,CAAC;AAClF,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEpE,SAAS,cAAc;IACrB,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;QAC3F,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IAC/D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,OAAO,CAAC;IACjB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,SAAS;IACvB,MAAM,OAAO,GAAG,IAAI,OA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,IAAI,CAAC,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,CAAC"}
@@ -0,0 +1,14 @@
1
+ export interface NewCommandOptions {
2
+ target?: string;
3
+ destination?: string;
4
+ output?: string;
5
+ repositories?: string[];
6
+ repository?: string[];
7
+ }
8
+ export interface NewCommandResult {
9
+ code: number;
10
+ packagePath?: string;
11
+ files?: string[];
12
+ error?: string;
13
+ }
14
+ export declare function runNewCommand(packageName: string | undefined, options?: NewCommandOptions, cwd?: string): NewCommandResult;
@@ -0,0 +1,78 @@
1
+ import { existsSync, mkdirSync, readdirSync, rmSync, statSync, writeFileSync, } from 'node:fs';
2
+ import { basename, dirname, join, resolve } from 'node:path';
3
+ import { createNewPackageFiles } from '../templates/new-package.js';
4
+ const PACKAGE_NAME = /^[a-z0-9][a-z0-9-]*$/;
5
+ const REPOSITORY_ID = /^[A-Za-z0-9][A-Za-z0-9._/-]*$/;
6
+ function optionTarget(options) {
7
+ return options.target ?? options.destination ?? options.output;
8
+ }
9
+ function repositoriesFromOptions(options) {
10
+ const values = options.repositories ?? options.repository ?? [];
11
+ return values.flatMap((value) => value.split(',').map((item) => item.trim())).filter(Boolean);
12
+ }
13
+ function validateInput(packageName, options) {
14
+ if (!packageName || !PACKAGE_NAME.test(packageName)) {
15
+ return 'package name must match ^[a-z0-9][a-z0-9-]*$';
16
+ }
17
+ const repositories = repositoriesFromOptions(options);
18
+ if (repositories.some((repository) => !REPOSITORY_ID.test(repository) || repository.includes('..'))) {
19
+ return 'repository identifiers must be non-empty and contain only letters, numbers, ".", "_", "-", or "/"';
20
+ }
21
+ const target = optionTarget(options);
22
+ if (target !== undefined && (!target.trim() || target.includes('\0'))) {
23
+ return 'target path must be a non-empty valid path';
24
+ }
25
+ return undefined;
26
+ }
27
+ export function runNewCommand(packageName, options = {}, cwd = process.cwd()) {
28
+ const inputError = validateInput(packageName, options);
29
+ if (inputError)
30
+ return { code: 1, error: inputError };
31
+ const name = packageName;
32
+ const target = resolve(cwd, optionTarget(options) ?? name);
33
+ if (optionTarget(options) !== undefined && basename(target) !== name) {
34
+ return { code: 1, error: `target directory name must equal package name '${name}'` };
35
+ }
36
+ if (existsSync(target)) {
37
+ if (!statSync(target).isDirectory())
38
+ return { code: 1, error: `target path is not a directory: ${target}` };
39
+ if (readdirSync(target).length > 0)
40
+ return { code: 1, error: `target directory is not empty: ${target}` };
41
+ }
42
+ const files = createNewPackageFiles({
43
+ packageName: name,
44
+ repositories: repositoriesFromOptions(options),
45
+ });
46
+ const createdPaths = [];
47
+ const targetWasCreated = !existsSync(target);
48
+ try {
49
+ mkdirSync(target, { recursive: true });
50
+ for (const file of files) {
51
+ const filePath = join(target, file.path);
52
+ const parent = dirname(filePath);
53
+ const missingDirectories = [];
54
+ let current = parent;
55
+ while (current !== target && !existsSync(current)) {
56
+ missingDirectories.push(current);
57
+ current = dirname(current);
58
+ }
59
+ mkdirSync(parent, { recursive: true });
60
+ createdPaths.push(...missingDirectories);
61
+ writeFileSync(filePath, file.contents, { encoding: 'utf8', flag: 'wx' });
62
+ createdPaths.push(filePath);
63
+ }
64
+ }
65
+ catch (error) {
66
+ for (const filePath of createdPaths.reverse())
67
+ rmSync(filePath, { force: true, recursive: true });
68
+ if (targetWasCreated)
69
+ rmSync(target, { recursive: true, force: true });
70
+ return { code: 1, error: `unable to create package: ${error instanceof Error ? error.message : String(error)}` };
71
+ }
72
+ const relativeFiles = files.map((file) => file.path);
73
+ console.log(`Created HagiTask package at ${target}`);
74
+ console.log(relativeFiles.map((file) => `- ${file}`).join('\n'));
75
+ console.log('Next: run `hagitask validate <path>` and add commands under commands/.');
76
+ return { code: 0, packagePath: target, files: relativeFiles };
77
+ }
78
+ //# sourceMappingURL=new-command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"new-command.js","sourceRoot":"","sources":["../../src/commands/new-command.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EACT,WAAW,EACX,MAAM,EACN,QAAQ,EACR,aAAa,GACd,M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AE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACvE,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,6BAA6B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC;IACnH,CAAC;IAED,MAAM,aAAa,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrD,OAAO,CAAC,GAAG,CAAC,+BAA+B,MAAM,EAAE,CAAC,CAAC;IACrD,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACjE,OAAO,CAAC,GAAG,CAAC,wEAAwE,CAAC,CAAC;IACtF,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC;AAChE,CAAC"}
@@ -0,0 +1,4 @@
1
+ export interface ValidateCommandOptions {
2
+ json?: boolean;
3
+ }
4
+ export declare function runValidateCommand(path?: string, options?: ValidateCommandOptions): number;
@@ -0,0 +1,14 @@
1
+ import { validatePackages } from '../index.js';
2
+ import { formatValidationText } from '../validation/diagnostics.js';
3
+ export function runValidateCommand(path = process.cwd(), options = {}) {
4
+ const result = validatePackages(path);
5
+ const output = options.json
6
+ ? JSON.stringify(result, null, 2)
7
+ : formatValidationText(result);
8
+ if (options.json || result.valid)
9
+ console.log(output);
10
+ else
11
+ console.error(output);
12
+ return result.valid ? 0 : 1;
13
+ }
14
+ //# sourceMappingURL=validate-command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-command.js","sourceRoot":"","sources":["../../src/commands/validate-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAMpE,MAAM,UAAU,kBAAkB,CAAC,IAAI,GAAG,OAAO,CAAC,GAAG,EAAE,EAAE,UAAkC,EAAE;IAC3F,MAAM,MAAM,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACtC,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI;QACzB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;QACjC,CAAC,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;IACjC,IAAI,OAAO,CAAC,IAAI,IAAI,MAAM,CAAC,KAAK;QAAE,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;;QACjD,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC3B,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,15 @@
1
+ export type { DiscoveredPackage, DiscoveryResult } from './validation/package-discovery.js';
2
+ export type { ValidationError, ValidationResult } from './validation/diagnostics.js';
3
+ export declare const PACKAGE_NAME = "@hagicode/hagitask";
4
+ export declare const PACKAGE_VERSION: string;
5
+ export declare const packageMetadata: {
6
+ readonly name: "@hagicode/hagitask";
7
+ readonly version: string;
8
+ };
9
+ export interface ValidateOptions {
10
+ /** Override the directory containing the published schemas. */
11
+ packageRoot?: string;
12
+ }
13
+ export declare function validatePackages(targetPath?: string, options?: ValidateOptions): import("./validation/diagnostics.js").ValidationResult;
14
+ export { discoverPackages } from './validation/package-discovery.js';
15
+ export { formatValidationError, formatValidationText } from './validation/diagnostics.js';
package/dist/index.js ADDED
@@ -0,0 +1,42 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { dirname, resolve } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { discoverPackages } from './validation/package-discovery.js';
5
+ import { validateDiscoveredPackages } from './validation/package-validator.js';
6
+ function readPackageVersion() {
7
+ try {
8
+ const packagePath = resolve(dirname(fileURLToPath(import.meta.url)), '..', 'package.json');
9
+ const version = JSON.parse(readFileSync(packagePath, 'utf8')).version;
10
+ return typeof version === 'string' ? version : '0.1.0';
11
+ }
12
+ catch {
13
+ return '0.1.0';
14
+ }
15
+ }
16
+ export const PACKAGE_NAME = '@hagicode/hagitask';
17
+ export const PACKAGE_VERSION = readPackageVersion();
18
+ export const packageMetadata = {
19
+ name: PACKAGE_NAME,
20
+ version: PACKAGE_VERSION,
21
+ };
22
+ export function validatePackages(targetPath = process.cwd(), options = {}) {
23
+ const root = resolve(targetPath);
24
+ const discovery = discoverPackages(root);
25
+ const packageRoot = options.packageRoot ?? resolve(dirname(fileURLToPath(import.meta.url)), '..');
26
+ if (discovery.errors.length > 0) {
27
+ return {
28
+ packages: discovery.packages.map((pkg) => pkg.rel).sort(),
29
+ errors: discovery.errors.map((message) => ({
30
+ packageId: '',
31
+ file: root,
32
+ field: 'path',
33
+ message,
34
+ })),
35
+ valid: false,
36
+ };
37
+ }
38
+ return validateDiscoveredPackages(discovery.packages, root, packageRoot);
39
+ }
40
+ export { discoverPackages } from './validation/package-discovery.js';
41
+ export { formatValidationError, formatValidationText } from './validation/diagnostics.js';
42
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAI/E,SAAS,kBAAk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CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;gBACzC,SAAS,EAAE,EAAE;gBACb,IAAI,EAAE,IAAI;gBACV,KAAK,EAAE,MAAM;gBACb,OAAO;aACR,CAAC,CAAC;YACH,KAAK,EAAE,KAAK;SACb,CAAC;IACJ,CAAC;IACD,OAAO,0BAA0B,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;AAC3E,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC"}
@@ -0,0 +1,9 @@
1
+ export interface NewPackageTemplateContext {
2
+ packageName: string;
3
+ repositories: string[];
4
+ }
5
+ export interface NewPackageFile {
6
+ path: string;
7
+ contents: string;
8
+ }
9
+ export declare function createNewPackageFiles(context: NewPackageTemplateContext): NewPackageFile[];