ultra-builder-pro-cli 0.20.0 → 0.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.ultra-template/docs/research/README.md +26 -5
- package/.ultra-template/specs/discovery.md +1 -1
- package/.ultra-template/tasks/tasks.json +1 -1
- package/CHANGELOG.md +66 -0
- package/README.md +54 -24
- package/adapters/_shared/codex-assets.cjs +69 -11
- package/adapters/_shared/interaction-contract.cjs +36 -3
- package/adapters/_shared/runtime-assets.cjs +41 -1
- package/adapters/claude.js +7 -5
- package/adapters/codex.js +1 -1
- package/adapters/kimi.js +2 -8
- package/adapters/opencode.js +30 -28
- package/bin/orchestrator.js +64 -24
- package/docs/AGENT-CONTEXT.md +74 -43
- package/docs/ARCHITECTURE.md +63 -31
- package/docs/ARTIFACT-AUTHORITY.md +234 -0
- package/docs/DECISIONS.md +10 -4
- package/docs/LEGACY-CLI-CROSSWALK.md +6 -4
- package/docs/PLUGIN-ISOLATION-CONTRACT.md +4 -3
- package/docs/ROADMAP.md +19 -5
- package/docs/RUNTIME-COMPAT-MATRIX.md +24 -13
- package/docs/STATE-DB-ACCESS-POLICY.md +11 -9
- package/docs/WORKFLOW-LIFECYCLE.md +70 -39
- package/hooks/README.md +6 -5
- package/hooks/active_task_context.py +97 -12
- package/hooks/context_spine.py +16 -4
- package/hooks/health_check.py +5 -4
- package/hooks/pre_stop_check.py +5 -2
- package/hooks/runtime_paths.py +396 -0
- package/hooks/subagent_tracker.py +5 -2
- package/hooks/workflow_checkpoint.py +16 -3
- package/hooks/workflow_context.py +11 -3
- package/hooks/workflow_resume.py +7 -4
- package/mcp-server/breadcrumb.cjs +20 -2
- package/mcp-server/lib/archive-journal.cjs +1026 -111
- package/mcp-server/lib/archive-mutation-worker.py +365 -0
- package/mcp-server/lib/artifact-registry.cjs +1126 -0
- package/mcp-server/lib/baseline-workflow.cjs +9 -4
- package/mcp-server/lib/change-packet.cjs +818 -0
- package/mcp-server/lib/change-workflow.cjs +932 -176
- package/mcp-server/lib/context-paths.cjs +111 -0
- package/mcp-server/lib/context-spine.cjs +511 -45
- package/mcp-server/lib/decision-dialogue.cjs +345 -3
- package/mcp-server/lib/delivery-transaction.cjs +471 -0
- package/mcp-server/lib/doctor-backup-worker.cjs +328 -0
- package/mcp-server/lib/doctor.cjs +373 -11
- package/mcp-server/lib/git-bootstrap.cjs +459 -47
- package/mcp-server/lib/init-project.cjs +190 -95
- package/mcp-server/lib/plan-publication-worker.cjs +830 -0
- package/mcp-server/lib/plan-store.cjs +700 -5
- package/mcp-server/lib/project-breadcrumb.cjs +23 -4
- package/mcp-server/lib/projector.cjs +174 -40
- package/mcp-server/lib/runtime-paths.cjs +1687 -0
- package/mcp-server/lib/safe-project-file.cjs +385 -0
- package/mcp-server/lib/spec-learning.cjs +28 -12
- package/mcp-server/lib/state-db.cjs +263 -9
- package/mcp-server/lib/state-ops.cjs +248 -49
- package/mcp-server/lib/telemetry.cjs +12 -3
- package/mcp-server/lib/workflow-state.cjs +610 -58
- package/mcp-server/server.cjs +278 -33
- package/orchestrator/daemon.cjs +2 -10
- package/orchestrator/parallel-orchestrator.cjs +314 -50
- package/orchestrator/planner/plan-builder.cjs +1 -1
- package/orchestrator/recovery.cjs +125 -7
- package/orchestrator/session-close-journal-worker.cjs +5 -0
- package/orchestrator/session-close-journal.cjs +1014 -0
- package/orchestrator/session-runner.cjs +679 -69
- package/orchestrator/worktree-manager.cjs +186 -35
- package/package.json +2 -3
- package/skills/cc-collab/SKILL.md +4 -1
- package/skills/codex-collab/SKILL.md +5 -2
- package/skills/ultra-change/SKILL.md +26 -8
- package/skills/ultra-deliver/SKILL.md +23 -11
- package/skills/ultra-dev/SKILL.md +33 -6
- package/skills/ultra-doctor/SKILL.md +6 -2
- package/skills/ultra-init/SKILL.md +4 -2
- package/skills/ultra-plan/SKILL.md +49 -16
- package/skills/ultra-research/SKILL.md +30 -27
- package/skills/ultra-review/SKILL.md +9 -5
- package/skills/ultra-status/SKILL.md +9 -4
- package/skills/ultra-test/SKILL.md +10 -5
- package/skills/ultra-think/SKILL.md +6 -2
- package/skills/ultra-think/references/decision-dialogue.md +17 -6
- package/skills/ultra-verify/SKILL.md +4 -1
- package/spec/cli-protocol.md +18 -7
- package/spec/mcp-tools.yaml +502 -44
- package/spec/schemas/change-delta.v1.schema.json +153 -0
- package/spec/schemas/documentation-reconciliation.v1.schema.json +106 -0
- package/spec/schemas/mcp-tools.schema.json +1 -1
- package/spec/schemas/state-db.sql +50 -13
- package/spec/schemas/tasks.v4.5.schema.json +1 -1
- package/ultra-tools/cli.cjs +3 -2
- package/ultra-tools/commands/db.cjs +76 -25
- package/ultra-tools/commands/migrate.cjs +995 -80
- package/ultra-tools/commands/session.cjs +34 -8
- package/ultra-tools/commands/status.cjs +32 -6
- package/ultra-tools/commands/system.cjs +129 -22
- package/commands/learn.md +0 -10
- package/orchestrator/skill-miner.cjs +0 -133
- package/output-styles/coding-vibes.md +0 -67
- package/output-styles/structural-thinking.md +0 -61
- package/skills/learn/SKILL.md +0 -58
|
@@ -5,10 +5,104 @@ const path = require('node:path');
|
|
|
5
5
|
const { spawnSync } = require('node:child_process');
|
|
6
6
|
|
|
7
7
|
const GIT_MODES = new Set(['auto', 'initialize', 'skip']);
|
|
8
|
-
// No trailing slash: isolated session worktrees expose `.ultra`
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
|
|
8
|
+
// No trailing slash: isolated session worktrees expose only `.ultra/.runtime`
|
|
9
|
+
// as a symlink, and Git's directory-only pattern does not ignore that symlink
|
|
10
|
+
// reliably. Semantic and evidence artifacts elsewhere in `.ultra/` remain
|
|
11
|
+
// trackable and travel with their task branch.
|
|
12
|
+
const ULTRA_RUNTIME_IGNORE_LINE = '.ultra/.runtime';
|
|
13
|
+
const ULTRA_LEGACY_STATE_IGNORE_LINES = Object.freeze([
|
|
14
|
+
'.ultra/[s]tate.db',
|
|
15
|
+
'.ultra/[s]tate.db-wal',
|
|
16
|
+
'.ultra/[s]tate.db-shm',
|
|
17
|
+
]);
|
|
18
|
+
const ULTRA_LEGACY_STATE_PROBES = Object.freeze([
|
|
19
|
+
'.ultra/' + 'state.db',
|
|
20
|
+
'.ultra/' + 'state.db-wal',
|
|
21
|
+
'.ultra/' + 'state.db-shm',
|
|
22
|
+
]);
|
|
23
|
+
const ULTRA_UNIGNORE_DIR_LINE = '!.ultra/';
|
|
24
|
+
const ULTRA_UNIGNORE_CONTENT_LINE = '!.ultra/**';
|
|
25
|
+
const LEGACY_BROAD_IGNORE_LINES = new Set(['.ultra', '.ultra/', '/.ultra', '/.ultra/']);
|
|
26
|
+
const ULTRA_GIT_ARTIFACT_CLASSES = Object.freeze({
|
|
27
|
+
runtime: Object.freeze({
|
|
28
|
+
compatibility: ULTRA_LEGACY_STATE_PROBES,
|
|
29
|
+
authority: Object.freeze([
|
|
30
|
+
'.ultra/.runtime/state.db',
|
|
31
|
+
'.ultra/.runtime/state.db-wal',
|
|
32
|
+
'.ultra/.runtime/state.db-shm',
|
|
33
|
+
]),
|
|
34
|
+
backups: Object.freeze([
|
|
35
|
+
'.ultra/.runtime/backups/state-db-2026-07-28.db',
|
|
36
|
+
'.ultra/.runtime/backups/legacy-state-2026-07-28/state.db',
|
|
37
|
+
'.ultra/.runtime/backups/projection-v4.5-2026-07-28/tasks/tasks.json',
|
|
38
|
+
'.ultra/.runtime/backups/backup-v4.4-2026-07-28/specs/product.md',
|
|
39
|
+
]),
|
|
40
|
+
coordination: Object.freeze([
|
|
41
|
+
'.ultra/.runtime/collab/review.json',
|
|
42
|
+
'.ultra/.runtime/sessions/session/metadata.json',
|
|
43
|
+
'.ultra/.runtime/worktrees/session/marker',
|
|
44
|
+
'.ultra/.runtime/telemetry/events.jsonl',
|
|
45
|
+
'.ultra/.runtime/debug/trace.jsonl',
|
|
46
|
+
'.ultra/.runtime/checkpoint.json',
|
|
47
|
+
'.ultra/.runtime/orchestrator/orchestrator.pid',
|
|
48
|
+
'.ultra/.runtime/orchestrator/orchestrator.log',
|
|
49
|
+
'.ultra/.runtime/recovery/worktrees/session/sentinel',
|
|
50
|
+
]),
|
|
51
|
+
}),
|
|
52
|
+
semantic: Object.freeze({
|
|
53
|
+
baseline: Object.freeze([
|
|
54
|
+
'.ultra/specs/discovery.md',
|
|
55
|
+
'.ultra/specs/product.md',
|
|
56
|
+
'.ultra/specs/architecture.md',
|
|
57
|
+
'.ultra/specs/research-distillate.md',
|
|
58
|
+
]),
|
|
59
|
+
planning: Object.freeze([
|
|
60
|
+
'.ultra/plan.md',
|
|
61
|
+
'.ultra/plan.json',
|
|
62
|
+
'.ultra/tasks/tasks.json',
|
|
63
|
+
'.ultra/tasks/plan.md',
|
|
64
|
+
'.ultra/tasks/plan.json',
|
|
65
|
+
'.ultra/tasks/contexts/example.md',
|
|
66
|
+
]),
|
|
67
|
+
research: Object.freeze([
|
|
68
|
+
'.ultra/docs/research/README.md',
|
|
69
|
+
'.ultra/docs/research/workflow/step.md',
|
|
70
|
+
]),
|
|
71
|
+
changes: Object.freeze([
|
|
72
|
+
'.ultra/changes/active/example/intent.md',
|
|
73
|
+
'.ultra/changes/active/example/plan.md',
|
|
74
|
+
'.ultra/changes/active/example/delta/spec.md',
|
|
75
|
+
'.ultra/changes/active/example/findings/review.md',
|
|
76
|
+
'.ultra/changes/active/example/evidence/build.json',
|
|
77
|
+
'.ultra/changes/active/example/reconciliation.json',
|
|
78
|
+
'.ultra/changes/active/example/verification.md',
|
|
79
|
+
'.ultra/changes/active/example/contexts/manifest.json',
|
|
80
|
+
'.ultra/changes/archive/example/intent.md',
|
|
81
|
+
'.ultra/changes/archive/example/plan.md',
|
|
82
|
+
'.ultra/changes/archive/example/evidence/release.json',
|
|
83
|
+
]),
|
|
84
|
+
reports: Object.freeze([
|
|
85
|
+
'.ultra/reports/templates/test-report.json',
|
|
86
|
+
'.ultra/reports/templates/delivery-report.json',
|
|
87
|
+
'.ultra/reports/tests/workflow.json',
|
|
88
|
+
'.ultra/reports/delivery/workflow.json',
|
|
89
|
+
'.ultra/reports/test-report.json',
|
|
90
|
+
'.ultra/reports/delivery-report.json',
|
|
91
|
+
]),
|
|
92
|
+
evidence: Object.freeze([
|
|
93
|
+
'.ultra/evidence/build.json',
|
|
94
|
+
'.ultra/findings/review.md',
|
|
95
|
+
'.ultra/reconciliation/change.md',
|
|
96
|
+
'.ultra/archive/change/evidence.json',
|
|
97
|
+
]),
|
|
98
|
+
}),
|
|
99
|
+
});
|
|
100
|
+
const ULTRA_RUNTIME_PROBES = Object.freeze(
|
|
101
|
+
Object.values(ULTRA_GIT_ARTIFACT_CLASSES.runtime).flat(),
|
|
102
|
+
);
|
|
103
|
+
const ULTRA_SEMANTIC_PROBES = Object.freeze(
|
|
104
|
+
Object.values(ULTRA_GIT_ARTIFACT_CLASSES.semantic).flat(),
|
|
105
|
+
);
|
|
12
106
|
|
|
13
107
|
class GitBootstrapError extends Error {
|
|
14
108
|
constructor(code, message, { cause } = {}) {
|
|
@@ -19,22 +113,63 @@ class GitBootstrapError extends Error {
|
|
|
19
113
|
}
|
|
20
114
|
}
|
|
21
115
|
|
|
22
|
-
function runGit(rootDir, args) {
|
|
23
|
-
return
|
|
116
|
+
function runGit(rootDir, args, spawnGit = spawnSync) {
|
|
117
|
+
return spawnGit('git', args, {
|
|
24
118
|
cwd: rootDir,
|
|
25
119
|
encoding: 'utf8',
|
|
26
120
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
27
121
|
});
|
|
28
122
|
}
|
|
29
123
|
|
|
30
|
-
function gitValue(rootDir, args
|
|
31
|
-
|
|
32
|
-
|
|
124
|
+
function gitValue(rootDir, args, spawnGit = spawnSync, {
|
|
125
|
+
absentStatuses = [],
|
|
126
|
+
} = {}) {
|
|
127
|
+
const result = runGit(rootDir, args, spawnGit);
|
|
128
|
+
if (result?.error) {
|
|
129
|
+
throw new GitBootstrapError(
|
|
130
|
+
'GIT_DISCOVERY_FAILED',
|
|
131
|
+
`Git probe failed: ${result.error.message}`,
|
|
132
|
+
{ cause: result.error },
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
if (result.status === 0) return String(result.stdout || '').trim();
|
|
136
|
+
if (absentStatuses.includes(result.status)) return null;
|
|
137
|
+
const detail = String(result.stderr || result.stdout || `exit ${result.status}`).trim();
|
|
138
|
+
throw new GitBootstrapError(
|
|
139
|
+
'GIT_DISCOVERY_FAILED',
|
|
140
|
+
`Git probe ${args.join(' ')} failed: ${detail}`,
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function hasGitMetadata(rootDir) {
|
|
145
|
+
let current = path.resolve(rootDir);
|
|
146
|
+
while (true) {
|
|
147
|
+
if (fs.lstatSync(path.join(current, '.git'), { throwIfNoEntry: false })) return true;
|
|
148
|
+
const parent = path.dirname(current);
|
|
149
|
+
if (parent === current) return false;
|
|
150
|
+
current = parent;
|
|
151
|
+
}
|
|
33
152
|
}
|
|
34
153
|
|
|
35
|
-
function inspectGitRepository(rootDir) {
|
|
36
|
-
const
|
|
154
|
+
function inspectGitRepository(rootDir, { spawnGit = spawnSync } = {}) {
|
|
155
|
+
const metadataPresent = hasGitMetadata(rootDir);
|
|
156
|
+
const result = runGit(rootDir, ['rev-parse', '--show-toplevel'], spawnGit);
|
|
157
|
+
const repositoryRoot = result?.status === 0 ? String(result.stdout || '').trim() : '';
|
|
37
158
|
if (!repositoryRoot) {
|
|
159
|
+
const detail = String(
|
|
160
|
+
result?.error?.message || result?.stderr || result?.stdout || 'unknown Git probe failure',
|
|
161
|
+
).trim();
|
|
162
|
+
const explicitlyNotRepository = !metadataPresent
|
|
163
|
+
&& result?.status !== null
|
|
164
|
+
&& result?.status !== 0
|
|
165
|
+
&& /not a git repository/i.test(detail);
|
|
166
|
+
if (!explicitlyNotRepository) {
|
|
167
|
+
throw new GitBootstrapError(
|
|
168
|
+
'GIT_DISCOVERY_FAILED',
|
|
169
|
+
`cannot classify repository state: ${detail}`,
|
|
170
|
+
{ cause: result?.error },
|
|
171
|
+
);
|
|
172
|
+
}
|
|
38
173
|
return {
|
|
39
174
|
present: false,
|
|
40
175
|
repository_root: null,
|
|
@@ -45,9 +180,19 @@ function inspectGitRepository(rootDir) {
|
|
|
45
180
|
return {
|
|
46
181
|
present: true,
|
|
47
182
|
repository_root: path.resolve(repositoryRoot),
|
|
48
|
-
branch: gitValue(
|
|
49
|
-
|
|
50
|
-
|
|
183
|
+
branch: gitValue(
|
|
184
|
+
rootDir,
|
|
185
|
+
['symbolic-ref', '--quiet', '--short', 'HEAD'],
|
|
186
|
+
spawnGit,
|
|
187
|
+
{ absentStatuses: [1] },
|
|
188
|
+
)
|
|
189
|
+
|| gitValue(rootDir, ['branch', '--show-current'], spawnGit),
|
|
190
|
+
head: gitValue(
|
|
191
|
+
rootDir,
|
|
192
|
+
['rev-parse', '--verify', '--quiet', 'HEAD'],
|
|
193
|
+
spawnGit,
|
|
194
|
+
{ absentStatuses: [1] },
|
|
195
|
+
),
|
|
51
196
|
};
|
|
52
197
|
}
|
|
53
198
|
|
|
@@ -68,21 +213,229 @@ function initializeRepository(rootDir) {
|
|
|
68
213
|
}
|
|
69
214
|
}
|
|
70
215
|
|
|
71
|
-
function
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
216
|
+
function checkIgnoreStates(rootDir, probes, spawnGit = spawnSync) {
|
|
217
|
+
const unique = [...new Set(probes)];
|
|
218
|
+
if (unique.length === 0) return new Map();
|
|
219
|
+
const result = spawnGit(
|
|
220
|
+
'git',
|
|
221
|
+
['check-ignore', '--no-index', '--stdin', '-z'],
|
|
222
|
+
{
|
|
223
|
+
cwd: rootDir,
|
|
224
|
+
encoding: 'utf8',
|
|
225
|
+
input: `${unique.join('\0')}\0`,
|
|
226
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
227
|
+
},
|
|
228
|
+
);
|
|
229
|
+
if (result?.error || ![0, 1].includes(result?.status)) {
|
|
230
|
+
const detail = String(
|
|
231
|
+
result?.error?.message || result?.stderr || result?.stdout
|
|
232
|
+
|| `exit ${String(result?.status)}`,
|
|
233
|
+
).trim();
|
|
234
|
+
throw new GitBootstrapError(
|
|
235
|
+
'GITIGNORE_PROBE_FAILED',
|
|
236
|
+
`cannot classify Ultra artifacts: ${detail}`,
|
|
237
|
+
{ cause: result?.error },
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
const ignored = new Set(
|
|
241
|
+
String(result.stdout || '').split('\0').filter(Boolean),
|
|
242
|
+
);
|
|
243
|
+
for (const output of ignored) {
|
|
244
|
+
if (!unique.includes(output)) {
|
|
245
|
+
throw new GitBootstrapError(
|
|
246
|
+
'GITIGNORE_PROBE_FAILED',
|
|
247
|
+
`Git returned an unexpected Ultra artifact path: ${output}`,
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return new Map(unique.map((probe) => [
|
|
252
|
+
probe,
|
|
253
|
+
ignored.has(probe) ? 'ignored' : 'trackable',
|
|
254
|
+
]));
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function checkIgnoreState(rootDir, probe) {
|
|
258
|
+
return checkIgnoreStates(rootDir, [probe]).get(probe);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function scanManagedArtifacts(rootDir) {
|
|
262
|
+
const ultraRoot = path.join(rootDir, '.ultra');
|
|
263
|
+
const stat = fs.lstatSync(ultraRoot, { throwIfNoEntry: false });
|
|
264
|
+
if (!stat || stat.isSymbolicLink() || !stat.isDirectory()) {
|
|
265
|
+
return { runtime: [], semantic: [] };
|
|
266
|
+
}
|
|
267
|
+
const found = { runtime: [], semantic: [] };
|
|
268
|
+
const pending = fs.readdirSync(ultraRoot)
|
|
269
|
+
.map((entry) => path.join(ultraRoot, entry));
|
|
270
|
+
while (pending.length > 0) {
|
|
271
|
+
const candidate = pending.pop();
|
|
272
|
+
const entry = fs.lstatSync(candidate, { throwIfNoEntry: false });
|
|
273
|
+
if (!entry) continue;
|
|
274
|
+
const relative = path.relative(rootDir, candidate).split(path.sep).join('/');
|
|
275
|
+
const runtime = relative === '.ultra/.runtime'
|
|
276
|
+
|| relative.startsWith('.ultra/.runtime/')
|
|
277
|
+
|| ULTRA_LEGACY_STATE_PROBES.includes(relative);
|
|
278
|
+
found[runtime ? 'runtime' : 'semantic'].push(relative);
|
|
279
|
+
if (entry.isSymbolicLink() || !entry.isDirectory()) continue;
|
|
280
|
+
const parts = relative.split('/');
|
|
281
|
+
if (parts.length === 4
|
|
282
|
+
&& parts[0] === '.ultra'
|
|
283
|
+
&& parts[1] === '.runtime'
|
|
284
|
+
&& parts[2] === 'worktrees') {
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
for (const child of fs.readdirSync(candidate)) {
|
|
288
|
+
pending.push(path.join(candidate, child));
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return found;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function runtimeIsIgnored(rootDir) {
|
|
295
|
+
const runtimeEntry = fs.lstatSync(
|
|
296
|
+
path.join(rootDir, '.ultra', '.runtime'),
|
|
297
|
+
{ throwIfNoEntry: false },
|
|
298
|
+
);
|
|
299
|
+
if (runtimeEntry?.isSymbolicLink()) {
|
|
300
|
+
// Git refuses to classify pathspecs beyond a symlink. For a task
|
|
301
|
+
// worktree the link itself is the complete runtime boundary, so proving
|
|
302
|
+
// the exact link ignored is both necessary and sufficient.
|
|
303
|
+
return checkIgnoreState(rootDir, '.ultra/.runtime') === 'ignored';
|
|
304
|
+
}
|
|
305
|
+
const actual = scanManagedArtifacts(rootDir).runtime;
|
|
306
|
+
const probes = [...new Set([...ULTRA_RUNTIME_PROBES, ...actual])];
|
|
307
|
+
const states = checkIgnoreStates(rootDir, probes);
|
|
308
|
+
return probes.every((probe) => states.get(probe) === 'ignored');
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function semanticArtifactsAreTrackable(rootDir) {
|
|
312
|
+
const actual = scanManagedArtifacts(rootDir).semantic;
|
|
313
|
+
const probes = [...new Set([...ULTRA_SEMANTIC_PROBES, ...actual])];
|
|
314
|
+
const states = checkIgnoreStates(rootDir, probes);
|
|
315
|
+
return probes.every((probe) => states.get(probe) === 'trackable');
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function rootRulesPreserveUltraBoundary(rootDir) {
|
|
319
|
+
const file = path.join(rootDir, '.gitignore');
|
|
320
|
+
const stat = fs.lstatSync(file, { throwIfNoEntry: false });
|
|
321
|
+
if (!stat) return true;
|
|
322
|
+
if (stat.isSymbolicLink() || !stat.isFile()) return false;
|
|
323
|
+
const rules = fs.readFileSync(file, 'utf8')
|
|
324
|
+
.split(/\r?\n/)
|
|
325
|
+
.map((line) => line.trim())
|
|
326
|
+
.filter((line) => line && !line.startsWith('#'));
|
|
327
|
+
let lastUnsafe = -1;
|
|
328
|
+
let unignoreDir = -1;
|
|
329
|
+
let unignoreContent = -1;
|
|
330
|
+
let runtimeIgnore = -1;
|
|
331
|
+
const compatibilityIgnores = new Map(
|
|
332
|
+
ULTRA_LEGACY_STATE_IGNORE_LINES.map((rule) => [rule, -1]),
|
|
333
|
+
);
|
|
334
|
+
rules.forEach((rule, index) => {
|
|
335
|
+
const normalized = rule.replace(/^\/+/, '').replace(/\/+$/u, '');
|
|
336
|
+
if (rule === ULTRA_UNIGNORE_DIR_LINE) unignoreDir = index;
|
|
337
|
+
else if (rule === ULTRA_UNIGNORE_CONTENT_LINE) unignoreContent = index;
|
|
338
|
+
else if (normalized === ULTRA_RUNTIME_IGNORE_LINE) runtimeIgnore = index;
|
|
339
|
+
else if (compatibilityIgnores.has(normalized)) compatibilityIgnores.set(normalized, index);
|
|
340
|
+
else if (normalized.includes('.ultra')) lastUnsafe = index;
|
|
78
341
|
});
|
|
342
|
+
if (lastUnsafe === -1) return true;
|
|
343
|
+
return unignoreDir > lastUnsafe
|
|
344
|
+
&& unignoreContent > unignoreDir
|
|
345
|
+
&& runtimeIgnore > unignoreContent
|
|
346
|
+
&& [...compatibilityIgnores.values()].every((index) => index > unignoreContent);
|
|
79
347
|
}
|
|
80
348
|
|
|
81
|
-
function
|
|
82
|
-
return
|
|
349
|
+
function effectiveUltraStorageBoundary(rootDir) {
|
|
350
|
+
return rootRulesPreserveUltraBoundary(rootDir)
|
|
351
|
+
&& runtimeIsIgnored(rootDir)
|
|
352
|
+
&& semanticArtifactsAreTrackable(rootDir);
|
|
83
353
|
}
|
|
84
354
|
|
|
85
|
-
function
|
|
355
|
+
function repositoryLocalRuntimePattern(rootDir, repository) {
|
|
356
|
+
const repositoryRoot = fs.realpathSync(repository.repository_root);
|
|
357
|
+
const projectRoot = fs.realpathSync(rootDir);
|
|
358
|
+
const relative = path.relative(repositoryRoot, projectRoot);
|
|
359
|
+
if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
|
|
360
|
+
throw new GitBootstrapError(
|
|
361
|
+
'GIT_REPOSITORY_SCOPE_INVALID',
|
|
362
|
+
`project root is outside its reported Git repository: ${rootDir}`,
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
const components = relative ? relative.split(path.sep) : [];
|
|
366
|
+
return `/${[...components, '.ultra', '.runtime'].join('/')}`;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function repositoryLocalCompatibilityPatterns(rootDir, repository) {
|
|
370
|
+
const runtimePattern = repositoryLocalRuntimePattern(rootDir, repository);
|
|
371
|
+
const prefix = runtimePattern.slice(0, -'.runtime'.length);
|
|
372
|
+
return ULTRA_LEGACY_STATE_IGNORE_LINES.map((line) => (
|
|
373
|
+
`${prefix}${line.slice('.ultra/'.length)}`
|
|
374
|
+
));
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function ensureLocalRuntimeIgnored(rootDir, repository) {
|
|
378
|
+
const result = runGit(rootDir, ['rev-parse', '--git-path', 'info/exclude']);
|
|
379
|
+
if (result.status !== 0) {
|
|
380
|
+
throw new GitBootstrapError(
|
|
381
|
+
'GITEXCLUDE_UNAVAILABLE',
|
|
382
|
+
`cannot resolve repository-local exclude file: ${(result.stderr || result.stdout).trim()}`,
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
const reported = result.stdout.trim();
|
|
386
|
+
const file = path.isAbsolute(reported) ? reported : path.resolve(rootDir, reported);
|
|
387
|
+
let stat = null;
|
|
388
|
+
try { stat = fs.lstatSync(file); }
|
|
389
|
+
catch (error) {
|
|
390
|
+
if (error.code !== 'ENOENT') throw error;
|
|
391
|
+
}
|
|
392
|
+
if (stat && (stat.isSymbolicLink() || !stat.isFile())) {
|
|
393
|
+
throw new GitBootstrapError(
|
|
394
|
+
'GITEXCLUDE_UNSAFE',
|
|
395
|
+
`refusing to update non-regular repository-local exclude file: ${file}`,
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
const existed = stat !== null;
|
|
399
|
+
const before = existed ? fs.readFileSync(file, 'utf8') : null;
|
|
400
|
+
if (runtimeIsIgnored(rootDir)) {
|
|
401
|
+
return { changed: false, path: file, rollback: { existed, before } };
|
|
402
|
+
}
|
|
403
|
+
const managedPattern = repositoryLocalRuntimePattern(rootDir, repository);
|
|
404
|
+
const compatibilityPatterns = repositoryLocalCompatibilityPatterns(rootDir, repository);
|
|
405
|
+
const preserved = (before || '')
|
|
406
|
+
.split(/\r?\n/)
|
|
407
|
+
.filter((line) => line.trim() !== '# Ultra Builder Pro local runtime')
|
|
408
|
+
.filter((line) => line.trim() !== ULTRA_RUNTIME_IGNORE_LINE)
|
|
409
|
+
.filter((line) => line.trim() !== managedPattern)
|
|
410
|
+
.filter((line) => !compatibilityPatterns.includes(line.trim()))
|
|
411
|
+
.join('\n')
|
|
412
|
+
.replace(/\n+$/u, '');
|
|
413
|
+
const prefix = preserved ? `${preserved}\n` : '';
|
|
414
|
+
const separator = prefix && !prefix.endsWith('\n\n') ? '\n' : '';
|
|
415
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
416
|
+
fs.writeFileSync(
|
|
417
|
+
file,
|
|
418
|
+
`${prefix}${separator}# Ultra Builder Pro local runtime\n`
|
|
419
|
+
+ `${managedPattern}\n${compatibilityPatterns.join('\n')}\n`,
|
|
420
|
+
);
|
|
421
|
+
return { changed: true, path: file, rollback: { existed, before } };
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function rollbackFileMutation(mutation) {
|
|
425
|
+
if (!mutation?.changed) return [];
|
|
426
|
+
try {
|
|
427
|
+
if (mutation.rollback.existed) {
|
|
428
|
+
fs.writeFileSync(mutation.path, mutation.rollback.before);
|
|
429
|
+
} else {
|
|
430
|
+
fs.rmSync(mutation.path, { force: true });
|
|
431
|
+
}
|
|
432
|
+
return [];
|
|
433
|
+
} catch (error) {
|
|
434
|
+
return [`${mutation.path}: ${error.message}`];
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
function ensureUltraRuntimeIgnored(rootDir) {
|
|
86
439
|
const file = path.join(rootDir, '.gitignore');
|
|
87
440
|
let stat = null;
|
|
88
441
|
try { stat = fs.lstatSync(file); }
|
|
@@ -99,23 +452,35 @@ function ensureUltraIgnored(rootDir, { requireSymlinkSafe = false } = {}) {
|
|
|
99
452
|
}
|
|
100
453
|
}
|
|
101
454
|
const before = existed ? fs.readFileSync(file, 'utf8') : null;
|
|
102
|
-
if (
|
|
455
|
+
if (effectiveUltraStorageBoundary(rootDir)) {
|
|
103
456
|
return {
|
|
104
457
|
changed: false,
|
|
105
458
|
path: file,
|
|
106
459
|
rollback: { existed, before },
|
|
107
460
|
};
|
|
108
461
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
462
|
+
const preserved = (before || '')
|
|
463
|
+
.split(/\r?\n/)
|
|
464
|
+
.filter((line) => !LEGACY_BROAD_IGNORE_LINES.has(line.trim()))
|
|
465
|
+
.filter((line) => ![
|
|
466
|
+
ULTRA_RUNTIME_IGNORE_LINE,
|
|
467
|
+
`/${ULTRA_RUNTIME_IGNORE_LINE}`,
|
|
468
|
+
`${ULTRA_RUNTIME_IGNORE_LINE}/`,
|
|
469
|
+
`/${ULTRA_RUNTIME_IGNORE_LINE}/`,
|
|
470
|
+
ULTRA_UNIGNORE_DIR_LINE,
|
|
471
|
+
ULTRA_UNIGNORE_CONTENT_LINE,
|
|
472
|
+
...ULTRA_LEGACY_STATE_IGNORE_LINES,
|
|
473
|
+
].includes(line.trim()))
|
|
474
|
+
.join('\n')
|
|
475
|
+
.replace(/\n+$/u, '');
|
|
476
|
+
const prefix = preserved ? `${preserved}\n` : '';
|
|
117
477
|
const separator = prefix && !prefix.endsWith('\n\n') ? '\n' : '';
|
|
118
|
-
const next = `${prefix}${separator}
|
|
478
|
+
const next = `${prefix}${separator}`
|
|
479
|
+
+ '# Ultra Builder Pro semantic artifacts are trackable; runtime state is local\n'
|
|
480
|
+
+ `${ULTRA_UNIGNORE_DIR_LINE}\n`
|
|
481
|
+
+ `${ULTRA_UNIGNORE_CONTENT_LINE}\n`
|
|
482
|
+
+ `${ULTRA_RUNTIME_IGNORE_LINE}\n`
|
|
483
|
+
+ `${ULTRA_LEGACY_STATE_IGNORE_LINES.join('\n')}\n`;
|
|
119
484
|
fs.writeFileSync(file, next);
|
|
120
485
|
return {
|
|
121
486
|
changed: true,
|
|
@@ -124,18 +489,63 @@ function ensureUltraIgnored(rootDir, { requireSymlinkSafe = false } = {}) {
|
|
|
124
489
|
};
|
|
125
490
|
}
|
|
126
491
|
|
|
127
|
-
function
|
|
128
|
-
|
|
129
|
-
if (result.status === 0) return;
|
|
130
|
-
const detail = result.status === 1
|
|
131
|
-
? 'the effective Git rules re-include .ultra'
|
|
132
|
-
: (result.stderr || result.stdout || 'Git could not evaluate the rule').trim();
|
|
492
|
+
function assertUltraStorageBoundary(rootDir) {
|
|
493
|
+
if (effectiveUltraStorageBoundary(rootDir)) return;
|
|
133
494
|
throw new GitBootstrapError(
|
|
134
495
|
'GITIGNORE_INEFFECTIVE',
|
|
135
|
-
|
|
496
|
+
'Git rules must ignore .ultra/.runtime while keeping semantic .ultra artifacts trackable',
|
|
136
497
|
);
|
|
137
498
|
}
|
|
138
499
|
|
|
500
|
+
function ensureExistingProjectStorageBoundary(rootDir) {
|
|
501
|
+
const repository = inspectGitRepository(rootDir);
|
|
502
|
+
if (!repository.present) {
|
|
503
|
+
return {
|
|
504
|
+
status: 'not_a_repository',
|
|
505
|
+
repository,
|
|
506
|
+
gitignore_changed: false,
|
|
507
|
+
gitignore_path: null,
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
let gitignore;
|
|
511
|
+
let localExclude;
|
|
512
|
+
try {
|
|
513
|
+
if (effectiveUltraStorageBoundary(rootDir)) {
|
|
514
|
+
return {
|
|
515
|
+
status: 'ready',
|
|
516
|
+
repository,
|
|
517
|
+
gitignore_changed: false,
|
|
518
|
+
gitignore_path: null,
|
|
519
|
+
local_exclude_changed: false,
|
|
520
|
+
local_exclude_path: null,
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
if (semanticArtifactsAreTrackable(rootDir)) {
|
|
524
|
+
localExclude = ensureLocalRuntimeIgnored(rootDir, repository);
|
|
525
|
+
if (!effectiveUltraStorageBoundary(rootDir)) {
|
|
526
|
+
rollbackFileMutation(localExclude);
|
|
527
|
+
localExclude = null;
|
|
528
|
+
gitignore = ensureUltraRuntimeIgnored(rootDir);
|
|
529
|
+
}
|
|
530
|
+
} else {
|
|
531
|
+
gitignore = ensureUltraRuntimeIgnored(rootDir);
|
|
532
|
+
}
|
|
533
|
+
assertUltraStorageBoundary(rootDir);
|
|
534
|
+
return {
|
|
535
|
+
status: 'ready',
|
|
536
|
+
repository,
|
|
537
|
+
gitignore_changed: Boolean(gitignore?.changed),
|
|
538
|
+
gitignore_path: gitignore?.path || null,
|
|
539
|
+
local_exclude_changed: Boolean(localExclude?.changed),
|
|
540
|
+
local_exclude_path: localExclude?.path || null,
|
|
541
|
+
};
|
|
542
|
+
} catch (error) {
|
|
543
|
+
rollbackFileMutation(localExclude);
|
|
544
|
+
rollbackGitBootstrap(rootDir, { created_repository: false, gitignore });
|
|
545
|
+
throw error;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
|
|
139
549
|
function rollbackGitBootstrap(rootDir, internal) {
|
|
140
550
|
const errors = [];
|
|
141
551
|
if (!internal) return errors;
|
|
@@ -194,12 +604,8 @@ function bootstrapGit(rootDir, { mode = 'auto' } = {}) {
|
|
|
194
604
|
initializeRepository(rootDir);
|
|
195
605
|
internal.created_repository = true;
|
|
196
606
|
}
|
|
197
|
-
internal.gitignore =
|
|
198
|
-
|
|
199
|
-
// so its ignore rule can be made safe for the session authority symlink.
|
|
200
|
-
requireSymlinkSafe: internal.created_repository,
|
|
201
|
-
});
|
|
202
|
-
assertUltraIgnored(rootDir);
|
|
607
|
+
internal.gitignore = ensureUltraRuntimeIgnored(rootDir);
|
|
608
|
+
assertUltraStorageBoundary(rootDir);
|
|
203
609
|
const after = inspectGitRepository(rootDir);
|
|
204
610
|
if (!after.present) {
|
|
205
611
|
throw new GitBootstrapError(
|
|
@@ -234,7 +640,13 @@ function bootstrapGit(rootDir, { mode = 'auto' } = {}) {
|
|
|
234
640
|
module.exports = {
|
|
235
641
|
GitBootstrapError,
|
|
236
642
|
GIT_MODES,
|
|
643
|
+
ULTRA_GIT_ARTIFACT_CLASSES,
|
|
644
|
+
ULTRA_RUNTIME_PROBES,
|
|
645
|
+
ULTRA_SEMANTIC_PROBES,
|
|
237
646
|
bootstrapGit,
|
|
647
|
+
assertUltraStorageBoundary,
|
|
648
|
+
effectiveUltraStorageBoundary,
|
|
649
|
+
ensureExistingProjectStorageBoundary,
|
|
238
650
|
inspectGitRepository,
|
|
239
651
|
rollbackGitBootstrap,
|
|
240
652
|
};
|