ultra-builder-pro-cli 0.26.2 → 5.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 (82) hide show
  1. package/.ultra-template/contexts/TEMPLATE.md +70 -29
  2. package/.ultra-template/north-star.md +35 -18
  3. package/.ultra-template/tasks.json +1 -0
  4. package/.ultra-template/test-report.json +17 -1
  5. package/CHANGELOG.md +235 -1
  6. package/README.md +210 -50
  7. package/README.zh-CN.md +440 -0
  8. package/adapters/_shared/host-profile.cjs +3 -95
  9. package/adapters/_shared/plugin-core.cjs +61 -5
  10. package/adapters/_shared/runtime-assets.cjs +66 -5
  11. package/adapters/zcode.js +375 -0
  12. package/bin/delegate-worker.cjs +2 -325
  13. package/bin/delegate.cjs +3 -461
  14. package/bin/install.js +11 -6
  15. package/docs/ARCHITECTURE.md +133 -31
  16. package/docs/ARTIFACT-AUTHORITY.md +185 -24
  17. package/docs/DECISIONS.md +153 -18
  18. package/docs/PHILOSOPHY.md +58 -7
  19. package/docs/PLUGIN-ISOLATION-CONTRACT.md +34 -12
  20. package/docs/RUNTIME-COMPAT-MATRIX.md +195 -23
  21. package/docs/SKILL-AUTHORING.md +19 -6
  22. package/docs/WORKFLOW-LIFECYCLE.md +196 -44
  23. package/docs/evals/adversarial-review-2026-08-14.md +84 -0
  24. package/docs/evals/ultra-5-0-journey-results.md +62 -0
  25. package/docs/evals/ultra-5-0-live-acp-conformance.md +93 -0
  26. package/docs/evals/ultra-5-0-route-journeys.md +145 -0
  27. package/docs/evals/zcode-automation-2026-08-14.md +103 -0
  28. package/hooks/README.md +27 -4
  29. package/hooks/_common.py +1678 -61
  30. package/hooks/adapters/zcode.py +227 -0
  31. package/hooks/compact_context.py +176 -17
  32. package/hooks/mid_workflow_recall.py +27 -5
  33. package/hooks/post_edit_guard.py +133 -23
  34. package/hooks/session_context.py +707 -22
  35. package/package.json +7 -3
  36. package/skills/ultra-change/SKILL.md +69 -12
  37. package/skills/ultra-change/references/change-contract.md +93 -27
  38. package/skills/ultra-change/references/execution-grant.md +109 -0
  39. package/skills/ultra-change/references/primary-transfer.md +273 -0
  40. package/skills/ultra-change/scripts/validate_primary_transfer.cjs +1928 -0
  41. package/skills/ultra-delegate/SKILL.md +103 -8
  42. package/skills/ultra-delegate/patches/zcode-acp-0.1.0-zcode-0.16.5.patch +184 -0
  43. package/skills/ultra-delegate/references/delegation-contract.md +80 -1
  44. package/skills/ultra-delegate/scripts/acp-conformance.cjs +287 -0
  45. package/skills/ultra-delegate/scripts/acp-driver.cjs +762 -0
  46. package/skills/ultra-delegate/scripts/agent-execution-driver.cjs +320 -0
  47. package/skills/ultra-delegate/scripts/cli-driver.cjs +61 -0
  48. package/skills/ultra-delegate/scripts/delegate-worker.cjs +328 -0
  49. package/skills/ultra-delegate/scripts/delegate.cjs +690 -0
  50. package/skills/ultra-delegate/scripts/host-profile.cjs +267 -0
  51. package/skills/ultra-deliver/SKILL.md +98 -11
  52. package/skills/ultra-dev/SKILL.md +188 -42
  53. package/skills/ultra-grilling/SKILL.md +10 -7
  54. package/skills/ultra-grilling/references/reframing.md +7 -3
  55. package/skills/ultra-init/SKILL.md +56 -7
  56. package/skills/ultra-init/scripts/init_project.cjs +968 -21
  57. package/skills/ultra-plan/SKILL.md +91 -47
  58. package/skills/ultra-plan/references/task-evidence-v2.md +300 -0
  59. package/skills/ultra-plan/scripts/validate_task_evidence.cjs +859 -0
  60. package/skills/ultra-research/SKILL.md +70 -14
  61. package/skills/ultra-research/references/04-product-strategy.md +11 -2
  62. package/skills/ultra-research/references/21-features-scope.md +8 -0
  63. package/skills/ultra-research/references/22-success-metrics.md +4 -3
  64. package/skills/ultra-research/references/99-synthesis.md +19 -2
  65. package/skills/ultra-research/references/north-star-v2.md +168 -0
  66. package/skills/ultra-research/references/wayfinding.md +8 -0
  67. package/skills/ultra-research/scripts/validate_north_star.cjs +1174 -0
  68. package/skills/ultra-review/SKILL.md +201 -27
  69. package/skills/ultra-review/references/adversarial-evaluation.md +31 -0
  70. package/skills/ultra-review/references/spec.md +5 -0
  71. package/skills/ultra-review/references/unified-schema.md +146 -11
  72. package/skills/ultra-review/references/worker-packet.md +151 -8
  73. package/skills/ultra-review/scripts/review_wait.py +2653 -63
  74. package/skills/ultra-status/SKILL.md +129 -15
  75. package/skills/ultra-status/references/route-contract.md +100 -0
  76. package/skills/ultra-tdd/SKILL.md +11 -4
  77. package/skills/ultra-tdd/references/test-execution.md +6 -1
  78. package/skills/ultra-test/SKILL.md +161 -18
  79. package/skills/ultra-test/scripts/validate_review_transport.cjs +549 -0
  80. package/skills/ultra-test/scripts/worktree_digest.cjs +518 -30
  81. /package/{adapters/_shared → skills/ultra-delegate/scripts}/delegate-profiles/kimi-read-only.md +0 -0
  82. /package/{adapters/_shared → skills/ultra-delegate/scripts}/delegate-profiles/kimi-write.md +0 -0
@@ -1,328 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- const crypto = require('node:crypto');
5
- const fs = require('node:fs');
6
- const path = require('node:path');
7
- const { execFileSync, spawn } = require('node:child_process');
8
-
9
- const RESULT_SCHEMA = 'ultra-delegation-result-v1';
10
- const PROTECTED_ROOT = '.ultra';
11
- const MODEL_FIELDS = new Set([
12
- '$schema', 'status', 'summary', 'changed_files', 'checks', 'evidence',
13
- 'questions', 'residual_risks',
14
- ]);
15
-
16
- function writeAtomic(file, payload) {
17
- const temporary = `${file}.tmp-${process.pid}`;
18
- fs.writeFileSync(temporary, `${JSON.stringify(payload, null, 2)}\n`, { mode: 0o600 });
19
- fs.renameSync(temporary, file);
20
- }
21
-
22
- function sha256(file) {
23
- try {
24
- return crypto.createHash('sha256').update(fs.readFileSync(file)).digest('hex');
25
- } catch {
26
- return null;
27
- }
28
- }
29
-
30
- function git(cwd, args, { binary = false } = {}) {
31
- return execFileSync('git', args, {
32
- cwd,
33
- encoding: binary ? 'buffer' : 'utf8',
34
- stdio: ['ignore', 'pipe', 'pipe'],
35
- });
36
- }
37
-
38
- function zeroSeparated(buffer) {
39
- return buffer.toString('utf8').split('\0').filter(Boolean);
40
- }
41
-
42
- function normalizeChangedPath(value) {
43
- if (typeof value !== 'string' || !value || value.includes('\\') || path.posix.isAbsolute(value)) {
44
- return null;
45
- }
46
- const normalized = path.posix.normalize(value);
47
- if (normalized !== value || normalized === '.' || normalized === '..' || normalized.startsWith('../')) {
48
- return null;
49
- }
50
- return normalized;
51
- }
52
-
53
- function changedFiles(spec) {
54
- const tracked = zeroSeparated(git(spec.cwd, [
55
- 'diff', '--name-only', '-z', spec.base_head, '--',
56
- ], { binary: true }));
57
- const untracked = zeroSeparated(git(spec.cwd, [
58
- 'ls-files', '--others', '--exclude-standard', '-z',
59
- ], { binary: true }));
60
- return [...new Set([...tracked, ...untracked]
61
- .map((item) => item.split(path.sep).join('/')))]
62
- .sort();
63
- }
64
-
65
- function parseJson(value) {
66
- if (typeof value !== 'string') return null;
67
- let text = value.trim();
68
- const fence = text.match(/^```(?:json)?\s*([\s\S]*?)\s*```$/i);
69
- if (fence) text = fence[1];
70
- try { return JSON.parse(text); } catch { return null; }
71
- }
72
-
73
- function collectResultCandidates(value, candidates, depth = 0) {
74
- if (depth > 12 || value === null || value === undefined) return;
75
- if (typeof value === 'string') {
76
- const parsed = parseJson(value);
77
- if (parsed !== null) collectResultCandidates(parsed, candidates, depth + 1);
78
- return;
79
- }
80
- if (Array.isArray(value)) {
81
- for (const item of value) collectResultCandidates(item, candidates, depth + 1);
82
- return;
83
- }
84
- if (typeof value !== 'object') return;
85
- if (value.$schema === RESULT_SCHEMA) candidates.push(value);
86
- for (const nested of Object.values(value)) {
87
- collectResultCandidates(nested, candidates, depth + 1);
88
- }
89
- }
90
-
91
- function extractModelResult(spec) {
92
- const candidates = [];
93
- for (const file of [spec.host_output, spec.stdout]) {
94
- if (!file || !fs.existsSync(file) || fs.statSync(file).size === 0) continue;
95
- const text = fs.readFileSync(file, 'utf8');
96
- const full = parseJson(text);
97
- if (full !== null) collectResultCandidates(full, candidates);
98
- for (const line of text.split('\n')) {
99
- const parsed = parseJson(line);
100
- if (parsed !== null) collectResultCandidates(parsed, candidates);
101
- }
102
- }
103
- return candidates.at(-1) || null;
104
- }
105
-
106
- function validateModelResult(payload) {
107
- if (!payload || Array.isArray(payload) || typeof payload !== 'object') {
108
- return 'result must be a JSON object';
109
- }
110
- const extra = Object.keys(payload).filter((key) => !MODEL_FIELDS.has(key));
111
- const missing = [...MODEL_FIELDS].filter((key) => !(key in payload));
112
- if (extra.length || missing.length) {
113
- return `result fields must be exact; missing=${missing.join(',') || 'none'} extra=${extra.join(',') || 'none'}`;
114
- }
115
- if (payload.$schema !== RESULT_SCHEMA) return `$schema must be ${RESULT_SCHEMA}`;
116
- if (!['finished', 'blocked', 'failed'].includes(payload.status)) {
117
- return 'status must be finished, blocked, or failed';
118
- }
119
- if (typeof payload.summary !== 'string' || !payload.summary.trim()) {
120
- return 'summary must be a non-empty string';
121
- }
122
- if (!Array.isArray(payload.changed_files)) return 'changed_files must be an array';
123
- const normalized = payload.changed_files.map(normalizeChangedPath);
124
- if (normalized.some((item) => item === null) || new Set(normalized).size !== normalized.length) {
125
- return 'changed_files must contain unique normalized repository-relative paths';
126
- }
127
- if (!Array.isArray(payload.checks)) return 'checks must be an array';
128
- for (const check of payload.checks) {
129
- if (!check || Array.isArray(check) || typeof check !== 'object') return 'checks items must be objects';
130
- const keys = Object.keys(check);
131
- if (!keys.every((key) => ['command', 'status', 'output_ref'].includes(key))) {
132
- return 'checks items contain an unknown field';
133
- }
134
- if (typeof check.command !== 'string' || !check.command.trim()) return 'checks.command must be non-empty';
135
- if (!['passed', 'failed', 'not_run'].includes(check.status)) return 'checks.status is invalid';
136
- if (check.output_ref !== undefined && (typeof check.output_ref !== 'string' || !check.output_ref.trim())) {
137
- return 'checks.output_ref must be a non-empty string when present';
138
- }
139
- }
140
- for (const field of ['evidence', 'questions', 'residual_risks']) {
141
- if (!Array.isArray(payload[field]) || !payload[field].every(
142
- (item) => typeof item === 'string' && item.trim(),
143
- )) return `${field} must be an array of non-empty strings`;
144
- }
145
- if (payload.status === 'blocked' && payload.questions.length === 0) {
146
- return 'blocked results require at least one question';
147
- }
148
- payload.changed_files = [...normalized].sort();
149
- return null;
150
- }
151
-
152
- // The project's memory has exactly one writer: the primary host. A worker that edits
153
- // `.ultra` in its own worktree collides in the files every later session reads to
154
- // resume, so no permission grants it — not even `writable_roots: ["."]`.
155
- function authorized(spec, file) {
156
- if (file === PROTECTED_ROOT || file.startsWith(`${PROTECTED_ROOT}/`)) return false;
157
- return spec.writable_roots.some((root) => (
158
- root === '.' || file === root || file.startsWith(`${root}/`)
159
- ));
160
- }
161
-
162
- function finalHead(spec) {
163
- try { return git(spec.cwd, ['rev-parse', 'HEAD']).trim(); } catch { return null; }
164
- }
165
-
166
- function mechanical(spec, exitCode, signal) {
167
- return {
168
- delegation_id: spec.delegation_id,
169
- host: spec.host,
170
- instruction_digest: spec.instruction_digest,
171
- permission_digest: spec.permission_digest,
172
- output_schema_digest: spec.output_schema_digest,
173
- read_only: spec.read_only,
174
- base_head: spec.base_head,
175
- final_head: finalHead(spec),
176
- started_at: spec.started_at,
177
- finished_at: new Date().toISOString(),
178
- exit_code: Number.isInteger(exitCode) ? exitCode : null,
179
- signal: signal || null,
180
- };
181
- }
182
-
183
- function failure(spec, type, summary, exitCode = null, signal = null, files = []) {
184
- return {
185
- $schema: RESULT_SCHEMA,
186
- status: 'failed',
187
- summary,
188
- changed_files: files,
189
- checks: [],
190
- evidence: [],
191
- questions: [],
192
- residual_risks: [],
193
- failure_type: type,
194
- ...mechanical(spec, exitCode, signal),
195
- };
196
- }
197
-
198
- function terminate(child, signal = 'SIGTERM') {
199
- if (!child || child.exitCode !== null || child.signalCode !== null) return;
200
- try {
201
- if (process.platform === 'win32') child.kill(signal);
202
- else process.kill(-child.pid, signal);
203
- } catch {}
204
- }
205
-
206
- function runChild(spec) {
207
- return new Promise((resolve) => {
208
- const stdoutFd = fs.openSync(spec.stdout, 'a');
209
- const stderrFd = fs.openSync(spec.stderr, 'a');
210
- let termination = null;
211
- let spawnError = null;
212
- let closed = false;
213
- let hardKill = null;
214
- const child = spawn(spec.command, spec.args, {
215
- cwd: spec.cwd,
216
- env: { ...process.env, ...spec.env },
217
- detached: process.platform !== 'win32',
218
- stdio: ['ignore', stdoutFd, stderrFd],
219
- });
220
- const finish = (code, signal) => {
221
- if (closed) return;
222
- closed = true;
223
- clearInterval(cancelPoll);
224
- clearTimeout(timeout);
225
- if (hardKill) clearTimeout(hardKill);
226
- fs.closeSync(stdoutFd);
227
- fs.closeSync(stderrFd);
228
- resolve({ code, signal, termination, spawnError });
229
- };
230
- child.on('error', (error) => { spawnError = error; });
231
- child.on('close', finish);
232
- const requestTermination = (reason) => {
233
- if (termination) return;
234
- termination = reason;
235
- terminate(child);
236
- hardKill = setTimeout(() => terminate(child, 'SIGKILL'), 1500);
237
- hardKill.unref();
238
- };
239
- const cancelPoll = setInterval(() => {
240
- if (fs.existsSync(spec.cancel)) requestTermination('cancelled');
241
- }, 100);
242
- const timeout = setTimeout(() => requestTermination('timeout'), spec.timeout_ms);
243
- cancelPoll.unref();
244
- timeout.unref();
245
- });
246
- }
247
-
248
- async function main() {
249
- const specFile = process.argv[2];
250
- const expectedSpecDigest = process.argv[3];
251
- if (!specFile || !/^[0-9a-f]{64}$/.test(expectedSpecDigest || '')) {
252
- throw new Error('worker requires a spec path and digest');
253
- }
254
- if (sha256(specFile) !== expectedSpecDigest) throw new Error('worker spec digest mismatch before launch');
255
- const spec = JSON.parse(fs.readFileSync(specFile, 'utf8'));
256
- let terminal;
257
- try {
258
- if (sha256(spec.instruction) !== spec.instruction_digest) {
259
- terminal = failure(spec, 'instruction_changed', 'Instruction digest changed before delegation started.');
260
- } else if (sha256(spec.permission) !== spec.permission_digest) {
261
- terminal = failure(spec, 'permission_changed', 'Permission digest changed before delegation started.');
262
- } else if (sha256(spec.output_schema) !== spec.output_schema_digest) {
263
- terminal = failure(spec, 'output_schema_changed', 'Output schema digest changed before delegation started.');
264
- } else if (fs.existsSync(spec.cancel)) {
265
- terminal = failure(spec, 'cancelled', 'Delegation was cancelled before the host process started.');
266
- } else {
267
- const processResult = await runChild(spec);
268
- let files = [];
269
- try { files = changedFiles(spec); } catch {}
270
- if (processResult.termination === 'cancelled') {
271
- terminal = failure(spec, 'cancelled', 'Delegation cancelled by request.', processResult.code, processResult.signal, files);
272
- } else if (processResult.termination === 'timeout') {
273
- terminal = failure(spec, 'timeout', 'Delegation timed out and the host process was terminated.', processResult.code, processResult.signal, files);
274
- } else if (sha256(specFile) !== expectedSpecDigest) {
275
- terminal = failure(spec, 'worker_spec_changed', 'Worker specification changed during delegation.', processResult.code, processResult.signal, files);
276
- } else if (sha256(spec.instruction) !== spec.instruction_digest) {
277
- terminal = failure(spec, 'instruction_changed', 'Instruction digest changed during delegation.', processResult.code, processResult.signal, files);
278
- } else if (sha256(spec.permission) !== spec.permission_digest) {
279
- terminal = failure(spec, 'permission_changed', 'Permission digest changed during delegation.', processResult.code, processResult.signal, files);
280
- } else if (sha256(spec.output_schema) !== spec.output_schema_digest) {
281
- terminal = failure(spec, 'output_schema_changed', 'Output schema digest changed during delegation.', processResult.code, processResult.signal, files);
282
- } else if (processResult.spawnError) {
283
- terminal = failure(spec, 'spawn_error', `Host process failed to start: ${processResult.spawnError.message}`, null, null, files);
284
- } else if (processResult.code !== 0) {
285
- terminal = failure(spec, 'process_exit', `Host process exited with code ${processResult.code}.`, processResult.code, processResult.signal, files);
286
- } else {
287
- const payload = extractModelResult(spec);
288
- if (!payload) {
289
- terminal = failure(
290
- spec, 'missing_result',
291
- 'Host process exited without a structured Ultra delegation result.',
292
- processResult.code, processResult.signal, files,
293
- );
294
- } else {
295
- const validation = validateModelResult(payload);
296
- if (validation) {
297
- terminal = failure(spec, 'invalid_result', validation, processResult.code, processResult.signal, files);
298
- } else {
299
- const unauthorized = files.filter((file) => !authorized(spec, file));
300
- if (unauthorized.length) {
301
- terminal = failure(
302
- spec, 'unauthorized_write',
303
- `Actual Git diff escaped writable_roots: ${unauthorized.join(', ')}`,
304
- processResult.code, processResult.signal, files,
305
- );
306
- } else if (JSON.stringify(payload.changed_files) !== JSON.stringify(files)) {
307
- terminal = failure(
308
- spec, 'changed_files_mismatch',
309
- `Declared changed_files do not match actual Git diff: ${files.join(', ') || 'none'}`,
310
- processResult.code, processResult.signal, files,
311
- );
312
- } else {
313
- terminal = { ...payload, ...mechanical(spec, processResult.code, processResult.signal) };
314
- }
315
- }
316
- }
317
- }
318
- }
319
- if (!fs.existsSync(spec.result)) writeAtomic(spec.result, terminal);
320
- } finally {
321
- try { fs.unlinkSync(spec.lock); } catch (error) { if (error.code !== 'ENOENT') throw error; }
322
- }
323
- }
324
-
325
- main().catch((error) => {
326
- process.stderr.write(`${error.stack || error.message}\n`);
327
- process.exitCode = 1;
328
- });
4
+ // Compatibility surface for callers that still resolve the historical path.
5
+ require('../skills/ultra-delegate/scripts/delegate-worker.cjs');