@yairabf/engineering-workflows 0.0.0-stage → 1.0.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 (58) hide show
  1. package/.agents/skills/grill-me/SKILL.md +7 -0
  2. package/.agents/skills/grill-me/agents/openai.yaml +5 -0
  3. package/.agents/skills/grilling/SKILL.md +28 -0
  4. package/.agents/skills/grilling/agents/openai.yaml +3 -0
  5. package/engineering-workflows/.agents/skills/workflow-implement/SKILL.md +17 -0
  6. package/engineering-workflows/.agents/skills/workflow-implement/references/implementation-handoff.md +17 -0
  7. package/engineering-workflows/.agents/skills/workflow-initiate/SKILL.md +49 -0
  8. package/engineering-workflows/.agents/skills/workflow-initiate/references/preparation.md +80 -0
  9. package/engineering-workflows/.agents/skills/workflow-initiate/references/prerequisites.json +53 -0
  10. package/engineering-workflows/.agents/skills/workflow-initiate/references/readiness.md +87 -0
  11. package/engineering-workflows/.agents/skills/workflow-initiate/scripts/marker.mjs +97 -0
  12. package/engineering-workflows/.agents/skills/workflow-investigate/SKILL.md +55 -0
  13. package/engineering-workflows/.agents/skills/workflow-investigate/references/investigation-brief.md +38 -0
  14. package/engineering-workflows/.agents/skills/workflow-plan/SKILL.md +46 -0
  15. package/engineering-workflows/.agents/skills/workflow-plan/references/implementation-plan.md +31 -0
  16. package/engineering-workflows/.agents/skills/workflow-review/SKILL.md +56 -0
  17. package/engineering-workflows/.agents/skills/workflow-review/references/independent-review.md +29 -0
  18. package/engineering-workflows/.claude/skills/workflow-implement/SKILL.md +10 -0
  19. package/engineering-workflows/.claude/skills/workflow-initiate/SKILL.md +10 -0
  20. package/engineering-workflows/.claude/skills/workflow-investigate/SKILL.md +10 -0
  21. package/engineering-workflows/.claude/skills/workflow-plan/SKILL.md +10 -0
  22. package/engineering-workflows/.claude/skills/workflow-review/SKILL.md +10 -0
  23. package/engineering-workflows/README.md +282 -0
  24. package/engineering-workflows/builder/delivery.mjs +177 -0
  25. package/engineering-workflows/builder/delivery.test.mjs +154 -0
  26. package/engineering-workflows/builder/drive.mjs +184 -0
  27. package/engineering-workflows/builder/drive.test.mjs +350 -0
  28. package/engineering-workflows/builder/handoff.mjs +40 -0
  29. package/engineering-workflows/builder/mission-role.mjs +294 -0
  30. package/engineering-workflows/builder/pi-session.mjs +45 -0
  31. package/engineering-workflows/builder/reader-guard.mjs +58 -0
  32. package/engineering-workflows/builder/role-session.mjs +42 -0
  33. package/engineering-workflows/builder/stage.mjs +446 -0
  34. package/engineering-workflows/builder/workspace-tool.mjs +20 -0
  35. package/engineering-workflows/builder-plan.mjs +174 -0
  36. package/engineering-workflows/builder-project.mjs +117 -0
  37. package/engineering-workflows/check-package-visibility.mjs +54 -0
  38. package/engineering-workflows/install.mjs +182 -0
  39. package/engineering-workflows/mission/README.md +281 -0
  40. package/engineering-workflows/mission/controller.mjs +54 -0
  41. package/engineering-workflows/mission/mission-controller.test.mjs +382 -0
  42. package/engineering-workflows/mission/mission-mcp.test.mjs +102 -0
  43. package/engineering-workflows/mission/status.mjs +113 -0
  44. package/engineering-workflows/mission/store.mjs +180 -0
  45. package/engineering-workflows/mission/tools.mjs +54 -0
  46. package/engineering-workflows/mission/transitions.mjs +269 -0
  47. package/engineering-workflows/mission-controller.mjs +72 -0
  48. package/engineering-workflows/mission-mcp.mjs +66 -0
  49. package/engineering-workflows/prerequisites.mjs +205 -0
  50. package/engineering-workflows/readiness.mjs +263 -0
  51. package/engineering-workflows/release-targets.mjs +12 -0
  52. package/engineering-workflows/setup.mjs +70 -0
  53. package/engineering-workflows/stage-release.mjs +45 -0
  54. package/engineering-workflows/upgrade.mjs +333 -0
  55. package/engineering-workflows/workflows/development.md +372 -0
  56. package/engineering-workflows/workflows/engineering-workflows.yml +90 -0
  57. package/package.json +21 -4
  58. package/README.md +0 -3
@@ -0,0 +1,333 @@
1
+ import { execFileSync } from 'node:child_process'
2
+ import {
3
+ chmodSync, linkSync, mkdirSync, mkdtempSync, readFileSync, readdirSync,
4
+ renameSync, rmdirSync, rmSync, unlinkSync, writeFileSync,
5
+ } from 'node:fs'
6
+ import { tmpdir } from 'node:os'
7
+ import { dirname, join, posix } from 'node:path'
8
+ import {
9
+ bundledPaths, checkWritableParent, ciPath, rolePaths, sourceRoot, stampPath, stat, targetPath,
10
+ } from './install.mjs'
11
+
12
+ const commitPattern = /^[a-f0-9]{40}$/
13
+ const executableBits = 0o111
14
+
15
+ function git(repository, ...args) {
16
+ const env = { ...process.env }
17
+ // Git hooks can export repository paths. The baseline must stay in staging.
18
+ for (const name of ['GIT_DIR', 'GIT_WORK_TREE', 'GIT_COMMON_DIR', 'GIT_INDEX_FILE',
19
+ 'GIT_OBJECT_DIRECTORY', 'GIT_ALTERNATE_OBJECT_DIRECTORIES', 'GIT_SHALLOW_FILE']) {
20
+ delete env[name]
21
+ }
22
+ try {
23
+ return execFileSync('git', ['-C', repository, '--no-replace-objects', ...args], {
24
+ env, stdio: ['ignore', 'pipe', 'pipe'], timeout: 180_000,
25
+ })
26
+ } catch (error) {
27
+ throw new Error(`Git ${args[0]} failed (${error.code ?? error.status ?? error.signal}).`)
28
+ }
29
+ }
30
+
31
+ function readFile(path, info = stat(path)) {
32
+ if (!info) return undefined
33
+ if (!info.isFile()) throw new Error(`Expected a regular file at ${path}`)
34
+ return { bytes: readFileSync(path), mode: info.mode & 0o777 }
35
+ }
36
+
37
+ function targetFile(target, path) {
38
+ const destination = join(targetPath(target, posix.dirname(path)), posix.basename(path))
39
+ let parent = target
40
+ for (const name of path.split('/')) {
41
+ const child = join(parent, name)
42
+ if (!stat(child)) break
43
+ if (!readdirSync(parent).includes(name)) {
44
+ throw new Error(`Upgrade path spelling differs from the installed entry at ${child}`)
45
+ }
46
+ parent = child
47
+ }
48
+ return destination
49
+ }
50
+
51
+ function sameEntry(left, right) {
52
+ if (!left || !right) return left === right
53
+ if (left.directory || right.directory) return left.directory === right.directory
54
+ return (left.mode & executableBits) === (right.mode & executableBits) &&
55
+ left.bytes.equals(right.bytes)
56
+ }
57
+
58
+ function fetchBaseline(directory, repository, revision) {
59
+ try {
60
+ git(directory, 'init', '--quiet')
61
+ git(directory, 'fetch', '--no-tags', '--no-recurse-submodules', '--depth=1', '--', repository, revision)
62
+ const fetched = git(directory, 'rev-parse', 'FETCH_HEAD^{commit}').toString().trim()
63
+ if (fetched !== revision) throw new Error('Fetched a different commit.')
64
+ git(directory, 'cat-file', '-e', `${revision}:engineering-workflows/install.mjs`)
65
+ } catch (error) {
66
+ throw new Error(`Cannot recover installed revision ${revision} from the pack source: ${error.message}`)
67
+ }
68
+ }
69
+
70
+ function baselineFiles(directory, revision, { source, target }) {
71
+ const entries = git(directory, 'ls-tree', '-rz', revision, '--', source).toString().split('\0')
72
+ return entries.filter(Boolean).map((entry) => {
73
+ const tab = entry.indexOf('\t')
74
+ const [mode, type, object] = entry.slice(0, tab).split(' ')
75
+ const path = entry.slice(tab + 1)
76
+ const suffix = path.slice(source.length)
77
+ if (type !== 'blob' || !['100644', '100755'].includes(mode) || path.includes('\\') ||
78
+ (path !== source && !path.startsWith(source + '/')) ||
79
+ path.split('/').some((part) => !part || part === '.' || part === '..')) {
80
+ throw new Error(`Unsupported pack path at ${revision}: ${path}`)
81
+ }
82
+ return [target + suffix, {
83
+ bytes: git(directory, 'cat-file', 'blob', object),
84
+ mode: Number.parseInt(mode.slice(-3), 8),
85
+ }]
86
+ })
87
+ }
88
+
89
+ function incomingFiles(source, target) {
90
+ const info = stat(source)
91
+ if (!info) return []
92
+ if (info.isDirectory()) {
93
+ return readdirSync(source).flatMap((name) => {
94
+ if (name.includes('\\')) throw new Error(`Unsupported pack path: ${join(source, name)}`)
95
+ return incomingFiles(join(source, name), `${target}/${name}`)
96
+ })
97
+ }
98
+ return [[target, readFile(source, info)]]
99
+ }
100
+
101
+ function parents(path) {
102
+ const directories = []
103
+ for (let parent = posix.dirname(path); parent !== '.'; parent = posix.dirname(parent)) {
104
+ directories.push(parent)
105
+ }
106
+ return directories
107
+ }
108
+
109
+ function recordDirectoryRemovals(target, path, oldFiles, oldDirectories, changes, conflicts) {
110
+ const directory = targetPath(target, path)
111
+ for (const name of readdirSync(directory)) {
112
+ const child = `${path}/${name}`
113
+ const info = stat(join(directory, name))
114
+ if (oldDirectories.has(child) && info?.isDirectory()) {
115
+ recordDirectoryRemovals(target, child, oldFiles, oldDirectories, changes, conflicts)
116
+ } else if (!oldFiles.has(child) || !info?.isFile()) {
117
+ conflicts.add(child)
118
+ }
119
+ }
120
+ changes.push({ path, current: { directory: true, mode: stat(directory).mode & 0o777 } })
121
+ }
122
+
123
+ function planPathTransitions(target, baseline, incoming, conflicts) {
124
+ const oldDirectories = new Set([...baseline.keys()].flatMap(parents))
125
+ const newDirectories = new Set([...incoming.keys()].flatMap(parents))
126
+ const expanding = new Set([...baseline.keys()].filter((path) => newDirectories.has(path)))
127
+ const collapsing = new Set([...incoming.keys()].filter((path) => oldDirectories.has(path)))
128
+ const hiddenChildren = new Set()
129
+ const directoryRemovals = []
130
+ for (const path of [...expanding, ...collapsing]) {
131
+ const info = stat(targetFile(target, path))
132
+ if (info?.isFile()) hiddenChildren.add(path)
133
+ if (info?.isDirectory() && collapsing.has(path)) {
134
+ recordDirectoryRemovals(target, path, baseline, oldDirectories, directoryRemovals, conflicts)
135
+ }
136
+ }
137
+
138
+ const directoryAdditions = []
139
+ for (const path of [...newDirectories].sort((left, right) => left.length - right.length)) {
140
+ if (!expanding.has(path) && !parents(path).some((parent) => expanding.has(parent))) continue
141
+ if (!hiddenChildren.has(path) && !parents(path).some((parent) => hiddenChildren.has(parent)) &&
142
+ stat(targetFile(target, path))) continue
143
+ directoryAdditions.push({ path, next: { directory: true, mode: 0o777 & ~process.umask() } })
144
+ }
145
+ return { expanding, collapsing, hiddenChildren, directoryRemovals, directoryAdditions }
146
+ }
147
+
148
+ function changedFiles(target, baseline, incoming) {
149
+ const changes = []
150
+ const conflicts = new Set()
151
+ const transitions = planPathTransitions(target, baseline, incoming, conflicts)
152
+ for (const path of new Set([...baseline.keys(), ...incoming.keys()])) {
153
+ if (conflicts.has(path)) continue
154
+ const previous = baseline.get(path)
155
+ const next = incoming.get(path)
156
+ if (sameEntry(previous, next)) continue
157
+ let current
158
+ if (!parents(path).some((parent) => transitions.hiddenChildren.has(parent) || conflicts.has(parent))) {
159
+ const destination = targetFile(target, path)
160
+ const info = stat(destination)
161
+ const transitionsThroughDirectory = transitions.expanding.has(path) || transitions.collapsing.has(path)
162
+ if (!(transitionsThroughDirectory && info?.isDirectory())) current = readFile(destination, info)
163
+ }
164
+ if (sameEntry(current, next)) continue
165
+ if (!sameEntry(current, previous)) {
166
+ conflicts.add(path)
167
+ continue
168
+ }
169
+ if (current && next) {
170
+ const mode = (current.mode & ~executableBits) | (next.mode & executableBits)
171
+ changes.push({ path, current, next: { ...next, mode } })
172
+ } else {
173
+ changes.push({ path, current, next })
174
+ }
175
+ }
176
+ if (conflicts.size) throwUpgradeConflicts(conflicts)
177
+ return {
178
+ changes: [
179
+ ...changes.filter(({ next }) => !next),
180
+ ...transitions.directoryRemovals,
181
+ ...transitions.directoryAdditions,
182
+ ...changes.filter(({ next }) => next),
183
+ ],
184
+ removed: [...baseline.keys()].filter((path) => !incoming.has(path) &&
185
+ !parents(path).some((parent) => transitions.collapsing.has(parent))),
186
+ }
187
+ }
188
+
189
+ function throwUpgradeConflicts(conflicts) {
190
+ throw new Error(`Upgrade conflicts with local changes at:\n ${[...conflicts].sort().join('\n ')}`)
191
+ }
192
+
193
+ export function prepareUpgrade(target, revision, repository) {
194
+ if (!commitPattern.test(revision)) throw new Error('Expected a full incoming Git commit pin.')
195
+ const stamp = readFile(targetFile(target, stampPath))
196
+ const previous = stamp?.bytes.toString().trim()
197
+ if (!commitPattern.test(previous)) {
198
+ throw new Error(`Expected an installed Git commit pin at ${stampPath}. Run setup for a fresh install.`)
199
+ }
200
+ if (previous === revision) return { previous }
201
+
202
+ const directory = mkdtempSync(join(tmpdir(), 'workflow-upgrade-base-'))
203
+ try {
204
+ fetchBaseline(directory, repository, previous)
205
+ const paths = [...rolePaths, ...bundledPaths]
206
+ if (stat(targetFile(target, ciPath.target))) paths.push(ciPath)
207
+ const baseline = new Map(paths.flatMap((path) => baselineFiles(directory, previous, path)))
208
+ const incoming = new Map(paths.flatMap((path) => incomingFiles(join(sourceRoot, path.source), path.target)))
209
+ return { previous, stamp, ...changedFiles(target, baseline, incoming) }
210
+ } finally {
211
+ rmSync(directory, { recursive: true, force: true })
212
+ }
213
+ }
214
+
215
+ function checkUnchanged(path, expected) {
216
+ const info = stat(path)
217
+ const current = info?.isDirectory()
218
+ ? { directory: true, mode: info.mode & 0o777 }
219
+ : readFile(path, info)
220
+ if (!sameEntry(current, expected) || current?.mode !== expected?.mode) {
221
+ throw new Error(`File changed while preparing the upgrade: ${path}`)
222
+ }
223
+ }
224
+
225
+ function cleanUp(path, remove) {
226
+ try {
227
+ remove(path)
228
+ } catch (error) {
229
+ console.warn(`Could not remove upgrade temporary path ${path}: ${error.message}`)
230
+ }
231
+ }
232
+
233
+ function applyEntry(target, { path, current, next }) {
234
+ const destination = targetFile(target, path)
235
+ checkWritableParent(destination)
236
+ if (!next) {
237
+ checkUnchanged(destination, current)
238
+ const remove = current.directory ? rmdirSync : unlinkSync
239
+ remove(destination)
240
+ return
241
+ }
242
+ if (next.directory) {
243
+ mkdirSync(dirname(destination), { recursive: true })
244
+ checkUnchanged(destination, current)
245
+ mkdirSync(destination)
246
+ try {
247
+ chmodSync(destination, next.mode)
248
+ } catch (error) {
249
+ cleanUp(destination, rmdirSync)
250
+ throw error
251
+ }
252
+ return
253
+ }
254
+
255
+ const parent = dirname(destination)
256
+ mkdirSync(parent, { recursive: true })
257
+ const stage = mkdtempSync(join(parent, '.workflow-upgrade-'))
258
+ try {
259
+ const file = join(stage, 'content')
260
+ writeFileSync(file, next.bytes)
261
+ chmodSync(file, next.mode)
262
+ checkUnchanged(targetFile(target, path), current)
263
+ // A concurrent addition must never be overwritten.
264
+ if (current) renameSync(file, destination)
265
+ else linkSync(file, destination)
266
+ } finally {
267
+ cleanUp(stage, (path) => rmSync(path, { recursive: true, force: true }))
268
+ }
269
+ }
270
+
271
+ function applyUpgrade(target, changes) {
272
+ const applied = []
273
+ try {
274
+ for (const change of changes) {
275
+ applyEntry(target, change)
276
+ applied.push(change)
277
+ }
278
+ } catch (error) {
279
+ const rollbackErrors = []
280
+ for (const { path, current, next } of applied.reverse()) {
281
+ try {
282
+ applyEntry(target, { path, current: next, next: current })
283
+ } catch (rollbackError) {
284
+ rollbackErrors.push(rollbackError.message)
285
+ }
286
+ }
287
+ if (!rollbackErrors.length) throw error
288
+ throw new Error(`${error.message}\nCould not restore every applied file:\n ${rollbackErrors.join('\n ')}\nResolve the reported paths and retry the same upgrade.`)
289
+ }
290
+ }
291
+
292
+ function pruneEmptyDirectories(target, removed) {
293
+ for (const path of removed) {
294
+ const root = [...rolePaths, ...bundledPaths].find(({ target }) => path.startsWith(target + '/'))
295
+ if (!root) continue
296
+ for (let parent = posix.dirname(path); parent.length >= root.target.length; parent = posix.dirname(parent)) {
297
+ try {
298
+ const directory = targetPath(target, parent)
299
+ if (stat(directory)) rmdirSync(directory)
300
+ } catch (error) {
301
+ if (!['ENOENT', 'ENOTEMPTY', 'EEXIST'].includes(error.code)) {
302
+ console.warn(`Could not remove empty upgrade directory ${parent}: ${error.message}`)
303
+ }
304
+ break
305
+ }
306
+ }
307
+ }
308
+ }
309
+
310
+ export function upgrade(target, revision, repository) {
311
+ const { previous, stamp, changes, removed } = prepareUpgrade(target, revision, repository)
312
+ if (previous === revision) {
313
+ console.log(`Already installed Engineering Workflows at ${revision}`)
314
+ return
315
+ }
316
+
317
+ const lock = targetFile(target, '.engineering-workflows/.upgrade-lock')
318
+ try {
319
+ mkdirSync(lock)
320
+ } catch (error) {
321
+ if (error.code !== 'EEXIST') throw error
322
+ throw new Error(`Another upgrade is using ${lock}. Retry after it finishes.`)
323
+ }
324
+ try {
325
+ checkUnchanged(targetFile(target, stampPath), stamp)
326
+ const next = { bytes: Buffer.from(revision + '\n'), mode: stamp.mode }
327
+ applyUpgrade(target, [...changes, { path: stampPath, current: stamp, next }])
328
+ pruneEmptyDirectories(target, removed)
329
+ } finally {
330
+ cleanUp(lock, rmdirSync)
331
+ }
332
+ console.log(`Upgraded Engineering Workflows from ${previous} to ${revision}`)
333
+ }