create-stencil-components 1.0.7 → 1.0.9
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.
- package/dist/templates/base/.agents/skills/link-workspace-packages/SKILL.md +127 -0
- package/dist/templates/base/.agents/skills/monitor-ci/SKILL.md +301 -0
- package/dist/templates/base/.agents/skills/monitor-ci/references/fix-flows.md +108 -0
- package/dist/templates/base/.agents/skills/monitor-ci/scripts/ci-poll-decide.mjs +356 -0
- package/dist/templates/base/.agents/skills/monitor-ci/scripts/ci-state-update.mjs +152 -0
- package/dist/templates/base/.agents/skills/nx-generate/SKILL.md +166 -0
- package/dist/templates/base/.agents/skills/nx-import/SKILL.md +238 -0
- package/dist/templates/base/.agents/skills/nx-import/references/ESLINT.md +109 -0
- package/dist/templates/base/.agents/skills/nx-import/references/GRADLE.md +12 -0
- package/dist/templates/base/.agents/skills/nx-import/references/JEST.md +223 -0
- package/dist/templates/base/.agents/skills/nx-import/references/NEXT.md +214 -0
- package/dist/templates/base/.agents/skills/nx-import/references/TURBOREPO.md +62 -0
- package/dist/templates/base/.agents/skills/nx-import/references/VITE.md +393 -0
- package/dist/templates/base/.agents/skills/nx-plugins/SKILL.md +9 -0
- package/dist/templates/base/.agents/skills/nx-run-tasks/SKILL.md +58 -0
- package/dist/templates/base/.agents/skills/nx-workspace/SKILL.md +284 -0
- package/dist/templates/base/.agents/skills/nx-workspace/references/AFFECTED.md +27 -0
- package/dist/templates/base/.claude/settings.json +13 -0
- package/dist/templates/base/.codex/agents/ci-monitor-subagent.toml +46 -0
- package/dist/templates/base/.codex/config.toml +10 -0
- package/dist/templates/base/.cursor/agents/ci-monitor-subagent.md +51 -0
- package/dist/templates/base/.gemini/commands/monitor-ci.toml +298 -0
- package/dist/templates/base/.gemini/settings.json +8 -11
- package/dist/templates/base/.github/agents/ci-monitor-subagent.agent.md +49 -0
- package/dist/templates/base/.github/prompts/monitor-ci.prompt.md +301 -0
- package/dist/templates/base/.github/skills/link-workspace-packages/SKILL.md +127 -0
- package/dist/templates/base/.github/skills/monitor-ci/SKILL.md +301 -0
- package/dist/templates/base/.github/skills/monitor-ci/references/fix-flows.md +108 -0
- package/dist/templates/base/.github/skills/monitor-ci/scripts/ci-poll-decide.mjs +356 -0
- package/dist/templates/base/.github/skills/monitor-ci/scripts/ci-state-update.mjs +152 -0
- package/dist/templates/base/.github/skills/nx-generate/SKILL.md +166 -0
- package/dist/templates/base/.github/skills/nx-import/SKILL.md +238 -0
- package/dist/templates/base/.github/skills/nx-import/references/ESLINT.md +109 -0
- package/dist/templates/base/.github/skills/nx-import/references/GRADLE.md +12 -0
- package/dist/templates/base/.github/skills/nx-import/references/JEST.md +223 -0
- package/dist/templates/base/.github/skills/nx-import/references/NEXT.md +214 -0
- package/dist/templates/base/.github/skills/nx-import/references/TURBOREPO.md +62 -0
- package/dist/templates/base/.github/skills/nx-import/references/VITE.md +393 -0
- package/dist/templates/base/.github/skills/nx-plugins/SKILL.md +9 -0
- package/dist/templates/base/.github/skills/nx-run-tasks/SKILL.md +58 -0
- package/dist/templates/base/.github/skills/nx-workspace/SKILL.md +284 -0
- package/dist/templates/base/.github/skills/nx-workspace/references/AFFECTED.md +27 -0
- package/dist/templates/base/.opencode/agents/ci-monitor-subagent.md +50 -0
- package/dist/templates/base/.opencode/commands/monitor-ci.md +301 -0
- package/dist/templates/base/.opencode/skills/link-workspace-packages/SKILL.md +127 -0
- package/dist/templates/base/.opencode/skills/monitor-ci/SKILL.md +301 -0
- package/dist/templates/base/.opencode/skills/monitor-ci/references/fix-flows.md +108 -0
- package/dist/templates/base/.opencode/skills/monitor-ci/scripts/ci-poll-decide.mjs +356 -0
- package/dist/templates/base/.opencode/skills/monitor-ci/scripts/ci-state-update.mjs +152 -0
- package/dist/templates/base/.opencode/skills/nx-generate/SKILL.md +166 -0
- package/dist/templates/base/.opencode/skills/nx-import/SKILL.md +238 -0
- package/dist/templates/base/.opencode/skills/nx-import/references/ESLINT.md +109 -0
- package/dist/templates/base/.opencode/skills/nx-import/references/GRADLE.md +12 -0
- package/dist/templates/base/.opencode/skills/nx-import/references/JEST.md +223 -0
- package/dist/templates/base/.opencode/skills/nx-import/references/NEXT.md +214 -0
- package/dist/templates/base/.opencode/skills/nx-import/references/TURBOREPO.md +62 -0
- package/dist/templates/base/.opencode/skills/nx-import/references/VITE.md +393 -0
- package/dist/templates/base/.opencode/skills/nx-plugins/SKILL.md +9 -0
- package/dist/templates/base/.opencode/skills/nx-run-tasks/SKILL.md +58 -0
- package/dist/templates/base/.opencode/skills/nx-workspace/SKILL.md +284 -0
- package/dist/templates/base/.opencode/skills/nx-workspace/references/AFFECTED.md +27 -0
- package/dist/templates/base/AGENTS.md +46 -36
- package/dist/templates/base/CLAUDE.md +15 -5
- package/dist/templates/base/package.json +3 -3
- package/dist/templates/variants/all/packages/components-{{PROJECT_NAME_KEBAB}}-core/package.json +3 -3
- package/dist/templates/variants/all/packages/components-{{PROJECT_NAME_KEBAB}}-react/package.json +2 -2
- package/dist/templates/variants/all/packages/components-{{PROJECT_NAME_KEBAB}}-react/tsconfig.json +5 -1
- package/dist/templates/variants/angular/packages/components-{{PROJECT_NAME_KEBAB}}-core/package.json +2 -2
- package/dist/templates/variants/react/packages/components-{{PROJECT_NAME_KEBAB}}-core/package.json +2 -2
- package/dist/templates/variants/react/packages/components-{{PROJECT_NAME_KEBAB}}-react/package.json +2 -2
- package/dist/templates/variants/react/packages/components-{{PROJECT_NAME_KEBAB}}-react/tsconfig.json +5 -1
- package/dist/templates/variants/vue/packages/components-{{PROJECT_NAME_KEBAB}}-core/package.json +1 -1
- package/dist/templates/variants/web-components/packages/components-{{PROJECT_NAME_KEBAB}}-core/package.json +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* CI Poll Decision Script
|
|
5
|
+
*
|
|
6
|
+
* Deterministic decision engine for CI monitoring.
|
|
7
|
+
* Takes ci_information JSON + state args, outputs a single JSON action line.
|
|
8
|
+
*
|
|
9
|
+
* Architecture:
|
|
10
|
+
* classify() — pure decision tree, returns { action, code, extra? }
|
|
11
|
+
* buildOutput() — maps classification to full output with messages, delays, counters
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* node ci-poll-decide.mjs '<ci_info_json>' <poll_count> <verbosity> \
|
|
15
|
+
* [--wait-mode] [--prev-cipe-url <url>] [--expected-sha <sha>] \
|
|
16
|
+
* [--prev-status <status>] [--timeout <seconds>] [--new-cipe-timeout <seconds>] \
|
|
17
|
+
* [--env-rerun-count <n>] [--no-progress-count <n>] \
|
|
18
|
+
* [--prev-cipe-status <status>] [--prev-sh-status <status>] \
|
|
19
|
+
* [--prev-verification-status <status>] [--prev-failure-classification <status>]
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
// --- Arg parsing ---
|
|
23
|
+
|
|
24
|
+
const args = process.argv.slice(2);
|
|
25
|
+
const ciInfoJson = args[0];
|
|
26
|
+
const pollCount = parseInt(args[1], 10) || 0;
|
|
27
|
+
const verbosity = args[2] || 'medium';
|
|
28
|
+
|
|
29
|
+
function getFlag(name) {
|
|
30
|
+
return args.includes(name);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function getArg(name) {
|
|
34
|
+
const idx = args.indexOf(name);
|
|
35
|
+
return idx !== -1 && idx + 1 < args.length ? args[idx + 1] : null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const waitMode = getFlag('--wait-mode');
|
|
39
|
+
const prevCipeUrl = getArg('--prev-cipe-url');
|
|
40
|
+
const expectedSha = getArg('--expected-sha');
|
|
41
|
+
const prevStatus = getArg('--prev-status');
|
|
42
|
+
const timeoutSeconds = parseInt(getArg('--timeout') || '0', 10);
|
|
43
|
+
const newCipeTimeoutSeconds = parseInt(getArg('--new-cipe-timeout') || '0', 10);
|
|
44
|
+
const envRerunCount = parseInt(getArg('--env-rerun-count') || '0', 10);
|
|
45
|
+
const inputNoProgressCount = parseInt(getArg('--no-progress-count') || '0', 10);
|
|
46
|
+
const prevCipeStatus = getArg('--prev-cipe-status');
|
|
47
|
+
const prevShStatus = getArg('--prev-sh-status');
|
|
48
|
+
const prevVerificationStatus = getArg('--prev-verification-status');
|
|
49
|
+
const prevFailureClassification = getArg('--prev-failure-classification');
|
|
50
|
+
|
|
51
|
+
// --- Parse CI info ---
|
|
52
|
+
|
|
53
|
+
let ci;
|
|
54
|
+
try {
|
|
55
|
+
ci = JSON.parse(ciInfoJson);
|
|
56
|
+
} catch {
|
|
57
|
+
console.log(
|
|
58
|
+
JSON.stringify({
|
|
59
|
+
action: 'done',
|
|
60
|
+
code: 'error',
|
|
61
|
+
message: 'Failed to parse ci_information JSON',
|
|
62
|
+
noProgressCount: inputNoProgressCount + 1,
|
|
63
|
+
envRerunCount,
|
|
64
|
+
}),
|
|
65
|
+
);
|
|
66
|
+
process.exit(0);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const {
|
|
70
|
+
cipeStatus,
|
|
71
|
+
selfHealingStatus,
|
|
72
|
+
verificationStatus,
|
|
73
|
+
selfHealingEnabled,
|
|
74
|
+
selfHealingSkippedReason,
|
|
75
|
+
failureClassification: rawFailureClassification,
|
|
76
|
+
failedTaskIds = [],
|
|
77
|
+
verifiedTaskIds = [],
|
|
78
|
+
couldAutoApplyTasks,
|
|
79
|
+
autoApplySkipped,
|
|
80
|
+
autoApplySkipReason,
|
|
81
|
+
userAction,
|
|
82
|
+
cipeUrl,
|
|
83
|
+
commitSha,
|
|
84
|
+
} = ci;
|
|
85
|
+
|
|
86
|
+
const failureClassification = rawFailureClassification?.toLowerCase() ?? null;
|
|
87
|
+
|
|
88
|
+
// --- Helpers ---
|
|
89
|
+
|
|
90
|
+
function categorizeTasks() {
|
|
91
|
+
const verifiedSet = new Set(verifiedTaskIds);
|
|
92
|
+
const unverified = failedTaskIds.filter(t => !verifiedSet.has(t));
|
|
93
|
+
if (unverified.length === 0) return { category: 'all_verified' };
|
|
94
|
+
|
|
95
|
+
const e2e = unverified.filter(t => {
|
|
96
|
+
const parts = t.split(':');
|
|
97
|
+
return parts.length >= 2 && parts[1].includes('e2e');
|
|
98
|
+
});
|
|
99
|
+
if (e2e.length === unverified.length) return { category: 'e2e_only' };
|
|
100
|
+
|
|
101
|
+
const verifiable = unverified.filter(t => {
|
|
102
|
+
const parts = t.split(':');
|
|
103
|
+
return !(parts.length >= 2 && parts[1].includes('e2e'));
|
|
104
|
+
});
|
|
105
|
+
return { category: 'needs_local_verify', verifiableTaskIds: verifiable };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function backoff(count) {
|
|
109
|
+
const delays = [60, 90, 120, 180];
|
|
110
|
+
return delays[Math.min(count, delays.length - 1)];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function hasStateChanged() {
|
|
114
|
+
if (prevCipeStatus && cipeStatus !== prevCipeStatus) return true;
|
|
115
|
+
if (prevShStatus && selfHealingStatus !== prevShStatus) return true;
|
|
116
|
+
if (prevVerificationStatus && verificationStatus !== prevVerificationStatus) return true;
|
|
117
|
+
if (prevFailureClassification && failureClassification !== prevFailureClassification) return true;
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function isTimedOut() {
|
|
122
|
+
if (timeoutSeconds <= 0) return false;
|
|
123
|
+
const avgDelay = pollCount === 0 ? 0 : backoff(Math.floor(pollCount / 2));
|
|
124
|
+
return pollCount * avgDelay >= timeoutSeconds;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function isWaitTimedOut() {
|
|
128
|
+
if (newCipeTimeoutSeconds <= 0) return false;
|
|
129
|
+
return pollCount * 30 >= newCipeTimeoutSeconds;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function isNewCipe() {
|
|
133
|
+
return (prevCipeUrl && cipeUrl && cipeUrl !== prevCipeUrl) || (expectedSha && commitSha && commitSha === expectedSha);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// ============================================================
|
|
137
|
+
// classify() — pure decision tree
|
|
138
|
+
//
|
|
139
|
+
// Returns: { action: 'poll'|'wait'|'done', code: string, extra? }
|
|
140
|
+
//
|
|
141
|
+
// Decision priority (top wins):
|
|
142
|
+
// WAIT MODE:
|
|
143
|
+
// 1. new CI Attempt detected → poll (new_cipe_detected)
|
|
144
|
+
// 2. wait timed out → done (no_new_cipe)
|
|
145
|
+
// 3. still waiting → wait (waiting_for_cipe)
|
|
146
|
+
// NORMAL MODE:
|
|
147
|
+
// 4. polling timeout → done (polling_timeout)
|
|
148
|
+
// 5. circuit breaker (13 polls) → done (circuit_breaker)
|
|
149
|
+
// 6. CI succeeded → done (ci_success)
|
|
150
|
+
// 7. CI canceled → done (cipe_canceled)
|
|
151
|
+
// 8. CI timed out → done (cipe_timed_out)
|
|
152
|
+
// 9. CI failed, no tasks recorded → done (cipe_no_tasks)
|
|
153
|
+
// 10. environment failure → done (environment_rerun_cap | environment_issue)
|
|
154
|
+
// 11. self-healing throttled → done (self_healing_throttled)
|
|
155
|
+
// 12. CI in progress / not started → poll (ci_running)
|
|
156
|
+
// 13. self-healing in progress → poll (sh_running)
|
|
157
|
+
// 14. flaky task auto-rerun → poll (flaky_rerun)
|
|
158
|
+
// 15. fix auto-applied → poll (fix_auto_applied)
|
|
159
|
+
// 16. auto-apply: skipped → done (fix_auto_apply_skipped)
|
|
160
|
+
// 17. auto-apply: verification pending→ poll (verification_pending)
|
|
161
|
+
// 18. auto-apply: verified → done (fix_auto_applying)
|
|
162
|
+
// 19. fix: verification failed/none → done (fix_needs_review)
|
|
163
|
+
// 20. fix: all/e2e verified → done (fix_apply_ready)
|
|
164
|
+
// 21. fix: needs local verify → done (fix_needs_local_verify)
|
|
165
|
+
// 22. self-healing failed → done (fix_failed)
|
|
166
|
+
// 23. no fix available → done (no_fix)
|
|
167
|
+
// 24. fallback → poll (fallback)
|
|
168
|
+
// ============================================================
|
|
169
|
+
|
|
170
|
+
function classify() {
|
|
171
|
+
// --- Wait mode ---
|
|
172
|
+
if (waitMode) {
|
|
173
|
+
if (isNewCipe()) return { action: 'poll', code: 'new_cipe_detected' };
|
|
174
|
+
if (isWaitTimedOut()) return { action: 'done', code: 'no_new_cipe' };
|
|
175
|
+
return { action: 'wait', code: 'waiting_for_cipe' };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// --- Guards ---
|
|
179
|
+
if (isTimedOut()) return { action: 'done', code: 'polling_timeout' };
|
|
180
|
+
if (noProgressCount >= 13) return { action: 'done', code: 'circuit_breaker' };
|
|
181
|
+
|
|
182
|
+
// --- Terminal CI states ---
|
|
183
|
+
if (cipeStatus === 'SUCCEEDED') return { action: 'done', code: 'ci_success' };
|
|
184
|
+
if (cipeStatus === 'CANCELED') return { action: 'done', code: 'cipe_canceled' };
|
|
185
|
+
if (cipeStatus === 'TIMED_OUT') return { action: 'done', code: 'cipe_timed_out' };
|
|
186
|
+
|
|
187
|
+
// --- CI failed, no tasks ---
|
|
188
|
+
if (cipeStatus === 'FAILED' && failedTaskIds.length === 0 && selfHealingStatus == null) return { action: 'done', code: 'cipe_no_tasks' };
|
|
189
|
+
|
|
190
|
+
// --- Environment failure ---
|
|
191
|
+
if (failureClassification === 'environment_state') {
|
|
192
|
+
if (envRerunCount >= 2) return { action: 'done', code: 'environment_rerun_cap' };
|
|
193
|
+
return { action: 'done', code: 'environment_issue' };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// --- Throttled ---
|
|
197
|
+
if (selfHealingSkippedReason === 'THROTTLED') return { action: 'done', code: 'self_healing_throttled' };
|
|
198
|
+
|
|
199
|
+
// --- Still running: CI ---
|
|
200
|
+
if (cipeStatus === 'IN_PROGRESS' || cipeStatus === 'NOT_STARTED') return { action: 'poll', code: 'ci_running' };
|
|
201
|
+
|
|
202
|
+
// --- Still running: self-healing ---
|
|
203
|
+
if ((selfHealingStatus === 'IN_PROGRESS' || selfHealingStatus === 'NOT_STARTED') && !selfHealingSkippedReason) return { action: 'poll', code: 'sh_running' };
|
|
204
|
+
|
|
205
|
+
// --- Still running: flaky rerun ---
|
|
206
|
+
if (failureClassification === 'flaky_task') return { action: 'poll', code: 'flaky_rerun' };
|
|
207
|
+
|
|
208
|
+
// --- Fix auto-applied, waiting for new CI Attempt ---
|
|
209
|
+
if (userAction === 'APPLIED_AUTOMATICALLY') return { action: 'poll', code: 'fix_auto_applied' };
|
|
210
|
+
|
|
211
|
+
// --- Auto-apply path (couldAutoApplyTasks) ---
|
|
212
|
+
if (couldAutoApplyTasks === true) {
|
|
213
|
+
if (autoApplySkipped === true)
|
|
214
|
+
return {
|
|
215
|
+
action: 'done',
|
|
216
|
+
code: 'fix_auto_apply_skipped',
|
|
217
|
+
extra: { autoApplySkipReason },
|
|
218
|
+
};
|
|
219
|
+
if (verificationStatus === 'NOT_STARTED' || verificationStatus === 'IN_PROGRESS') return { action: 'poll', code: 'verification_pending' };
|
|
220
|
+
if (verificationStatus === 'COMPLETED') return { action: 'done', code: 'fix_auto_applying' };
|
|
221
|
+
// verification FAILED or NOT_EXECUTABLE → falls through to fix_needs_review
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// --- Fix available ---
|
|
225
|
+
if (selfHealingStatus === 'COMPLETED') {
|
|
226
|
+
if (verificationStatus === 'FAILED' || verificationStatus === 'NOT_EXECUTABLE' || (couldAutoApplyTasks !== true && !verificationStatus))
|
|
227
|
+
return { action: 'done', code: 'fix_needs_review' };
|
|
228
|
+
|
|
229
|
+
const tasks = categorizeTasks();
|
|
230
|
+
if (tasks.category === 'all_verified' || tasks.category === 'e2e_only') return { action: 'done', code: 'fix_apply_ready' };
|
|
231
|
+
return {
|
|
232
|
+
action: 'done',
|
|
233
|
+
code: 'fix_needs_local_verify',
|
|
234
|
+
extra: { verifiableTaskIds: tasks.verifiableTaskIds },
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// --- Fix failed ---
|
|
239
|
+
if (selfHealingStatus === 'FAILED') return { action: 'done', code: 'fix_failed' };
|
|
240
|
+
|
|
241
|
+
// --- No fix available ---
|
|
242
|
+
if (cipeStatus === 'FAILED' && (selfHealingEnabled === false || selfHealingStatus === 'NOT_EXECUTABLE')) return { action: 'done', code: 'no_fix' };
|
|
243
|
+
|
|
244
|
+
// --- Fallback ---
|
|
245
|
+
return { action: 'poll', code: 'fallback' };
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// ============================================================
|
|
249
|
+
// buildOutput() — maps classification to full JSON output
|
|
250
|
+
// ============================================================
|
|
251
|
+
|
|
252
|
+
// Message templates keyed by status or key
|
|
253
|
+
const messages = {
|
|
254
|
+
// wait mode
|
|
255
|
+
new_cipe_detected: () => `New CI Attempt detected! CI: ${cipeStatus || 'N/A'}`,
|
|
256
|
+
no_new_cipe: () => 'New CI Attempt timeout exceeded. No new CI Attempt detected.',
|
|
257
|
+
waiting_for_cipe: () => 'Waiting for new CI Attempt...',
|
|
258
|
+
|
|
259
|
+
// guards
|
|
260
|
+
polling_timeout: () => 'Polling timeout exceeded.',
|
|
261
|
+
circuit_breaker: () => 'No progress after 13 consecutive polls. Stopping.',
|
|
262
|
+
|
|
263
|
+
// terminal
|
|
264
|
+
ci_success: () => 'CI passed successfully!',
|
|
265
|
+
cipe_canceled: () => 'CI Attempt was canceled.',
|
|
266
|
+
cipe_timed_out: () => 'CI Attempt timed out.',
|
|
267
|
+
cipe_no_tasks: () => 'CI failed but no Nx tasks were recorded.',
|
|
268
|
+
|
|
269
|
+
// environment
|
|
270
|
+
environment_rerun_cap: () => 'Environment rerun cap (2) exceeded. Bailing.',
|
|
271
|
+
environment_issue: () => 'CI: FAILED | Classification: ENVIRONMENT_STATE',
|
|
272
|
+
|
|
273
|
+
// throttled
|
|
274
|
+
self_healing_throttled: () => 'Self-healing throttled \u2014 too many unapplied fixes.',
|
|
275
|
+
|
|
276
|
+
// polling
|
|
277
|
+
ci_running: () => `CI: ${cipeStatus}`,
|
|
278
|
+
sh_running: () => `CI: ${cipeStatus} | Self-healing: ${selfHealingStatus}`,
|
|
279
|
+
flaky_rerun: () => 'CI: FAILED | Classification: FLAKY_TASK (auto-rerun in progress)',
|
|
280
|
+
fix_auto_applied: () => 'CI: FAILED | Fix auto-applied, new CI Attempt spawning',
|
|
281
|
+
verification_pending: () => `CI: FAILED | Self-healing: COMPLETED | Verification: ${verificationStatus}`,
|
|
282
|
+
|
|
283
|
+
// actionable
|
|
284
|
+
fix_auto_applying: () => 'Fix verified! Auto-applying...',
|
|
285
|
+
fix_auto_apply_skipped: extra => `Fix verified but auto-apply was skipped. ${extra?.autoApplySkipReason ? `Reason: ${extra.autoApplySkipReason}` : 'Offer to apply manually.'}`,
|
|
286
|
+
fix_needs_review: () => `Fix available but needs review. Verification: ${verificationStatus || 'N/A'}`,
|
|
287
|
+
fix_apply_ready: () => 'Fix available and verified. Ready to apply.',
|
|
288
|
+
fix_needs_local_verify: extra => `Fix available. ${extra.verifiableTaskIds.length} task(s) need local verification.`,
|
|
289
|
+
fix_failed: () => 'Self-healing failed to generate a fix.',
|
|
290
|
+
no_fix: () => 'CI failed, no fix available.',
|
|
291
|
+
|
|
292
|
+
// fallback
|
|
293
|
+
fallback: () => `CI: ${cipeStatus || 'N/A'} | Self-healing: ${selfHealingStatus || 'N/A'} | Verification: ${verificationStatus || 'N/A'}`,
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
// Codes where noProgressCount resets to 0 (genuine progress occurred)
|
|
297
|
+
const resetProgressCodes = new Set(['ci_success', 'fix_auto_applying', 'fix_auto_apply_skipped', 'fix_needs_review', 'fix_apply_ready', 'fix_needs_local_verify']);
|
|
298
|
+
|
|
299
|
+
function formatMessage(msg) {
|
|
300
|
+
if (verbosity === 'minimal') {
|
|
301
|
+
const currentStatus = `${cipeStatus}|${selfHealingStatus}|${verificationStatus}`;
|
|
302
|
+
if (currentStatus === (prevStatus || '')) return null;
|
|
303
|
+
return msg;
|
|
304
|
+
}
|
|
305
|
+
if (verbosity === 'verbose') {
|
|
306
|
+
return [`Poll #${pollCount + 1} | CI: ${cipeStatus || 'N/A'} | Self-healing: ${selfHealingStatus || 'N/A'} | Verification: ${verificationStatus || 'N/A'}`, msg].join('\n');
|
|
307
|
+
}
|
|
308
|
+
return `Poll #${pollCount + 1} | ${msg}`;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function buildOutput(decision) {
|
|
312
|
+
const { action, code, extra } = decision;
|
|
313
|
+
|
|
314
|
+
// noProgressCount is already computed before classify() was called.
|
|
315
|
+
// Here we only handle the reset for "genuine progress" done-codes.
|
|
316
|
+
|
|
317
|
+
const msgFn = messages[code];
|
|
318
|
+
const rawMsg = msgFn ? msgFn(extra) : `Unknown: ${code}`;
|
|
319
|
+
const message = formatMessage(rawMsg);
|
|
320
|
+
|
|
321
|
+
const result = {
|
|
322
|
+
action,
|
|
323
|
+
code,
|
|
324
|
+
message,
|
|
325
|
+
noProgressCount: resetProgressCodes.has(code) ? 0 : noProgressCount,
|
|
326
|
+
envRerunCount,
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
// Add delay
|
|
330
|
+
if (action === 'wait') {
|
|
331
|
+
result.delay = 30;
|
|
332
|
+
} else if (action === 'poll') {
|
|
333
|
+
result.delay = code === 'new_cipe_detected' ? 60 : backoff(noProgressCount);
|
|
334
|
+
result.fields = 'light';
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// Add extras
|
|
338
|
+
if (code === 'new_cipe_detected') result.newCipeDetected = true;
|
|
339
|
+
if (extra?.verifiableTaskIds) result.verifiableTaskIds = extra.verifiableTaskIds;
|
|
340
|
+
if (extra?.autoApplySkipReason) result.autoApplySkipReason = extra.autoApplySkipReason;
|
|
341
|
+
|
|
342
|
+
console.log(JSON.stringify(result));
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// --- Run ---
|
|
346
|
+
|
|
347
|
+
// Compute noProgressCount from input. Single assignment, no mutation.
|
|
348
|
+
// Wait mode: reset on new cipe, otherwise unchanged (wait doesn't count as no-progress).
|
|
349
|
+
// Normal mode: reset on any state change, otherwise increment.
|
|
350
|
+
const noProgressCount = (() => {
|
|
351
|
+
if (waitMode) return isNewCipe() ? 0 : inputNoProgressCount;
|
|
352
|
+
if (isNewCipe() || hasStateChanged()) return 0;
|
|
353
|
+
return inputNoProgressCount + 1;
|
|
354
|
+
})();
|
|
355
|
+
|
|
356
|
+
buildOutput(classify());
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* CI State Update Script
|
|
5
|
+
*
|
|
6
|
+
* Deterministic state management for CI monitor actions.
|
|
7
|
+
* Three commands: gate, post-action, cycle-check.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* node ci-state-update.mjs gate --gate-type <local-fix|env-rerun> [counter args]
|
|
11
|
+
* node ci-state-update.mjs post-action --action <type> [--cipe-url <url>] [--commit-sha <sha>]
|
|
12
|
+
* node ci-state-update.mjs cycle-check --code <code> [--agent-triggered] [counter args]
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
// --- Arg parsing ---
|
|
16
|
+
|
|
17
|
+
const args = process.argv.slice(2);
|
|
18
|
+
const command = args[0];
|
|
19
|
+
|
|
20
|
+
function getFlag(name) {
|
|
21
|
+
return args.includes(name);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function getArg(name) {
|
|
25
|
+
const idx = args.indexOf(name);
|
|
26
|
+
return idx !== -1 && idx + 1 < args.length ? args[idx + 1] : null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function output(result) {
|
|
30
|
+
console.log(JSON.stringify(result));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// --- gate ---
|
|
34
|
+
// Check if an action is allowed and return incremented counter.
|
|
35
|
+
// Called before any local fix attempt or environment rerun.
|
|
36
|
+
|
|
37
|
+
function gate() {
|
|
38
|
+
const gateType = getArg('--gate-type');
|
|
39
|
+
|
|
40
|
+
if (gateType === 'local-fix') {
|
|
41
|
+
const count = parseInt(getArg('--local-verify-count') || '0', 10);
|
|
42
|
+
const max = parseInt(getArg('--local-verify-attempts') || '3', 10);
|
|
43
|
+
if (count >= max) {
|
|
44
|
+
return output({
|
|
45
|
+
allowed: false,
|
|
46
|
+
localVerifyCount: count,
|
|
47
|
+
message: `Local fix budget exhausted (${count}/${max} attempts)`,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return output({
|
|
51
|
+
allowed: true,
|
|
52
|
+
localVerifyCount: count + 1,
|
|
53
|
+
message: null,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (gateType === 'env-rerun') {
|
|
58
|
+
const count = parseInt(getArg('--env-rerun-count') || '0', 10);
|
|
59
|
+
if (count >= 2) {
|
|
60
|
+
return output({
|
|
61
|
+
allowed: false,
|
|
62
|
+
envRerunCount: count,
|
|
63
|
+
message: `Environment issue persists after ${count} reruns. Manual investigation needed.`,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return output({
|
|
67
|
+
allowed: true,
|
|
68
|
+
envRerunCount: count + 1,
|
|
69
|
+
message: null,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
output({ allowed: false, message: `Unknown gate type: ${gateType}` });
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// --- post-action ---
|
|
77
|
+
// Compute next state after an action is taken.
|
|
78
|
+
// Returns wait mode params and whether the action was agent-triggered.
|
|
79
|
+
|
|
80
|
+
function postAction() {
|
|
81
|
+
const action = getArg('--action');
|
|
82
|
+
const cipeUrl = getArg('--cipe-url');
|
|
83
|
+
const commitSha = getArg('--commit-sha');
|
|
84
|
+
|
|
85
|
+
// MCP-triggered or auto-applied: track by cipeUrl
|
|
86
|
+
const cipeUrlActions = ['fix-auto-applying', 'apply-mcp', 'env-rerun'];
|
|
87
|
+
// Local push: track by commitSha
|
|
88
|
+
const commitShaActions = ['apply-local-push', 'reject-fix-push', 'local-fix-push', 'auto-fix-push', 'empty-commit-push'];
|
|
89
|
+
|
|
90
|
+
const trackByCipeUrl = cipeUrlActions.includes(action);
|
|
91
|
+
const trackByCommitSha = commitShaActions.includes(action);
|
|
92
|
+
|
|
93
|
+
if (!trackByCipeUrl && !trackByCommitSha) {
|
|
94
|
+
return output({ error: `Unknown action: ${action}` });
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// fix-auto-applying: self-healing did it, NOT the monitor
|
|
98
|
+
const agentTriggered = action !== 'fix-auto-applying';
|
|
99
|
+
|
|
100
|
+
output({
|
|
101
|
+
waitMode: true,
|
|
102
|
+
pollCount: 0,
|
|
103
|
+
lastCipeUrl: trackByCipeUrl ? cipeUrl : null,
|
|
104
|
+
expectedCommitSha: trackByCommitSha ? commitSha : null,
|
|
105
|
+
agentTriggered,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// --- cycle-check ---
|
|
110
|
+
// Cycle classification + counter resets when a new "done" code is received.
|
|
111
|
+
// Called at the start of handling each actionable code.
|
|
112
|
+
|
|
113
|
+
function cycleCheck() {
|
|
114
|
+
const status = getArg('--code');
|
|
115
|
+
const wasAgentTriggered = getFlag('--agent-triggered');
|
|
116
|
+
let cycleCount = parseInt(getArg('--cycle-count') || '0', 10);
|
|
117
|
+
const maxCycles = parseInt(getArg('--max-cycles') || '10', 10);
|
|
118
|
+
let envRerunCount = parseInt(getArg('--env-rerun-count') || '0', 10);
|
|
119
|
+
|
|
120
|
+
// Cycle classification: if previous cycle was agent-triggered, count it
|
|
121
|
+
if (wasAgentTriggered) cycleCount++;
|
|
122
|
+
|
|
123
|
+
// Reset env_rerun_count on non-environment status
|
|
124
|
+
if (status !== 'environment_issue') envRerunCount = 0;
|
|
125
|
+
|
|
126
|
+
// Approaching limit gate
|
|
127
|
+
const approachingLimit = cycleCount >= maxCycles - 2;
|
|
128
|
+
|
|
129
|
+
output({
|
|
130
|
+
cycleCount,
|
|
131
|
+
agentTriggered: false,
|
|
132
|
+
envRerunCount,
|
|
133
|
+
approachingLimit,
|
|
134
|
+
message: approachingLimit ? `Approaching cycle limit (${cycleCount}/${maxCycles})` : null,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// --- Dispatch ---
|
|
139
|
+
|
|
140
|
+
switch (command) {
|
|
141
|
+
case 'gate':
|
|
142
|
+
gate();
|
|
143
|
+
break;
|
|
144
|
+
case 'post-action':
|
|
145
|
+
postAction();
|
|
146
|
+
break;
|
|
147
|
+
case 'cycle-check':
|
|
148
|
+
cycleCheck();
|
|
149
|
+
break;
|
|
150
|
+
default:
|
|
151
|
+
output({ error: `Unknown command: ${command}` });
|
|
152
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: nx-generate
|
|
3
|
+
description: Generate code using nx generators. INVOKE IMMEDIATELY when user mentions scaffolding, setup, structure, creating apps/libs, or setting up project structure. Trigger words - scaffold, setup, create a ... app, create a ... lib, project structure, generate, add a new project. ALWAYS use this BEFORE calling nx_docs or exploring - this skill handles discovery internally.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Run Nx Generator
|
|
7
|
+
|
|
8
|
+
Nx generators are powerful tools that scaffold projects, make automated code migrations or automate repetitive tasks in a monorepo. They ensure consistency across the codebase and reduce boilerplate work.
|
|
9
|
+
|
|
10
|
+
This skill applies when the user wants to:
|
|
11
|
+
|
|
12
|
+
- Create new projects like libraries or applications
|
|
13
|
+
- Scaffold features or boilerplate code
|
|
14
|
+
- Run workspace-specific or custom generators
|
|
15
|
+
- Do anything else that an nx generator exists for
|
|
16
|
+
|
|
17
|
+
## Key Principles
|
|
18
|
+
|
|
19
|
+
1. **Always use `--no-interactive`** - Prevents prompts that would hang execution
|
|
20
|
+
2. **Read the generator source code** - The schema alone is not enough; understand what the generator actually does
|
|
21
|
+
3. **Match existing repo patterns** - Study similar artifacts in the repo and follow their conventions
|
|
22
|
+
4. **Verify with lint/test/build/typecheck etc.** - Generated code must pass verification. The listed targets are just an example, use what's appropriate for this workspace.
|
|
23
|
+
|
|
24
|
+
## Steps
|
|
25
|
+
|
|
26
|
+
### 1. Discover Available Generators
|
|
27
|
+
|
|
28
|
+
Use the Nx CLI to discover available generators:
|
|
29
|
+
|
|
30
|
+
- List all generators for a plugin: `npx nx list @nx/react`
|
|
31
|
+
- View available plugins: `npx nx list`
|
|
32
|
+
|
|
33
|
+
This includes plugin generators (e.g., `@nx/react:library`) and local workspace generators.
|
|
34
|
+
|
|
35
|
+
### 2. Match Generator to User Request
|
|
36
|
+
|
|
37
|
+
Identify which generator(s) could fulfill the user's needs. Consider what artifact type they want, which framework is relevant, and any specific generator names mentioned.
|
|
38
|
+
|
|
39
|
+
**IMPORTANT**: When both a local workspace generator and an external plugin generator could satisfy the request, **always prefer the local workspace generator**. Local generators are customized for the specific repo's patterns.
|
|
40
|
+
|
|
41
|
+
If no suitable generator exists, you can stop using this skill. However, the burden of proof is high—carefully consider all available generators before deciding none apply.
|
|
42
|
+
|
|
43
|
+
### 3. Get Generator Options
|
|
44
|
+
|
|
45
|
+
Use the `--help` flag to understand available options:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npx nx g @nx/react:library --help
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Pay attention to required options, defaults that might need overriding, and options relevant to the user's request.
|
|
52
|
+
|
|
53
|
+
### Library Buildability
|
|
54
|
+
|
|
55
|
+
**Default to non-buildable libraries** unless there's a specific reason for buildable.
|
|
56
|
+
|
|
57
|
+
| Type | When to use | Generator flags |
|
|
58
|
+
| --------------------------- | ----------------------------------------------------------------- | ----------------------------------- |
|
|
59
|
+
| **Non-buildable** (default) | Internal monorepo libs consumed by apps | No `--bundler` flag |
|
|
60
|
+
| **Buildable** | Publishing to npm, cross-repo sharing, stable libs for cache hits | `--bundler=vite` or `--bundler=swc` |
|
|
61
|
+
|
|
62
|
+
Non-buildable libs:
|
|
63
|
+
|
|
64
|
+
- Export `.ts`/`.tsx` source directly
|
|
65
|
+
- Consumer's bundler compiles them
|
|
66
|
+
- Faster dev experience, less config
|
|
67
|
+
|
|
68
|
+
Buildable libs:
|
|
69
|
+
|
|
70
|
+
- Have their own build target
|
|
71
|
+
- Useful for stable libs that rarely change (cache hits)
|
|
72
|
+
- Required for npm publishing
|
|
73
|
+
|
|
74
|
+
**If unclear, ask the user:** "Should this library be buildable (own build step, better caching) or non-buildable (source consumed directly, simpler setup)?"
|
|
75
|
+
|
|
76
|
+
### 4. Read Generator Source Code
|
|
77
|
+
|
|
78
|
+
**This step is critical.** The schema alone does not tell you everything. Reading the source code helps you:
|
|
79
|
+
|
|
80
|
+
- Know exactly what files will be created/modified and where
|
|
81
|
+
- Understand side effects (updating configs, installing deps, etc.)
|
|
82
|
+
- Identify behaviors and options not obvious from the schema
|
|
83
|
+
- Understand how options interact with each other
|
|
84
|
+
|
|
85
|
+
To find generator source code:
|
|
86
|
+
|
|
87
|
+
- For plugin generators: Use `node -e "console.log(require.resolve('@nx/<plugin>/generators.json'));"` to find the generators.json, then locate the source from there
|
|
88
|
+
- If that fails, read directly from `node_modules/<plugin>/generators.json`
|
|
89
|
+
- For local generators: Typically in `tools/generators/` or a local plugin directory. Search the repo for the generator name.
|
|
90
|
+
|
|
91
|
+
After reading the source, reconsider: Is this the right generator? If not, go back to step 2.
|
|
92
|
+
|
|
93
|
+
> **⚠️ `--directory` flag behavior can be misleading.**
|
|
94
|
+
> It should specify the full path of the generated library or component, not the parent path that it will be generated in.
|
|
95
|
+
>
|
|
96
|
+
> ```bash
|
|
97
|
+
> # ✅ Correct - directory is the full path for the library
|
|
98
|
+
> nx g @nx/react:library --directory=libs/my-lib
|
|
99
|
+
> # generates libs/my-lib/package.json and more
|
|
100
|
+
>
|
|
101
|
+
> # ❌ Wrong - this will create files at libs and libs/src/...
|
|
102
|
+
> nx g @nx/react:library --name=my-lib --directory=libs
|
|
103
|
+
> # generates libs/package.json and more
|
|
104
|
+
> ```
|
|
105
|
+
|
|
106
|
+
### 5. Examine Existing Patterns
|
|
107
|
+
|
|
108
|
+
Before generating, examine the target area of the codebase:
|
|
109
|
+
|
|
110
|
+
- Look at similar existing artifacts (other libraries, applications, etc.)
|
|
111
|
+
- Identify naming conventions, file structures, and configuration patterns
|
|
112
|
+
- Note which test runners, build tools, and linters are used
|
|
113
|
+
- Configure the generator to match these patterns
|
|
114
|
+
|
|
115
|
+
### 6. Dry-Run to Verify File Placement
|
|
116
|
+
|
|
117
|
+
**Always run with `--dry-run` first** to verify files will be created in the correct location:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
npx nx g @nx/react:library --name=my-lib --dry-run --no-interactive
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Review the output carefully. If files would be created in the wrong location, adjust your options based on what you learned from the generator source code.
|
|
124
|
+
|
|
125
|
+
Note: Some generators don't support dry-run (e.g., if they install npm packages). If dry-run fails for this reason, proceed to running the generator for real.
|
|
126
|
+
|
|
127
|
+
### 7. Run the Generator
|
|
128
|
+
|
|
129
|
+
Execute the generator:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
nx generate <generator-name> <options> --no-interactive
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
> **Tip:** New packages often need workspace dependencies wired up (e.g., importing shared types, being consumed by apps). The `link-workspace-packages` skill can help add these correctly.
|
|
136
|
+
|
|
137
|
+
### 8. Modify Generated Code (If Needed)
|
|
138
|
+
|
|
139
|
+
Generators provide a starting point. Modify the output as needed to:
|
|
140
|
+
|
|
141
|
+
- Add or modify functionality as requested
|
|
142
|
+
- Adjust imports, exports, or configurations
|
|
143
|
+
- Integrate with existing code patterns
|
|
144
|
+
|
|
145
|
+
**Important:** If you replace or delete generated test files (e.g., `*.spec.ts`), either write meaningful replacement tests or remove the `test` target from the project configuration. Empty test suites will cause `nx test` to fail.
|
|
146
|
+
|
|
147
|
+
### 9. Format and Verify
|
|
148
|
+
|
|
149
|
+
Format all generated/modified files:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
nx format --fix
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
This example is for built-in nx formatting with prettier. There might be other formatting tools for this workspace, use these when appropriate.
|
|
156
|
+
|
|
157
|
+
Then verify the generated code works. Keep in mind that the changes you make with a generator or subsequent modifications might impact various projects so it's usually not enough to only run targets for the artifact you just created.
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
# these targets are just an example!
|
|
161
|
+
nx run-many -t build,lint,test,typecheck
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
These targets are common examples used across many workspaces. You should do research into other targets available for this workspace and its projects. CI configuration is usually a good guide for what the critical targets are that have to pass.
|
|
165
|
+
|
|
166
|
+
If verification fails with manageable issues (a few lint errors, minor type issues), fix them. If issues are extensive, attempt obvious fixes first, then escalate to the user with details about what was generated, what's failing, and what you've attempted.
|