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