@sublang/slc 0.1.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/LICENSE +201 -0
- package/README.md +192 -0
- package/dist/app.d.ts +85 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +233 -0
- package/dist/app.js.map +1 -0
- package/dist/artifacts.d.ts +61 -0
- package/dist/artifacts.d.ts.map +1 -0
- package/dist/artifacts.js +97 -0
- package/dist/artifacts.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +26 -0
- package/dist/cli.js.map +1 -0
- package/dist/cligent-agent.d.ts +11 -0
- package/dist/cligent-agent.d.ts.map +1 -0
- package/dist/cligent-agent.js +66 -0
- package/dist/cligent-agent.js.map +1 -0
- package/dist/compiled-executor.d.ts +42 -0
- package/dist/compiled-executor.d.ts.map +1 -0
- package/dist/compiled-executor.js +433 -0
- package/dist/compiled-executor.js.map +1 -0
- package/dist/config-file.d.ts +52 -0
- package/dist/config-file.d.ts.map +1 -0
- package/dist/config-file.js +159 -0
- package/dist/config-file.js.map +1 -0
- package/dist/config.d.ts +82 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +161 -0
- package/dist/config.js.map +1 -0
- package/dist/entry-module.d.ts +22 -0
- package/dist/entry-module.d.ts.map +1 -0
- package/dist/entry-module.js +216 -0
- package/dist/entry-module.js.map +1 -0
- package/dist/execution.d.ts +71 -0
- package/dist/execution.d.ts.map +1 -0
- package/dist/execution.js +207 -0
- package/dist/execution.js.map +1 -0
- package/dist/file-capability.d.ts +46 -0
- package/dist/file-capability.d.ts.map +1 -0
- package/dist/file-capability.js +234 -0
- package/dist/file-capability.js.map +1 -0
- package/dist/file-grants.d.ts +79 -0
- package/dist/file-grants.d.ts.map +1 -0
- package/dist/file-grants.js +133 -0
- package/dist/file-grants.js.map +1 -0
- package/dist/hash.d.ts +14 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +34 -0
- package/dist/hash.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/interpreter.d.ts +48 -0
- package/dist/interpreter.d.ts.map +1 -0
- package/dist/interpreter.js +118 -0
- package/dist/interpreter.js.map +1 -0
- package/dist/invocation.d.ts +64 -0
- package/dist/invocation.d.ts.map +1 -0
- package/dist/invocation.js +148 -0
- package/dist/invocation.js.map +1 -0
- package/dist/link.d.ts +63 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +172 -0
- package/dist/link.js.map +1 -0
- package/dist/markdown.d.ts +12 -0
- package/dist/markdown.d.ts.map +1 -0
- package/dist/markdown.js +63 -0
- package/dist/markdown.js.map +1 -0
- package/dist/normalize.md +68 -0
- package/dist/phase-runner.d.ts +64 -0
- package/dist/phase-runner.d.ts.map +1 -0
- package/dist/phase-runner.js +322 -0
- package/dist/phase-runner.js.map +1 -0
- package/dist/phase.d.ts +62 -0
- package/dist/phase.d.ts.map +1 -0
- package/dist/phase.js +111 -0
- package/dist/phase.js.map +1 -0
- package/dist/pin-closure.d.ts +19 -0
- package/dist/pin-closure.d.ts.map +1 -0
- package/dist/pin-closure.js +110 -0
- package/dist/pin-closure.js.map +1 -0
- package/dist/pin-currency.d.ts +55 -0
- package/dist/pin-currency.d.ts.map +1 -0
- package/dist/pin-currency.js +435 -0
- package/dist/pin-currency.js.map +1 -0
- package/dist/pin-generate.d.ts +46 -0
- package/dist/pin-generate.d.ts.map +1 -0
- package/dist/pin-generate.js +131 -0
- package/dist/pin-generate.js.map +1 -0
- package/dist/pin-paths.d.ts +11 -0
- package/dist/pin-paths.d.ts.map +1 -0
- package/dist/pin-paths.js +108 -0
- package/dist/pin-paths.js.map +1 -0
- package/dist/pins.d.ts +84 -0
- package/dist/pins.d.ts.map +1 -0
- package/dist/pins.js +265 -0
- package/dist/pins.js.map +1 -0
- package/dist/pipeline.d.ts +61 -0
- package/dist/pipeline.d.ts.map +1 -0
- package/dist/pipeline.js +147 -0
- package/dist/pipeline.js.map +1 -0
- package/dist/playbook-contract.d.ts +194 -0
- package/dist/playbook-contract.d.ts.map +1 -0
- package/dist/playbook-contract.js +180 -0
- package/dist/playbook-contract.js.map +1 -0
- package/dist/playbook-ports.d.ts +53 -0
- package/dist/playbook-ports.d.ts.map +1 -0
- package/dist/playbook-ports.js +217 -0
- package/dist/playbook-ports.js.map +1 -0
- package/dist/resolver.d.ts +68 -0
- package/dist/resolver.d.ts.map +1 -0
- package/dist/resolver.js +133 -0
- package/dist/resolver.js.map +1 -0
- package/dist/runner.d.ts +45 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +506 -0
- package/dist/runner.js.map +1 -0
- package/dist/runtime-package.d.ts +7 -0
- package/dist/runtime-package.d.ts.map +1 -0
- package/dist/runtime-package.js +132 -0
- package/dist/runtime-package.js.map +1 -0
- package/dist/slc.config.template.yaml +5 -0
- package/dist/verify-coverage.d.ts +99 -0
- package/dist/verify-coverage.d.ts.map +1 -0
- package/dist/verify-coverage.js +1949 -0
- package/dist/verify-coverage.js.map +1 -0
- package/dist/verify-support.d.ts +10 -0
- package/dist/verify-support.d.ts.map +1 -0
- package/dist/verify-support.js +52 -0
- package/dist/verify-support.js.map +1 -0
- package/dist/verify.d.ts +393 -0
- package/dist/verify.d.ts.map +1 -0
- package/dist/verify.js +1790 -0
- package/dist/verify.js.map +1 -0
- package/package.json +76 -0
package/dist/runner.js
ADDED
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
|
|
3
|
+
/**
|
|
4
|
+
* End-to-end `slc` runner: composes the generic mechanics (DR-001, DR-002) with
|
|
5
|
+
* the execution boundary (DR-003) and an injected {@link PhaseExecutor}
|
|
6
|
+
* (interpreted per DR-004). It parses an invocation, resolves and loads the
|
|
7
|
+
* pipeline, computes artifact paths, then runs each phase through `runPhase`,
|
|
8
|
+
* stopping at the first failure with its report. The resolver and executor are
|
|
9
|
+
* injected so a host wires the real pipeline resolution and Cligent agent while
|
|
10
|
+
* tests supply fakes. See specs/dev/pipeline.md and specs/dev/phase-execution.md.
|
|
11
|
+
*/
|
|
12
|
+
import { mkdir } from 'node:fs/promises';
|
|
13
|
+
import { dirname, join } from 'node:path';
|
|
14
|
+
import { fileURLToPath } from 'node:url';
|
|
15
|
+
import { artifactDir, planArtifacts, parseSource } from './artifacts.js';
|
|
16
|
+
import { emitEntryModule } from './entry-module.js';
|
|
17
|
+
import { formatFailureReport, runPhase, } from './execution.js';
|
|
18
|
+
import { parseInvocation } from './invocation.js';
|
|
19
|
+
import { linkedArtifactPath, loadLinkFile } from './link.js';
|
|
20
|
+
import { evaluatePin, evaluatePinFile } from './pin-currency.js';
|
|
21
|
+
import { PinError, loadPinFile } from './pins.js';
|
|
22
|
+
import { loadPipeline, resolvePipeline, } from './pipeline.js';
|
|
23
|
+
import { defaultPlaybookLinkTarget, isReservedPipeline } from './resolver.js';
|
|
24
|
+
import { emitFsmCoverageTest, emitFsmIntrospectionTest, emitGearsFsmConformanceTest, emitPromptContractTest, } from './verify.js';
|
|
25
|
+
import { VERIFIER_SUPPORT_MODULE, emitVerifierSupport, } from './verify-support.js';
|
|
26
|
+
/**
|
|
27
|
+
* Parses argv and runs the requested pipeline, phase, or link end-to-end.
|
|
28
|
+
* Never rejects: malformed invocations, refusals, and phase failures all return
|
|
29
|
+
* `{ ok: false }` with diagnostics.
|
|
30
|
+
*/
|
|
31
|
+
export async function runSlc(argv, deps) {
|
|
32
|
+
let invocation;
|
|
33
|
+
try {
|
|
34
|
+
invocation = parseInvocation(argv);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
return failure(messageOf(error));
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
switch (invocation.kind) {
|
|
41
|
+
case 'full':
|
|
42
|
+
// The reserved playbook pipeline supplies a default link target
|
|
43
|
+
// (SELFHOST-13): a bare full run becomes a full-link against the
|
|
44
|
+
// installed @sublang/playbook runtime contract module (DR-014).
|
|
45
|
+
if (invocation.pipeline === 'playbook') {
|
|
46
|
+
return await runFullLink({
|
|
47
|
+
...invocation,
|
|
48
|
+
kind: 'full-link',
|
|
49
|
+
linkTarget: defaultPlaybookLinkTarget(),
|
|
50
|
+
options: [],
|
|
51
|
+
}, deps);
|
|
52
|
+
}
|
|
53
|
+
return await runFull(invocation, deps);
|
|
54
|
+
case 'phase':
|
|
55
|
+
return await runSinglePhase(invocation, deps);
|
|
56
|
+
case 'link':
|
|
57
|
+
return await runDirectLink(invocation, deps);
|
|
58
|
+
case 'full-link':
|
|
59
|
+
return await runFullLink(invocation, deps);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
return failure(messageOf(error));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async function runFull(invocation, deps) {
|
|
67
|
+
const pipeline = await loadPipeline(await resolvePipeline(invocation.pipeline, deps.resolver));
|
|
68
|
+
const entry = pipeline.phases[0];
|
|
69
|
+
const { basename, raw } = parseSource({
|
|
70
|
+
path: invocation.source,
|
|
71
|
+
sourceFormat: entry.source.format,
|
|
72
|
+
ext: entry.source.ext,
|
|
73
|
+
entry: true,
|
|
74
|
+
});
|
|
75
|
+
const artDir = artifactDir(runCwd(deps), basename, invocation.pipeline);
|
|
76
|
+
await mkdir(artDir, { recursive: true });
|
|
77
|
+
const plan = planArtifacts({
|
|
78
|
+
phases: pipeline.phases,
|
|
79
|
+
basename,
|
|
80
|
+
artDir,
|
|
81
|
+
output: invocation.output ?? undefined,
|
|
82
|
+
});
|
|
83
|
+
const steps = buildCompileSteps({
|
|
84
|
+
pipeline,
|
|
85
|
+
plan,
|
|
86
|
+
source: invocation.source,
|
|
87
|
+
artDir,
|
|
88
|
+
basename,
|
|
89
|
+
optimize: !invocation.noOptimize,
|
|
90
|
+
normalize: invocation.normalize || raw,
|
|
91
|
+
});
|
|
92
|
+
const result = await executeSteps(steps, pipeline, deps);
|
|
93
|
+
return emitVerification(result, {
|
|
94
|
+
pipeline: invocation.pipeline,
|
|
95
|
+
plan,
|
|
96
|
+
artDir,
|
|
97
|
+
basename,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
async function runSinglePhase(invocation, deps) {
|
|
101
|
+
const pipeline = await loadPipeline(await resolvePipeline(invocation.pipeline, deps.resolver));
|
|
102
|
+
const phase = [...pipeline.phases, ...pipeline.passes].find((candidate) => candidate.name === invocation.phase);
|
|
103
|
+
if (phase === undefined) {
|
|
104
|
+
return failure(`phase "${invocation.phase}" is not part of pipeline "${invocation.pipeline}"`);
|
|
105
|
+
}
|
|
106
|
+
const { basename, raw } = parseSource({
|
|
107
|
+
path: invocation.source,
|
|
108
|
+
sourceFormat: phase.source.format,
|
|
109
|
+
ext: phase.source.ext,
|
|
110
|
+
entry: pipeline.phases[0] === phase,
|
|
111
|
+
});
|
|
112
|
+
if (raw) {
|
|
113
|
+
// A named phase cannot normalize (PIPE-37), so a raw entry source has no
|
|
114
|
+
// path into the phase's declared source format here.
|
|
115
|
+
return failure(`source "${invocation.source}" is a raw input; run the full pipeline to normalize it`);
|
|
116
|
+
}
|
|
117
|
+
const artDir = artifactDir(runCwd(deps), basename, invocation.pipeline);
|
|
118
|
+
await mkdir(artDir, { recursive: true });
|
|
119
|
+
if (phase.pass) {
|
|
120
|
+
// A standalone pass run cannot overwrite its own source: it writes the
|
|
121
|
+
// `.opt` sibling unless `-o` relocates it (DR-013).
|
|
122
|
+
const target = invocation.output ??
|
|
123
|
+
join(artDir, `${basename}.${phase.target.format}.opt${phase.target.ext}`);
|
|
124
|
+
const step = compileStep(pipeline, phase, invocation.source, target);
|
|
125
|
+
return executeSteps([step], pipeline, deps);
|
|
126
|
+
}
|
|
127
|
+
// Plan over the whole chain so the named phase keeps its pipeline role: a
|
|
128
|
+
// non-terminal phase writes its canonical intermediate and ignores `-o`
|
|
129
|
+
// (DR-001 -- artifact location depends on role, not invocation mode).
|
|
130
|
+
const plan = planArtifacts({
|
|
131
|
+
phases: pipeline.phases,
|
|
132
|
+
basename,
|
|
133
|
+
artDir,
|
|
134
|
+
output: invocation.output ?? undefined,
|
|
135
|
+
});
|
|
136
|
+
const artifact = plan[pipeline.phases.indexOf(phase)];
|
|
137
|
+
const step = compileStep(pipeline, phase, invocation.source, artifact.path);
|
|
138
|
+
return executeSteps([step], pipeline, deps);
|
|
139
|
+
}
|
|
140
|
+
async function runDirectLink(invocation, deps) {
|
|
141
|
+
const pipeline = await loadPipeline(await resolvePipeline(invocation.pipeline, deps.resolver));
|
|
142
|
+
const link = await requireLink(pipeline, invocation.pipeline);
|
|
143
|
+
const linked = linkedArtifactPath({
|
|
144
|
+
kind: 'link',
|
|
145
|
+
pipeline: invocation.pipeline,
|
|
146
|
+
objects: invocation.objects,
|
|
147
|
+
source: link.source,
|
|
148
|
+
linked: link.target,
|
|
149
|
+
output: invocation.output,
|
|
150
|
+
cwd: runCwd(deps),
|
|
151
|
+
});
|
|
152
|
+
await mkdir(dirname(linked), { recursive: true });
|
|
153
|
+
const step = {
|
|
154
|
+
request: {
|
|
155
|
+
kind: 'link',
|
|
156
|
+
definitionPath: pipeline.linkFile,
|
|
157
|
+
objects: invocation.objects,
|
|
158
|
+
linkTarget: invocation.linkTarget,
|
|
159
|
+
options: invocation.options,
|
|
160
|
+
linked,
|
|
161
|
+
},
|
|
162
|
+
phase: 'link',
|
|
163
|
+
targetExt: link.target.ext,
|
|
164
|
+
};
|
|
165
|
+
return executeSteps([step], pipeline, deps);
|
|
166
|
+
}
|
|
167
|
+
async function runFullLink(invocation, deps) {
|
|
168
|
+
const pipeline = await loadPipeline(await resolvePipeline(invocation.pipeline, deps.resolver));
|
|
169
|
+
const link = await requireLink(pipeline, invocation.pipeline);
|
|
170
|
+
const entry = pipeline.phases[0];
|
|
171
|
+
const { basename, raw } = parseSource({
|
|
172
|
+
path: invocation.source,
|
|
173
|
+
sourceFormat: entry.source.format,
|
|
174
|
+
ext: entry.source.ext,
|
|
175
|
+
entry: true,
|
|
176
|
+
});
|
|
177
|
+
const normalize = invocation.normalize || raw;
|
|
178
|
+
const artDir = artifactDir(runCwd(deps), basename, invocation.pipeline);
|
|
179
|
+
await mkdir(artDir, { recursive: true });
|
|
180
|
+
// Compile chain: the exit artifact becomes the object artifact (PIPE-15).
|
|
181
|
+
const plan = planArtifacts({ phases: pipeline.phases, basename, artDir });
|
|
182
|
+
const compileSteps = buildCompileSteps({
|
|
183
|
+
pipeline,
|
|
184
|
+
plan,
|
|
185
|
+
source: invocation.source,
|
|
186
|
+
artDir,
|
|
187
|
+
basename,
|
|
188
|
+
optimize: !invocation.noOptimize,
|
|
189
|
+
normalize,
|
|
190
|
+
});
|
|
191
|
+
const linked = linkedArtifactPath({
|
|
192
|
+
kind: 'full',
|
|
193
|
+
artDir,
|
|
194
|
+
basename,
|
|
195
|
+
linked: link.target,
|
|
196
|
+
output: invocation.output,
|
|
197
|
+
});
|
|
198
|
+
const linkStep = {
|
|
199
|
+
request: {
|
|
200
|
+
kind: 'link',
|
|
201
|
+
definitionPath: pipeline.linkFile,
|
|
202
|
+
objects: [plan[plan.length - 1].path],
|
|
203
|
+
linkTarget: invocation.linkTarget,
|
|
204
|
+
options: invocation.options,
|
|
205
|
+
linked,
|
|
206
|
+
},
|
|
207
|
+
phase: 'link',
|
|
208
|
+
targetExt: link.target.ext,
|
|
209
|
+
};
|
|
210
|
+
const result = await executeSteps([...compileSteps, linkStep], pipeline, deps);
|
|
211
|
+
const verified = await emitVerification(result, {
|
|
212
|
+
pipeline: invocation.pipeline,
|
|
213
|
+
plan,
|
|
214
|
+
artDir,
|
|
215
|
+
basename,
|
|
216
|
+
});
|
|
217
|
+
// Entry-module emission (DR-014, SELFHOST-15): only the playbook pipeline,
|
|
218
|
+
// only with the linked artifact at its canonical path.
|
|
219
|
+
if (verified.ok &&
|
|
220
|
+
invocation.pipeline === 'playbook' &&
|
|
221
|
+
invocation.output === null) {
|
|
222
|
+
const gearsPlan = plan.find((artifact) => artifact.phase.target.format === 'gears');
|
|
223
|
+
if (gearsPlan !== undefined) {
|
|
224
|
+
const textPath = normalize
|
|
225
|
+
? join(artDir, `${basename}.${entry.source.format}${entry.source.ext}`)
|
|
226
|
+
: invocation.source;
|
|
227
|
+
const entryPath = await emitEntryModule({
|
|
228
|
+
cwd: runCwd(deps),
|
|
229
|
+
basename,
|
|
230
|
+
pipeline: invocation.pipeline,
|
|
231
|
+
gearsPath: gearsPlan.path,
|
|
232
|
+
textPath,
|
|
233
|
+
});
|
|
234
|
+
return { ...verified, outputs: [...verified.outputs, entryPath] };
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return verified;
|
|
238
|
+
}
|
|
239
|
+
/** The invocation working directory anchoring artifact placement (DR-014). */
|
|
240
|
+
function runCwd(deps) {
|
|
241
|
+
return deps.cwd ?? process.cwd();
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* After a reserved-pipeline full run produces a `gears` intermediate and an `fsm`
|
|
245
|
+
* object at their canonical `<basename>.playbook/` locations, emits the
|
|
246
|
+
* artifact-local checker support plus compilation-correctness tests beside
|
|
247
|
+
* them as `slc` output, appending their paths to the outputs (VERIFY-2,
|
|
248
|
+
* VERIFY-4;
|
|
249
|
+
* [DR-009](../decisions/009-slc-playbook-pipeline-compilation.md)).
|
|
250
|
+
* Non-reserved pipelines, runs without a gears+fsm pair, and runs whose `fsm` was
|
|
251
|
+
* relocated out of that directory by `-o` (PIPE-8) are left unchanged, so an
|
|
252
|
+
* emitted test never imports a file that was not written beside it. A test whose
|
|
253
|
+
* emission needs the produced `fsm` imported (the pinned introspection) degrades
|
|
254
|
+
* to a diagnostic when the artifact cannot be loaded, leaving the run outcome
|
|
255
|
+
* unchanged — the conformance test still fails at test time on a broken module.
|
|
256
|
+
*/
|
|
257
|
+
async function emitVerification(result, ctx) {
|
|
258
|
+
if (!result.ok || !isReservedPipeline(ctx.pipeline))
|
|
259
|
+
return result;
|
|
260
|
+
const fsm = ctx.plan.find((artifact) => artifact.phase.target.format === 'fsm');
|
|
261
|
+
const hasGears = ctx.plan.some((artifact) => artifact.phase.target.format === 'gears');
|
|
262
|
+
if (fsm === undefined || !hasGears)
|
|
263
|
+
return result;
|
|
264
|
+
// The emitted tests import the canonical sibling FSM through the NodeNext
|
|
265
|
+
// `./<basename>.fsm.js` specifier; skip when `-o` relocated the physical FSM
|
|
266
|
+
// elsewhere (PIPE-8), so that edge never targets a missing sibling artifact.
|
|
267
|
+
const canonicalFsm = join(ctx.artDir, `${ctx.basename}.fsm${fsm.phase.target.ext}`);
|
|
268
|
+
if (fsm.path !== canonicalFsm)
|
|
269
|
+
return result;
|
|
270
|
+
const outputs = [...result.outputs];
|
|
271
|
+
const diagnostics = [...result.diagnostics];
|
|
272
|
+
outputs.push(...(await emitVerifierSupport(ctx.artDir)));
|
|
273
|
+
outputs.push(await emitGearsFsmConformanceTest({
|
|
274
|
+
artifactDir: ctx.artDir,
|
|
275
|
+
basename: ctx.basename,
|
|
276
|
+
verifyModule: VERIFIER_SUPPORT_MODULE,
|
|
277
|
+
}));
|
|
278
|
+
try {
|
|
279
|
+
outputs.push(await emitFsmIntrospectionTest({
|
|
280
|
+
artifactDir: ctx.artDir,
|
|
281
|
+
basename: ctx.basename,
|
|
282
|
+
verifyModule: VERIFIER_SUPPORT_MODULE,
|
|
283
|
+
}));
|
|
284
|
+
}
|
|
285
|
+
catch (error) {
|
|
286
|
+
diagnostics.push(`verification: introspection test not emitted: ${messageOf(error)}`);
|
|
287
|
+
}
|
|
288
|
+
try {
|
|
289
|
+
const promptContract = await emitPromptContractTest({
|
|
290
|
+
artifactDir: ctx.artDir,
|
|
291
|
+
basename: ctx.basename,
|
|
292
|
+
verifyModule: VERIFIER_SUPPORT_MODULE,
|
|
293
|
+
});
|
|
294
|
+
outputs.push(promptContract.path);
|
|
295
|
+
diagnostics.push(...promptContract.diagnostics.map((diagnostic) => `verification: ${diagnostic}`));
|
|
296
|
+
}
|
|
297
|
+
catch (error) {
|
|
298
|
+
diagnostics.push(`verification: prompt-contract test not emitted: ${messageOf(error)}`);
|
|
299
|
+
}
|
|
300
|
+
try {
|
|
301
|
+
const coverage = await emitFsmCoverageTest({
|
|
302
|
+
artifactDir: ctx.artDir,
|
|
303
|
+
basename: ctx.basename,
|
|
304
|
+
verifyModule: VERIFIER_SUPPORT_MODULE,
|
|
305
|
+
});
|
|
306
|
+
outputs.push(coverage.path);
|
|
307
|
+
diagnostics.push(...coverage.diagnostics.map((diagnostic) => `verification: ${diagnostic}`));
|
|
308
|
+
}
|
|
309
|
+
catch (error) {
|
|
310
|
+
diagnostics.push(`verification: coverage test not emitted: ${messageOf(error)}`);
|
|
311
|
+
}
|
|
312
|
+
return { ...result, outputs, diagnostics };
|
|
313
|
+
}
|
|
314
|
+
/** Resolves the built-in pipeline-agnostic normalize definition (DR-013). */
|
|
315
|
+
export function normalizeDefinitionPath() {
|
|
316
|
+
return fileURLToPath(new URL('./normalize.md', import.meta.url));
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Builds the ordered compile steps for a full run: an optional generic
|
|
320
|
+
* normalize step ahead of the entry phase (`--normalize`), each chain phase,
|
|
321
|
+
* and — with `-O` — the pipeline's pass phases spliced in after the phase
|
|
322
|
+
* producing their format (DR-013). With passes active on a format, the
|
|
323
|
+
* producing phase writes the `.raw` intermediate and the final pass lands on
|
|
324
|
+
* the planned path, so downstream phases and verification see the canonical
|
|
325
|
+
* artifact regardless of optimization.
|
|
326
|
+
*/
|
|
327
|
+
function buildCompileSteps(opts) {
|
|
328
|
+
const { pipeline, plan, artDir, basename } = opts;
|
|
329
|
+
const steps = [];
|
|
330
|
+
let previous = opts.source;
|
|
331
|
+
if (opts.normalize) {
|
|
332
|
+
const entry = pipeline.phases[0];
|
|
333
|
+
const normalized = join(artDir, `${basename}.${entry.source.format}${entry.source.ext}`);
|
|
334
|
+
steps.push({
|
|
335
|
+
request: {
|
|
336
|
+
kind: 'compile',
|
|
337
|
+
definitionPath: normalizeDefinitionPath(),
|
|
338
|
+
source: previous,
|
|
339
|
+
target: normalized,
|
|
340
|
+
references: [phaseDefinition(pipeline, entry.name)],
|
|
341
|
+
},
|
|
342
|
+
phase: 'normalize',
|
|
343
|
+
targetExt: entry.source.ext,
|
|
344
|
+
});
|
|
345
|
+
previous = normalized;
|
|
346
|
+
}
|
|
347
|
+
for (const artifact of plan) {
|
|
348
|
+
const phase = artifact.phase;
|
|
349
|
+
const passes = opts.optimize
|
|
350
|
+
? pipeline.passes.filter((pass) => pass.source.format === phase.target.format)
|
|
351
|
+
: [];
|
|
352
|
+
if (passes.length === 0) {
|
|
353
|
+
steps.push(compileStep(pipeline, phase, previous, artifact.path));
|
|
354
|
+
previous = artifact.path;
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
const raw = join(artDir, `${basename}.${phase.target.format}.raw${phase.target.ext}`);
|
|
358
|
+
steps.push(compileStep(pipeline, phase, previous, raw));
|
|
359
|
+
previous = raw;
|
|
360
|
+
passes.forEach((pass, index) => {
|
|
361
|
+
const target = index === passes.length - 1
|
|
362
|
+
? artifact.path
|
|
363
|
+
: join(artDir, `${basename}.${phase.target.format}.opt${index + 1}${phase.target.ext}`);
|
|
364
|
+
steps.push(compileStep(pipeline, pass, previous, target));
|
|
365
|
+
previous = target;
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
return steps;
|
|
369
|
+
}
|
|
370
|
+
function compileStep(pipeline, phase, source, target) {
|
|
371
|
+
return {
|
|
372
|
+
request: {
|
|
373
|
+
kind: 'compile',
|
|
374
|
+
definitionPath: phaseDefinition(pipeline, phase.name),
|
|
375
|
+
source,
|
|
376
|
+
target,
|
|
377
|
+
},
|
|
378
|
+
phase: phase.name,
|
|
379
|
+
targetExt: phase.target.ext,
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Runs steps in order, selecting interpreted or compiled execution per phase from
|
|
384
|
+
* the pin index and stopping at the first failure with its report (PHEXEC-9,
|
|
385
|
+
* PHEXEC-27). An unparseable pin file fails the run closed before any phase.
|
|
386
|
+
*/
|
|
387
|
+
async function executeSteps(steps, pipeline, deps) {
|
|
388
|
+
let pinFile;
|
|
389
|
+
try {
|
|
390
|
+
pinFile = (await loadPinFile(pipeline.dir)).file;
|
|
391
|
+
}
|
|
392
|
+
catch (error) {
|
|
393
|
+
if (error instanceof PinError) {
|
|
394
|
+
return { ok: false, outputs: [], diagnostics: [error.message] };
|
|
395
|
+
}
|
|
396
|
+
throw error;
|
|
397
|
+
}
|
|
398
|
+
if (pinFile !== undefined) {
|
|
399
|
+
const verdicts = await evaluatePinFile(pipeline.dir, pinFile);
|
|
400
|
+
const malformed = Object.entries(verdicts).find(([, verdict]) => verdict.status === 'malformed');
|
|
401
|
+
if (malformed !== undefined) {
|
|
402
|
+
return {
|
|
403
|
+
ok: false,
|
|
404
|
+
outputs: [],
|
|
405
|
+
diagnostics: [
|
|
406
|
+
`pin is malformed: ${malformed[1].status === 'malformed'
|
|
407
|
+
? malformed[1].reason
|
|
408
|
+
: 'invalid pin index'}`,
|
|
409
|
+
],
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
const definitions = chainDefinitions(pipeline);
|
|
414
|
+
const outputs = [];
|
|
415
|
+
const diagnostics = [];
|
|
416
|
+
for (const step of steps) {
|
|
417
|
+
const target = step.request.kind === 'compile'
|
|
418
|
+
? step.request.target
|
|
419
|
+
: step.request.linked;
|
|
420
|
+
const selection = await selectExecutor(step.phase, pipeline.dir, pinFile, deps);
|
|
421
|
+
if (selection.kind === 'fail') {
|
|
422
|
+
diagnostics.push(formatFailureReport({
|
|
423
|
+
phase: step.phase,
|
|
424
|
+
target,
|
|
425
|
+
reasons: selection.reasons,
|
|
426
|
+
}));
|
|
427
|
+
return { ok: false, outputs, diagnostics };
|
|
428
|
+
}
|
|
429
|
+
const result = await runPhase({
|
|
430
|
+
request: step.request,
|
|
431
|
+
phase: step.phase,
|
|
432
|
+
targetExt: step.targetExt,
|
|
433
|
+
executor: selection.executor,
|
|
434
|
+
definitions,
|
|
435
|
+
revalidate: () => revalidateChain(pipeline.dir),
|
|
436
|
+
signal: deps.signal,
|
|
437
|
+
});
|
|
438
|
+
if (!result.ok) {
|
|
439
|
+
diagnostics.push(formatFailureReport(result.report));
|
|
440
|
+
return { ok: false, outputs, diagnostics };
|
|
441
|
+
}
|
|
442
|
+
diagnostics.push(...result.diagnostics);
|
|
443
|
+
outputs.push(target);
|
|
444
|
+
}
|
|
445
|
+
return { ok: true, outputs, diagnostics };
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Selects a phase's execution strategy from the pin index (PHEXEC-27; DR-005,
|
|
449
|
+
* DR-007): a phase with no pin interprets, a current pin runs its compiled
|
|
450
|
+
* artifact, and a stale or malformed pin fails closed and is never silently
|
|
451
|
+
* interpreted.
|
|
452
|
+
*/
|
|
453
|
+
async function selectExecutor(phase, pipelineDir, pinFile, deps) {
|
|
454
|
+
const record = pinFile?.pins[phase];
|
|
455
|
+
if (pinFile === undefined || record === undefined) {
|
|
456
|
+
return { kind: 'run', executor: deps.executor };
|
|
457
|
+
}
|
|
458
|
+
const verdict = await evaluatePin(pipelineDir, pinFile, phase, record);
|
|
459
|
+
if (verdict.status === 'current') {
|
|
460
|
+
if (deps.compiled === undefined) {
|
|
461
|
+
return {
|
|
462
|
+
kind: 'fail',
|
|
463
|
+
reasons: [
|
|
464
|
+
`phase "${phase}" is pinned to a compiled artifact, but this host has no compiled executor configured`,
|
|
465
|
+
],
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
return {
|
|
469
|
+
kind: 'run',
|
|
470
|
+
executor: deps.compiled({ phase, pipelineDir, record }),
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
return {
|
|
474
|
+
kind: 'fail',
|
|
475
|
+
reasons: [`pin is ${verdict.status}: ${verdict.reason}`],
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
function phaseDefinition(pipeline, name) {
|
|
479
|
+
return join(pipeline.dir, `${name}.md`);
|
|
480
|
+
}
|
|
481
|
+
function chainDefinitions(pipeline) {
|
|
482
|
+
const definitions = [...pipeline.phases, ...pipeline.passes].map((phase) => phaseDefinition(pipeline, phase.name));
|
|
483
|
+
if (pipeline.linkFile !== null) {
|
|
484
|
+
definitions.push(pipeline.linkFile);
|
|
485
|
+
}
|
|
486
|
+
return definitions;
|
|
487
|
+
}
|
|
488
|
+
async function requireLink(pipeline, reference) {
|
|
489
|
+
if (pipeline.linkFile === null) {
|
|
490
|
+
throw new Error(`pipeline "${reference}" has no link phase`);
|
|
491
|
+
}
|
|
492
|
+
// `loadLinkFile` relaxes the ## Link Targets requirement intrinsically for
|
|
493
|
+
// Playbook's `playbook` linked format (DR-002, DR-009, PIPE-11), so the
|
|
494
|
+
// requirement does not depend on how the pipeline reference resolved.
|
|
495
|
+
return loadLinkFile(pipeline.linkFile);
|
|
496
|
+
}
|
|
497
|
+
async function revalidateChain(dir) {
|
|
498
|
+
await loadPipeline(dir);
|
|
499
|
+
}
|
|
500
|
+
function failure(message) {
|
|
501
|
+
return { ok: false, outputs: [], diagnostics: [message] };
|
|
502
|
+
}
|
|
503
|
+
function messageOf(error) {
|
|
504
|
+
return error instanceof Error ? error.message : String(error);
|
|
505
|
+
}
|
|
506
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,0EAA0E;AAE1E;;;;;;;;GAQG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE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AI,CAAC,CACtC,CAAC;IACF,IAAI,QAAQ,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;QAC/B,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACtC,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,KAAK,UAAU,WAAW,CACxB,QAAkB,EAClB,SAAiB;IAEjB,IAAI,QAAQ,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,aAAa,SAAS,qBAAqB,CAAC,CAAC;IAC/D,CAAC;IACD,2EAA2E;IAC3E,wEAAwE;IACxE,sEAAsE;IACtE,OAAO,YAAY,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACzC,CAAC;AAED,KAAK,UAAU,eAAe,CAAC,GAAW;IACxC,MAAM,YAAY,CAAC,GAAG,CAAC,CAAC;AAC1B,CAAC;AAED,SAAS,OAAO,CAAC,OAAe;IAC9B,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;AAC5D,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface ResolvedRuntimePackage {
|
|
2
|
+
root: string;
|
|
3
|
+
version: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function resolveRuntimePackage(fromFile: string, specifier: string): ResolvedRuntimePackage;
|
|
6
|
+
export declare function isBarePackageSpecifier(specifier: string): boolean;
|
|
7
|
+
//# sourceMappingURL=runtime-package.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-package.d.ts","sourceRoot":"","sources":["../src/runtime-package.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,sBAAsB,CAyExB;AA4CD,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAOjE"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
|
|
3
|
+
/**
|
|
4
|
+
* Resolve a bare package import from the same location as a compiled artifact.
|
|
5
|
+
* The returned root preserves the lexical `node_modules` path (including a root
|
|
6
|
+
* symlink) so pin hashing binds the package Node will actually select.
|
|
7
|
+
*/
|
|
8
|
+
import { lstatSync, readFileSync, realpathSync } from 'node:fs';
|
|
9
|
+
import { createRequire, isBuiltin } from 'node:module';
|
|
10
|
+
import { isAbsolute, join, relative, sep } from 'node:path';
|
|
11
|
+
export function resolveRuntimePackage(fromFile, specifier) {
|
|
12
|
+
const packageName = packageNameFromSpecifier(specifier);
|
|
13
|
+
const requireFromArtifact = createRequire(fromFile);
|
|
14
|
+
// Confirm that Node can load this exact specifier. Package search paths alone
|
|
15
|
+
// do not account for an invalid entry point or a blocked exports subpath.
|
|
16
|
+
const selectedEntry = realpathSync.native(requireFromArtifact.resolve(specifier));
|
|
17
|
+
const searchPaths = requireFromArtifact.resolve.paths(packageName);
|
|
18
|
+
if (searchPaths === null) {
|
|
19
|
+
throw new Error(`runtime dependency is not a local package: ${specifier}`);
|
|
20
|
+
}
|
|
21
|
+
for (const searchPath of searchPaths) {
|
|
22
|
+
const root = join(searchPath, packageName);
|
|
23
|
+
const selectedPath = firstExistingPackagePath(root);
|
|
24
|
+
if (selectedPath === undefined)
|
|
25
|
+
continue;
|
|
26
|
+
if (selectedPath !== root) {
|
|
27
|
+
throw new Error(`selected runtime dependency is a file, not a package directory (${selectedPath})`);
|
|
28
|
+
}
|
|
29
|
+
const realRoot = realpathSync.native(root);
|
|
30
|
+
if (!isInside(realRoot, selectedEntry)) {
|
|
31
|
+
throw new Error(`runtime dependency does not resolve from the nearest package root (${root})`);
|
|
32
|
+
}
|
|
33
|
+
const manifestPath = join(root, 'package.json');
|
|
34
|
+
let source;
|
|
35
|
+
try {
|
|
36
|
+
source = readFileSync(manifestPath, 'utf8');
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (isAbsent(error)) {
|
|
40
|
+
throw new Error(`selected runtime dependency has no package manifest (${root})`, { cause: error });
|
|
41
|
+
}
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
let manifest;
|
|
45
|
+
try {
|
|
46
|
+
manifest = JSON.parse(source);
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
throw new Error(`runtime dependency package manifest is not JSON (${manifestPath}): ${messageOf(error)}`, { cause: error });
|
|
50
|
+
}
|
|
51
|
+
if (typeof manifest !== 'object' ||
|
|
52
|
+
manifest === null ||
|
|
53
|
+
Array.isArray(manifest) ||
|
|
54
|
+
!('name' in manifest) ||
|
|
55
|
+
manifest.name !== packageName ||
|
|
56
|
+
!('version' in manifest) ||
|
|
57
|
+
typeof manifest.version !== 'string' ||
|
|
58
|
+
manifest.version.length === 0) {
|
|
59
|
+
throw new Error(`runtime dependency package manifest has no matching name and version (${manifestPath})`);
|
|
60
|
+
}
|
|
61
|
+
return { root, version: manifest.version };
|
|
62
|
+
}
|
|
63
|
+
throw new Error(`runtime dependency package root cannot be located for ${specifier}`);
|
|
64
|
+
}
|
|
65
|
+
function firstExistingPackagePath(root) {
|
|
66
|
+
for (const candidate of [
|
|
67
|
+
root,
|
|
68
|
+
`${root}.js`,
|
|
69
|
+
`${root}.json`,
|
|
70
|
+
`${root}.node`,
|
|
71
|
+
]) {
|
|
72
|
+
try {
|
|
73
|
+
lstatSync(candidate);
|
|
74
|
+
return candidate;
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (!isAbsent(error))
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
function packageNameFromSpecifier(specifier) {
|
|
84
|
+
if (specifier.length === 0 ||
|
|
85
|
+
specifier.startsWith('.') ||
|
|
86
|
+
specifier.startsWith('/') ||
|
|
87
|
+
specifier.startsWith('#') ||
|
|
88
|
+
specifier.includes('\\') ||
|
|
89
|
+
specifier.includes('\0') ||
|
|
90
|
+
specifier.includes(':') ||
|
|
91
|
+
isBuiltin(specifier)) {
|
|
92
|
+
throw new Error(`runtime dependency must use a bare package specifier`);
|
|
93
|
+
}
|
|
94
|
+
const parts = specifier.split('/');
|
|
95
|
+
const name = specifier.startsWith('@')
|
|
96
|
+
? parts.length >= 2 && parts[0] !== '@' && parts[1].length > 0
|
|
97
|
+
? `${parts[0]}/${parts[1]}`
|
|
98
|
+
: ''
|
|
99
|
+
: parts[0];
|
|
100
|
+
if (name.length === 0) {
|
|
101
|
+
throw new Error(`runtime dependency must use a bare package specifier`);
|
|
102
|
+
}
|
|
103
|
+
return name;
|
|
104
|
+
}
|
|
105
|
+
export function isBarePackageSpecifier(specifier) {
|
|
106
|
+
try {
|
|
107
|
+
packageNameFromSpecifier(specifier);
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function isInside(root, path) {
|
|
115
|
+
if (root === path)
|
|
116
|
+
return true;
|
|
117
|
+
const rel = relative(root, path);
|
|
118
|
+
return (rel !== '' &&
|
|
119
|
+
rel !== '..' &&
|
|
120
|
+
!rel.startsWith(`..${sep}`) &&
|
|
121
|
+
!isAbsolute(rel));
|
|
122
|
+
}
|
|
123
|
+
function isAbsent(error) {
|
|
124
|
+
return (typeof error === 'object' &&
|
|
125
|
+
error !== null &&
|
|
126
|
+
'code' in error &&
|
|
127
|
+
(error.code === 'ENOENT' || error.code === 'ENOTDIR'));
|
|
128
|
+
}
|
|
129
|
+
function messageOf(error) {
|
|
130
|
+
return error instanceof Error ? error.message : String(error);
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=runtime-package.js.map
|