ai-engineering-loop 1.12.0 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/.agents/workflows/ai-engineering-loop.md +47 -11
  2. package/.claude/commands/ai-engineering-loop.md +1 -1
  3. package/.claude/skills/ai-engineering-loop/SKILL.md +26 -44
  4. package/.claude/skills/ai-engineering-loop/references/loop-commands.md +20 -0
  5. package/.claude/skills/ai-engineering-loop/references/loop-deliver.md +8 -0
  6. package/.claude/skills/ai-engineering-loop/references/loop-goal.md +10 -0
  7. package/.claude/skills/ai-engineering-loop/references/loop-maker.md +8 -0
  8. package/.claude/skills/ai-engineering-loop/references/loop-review.md +18 -0
  9. package/.claude/skills/ai-engineering-loop/references/loop-risky.md +9 -0
  10. package/.claude/skills/ai-engineering-loop/references/loop-verify.md +20 -0
  11. package/.gemini/skills/ai-engineering-loop/SKILL.md +24 -37
  12. package/.gemini/skills/ai-engineering-loop/references/loop-commands.md +20 -0
  13. package/.gemini/skills/ai-engineering-loop/references/loop-deliver.md +8 -0
  14. package/.gemini/skills/ai-engineering-loop/references/loop-goal.md +10 -0
  15. package/.gemini/skills/ai-engineering-loop/references/loop-maker.md +8 -0
  16. package/.gemini/skills/ai-engineering-loop/references/loop-review.md +18 -0
  17. package/.gemini/skills/ai-engineering-loop/references/loop-risky.md +9 -0
  18. package/.gemini/skills/ai-engineering-loop/references/loop-verify.md +20 -0
  19. package/.grok/skills/ai-engineering-loop/SKILL.md +29 -61
  20. package/.grok/skills/ai-engineering-loop/references/loop-commands.md +20 -0
  21. package/.grok/skills/ai-engineering-loop/references/loop-deliver.md +8 -0
  22. package/.grok/skills/ai-engineering-loop/references/loop-goal.md +10 -0
  23. package/.grok/skills/ai-engineering-loop/references/loop-maker.md +8 -0
  24. package/.grok/skills/ai-engineering-loop/references/loop-review.md +18 -0
  25. package/.grok/skills/ai-engineering-loop/references/loop-risky.md +9 -0
  26. package/.grok/skills/ai-engineering-loop/references/loop-verify.md +20 -0
  27. package/CHANGELOG.md +69 -0
  28. package/README.md +52 -1
  29. package/README.npm.md +6 -2
  30. package/THIRD_PARTY_NOTICES.md +29 -0
  31. package/adapters/dot/skills/dot-dev-skill-router/SKILL.md +24 -16
  32. package/adapters/project-onboarding/SKILL.md +27 -0
  33. package/adapters/project-onboarding/references/output.md +29 -0
  34. package/adapters/quality/skills/ael-code-simplifier/SKILL.md +43 -0
  35. package/adapters/quality/skills/ael-receiving-code-review/SKILL.md +37 -0
  36. package/bin/ai-engineering-loop.js +1137 -78
  37. package/core/artifact-gates.md +32 -1
  38. package/core/root-cause-analysis.md +6 -0
  39. package/core/runtime-safety.md +32 -4
  40. package/core/verification-loop.md +6 -0
  41. package/evals/cases/21-tier-t0-docs.json +34 -0
  42. package/evals/cases/22-tier-t1-small-pass.json +30 -0
  43. package/evals/cases/23-tier-t1-blocker.json +26 -0
  44. package/evals/cases/24-tier-t1-auth-escalates.json +30 -0
  45. package/lib/agent-artifacts.js +250 -0
  46. package/lib/auto-update.js +486 -0
  47. package/lib/budget.js +31 -1
  48. package/lib/claimed-vs-reality.js +134 -0
  49. package/lib/cli-args.js +84 -0
  50. package/lib/docs.js +91 -0
  51. package/lib/doctor.js +7 -1
  52. package/lib/gates.js +114 -1
  53. package/lib/host-skill-build.js +121 -0
  54. package/lib/migrations.js +84 -0
  55. package/lib/project-registry.js +148 -0
  56. package/lib/run-state.js +6 -3
  57. package/lib/safe-context.js +62 -4
  58. package/lib/sync-hosts.js +356 -28
  59. package/lib/tier.js +134 -0
  60. package/lib/update-manager.js +17 -1
  61. package/lib/update-notice.js +192 -0
  62. package/lib/user-state.js +80 -0
  63. package/lib/verification-recorder.js +268 -0
  64. package/lib/workflow-runtime.js +26 -1
  65. package/migrations/README.md +21 -0
  66. package/package.json +7 -2
  67. package/policies/review-budget.md +1 -1
  68. package/schemas/verification.schema.json +2 -2
@@ -0,0 +1,148 @@
1
+ 'use strict';
2
+
3
+ // Project registry (issue #37): ~/.ai-engineering-loop/projects.json lists local
4
+ // repositories that contain `.ai-engineering-loop/`, so a CLI update can refresh
5
+ // every project. It only holds local paths and is never sent anywhere.
6
+
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+ const { homeDir, userStatePath, readJsonFile, writeJsonFile } = require('./user-state.js');
10
+
11
+ const REGISTRY_FILE = 'projects.json';
12
+ const CONTEXT_DIR = '.ai-engineering-loop';
13
+ const SCAN_EXCLUDES = new Set(['node_modules', '.git', '.hg', '.svn', 'vendor', 'dist', 'build', '.next', '.cache', 'Library', 'AppData']);
14
+
15
+ // Automatic writes to the user's home are disabled by AEL_NO_REGISTRY and,
16
+ // as a safety net, inside the Node test runner unless a sandbox AEL_HOME is set.
17
+ function registryEnabled(env = process.env) {
18
+ if (env.AEL_NO_REGISTRY === '1') return false;
19
+ if (env.NODE_TEST_CONTEXT && !env.AEL_HOME) return false;
20
+ return true;
21
+ }
22
+
23
+ function registryPath(home = homeDir()) {
24
+ return userStatePath(REGISTRY_FILE, home);
25
+ }
26
+
27
+ function hasContext(dir) {
28
+ try {
29
+ return fs.statSync(path.join(dir, CONTEXT_DIR)).isDirectory();
30
+ } catch {
31
+ return false;
32
+ }
33
+ }
34
+
35
+ function readContextVersion(dir) {
36
+ const metadata = readJsonFile(path.join(dir, CONTEXT_DIR, 'metadata.json'), null);
37
+ return metadata && metadata.contextVersion ? String(metadata.contextVersion) : null;
38
+ }
39
+
40
+ function readRegistry(home = homeDir()) {
41
+ const value = readJsonFile(registryPath(home), null);
42
+ const projects = value && Array.isArray(value.projects) ? value.projects.filter((p) => p && typeof p.path === 'string') : [];
43
+ return { schemaVersion: 1, projects };
44
+ }
45
+
46
+ function writeRegistry(registry, home = homeDir()) {
47
+ const projects = [...registry.projects].sort((a, b) => a.path.localeCompare(b.path));
48
+ writeJsonFile(registryPath(home), { schemaVersion: 1, projects });
49
+ }
50
+
51
+ function canonical(dir) {
52
+ const abs = path.resolve(dir);
53
+ try {
54
+ return fs.realpathSync(abs);
55
+ } catch {
56
+ return abs;
57
+ }
58
+ }
59
+
60
+ function upsert(registry, dir, now) {
61
+ const abs = canonical(dir);
62
+ const entry = { path: abs, contextVersion: readContextVersion(abs), lastSeen: now.toISOString() };
63
+ const index = registry.projects.findIndex((p) => p.path === abs);
64
+ if (index === -1) registry.projects.push(entry);
65
+ else registry.projects[index] = { ...registry.projects[index], ...entry };
66
+ return entry;
67
+ }
68
+
69
+ // Called by init/run/status/refresh. Never throws: the registry is a convenience.
70
+ function registerProject(dir, { home = homeDir(), env = process.env, now = new Date() } = {}) {
71
+ if (!registryEnabled(env) || !hasContext(dir)) return null;
72
+ try {
73
+ const registry = readRegistry(home);
74
+ const entry = upsert(registry, dir, now);
75
+ writeRegistry(registry, home);
76
+ return entry;
77
+ } catch {
78
+ return null;
79
+ }
80
+ }
81
+
82
+ function addProject(dir, { home = homeDir(), now = new Date() } = {}) {
83
+ if (!hasContext(dir)) {
84
+ const err = new Error(`${path.resolve(dir)} has no ${CONTEXT_DIR}/ (run init there first)`);
85
+ err.code = 'NO_CONTEXT';
86
+ throw err;
87
+ }
88
+ const registry = readRegistry(home);
89
+ const entry = upsert(registry, dir, now);
90
+ writeRegistry(registry, home);
91
+ return entry;
92
+ }
93
+
94
+ function removeProject(dir, { home = homeDir() } = {}) {
95
+ const abs = canonical(dir);
96
+ const registry = readRegistry(home);
97
+ const before = registry.projects.length;
98
+ registry.projects = registry.projects.filter((p) => p.path !== abs && p.path !== path.resolve(dir));
99
+ writeRegistry(registry, home);
100
+ return before !== registry.projects.length;
101
+ }
102
+
103
+ // Lists projects and drops entries whose folder or context directory is gone.
104
+ function listProjects({ home = homeDir(), prune = true } = {}) {
105
+ const registry = readRegistry(home);
106
+ const kept = registry.projects.filter((p) => hasContext(p.path));
107
+ const removed = registry.projects.filter((p) => !kept.includes(p));
108
+ if (prune && removed.length) writeRegistry({ projects: kept }, home);
109
+ return { projects: kept.map((p) => ({ ...p, contextVersion: readContextVersion(p.path) || p.contextVersion || null })), removed: removed.map((p) => p.path) };
110
+ }
111
+
112
+ // Manual, bounded scan. Does not follow symlinks or descend into excluded dirs.
113
+ function scanProjects(root, { home = homeDir(), maxDepth = 4, now = new Date() } = {}) {
114
+ const found = [];
115
+ const walk = (dir, depth) => {
116
+ if (hasContext(dir)) found.push(dir);
117
+ if (depth >= maxDepth) return;
118
+ let entries;
119
+ try {
120
+ entries = fs.readdirSync(dir, { withFileTypes: true });
121
+ } catch {
122
+ return;
123
+ }
124
+ for (const entry of entries) {
125
+ if (!entry.isDirectory() || entry.isSymbolicLink()) continue;
126
+ if (SCAN_EXCLUDES.has(entry.name) || entry.name === CONTEXT_DIR) continue;
127
+ walk(path.join(dir, entry.name), depth + 1);
128
+ }
129
+ };
130
+ walk(path.resolve(root), 0);
131
+ const registry = readRegistry(home);
132
+ const entries = found.map((dir) => upsert(registry, dir, now));
133
+ writeRegistry(registry, home);
134
+ return { root: path.resolve(root), maxDepth, found: entries };
135
+ }
136
+
137
+ module.exports = {
138
+ REGISTRY_FILE,
139
+ SCAN_EXCLUDES,
140
+ registryEnabled,
141
+ registryPath,
142
+ readRegistry,
143
+ registerProject,
144
+ addProject,
145
+ removeProject,
146
+ listProjects,
147
+ scanProjects
148
+ };
package/lib/run-state.js CHANGED
@@ -207,7 +207,8 @@ function createRun(
207
207
  now = new Date(),
208
208
  workflow = null,
209
209
  displayName = '',
210
- constraints = ''
210
+ constraints = '',
211
+ tier = null
211
212
  } = {}
212
213
  ) {
213
214
  assertRunId(runId);
@@ -241,6 +242,7 @@ function createRun(
241
242
  createdAt: timestamp,
242
243
  updatedAt: timestamp,
243
244
  artifacts: {},
245
+ ...(tier ? { tier } : {}),
244
246
  ...(workflowMetadata ? { workflow: workflowMetadata } : {}),
245
247
  history: [
246
248
  {
@@ -259,7 +261,7 @@ function createRun(
259
261
 
260
262
  function createOrResumeRun(
261
263
  rootDir,
262
- { task = '', runId, mode = null, forceNew = false, now = new Date(), workflow = null } = {}
264
+ { task = '', runId, mode = null, forceNew = false, now = new Date(), workflow = null, tier = null } = {}
263
265
  ) {
264
266
  const current = getCurrentRun(rootDir);
265
267
  const requestedTask = String(task || '').trim();
@@ -289,7 +291,8 @@ function createOrResumeRun(
289
291
  ...(runId ? { runId } : {}),
290
292
  mode: mode || RUN_MODES.ASSISTED,
291
293
  now,
292
- workflow
294
+ workflow,
295
+ tier
293
296
  }),
294
297
  resumed: false
295
298
  };
@@ -35,9 +35,11 @@ const SENSITIVE_NAMES = [
35
35
  /\.(?:pem|key|p12|pfx|jks)$/i
36
36
  ];
37
37
 
38
- function contextError(message, code = 'UNSAFE_CONTEXT') {
38
+ function contextError(message, code = 'UNSAFE_CONTEXT', details = [], budget = null) {
39
39
  const err = new Error(message);
40
40
  err.code = code;
41
+ if (details.length) err.details = details;
42
+ if (budget) err.budget = budget;
41
43
  return err;
42
44
  }
43
45
 
@@ -95,10 +97,15 @@ function redactSecrets(input) {
95
97
  replace(/\bAKIA[A-Z0-9]{16}\b/g, 'aws-access-key', '[REDACTED AWS ACCESS KEY]');
96
98
  replace(/\bsk-(?:live-|test-)?[A-Za-z0-9_-]{8,}\b/g, 'api-token', '[REDACTED API TOKEN]');
97
99
  replace(
98
- /(\b(?:api[_-]?key|access[_-]?token|auth[_-]?token|secret|password|authorization)\b\s*[:=]\s*["']?)([^"'\s,;]+)/gi,
100
+ /(\b(?:api[_-]?key|access[_-]?token|auth[_-]?token|token|secret|password|authorization)\b\s*[:=]\s*["']?)([^"'\s,;]+)/gi,
99
101
  'key-value-secret',
100
102
  (_match, prefix) => `${prefix}[REDACTED]`
101
103
  );
104
+ replace(
105
+ /(^|[^\w-])(--?(?:api[_-]?key|access[_-]?token|auth[_-]?token|token|secret|password|authorization)\s+)(?:"[^"]*"|'[^']*'|[^\s,;]+)/gi,
106
+ 'key-value-secret',
107
+ (_match, boundary, prefix) => `${boundary}${prefix}[REDACTED]`
108
+ );
102
109
 
103
110
  return { text, categories: [...categories].sort() };
104
111
  }
@@ -149,6 +156,7 @@ function createContextPack(rootDir, { runId, stage, files, profile } = {}) {
149
156
  }
150
157
 
151
158
  const entries = [];
159
+ const budgetEntries = [];
152
160
  let totalBytes = 0;
153
161
  let estimatedTokens = 0;
154
162
  for (const requested of uniqueFiles) {
@@ -157,17 +165,67 @@ function createContextPack(rootDir, { runId, stage, files, profile } = {}) {
157
165
  if (raw.includes(0)) throw contextError(`Binary context is blocked: ${requested}`, 'BINARY_CONTEXT');
158
166
 
159
167
  const remaining = limits.maxTotalBytes - totalBytes;
160
- if (remaining <= 0) throw contextError(`${stage} context exceeds its byte budget`, 'CONTEXT_BYTE_LIMIT');
168
+ if (remaining <= 0) {
169
+ const budget = {
170
+ stage,
171
+ reviewProfile,
172
+ maxTotalBytes: limits.maxTotalBytes,
173
+ requestedBytes: totalBytes + raw.length,
174
+ files: [...budgetEntries, {
175
+ path: safe.relative,
176
+ sourceBytes: raw.length,
177
+ includedBytes: 0,
178
+ estimatedTokens: 0,
179
+ truncated: true
180
+ }]
181
+ };
182
+ throw contextError(
183
+ `${stage} context exceeds its byte budget (${limits.maxTotalBytes.toLocaleString()}-byte limit; ${budget.requestedBytes.toLocaleString()} requested)`,
184
+ 'CONTEXT_BYTE_LIMIT',
185
+ budget.files.map((entry) =>
186
+ `${entry.path}: ${entry.estimatedTokens.toLocaleString()} estimated tokens, ${entry.includedBytes.toLocaleString()}/${entry.sourceBytes.toLocaleString()} bytes included`
187
+ ),
188
+ budget
189
+ );
190
+ }
161
191
  const allowedBytes = Math.min(raw.length, limits.maxFileBytes, remaining);
162
192
  const source = raw.subarray(0, allowedBytes).toString('utf8');
163
193
  const redacted = redactSecrets(source);
164
194
  const tokens = estimateTokens(redacted.text);
165
195
  if (estimatedTokens + tokens > limits.maxEstimatedTokens) {
166
- throw contextError(`${stage} context exceeds its estimated token budget`, 'CONTEXT_TOKEN_LIMIT');
196
+ const files = [...budgetEntries, {
197
+ path: safe.relative,
198
+ sourceBytes: raw.length,
199
+ includedBytes: allowedBytes,
200
+ estimatedTokens: tokens,
201
+ truncated: allowedBytes < raw.length
202
+ }];
203
+ const budget = {
204
+ stage,
205
+ reviewProfile,
206
+ maxEstimatedTokens: limits.maxEstimatedTokens,
207
+ requestedTokens: estimatedTokens + tokens,
208
+ files
209
+ };
210
+ throw contextError(
211
+ `${stage} context exceeds its estimated token budget (${limits.maxEstimatedTokens.toLocaleString()}-token limit; ${budget.requestedTokens.toLocaleString()} requested)`,
212
+ 'CONTEXT_TOKEN_LIMIT',
213
+ files.map((entry) =>
214
+ `${entry.path}: ${entry.estimatedTokens.toLocaleString()} estimated tokens, ${entry.includedBytes.toLocaleString()}/${entry.sourceBytes.toLocaleString()} bytes included${entry.truncated ? ' (truncated)' : ''}`
215
+ ),
216
+ budget
217
+ );
167
218
  }
168
219
 
169
220
  totalBytes += allowedBytes;
170
221
  estimatedTokens += tokens;
222
+ budgetEntries.push({
223
+ path: safe.relative,
224
+ sourceBytes: raw.length,
225
+ includedBytes: allowedBytes,
226
+ estimatedTokens: tokens,
227
+ truncated: allowedBytes < raw.length
228
+ });
171
229
  entries.push({
172
230
  path: safe.relative,
173
231
  sourceSha256: sha256(raw),