@kici-dev/compiler 0.0.0 → 0.1.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 (221) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +1 -6
  3. package/dist/assets/api-TJJVHrjC.json +118 -0
  4. package/dist/assets/descriptor-BTtjzN9L.json +1382 -0
  5. package/dist/assets/package-BpQF9kR8.json +74 -0
  6. package/dist/assets/package-Ceo2h27X.json +89 -0
  7. package/dist/assets/source_context-D0atuL28.json +20 -0
  8. package/dist/assets/type-BFqO8SCZ.json +202 -0
  9. package/dist/auth/headless-detect.d.ts +14 -0
  10. package/dist/auth/headless-detect.js +25 -0
  11. package/dist/chunk-gOLHoazu.js +4 -0
  12. package/dist/cli.d.ts +3 -0
  13. package/dist/cli.js +193 -0
  14. package/dist/commands/cancel.d.ts +22 -0
  15. package/dist/commands/cancel.js +124 -0
  16. package/dist/commands/compile.d.ts +17 -0
  17. package/dist/commands/compile.js +99 -0
  18. package/dist/commands/docs.d.ts +26 -0
  19. package/dist/commands/docs.js +60 -0
  20. package/dist/commands/drain-worker.d.ts +19 -0
  21. package/dist/commands/drain-worker.js +45 -0
  22. package/dist/commands/endpoints.d.ts +53 -0
  23. package/dist/commands/endpoints.js +185 -0
  24. package/dist/commands/fixture.d.ts +14 -0
  25. package/dist/commands/fixture.js +104 -0
  26. package/dist/commands/hook.d.ts +20 -0
  27. package/dist/commands/hook.js +97 -0
  28. package/dist/commands/index.d.ts +33 -0
  29. package/dist/commands/index.js +20 -0
  30. package/dist/commands/init.d.ts +35 -0
  31. package/dist/commands/init.js +393 -0
  32. package/dist/commands/login.d.ts +23 -0
  33. package/dist/commands/login.js +144 -0
  34. package/dist/commands/logout.d.ts +18 -0
  35. package/dist/commands/logout.js +55 -0
  36. package/dist/commands/org.d.ts +27 -0
  37. package/dist/commands/org.js +126 -0
  38. package/dist/commands/run.d.ts +21 -0
  39. package/dist/commands/run.js +562 -0
  40. package/dist/commands/secrets-list.d.ts +16 -0
  41. package/dist/commands/secrets-list.js +85 -0
  42. package/dist/commands/status.d.ts +30 -0
  43. package/dist/commands/status.js +210 -0
  44. package/dist/commands/test.d.ts +61 -0
  45. package/dist/commands/test.js +220 -0
  46. package/dist/commands/types.d.ts +18 -0
  47. package/dist/commands/types.js +74 -0
  48. package/dist/commands/watch.d.ts +14 -0
  49. package/dist/commands/watch.js +97 -0
  50. package/dist/commands/workflows.d.ts +28 -0
  51. package/dist/commands/workflows.js +154 -0
  52. package/dist/comment-created.json +30 -0
  53. package/dist/create-branch.json +17 -0
  54. package/dist/delete-branch.json +15 -0
  55. package/dist/dispatch.json +15 -0
  56. package/dist/errors/capability-gap.d.ts +50 -0
  57. package/dist/errors/capability-gap.js +54 -0
  58. package/dist/errors/codes.d.ts +25 -0
  59. package/dist/errors/formatter.d.ts +32 -0
  60. package/dist/errors/formatter.js +35 -0
  61. package/dist/errors/index.d.ts +5 -0
  62. package/dist/errors/index.js +4 -0
  63. package/dist/execution/executor.d.ts +61 -0
  64. package/dist/execution/executor.js +230 -0
  65. package/dist/execution/index.d.ts +4 -0
  66. package/dist/execution/index.js +3 -0
  67. package/dist/execution/sdk-alias.d.ts +33 -0
  68. package/dist/execution/sdk-alias.js +102 -0
  69. package/dist/fixtures/compiler.d.ts +47 -0
  70. package/dist/fixtures/compiler.js +177 -0
  71. package/dist/fixtures/defaults/comment-created.json +30 -0
  72. package/dist/fixtures/defaults/create-branch.json +17 -0
  73. package/dist/fixtures/defaults/delete-branch.json +15 -0
  74. package/dist/fixtures/defaults/dispatch.json +15 -0
  75. package/dist/fixtures/defaults/fork.json +19 -0
  76. package/dist/fixtures/defaults/index.d.ts +16 -0
  77. package/dist/fixtures/defaults/index.js +105 -0
  78. package/dist/fixtures/defaults/index.ts +145 -0
  79. package/dist/fixtures/defaults/pr-closed.json +28 -0
  80. package/dist/fixtures/defaults/pr-opened.json +27 -0
  81. package/dist/fixtures/defaults/pr-reopened.json +27 -0
  82. package/dist/fixtures/defaults/pr-synchronize.json +27 -0
  83. package/dist/fixtures/defaults/push.json +16 -0
  84. package/dist/fixtures/defaults/release-published.json +23 -0
  85. package/dist/fixtures/defaults/review-comment-created.json +36 -0
  86. package/dist/fixtures/defaults/review-submitted.json +35 -0
  87. package/dist/fixtures/defaults/star-created.json +15 -0
  88. package/dist/fixtures/defaults/status.json +26 -0
  89. package/dist/fixtures/defaults/tag-push.json +20 -0
  90. package/dist/fixtures/defaults/watch-started.json +15 -0
  91. package/dist/fixtures/defaults/workflow-run-completed.json +23 -0
  92. package/dist/fork.json +19 -0
  93. package/dist/format.d.ts +5 -0
  94. package/dist/format.js +20 -0
  95. package/dist/generators/secrets-dts.d.ts +29 -0
  96. package/dist/generators/secrets-dts.js +67 -0
  97. package/dist/hooks/detector.d.ts +39 -0
  98. package/dist/hooks/detector.js +133 -0
  99. package/dist/hooks/index.d.ts +6 -0
  100. package/dist/hooks/index.js +5 -0
  101. package/dist/hooks/installer.d.ts +24 -0
  102. package/dist/hooks/installer.js +328 -0
  103. package/dist/hooks/templates.d.ts +26 -0
  104. package/dist/hooks/templates.js +63 -0
  105. package/dist/index.d.ts +12 -0
  106. package/dist/index.js +12 -0
  107. package/dist/llm-context/llms-full.txt +9974 -0
  108. package/dist/llm-context/llms.txt +61 -0
  109. package/dist/local-executor/dag-scheduler.d.ts +44 -0
  110. package/dist/local-executor/dag-scheduler.js +183 -0
  111. package/dist/local-executor/index.d.ts +23 -0
  112. package/dist/local-executor/index.js +309 -0
  113. package/dist/local-executor/job-runner.d.ts +40 -0
  114. package/dist/local-executor/job-runner.js +307 -0
  115. package/dist/local-executor/output-streamer.d.ts +31 -0
  116. package/dist/local-executor/output-streamer.js +166 -0
  117. package/dist/local-executor/payload-generator.d.ts +16 -0
  118. package/dist/local-executor/payload-generator.js +138 -0
  119. package/dist/local-executor/picker.d.ts +33 -0
  120. package/dist/local-executor/picker.js +109 -0
  121. package/dist/local-executor/secret-loader.d.ts +18 -0
  122. package/dist/local-executor/secret-loader.js +105 -0
  123. package/dist/local-executor/types.d.ts +80 -0
  124. package/dist/local-executor/types.js +2 -0
  125. package/dist/local-executor/workflow-lock.d.ts +81 -0
  126. package/dist/local-executor/workflow-lock.js +0 -0
  127. package/dist/lockfile/generator.d.ts +39 -0
  128. package/dist/lockfile/generator.js +688 -0
  129. package/dist/lockfile/hash-files.d.ts +14 -0
  130. package/dist/lockfile/hash-files.js +50 -0
  131. package/dist/lockfile/hasher.d.ts +36 -0
  132. package/dist/lockfile/hasher.js +46 -0
  133. package/dist/lockfile/index.d.ts +3 -0
  134. package/dist/lockfile/index.js +4 -0
  135. package/dist/lockfile/purity-analyzer.d.ts +25 -0
  136. package/dist/lockfile/purity-analyzer.js +204 -0
  137. package/dist/package-F7UXSDHW.json +74 -0
  138. package/dist/postinstall.d.ts +9 -0
  139. package/dist/postinstall.js +60 -0
  140. package/dist/pr-closed.json +28 -0
  141. package/dist/pr-opened.json +27 -0
  142. package/dist/pr-reopened.json +27 -0
  143. package/dist/pr-synchronize.json +27 -0
  144. package/dist/push.json +16 -0
  145. package/dist/release-published.json +23 -0
  146. package/dist/remote/client.d.ts +204 -0
  147. package/dist/remote/client.js +203 -0
  148. package/dist/remote/config.d.ts +54 -0
  149. package/dist/remote/config.js +92 -0
  150. package/dist/remote/encryption.d.ts +35 -0
  151. package/dist/remote/encryption.js +87 -0
  152. package/dist/remote/history.d.ts +91 -0
  153. package/dist/remote/history.js +146 -0
  154. package/dist/remote/oauth.d.ts +65 -0
  155. package/dist/remote/oauth.js +302 -0
  156. package/dist/remote/observer.d.ts +81 -0
  157. package/dist/remote/observer.js +174 -0
  158. package/dist/remote/output/json.d.ts +13 -0
  159. package/dist/remote/output/json.js +36 -0
  160. package/dist/remote/output/junit.d.ts +18 -0
  161. package/dist/remote/output/junit.js +50 -0
  162. package/dist/remote/output/streaming.d.ts +57 -0
  163. package/dist/remote/output/streaming.js +124 -0
  164. package/dist/remote/output/summary.d.ts +39 -0
  165. package/dist/remote/output/summary.js +99 -0
  166. package/dist/remote/uploader.d.ts +87 -0
  167. package/dist/remote/uploader.js +197 -0
  168. package/dist/review-comment-created.json +36 -0
  169. package/dist/review-submitted.json +35 -0
  170. package/dist/star-created.json +15 -0
  171. package/dist/status.json +26 -0
  172. package/dist/tag-push.json +20 -0
  173. package/dist/templates/agents-md.d.ts +8 -0
  174. package/dist/templates/agents-md.js +130 -0
  175. package/dist/templates/index.d.ts +43 -0
  176. package/dist/templates/index.js +48 -0
  177. package/dist/templates/package-json.d.ts +18 -0
  178. package/dist/templates/package-json.js +34 -0
  179. package/dist/templates/tsconfig-json.d.ts +9 -0
  180. package/dist/templates/tsconfig-json.js +26 -0
  181. package/dist/templates/workflows/hello-world.d.ts +2 -0
  182. package/dist/templates/workflows/hello-world.js +16 -0
  183. package/dist/templates/workflows/hello-world.ts +21 -0
  184. package/dist/templates/workflows/pr-checks.d.ts +2 -0
  185. package/dist/templates/workflows/pr-checks.js +40 -0
  186. package/dist/templates/workflows/pr-checks.ts +57 -0
  187. package/dist/test-runner/dry-run.d.ts +12 -0
  188. package/dist/test-runner/dry-run.js +66 -0
  189. package/dist/test-runner/event-types.d.ts +86 -0
  190. package/dist/test-runner/event-types.js +330 -0
  191. package/dist/test-runner/git-detector.d.ts +15 -0
  192. package/dist/test-runner/git-detector.js +30 -0
  193. package/dist/test-runner/index.d.ts +13 -0
  194. package/dist/test-runner/index.js +11 -0
  195. package/dist/test-runner/job-executor.d.ts +48 -0
  196. package/dist/test-runner/job-executor.js +245 -0
  197. package/dist/test-runner/output-formatter.d.ts +47 -0
  198. package/dist/test-runner/output-formatter.js +92 -0
  199. package/dist/test-runner/payload-builder.d.ts +20 -0
  200. package/dist/test-runner/payload-builder.js +216 -0
  201. package/dist/test-runner/rule-evaluator.d.ts +14 -0
  202. package/dist/test-runner/rule-evaluator.js +31 -0
  203. package/dist/test-runner/secrets-file.d.ts +24 -0
  204. package/dist/test-runner/secrets-file.js +62 -0
  205. package/dist/test-runner/step-context.d.ts +15 -0
  206. package/dist/test-runner/step-context.js +140 -0
  207. package/dist/test-runner/summary.d.ts +7 -0
  208. package/dist/types.d.ts +525 -0
  209. package/dist/types.js +33 -0
  210. package/dist/validation/index.d.ts +3 -0
  211. package/dist/validation/index.js +3 -0
  212. package/dist/validation/validator.d.ts +26 -0
  213. package/dist/validation/validator.js +164 -0
  214. package/dist/watch-started.json +15 -0
  215. package/dist/workflow-run-completed.json +23 -0
  216. package/dist/workflows/hello-world.ts +21 -0
  217. package/dist/workflows/pr-checks.ts +57 -0
  218. package/hack/postinstall.mjs +105 -0
  219. package/package.json +61 -5
  220. package/sbom.spdx.json +10997 -0
  221. package/index.js +0 -3
@@ -0,0 +1,164 @@
1
+ import "../chunk-gOLHoazu.js";
2
+ import { compilerError } from "../errors/formatter.js";
3
+ import "../errors/index.js";
4
+ import { getDynamicJobGroup, isDynamicGroupRef, isDynamicJobFn, isStaticArray, isStaticObject, validateDag } from "@kici-dev/sdk";
5
+ //#region src/validation/validator.ts
6
+ /** Maximum jobs from static matrix expansion (GitHub Actions limit) */
7
+ const MAX_STATIC_MATRIX_JOBS = 256;
8
+ /**
9
+ * Validate workflows at compile-time.
10
+ *
11
+ * Checks performed:
12
+ * 1. No duplicate workflow names
13
+ * 2. No duplicate job names within each workflow
14
+ * 3. Job dependencies are valid (exist, no cycles, no self-refs)
15
+ * 4. Static matrix expansions stay under 256 job limit
16
+ *
17
+ * @param workflows - Array of workflows from config
18
+ * @param configPath - Path for error location reporting
19
+ * @returns Validation result with errors if any
20
+ */
21
+ function validateConfig(workflows, configPath) {
22
+ const errors = [];
23
+ const workflowNames = /* @__PURE__ */ new Set();
24
+ for (const workflow of workflows) {
25
+ if (workflowNames.has(workflow.name)) errors.push(compilerError("E107", `Duplicate workflow name: "${workflow.name}"`, {
26
+ location: {
27
+ file: configPath,
28
+ line: 1,
29
+ column: 1
30
+ },
31
+ suggestion: "Each workflow must have a unique name"
32
+ }));
33
+ workflowNames.add(workflow.name);
34
+ }
35
+ for (const workflow of workflows) {
36
+ const workflowErrors = validateWorkflow(workflow, configPath);
37
+ errors.push(...workflowErrors);
38
+ }
39
+ if (errors.length > 0) return {
40
+ valid: false,
41
+ errors
42
+ };
43
+ return { valid: true };
44
+ }
45
+ /**
46
+ * Validate a single workflow.
47
+ */
48
+ function validateWorkflow(workflow, configPath) {
49
+ const errors = [];
50
+ const staticJobs = [];
51
+ for (const jobOrFactory of workflow.jobs) if (!isDynamicJobFn(jobOrFactory)) staticJobs.push(jobOrFactory);
52
+ const jobNames = /* @__PURE__ */ new Set();
53
+ for (const job of staticJobs) {
54
+ if (jobNames.has(job.name)) errors.push(compilerError("E106", `Duplicate job name "${job.name}" in workflow "${workflow.name}"`, {
55
+ location: {
56
+ file: configPath,
57
+ line: 1,
58
+ column: 1
59
+ },
60
+ suggestion: "Each job in a workflow must have a unique name"
61
+ }));
62
+ jobNames.add(job.name);
63
+ }
64
+ const dynamicGroupNames = /* @__PURE__ */ new Set();
65
+ for (const jobOrFactory of workflow.jobs) if (isDynamicJobFn(jobOrFactory)) {
66
+ const groupName = getDynamicJobGroup(jobOrFactory);
67
+ if (groupName) dynamicGroupNames.add(groupName);
68
+ }
69
+ const dagErrors = validateJobDag(staticJobs, workflow.name, configPath, dynamicGroupNames);
70
+ errors.push(...dagErrors);
71
+ for (const job of staticJobs) {
72
+ const matrixErrors = validateStaticMatrix(job, workflow.name, configPath);
73
+ errors.push(...matrixErrors);
74
+ }
75
+ return errors;
76
+ }
77
+ /**
78
+ * Validate job dependency DAG.
79
+ * Includes synthetic __group: nodes for tagged dynamic job functions ( Layer 1).
80
+ */
81
+ function validateJobDag(jobs, workflowName, configPath, dynamicGroupNames) {
82
+ const errors = [];
83
+ const dagNodes = jobs.map((job) => ({
84
+ id: job.name,
85
+ needs: resolveNeeds(job.needs)
86
+ }));
87
+ if (dynamicGroupNames) for (const groupName of dynamicGroupNames) dagNodes.push({
88
+ id: `__group:${groupName}`,
89
+ needs: []
90
+ });
91
+ const result = validateDag(dagNodes);
92
+ if (!result.valid) switch (result.error) {
93
+ case "cycle":
94
+ errors.push(compilerError("E102", `Circular dependency in workflow "${workflowName}": ${result.nodesInCycle.join(" -> ")}`, {
95
+ location: {
96
+ file: configPath,
97
+ line: 1,
98
+ column: 1
99
+ },
100
+ suggestion: "Break the cycle by removing one of the dependencies"
101
+ }));
102
+ break;
103
+ case "self-reference":
104
+ errors.push(compilerError("E103", `Job "${result.nodeId}" in workflow "${workflowName}" depends on itself`, {
105
+ location: {
106
+ file: configPath,
107
+ line: 1,
108
+ column: 1
109
+ },
110
+ suggestion: "Remove the self-dependency"
111
+ }));
112
+ break;
113
+ case "missing-dependency":
114
+ errors.push(compilerError("E101", `Job "${result.nodeId}" in workflow "${workflowName}" depends on non-existent job "${result.missingDep}"`, {
115
+ location: {
116
+ file: configPath,
117
+ line: 1,
118
+ column: 1
119
+ },
120
+ suggestion: `Create a job named "${result.missingDep}" or fix the dependency name`
121
+ }));
122
+ break;
123
+ }
124
+ return errors;
125
+ }
126
+ /**
127
+ * Resolve needs array to job names (handling Job objects, strings, DynamicGroupRef, and object forms).
128
+ * DynamicGroupRef and { group } forms resolve to synthetic __group: node names.
129
+ */
130
+ function resolveNeeds(needs) {
131
+ if (!needs) return [];
132
+ return needs.map((need) => {
133
+ if (typeof need === "string") return need;
134
+ if (isDynamicGroupRef(need)) return `__group:${need.group}`;
135
+ if ("group" in need && typeof need.group === "string") return `__group:${need.group}`;
136
+ if ("name" in need) return need.name;
137
+ return String(need);
138
+ });
139
+ }
140
+ /**
141
+ * Validate static matrix doesn't exceed job limit.
142
+ */
143
+ function validateStaticMatrix(job, workflowName, configPath) {
144
+ const errors = [];
145
+ if (!job.matrix) return errors;
146
+ if (typeof job.matrix === "function") return errors;
147
+ let expansionCount = 1;
148
+ if (isStaticArray(job.matrix)) expansionCount = job.matrix.length;
149
+ else if (isStaticObject(job.matrix)) expansionCount = Object.values(job.matrix).reduce((acc, dimension) => acc * dimension.length, 1);
150
+ if (job.include) expansionCount += job.include.length;
151
+ if (expansionCount > MAX_STATIC_MATRIX_JOBS) errors.push(compilerError("E104", `Static matrix for job "${job.name}" in workflow "${workflowName}" would generate ${expansionCount} jobs (max: ${MAX_STATIC_MATRIX_JOBS})`, {
152
+ location: {
153
+ file: configPath,
154
+ line: 1,
155
+ column: 1
156
+ },
157
+ suggestion: "Reduce matrix dimensions or use exclude patterns to limit combinations"
158
+ }));
159
+ return errors;
160
+ }
161
+ //#endregion
162
+ export { validateConfig };
163
+
164
+ //# sourceMappingURL=validator.js.map
@@ -0,0 +1,15 @@
1
+ {
2
+ "action": "started",
3
+ "repository": {
4
+ "name": "test-repo",
5
+ "full_name": "test-org/test-repo",
6
+ "owner": {
7
+ "login": "test-org"
8
+ },
9
+ "default_branch": "main",
10
+ "watchers_count": 50
11
+ },
12
+ "sender": {
13
+ "login": "test-user"
14
+ }
15
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "action": "completed",
3
+ "workflow_run": {
4
+ "id": 1,
5
+ "name": "CI",
6
+ "head_branch": "main",
7
+ "head_sha": "abc123def456",
8
+ "status": "completed",
9
+ "conclusion": "success",
10
+ "event": "push"
11
+ },
12
+ "repository": {
13
+ "name": "test-repo",
14
+ "full_name": "test-org/test-repo",
15
+ "owner": {
16
+ "login": "test-org"
17
+ },
18
+ "default_branch": "main"
19
+ },
20
+ "sender": {
21
+ "login": "test-user"
22
+ }
23
+ }
@@ -0,0 +1,21 @@
1
+ // Hello World -- minimal push workflow
2
+ // Docs: https://kici.dev/docs/sdk-reference
3
+
4
+ import { workflow, job, step, push } from '@kici-dev/sdk';
5
+
6
+ export const helloWorldWorkflow = workflow('hello-world', {
7
+ // Trigger: push() matches any push event
8
+ // Options: branches, tags, paths, description (config-style; use !-prefix for exclusions)
9
+ on: push(),
10
+
11
+ jobs: [
12
+ job('greet', {
13
+ runsOn: 'ubuntu-latest',
14
+ steps: [
15
+ step('say-hello', async ({ $ }) => {
16
+ await $`echo "Hello, World!"`;
17
+ }),
18
+ ],
19
+ }),
20
+ ],
21
+ });
@@ -0,0 +1,57 @@
1
+ // PR Checks -- workflow with rules, dependencies, and multiple jobs
2
+ // Docs: https://kici.dev/docs/sdk-reference
3
+ // Patterns: https://kici.dev/docs/workflow-patterns
4
+
5
+ import { workflow, job, step, pr, rule, skip } from '@kici-dev/sdk';
6
+
7
+ export const prChecksWorkflow = workflow('pr-checks', {
8
+ // Trigger: pr() matches pull request events
9
+ // Options: target, paths, events (config-style)
10
+ on: pr({ target: 'main', paths: ['src/**'] }),
11
+
12
+ // Rules: evaluated before workflow runs
13
+ // skip() = skip if true, rule() = run only if true
14
+ rules: [
15
+ skip('skip-draft-prs', async (ctx) => {
16
+ return (ctx.event as any).pull_request?.draft === true;
17
+ }),
18
+
19
+ rule('require-src-changes', async (ctx) => {
20
+ return ctx.changedFiles.some((file) => file.startsWith('src/'));
21
+ }),
22
+ ],
23
+
24
+ // Jobs: run in parallel unless connected via `needs`
25
+ jobs: [
26
+ job('lint', {
27
+ runsOn: 'ubuntu-latest',
28
+ steps: [
29
+ step('checkout', async ({ $ }) => {
30
+ await $`echo "Checking out code..."`;
31
+ }),
32
+ step('run-linter', async ({ $ }) => {
33
+ // Replace with your linter: eslint, biome, cargo clippy, etc.
34
+ await $`echo "Running linter..."`;
35
+ }),
36
+ ],
37
+ }),
38
+
39
+ job('test', {
40
+ runsOn: 'ubuntu-latest',
41
+ needs: ['lint'], // Waits for lint to pass
42
+ steps: [
43
+ step('checkout', async ({ $ }) => {
44
+ await $`echo "Checking out code..."`;
45
+ }),
46
+ step('install-deps', async ({ $ }) => {
47
+ // Replace with: npm ci, etc.
48
+ await $`echo "Installing dependencies..."`;
49
+ }),
50
+ step('run-tests', async ({ $ }) => {
51
+ // Replace with: npm test, vitest run, cargo test, etc.
52
+ await $`echo "Running tests..."`;
53
+ }),
54
+ ],
55
+ }),
56
+ ],
57
+ });
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Postinstall wrapper script for @kici-dev/compiler
4
+ *
5
+ * This wrapper:
6
+ * 1. Detects development mode (KICI_DEV env or kici.development in root package.json)
7
+ * 2. Skips postinstall in dev mode (prevents "Cannot find dist/postinstall.mjs" errors)
8
+ * 3. Delegates to dist/postinstall.mjs in production mode
9
+ *
10
+ * Purpose: Allow `pnpm install` to succeed even when dist/ hasn't been built yet
11
+ */
12
+
13
+ import { spawn } from 'node:child_process';
14
+ import { readFile } from 'node:fs/promises';
15
+ import path from 'node:path';
16
+ import { fileURLToPath } from 'node:url';
17
+
18
+ const __filename = fileURLToPath(import.meta.url);
19
+ const __dirname = path.dirname(__filename);
20
+
21
+ /**
22
+ * Detect if running in development mode
23
+ *
24
+ * Development mode is used when developing KiCI itself.
25
+ * Checks:
26
+ * 1. KICI_DEV environment variable
27
+ * 2. Root package.json kici.development flag
28
+ *
29
+ * @returns {Promise<boolean>} true if in development mode
30
+ */
31
+ async function detectDevelopmentMode() {
32
+ // Method 1: Environment variable
33
+ if (process.env.KICI_DEV === 'true') {
34
+ if (process.env.KICI_DEBUG === 'true') {
35
+ console.log('[postinstall] Skipping: KICI_DEV=true');
36
+ }
37
+ return true;
38
+ }
39
+
40
+ // Method 2: Check root package.json for kici.development flag
41
+ // During npm/pnpm install, INIT_CWD contains the original working directory (project root)
42
+ try {
43
+ const rootDir = process.env.INIT_CWD || process.cwd();
44
+ const rootPkgPath = path.join(rootDir, 'package.json');
45
+ const content = await readFile(rootPkgPath, 'utf-8');
46
+ const pkg = JSON.parse(content);
47
+
48
+ if (pkg.kici?.development === true) {
49
+ if (process.env.KICI_DEBUG === 'true') {
50
+ console.log('[postinstall] Skipping: kici.development=true in root package.json');
51
+ }
52
+ return true;
53
+ }
54
+ } catch {
55
+ // Root package.json doesn't exist or can't be read
56
+ }
57
+
58
+ return false;
59
+ }
60
+
61
+ /**
62
+ * Run the actual postinstall script
63
+ *
64
+ * @returns {Promise<void>}
65
+ */
66
+ function runPostinstall() {
67
+ return new Promise((resolve, reject) => {
68
+ const postinstallPath = path.join(__dirname, '..', 'dist', 'postinstall.js');
69
+
70
+ const child = spawn('node', [postinstallPath], {
71
+ stdio: 'inherit',
72
+ });
73
+
74
+ child.on('close', (code) => {
75
+ if (code === 0) {
76
+ resolve();
77
+ } else {
78
+ reject(new Error(`postinstall.mjs exited with code ${code}`));
79
+ }
80
+ });
81
+
82
+ child.on('error', (err) => {
83
+ reject(err);
84
+ });
85
+ });
86
+ }
87
+
88
+ async function main() {
89
+ try {
90
+ // Skip in development mode
91
+ if (await detectDevelopmentMode()) {
92
+ return;
93
+ }
94
+
95
+ // Run the actual postinstall
96
+ await runPostinstall();
97
+ } catch (err) {
98
+ // Silently fail - postinstall should not break npm install
99
+ if (process.env.KICI_DEBUG === 'true') {
100
+ console.error('[postinstall] Error:', err.message);
101
+ }
102
+ }
103
+ }
104
+
105
+ main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kici-dev/compiler",
3
- "version": "0.0.0",
3
+ "version": "0.1.1",
4
4
  "description": "Compiler and CLI for KiCI workflows. Compiles `.kici/workflows/*.ts` to a `kici.lock.json` file consumed by the orchestrator and agents, and runs workflows locally or against a remote orchestrator.",
5
5
  "keywords": [
6
6
  "kici",
@@ -9,7 +9,9 @@
9
9
  "ci-cd",
10
10
  "typescript",
11
11
  "workflows",
12
- "devops"
12
+ "devops",
13
+ "cli",
14
+ "compiler"
13
15
  ],
14
16
  "homepage": "https://kici.dev",
15
17
  "author": {
@@ -17,9 +19,63 @@
17
19
  "email": "hello@kici.dev"
18
20
  },
19
21
  "license": "Apache-2.0",
20
- "main": "index.js",
22
+ "engines": {
23
+ "node": ">=24"
24
+ },
21
25
  "publishConfig": {
22
- "access": "public",
23
- "registry": "https://registry.npmjs.org/"
26
+ "registry": "https://registry.npmjs.org/",
27
+ "access": "public"
28
+ },
29
+ "type": "module",
30
+ "bin": {
31
+ "kici": "./dist/cli.js"
32
+ },
33
+ "files": [
34
+ "dist",
35
+ "!dist/**/*.map",
36
+ "hack/postinstall.mjs",
37
+ "sbom.spdx.json"
38
+ ],
39
+ "main": "dist/index.js",
40
+ "types": "dist/index.d.ts",
41
+ "exports": {
42
+ ".": {
43
+ "import": "./dist/index.js",
44
+ "types": "./dist/index.d.ts"
45
+ },
46
+ "./cli": "./dist/cli.js"
47
+ },
48
+ "scripts": {
49
+ "build": "node ../../scripts/build-ts.mjs && tsc --emitDeclarationOnly",
50
+ "postbuild": "zx hack/postbuild.mjs",
51
+ "typecheck": "tsc --noEmit",
52
+ "test": "vitest run",
53
+ "test:watch": "vitest",
54
+ "postinstall": "node hack/postinstall.mjs",
55
+ "postpublish": "node ../../packages/kici/hack/publish-wrapper.mjs",
56
+ "prepublishOnly": "npx tsx ../../hack/generate-sbom.ts --package packages/compiler --name @kici-dev/compiler"
57
+ },
58
+ "dependencies": {
59
+ "@inquirer/prompts": "^8.4.2",
60
+ "@kici-dev/engine": "workspace:*",
61
+ "@kici-dev/shared": "workspace:*",
62
+ "chokidar": "^5.0.0",
63
+ "commander": "^14.0.3",
64
+ "fast-glob": "^3.3.3",
65
+ "open": "^11.0.0",
66
+ "picocolors": "^1.1.1",
67
+ "picomatch": "^4.0.4",
68
+ "proper-lockfile": "^4.1.2",
69
+ "tar": "^7.5.13",
70
+ "typescript": "^6.0.3",
71
+ "ws": "^8.20.0",
72
+ "yaml": "^2.8.3",
73
+ "zx": "^8.8.5"
74
+ },
75
+ "peerDependencies": {
76
+ "@kici-dev/sdk": "workspace:*"
77
+ },
78
+ "devDependencies": {
79
+ "@types/proper-lockfile": "^4.1.4"
24
80
  }
25
81
  }