@interf/compiler 0.4.1 → 0.5.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/README.md +71 -66
- package/builtin-workflows/interf/README.md +6 -6
- package/builtin-workflows/interf/compile/stages/shape/SKILL.md +7 -7
- package/builtin-workflows/interf/compile/stages/structure/SKILL.md +2 -2
- package/builtin-workflows/interf/compile/stages/summarize/SKILL.md +1 -1
- package/builtin-workflows/interf/{workspace.schema.json → compiled.schema.json} +5 -5
- package/builtin-workflows/interf/improve/SKILL.md +3 -3
- package/builtin-workflows/interf/use/query/SKILL.md +2 -2
- package/builtin-workflows/interf/workflow.json +42 -31
- package/dist/commands/check-draft.d.ts +19 -0
- package/dist/commands/check-draft.js +110 -0
- package/dist/commands/compile-controller.d.ts +4 -4
- package/dist/commands/compile-controller.js +117 -81
- package/dist/commands/compile.d.ts +5 -5
- package/dist/commands/compile.js +61 -62
- package/dist/commands/compiled-flow.d.ts +23 -0
- package/dist/commands/compiled-flow.js +112 -0
- package/dist/commands/create-workflow-wizard.d.ts +3 -3
- package/dist/commands/create-workflow-wizard.js +11 -11
- package/dist/commands/create.d.ts +2 -2
- package/dist/commands/create.js +50 -57
- package/dist/commands/default.js +2 -2
- package/dist/commands/executor-flow.d.ts +20 -1
- package/dist/commands/executor-flow.js +67 -7
- package/dist/commands/init.js +242 -289
- package/dist/commands/list.js +14 -10
- package/dist/commands/reset.js +6 -6
- package/dist/commands/source-config-wizard.d.ts +12 -8
- package/dist/commands/source-config-wizard.js +356 -119
- package/dist/commands/status.js +49 -26
- package/dist/commands/test-flow.d.ts +23 -10
- package/dist/commands/test-flow.js +278 -58
- package/dist/commands/test.d.ts +7 -1
- package/dist/commands/test.js +264 -65
- package/dist/commands/verify.js +23 -14
- package/dist/index.d.ts +7 -7
- package/dist/index.js +4 -4
- package/dist/lib/agent-args.js +2 -1
- package/dist/lib/agent-constants.js +1 -1
- package/dist/lib/agent-render.js +4 -4
- package/dist/lib/agent-shells.d.ts +8 -8
- package/dist/lib/agent-shells.js +231 -142
- package/dist/lib/compiled-compile.d.ts +52 -0
- package/dist/lib/compiled-compile.js +274 -0
- package/dist/lib/compiled-home.d.ts +5 -0
- package/dist/lib/compiled-home.js +32 -0
- package/dist/lib/compiled-layout.d.ts +2 -0
- package/dist/lib/compiled-layout.js +60 -0
- package/dist/lib/compiled-paths.d.ts +41 -0
- package/dist/lib/compiled-paths.js +111 -0
- package/dist/lib/{workspace-raw.d.ts → compiled-raw.d.ts} +8 -7
- package/dist/lib/{workspace-raw.js → compiled-raw.js} +16 -14
- package/dist/lib/compiled-reset.d.ts +1 -0
- package/dist/lib/compiled-reset.js +44 -0
- package/dist/lib/compiled-schema.d.ts +27 -0
- package/dist/lib/compiled-schema.js +110 -0
- package/dist/lib/config.d.ts +0 -1
- package/dist/lib/config.js +0 -1
- package/dist/lib/discovery.d.ts +1 -1
- package/dist/lib/discovery.js +3 -3
- package/dist/lib/interf-bootstrap.d.ts +1 -1
- package/dist/lib/interf-bootstrap.js +4 -4
- package/dist/lib/interf-detect.d.ts +10 -10
- package/dist/lib/interf-detect.js +78 -56
- package/dist/lib/interf-scaffold.d.ts +2 -2
- package/dist/lib/interf-scaffold.js +90 -57
- package/dist/lib/interf-workflow-package.d.ts +3 -3
- package/dist/lib/interf-workflow-package.js +30 -30
- package/dist/lib/interf.d.ts +5 -5
- package/dist/lib/interf.js +4 -4
- package/dist/lib/local-workflows.d.ts +4 -4
- package/dist/lib/local-workflows.js +35 -70
- package/dist/lib/obsidian.d.ts +1 -1
- package/dist/lib/parse.js +92 -1
- package/dist/lib/project-paths.d.ts +13 -0
- package/dist/lib/project-paths.js +29 -0
- package/dist/lib/runtime-acceptance.d.ts +7 -1
- package/dist/lib/runtime-acceptance.js +194 -59
- package/dist/lib/runtime-contracts.d.ts +2 -4
- package/dist/lib/runtime-contracts.js +17 -161
- package/dist/lib/runtime-inventory.d.ts +7 -0
- package/dist/lib/runtime-inventory.js +29 -0
- package/dist/lib/runtime-paths.js +5 -5
- package/dist/lib/runtime-prompt.js +9 -6
- package/dist/lib/runtime-reconcile.d.ts +2 -3
- package/dist/lib/runtime-reconcile.js +92 -171
- package/dist/lib/runtime-runs.js +30 -39
- package/dist/lib/runtime-types.d.ts +10 -19
- package/dist/lib/runtime.d.ts +2 -2
- package/dist/lib/runtime.js +1 -1
- package/dist/lib/schema.d.ts +163 -140
- package/dist/lib/schema.js +163 -124
- package/dist/lib/source-config.d.ts +24 -20
- package/dist/lib/source-config.js +154 -116
- package/dist/lib/state-artifacts.d.ts +5 -5
- package/dist/lib/state-artifacts.js +8 -8
- package/dist/lib/state-health.d.ts +4 -4
- package/dist/lib/state-health.js +108 -126
- package/dist/lib/state-io.d.ts +8 -8
- package/dist/lib/state-io.js +77 -50
- package/dist/lib/state-paths.js +5 -5
- package/dist/lib/state-view.d.ts +4 -4
- package/dist/lib/state-view.js +52 -55
- package/dist/lib/state.d.ts +5 -5
- package/dist/lib/state.js +4 -4
- package/dist/lib/summarize-plan.d.ts +3 -2
- package/dist/lib/summarize-plan.js +18 -16
- package/dist/lib/test-execution.js +9 -9
- package/dist/lib/test-matrices.d.ts +3 -3
- package/dist/lib/test-matrices.js +6 -6
- package/dist/lib/test-paths.d.ts +4 -4
- package/dist/lib/test-paths.js +16 -10
- package/dist/lib/test-sandbox.d.ts +1 -1
- package/dist/lib/test-sandbox.js +38 -31
- package/dist/lib/test-targets.d.ts +2 -2
- package/dist/lib/test-targets.js +11 -11
- package/dist/lib/test-types.d.ts +1 -1
- package/dist/lib/test.d.ts +1 -1
- package/dist/lib/test.js +1 -1
- package/dist/lib/util.d.ts +2 -0
- package/dist/lib/util.js +14 -1
- package/dist/lib/validate-compiled.d.ts +27 -0
- package/dist/lib/validate-compiled.js +236 -0
- package/dist/lib/validate-helpers.d.ts +0 -8
- package/dist/lib/validate-helpers.js +0 -30
- package/dist/lib/validate.d.ts +4 -4
- package/dist/lib/validate.js +49 -15
- package/dist/lib/workflow-abi.d.ts +37 -46
- package/dist/lib/workflow-abi.js +51 -76
- package/dist/lib/workflow-definitions.d.ts +11 -11
- package/dist/lib/workflow-definitions.js +36 -53
- package/dist/lib/workflow-helpers.d.ts +2 -3
- package/dist/lib/workflow-helpers.js +9 -13
- package/dist/lib/workflow-improvement.d.ts +3 -3
- package/dist/lib/workflow-improvement.js +48 -48
- package/dist/lib/workflow-review-paths.d.ts +3 -3
- package/dist/lib/workflow-review-paths.js +11 -11
- package/dist/lib/workflow-stage-runner.d.ts +1 -1
- package/dist/lib/workflow-stage-runner.js +8 -8
- package/dist/lib/workflows.d.ts +9 -9
- package/dist/lib/workflows.js +15 -17
- package/package.json +10 -9
- package/dist/commands/workspace-flow.d.ts +0 -23
- package/dist/commands/workspace-flow.js +0 -109
- package/dist/lib/registry.d.ts +0 -16
- package/dist/lib/registry.js +0 -65
- package/dist/lib/validate-workspace.d.ts +0 -121
- package/dist/lib/validate-workspace.js +0 -407
- package/dist/lib/workspace-compile.d.ts +0 -54
- package/dist/lib/workspace-compile.js +0 -476
- package/dist/lib/workspace-home.d.ts +0 -5
- package/dist/lib/workspace-home.js +0 -32
- package/dist/lib/workspace-layout.d.ts +0 -2
- package/dist/lib/workspace-layout.js +0 -60
- package/dist/lib/workspace-paths.d.ts +0 -41
- package/dist/lib/workspace-paths.js +0 -107
- package/dist/lib/workspace-reset.d.ts +0 -1
- package/dist/lib/workspace-reset.js +0 -43
- package/dist/lib/workspace-schema.d.ts +0 -17
- package/dist/lib/workspace-schema.js +0 -74
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { discoverSourceFiles } from "./discovery.js";
|
|
4
|
+
import { compiledZoneAbsolutePath, findCompiledSchemaZone, readCompiledSchemaFile, } from "./compiled-schema.js";
|
|
5
|
+
import { resolveSourceFolderPath } from "./interf.js";
|
|
6
|
+
import { compiledInterfConfigPath, workflowPackagePathForCompiled } from "./compiled-paths.js";
|
|
7
|
+
import { readCompiledConfig } from "./validate.js";
|
|
8
|
+
import { loadState } from "./state.js";
|
|
9
|
+
import { validateResolvedStageAcceptance, stageRecordFromState } from "./runtime-acceptance.js";
|
|
10
|
+
import { getActiveCompiledWorkflow, resolveCompiledWorkflowFromConfig, } from "./workflow-definitions.js";
|
|
11
|
+
import { listFilesRecursive } from "./filesystem.js";
|
|
12
|
+
function countZoneArtifacts(compiledPath, zonePath, kind) {
|
|
13
|
+
const absolutePath = compiledZoneAbsolutePath(compiledPath, { path: zonePath });
|
|
14
|
+
if (!existsSync(absolutePath))
|
|
15
|
+
return 0;
|
|
16
|
+
if (kind === "file")
|
|
17
|
+
return 1;
|
|
18
|
+
return listFilesRecursive(absolutePath).length;
|
|
19
|
+
}
|
|
20
|
+
function readWorkflowContext(dirPath) {
|
|
21
|
+
const config = readCompiledConfig(dirPath);
|
|
22
|
+
const workflowId = config.valid ? resolveCompiledWorkflowFromConfig(config.value) : null;
|
|
23
|
+
let workflow = null;
|
|
24
|
+
if (workflowId) {
|
|
25
|
+
try {
|
|
26
|
+
workflow = getActiveCompiledWorkflow(dirPath, workflowId);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
workflow = null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const schema = readCompiledSchemaFile(workflowPackagePathForCompiled(dirPath));
|
|
33
|
+
const state = loadState(dirPath);
|
|
34
|
+
const sourceTotal = config.valid
|
|
35
|
+
? discoverSourceFiles(resolveSourceFolderPath(dirPath, config.value), dirPath).totalCount
|
|
36
|
+
: 0;
|
|
37
|
+
return {
|
|
38
|
+
config,
|
|
39
|
+
workflow,
|
|
40
|
+
schema,
|
|
41
|
+
state,
|
|
42
|
+
sourceTotal,
|
|
43
|
+
workflowId,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function stageRequired(sourceTotal, writeCounts, stageRecordPresent) {
|
|
47
|
+
return sourceTotal > 0 || writeCounts > 0 || stageRecordPresent;
|
|
48
|
+
}
|
|
49
|
+
function zoneWriteCount(compiledPath, schema, stage) {
|
|
50
|
+
const zoneCounts = {};
|
|
51
|
+
let total = 0;
|
|
52
|
+
for (const zoneId of stage.writes) {
|
|
53
|
+
const zone = findCompiledSchemaZone(schema, zoneId);
|
|
54
|
+
if (!zone)
|
|
55
|
+
continue;
|
|
56
|
+
const count = countZoneArtifacts(compiledPath, zone.path, zone.kind);
|
|
57
|
+
zoneCounts[zoneId] = count;
|
|
58
|
+
total += count;
|
|
59
|
+
}
|
|
60
|
+
return { total, zoneCounts };
|
|
61
|
+
}
|
|
62
|
+
function mergeValidationCounts(sourceTotal, stageRecord, zoneCounts) {
|
|
63
|
+
const merged = {
|
|
64
|
+
source_total: sourceTotal,
|
|
65
|
+
...zoneCounts,
|
|
66
|
+
};
|
|
67
|
+
const stageCounts = stageRecord?.counts;
|
|
68
|
+
if (stageCounts && typeof stageCounts === "object" && !Array.isArray(stageCounts)) {
|
|
69
|
+
for (const [key, value] of Object.entries(stageCounts)) {
|
|
70
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
71
|
+
merged[key] = value;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return merged;
|
|
76
|
+
}
|
|
77
|
+
export function validateCompiled(dirPath) {
|
|
78
|
+
const context = readWorkflowContext(dirPath);
|
|
79
|
+
return {
|
|
80
|
+
config_present: context.config.present,
|
|
81
|
+
config_valid: context.config.valid,
|
|
82
|
+
config_type_match: context.config.typeMatch(),
|
|
83
|
+
workflow_present: existsSync(join(dirPath, ".interf", "workflow", "workflow.json")),
|
|
84
|
+
workflow_valid: context.workflow !== null,
|
|
85
|
+
schema_present: existsSync(join(dirPath, ".interf", "workflow", "compiled.schema.json")),
|
|
86
|
+
schema_valid: context.schema !== null,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export function validateCompiledStage(dirPath, stageId) {
|
|
90
|
+
const context = readWorkflowContext(dirPath);
|
|
91
|
+
const checks = {
|
|
92
|
+
config_present: context.config.present,
|
|
93
|
+
config_valid: context.config.valid,
|
|
94
|
+
config_type_match: context.config.typeMatch(),
|
|
95
|
+
workflow_present: existsSync(join(dirPath, ".interf", "workflow", "workflow.json")),
|
|
96
|
+
workflow_valid: context.workflow !== null,
|
|
97
|
+
schema_present: existsSync(join(dirPath, ".interf", "workflow", "compiled.schema.json")),
|
|
98
|
+
schema_valid: context.schema !== null,
|
|
99
|
+
};
|
|
100
|
+
const errors = [];
|
|
101
|
+
if (!checks.config_present)
|
|
102
|
+
errors.push(`Missing ${compiledInterfConfigPath(dirPath)}.`);
|
|
103
|
+
else if (!checks.config_valid)
|
|
104
|
+
errors.push(`Could not parse ${compiledInterfConfigPath(dirPath)}.`);
|
|
105
|
+
else if (!checks.config_type_match)
|
|
106
|
+
errors.push("Config is not a compiled dataset.");
|
|
107
|
+
if (!checks.workflow_present)
|
|
108
|
+
errors.push("Missing .interf/workflow/workflow.json.");
|
|
109
|
+
else if (!checks.workflow_valid)
|
|
110
|
+
errors.push("Could not load the active workflow package.");
|
|
111
|
+
if (!checks.schema_present)
|
|
112
|
+
errors.push("Missing .interf/workflow/compiled.schema.json.");
|
|
113
|
+
else if (!checks.schema_valid)
|
|
114
|
+
errors.push("Could not parse .interf/workflow/compiled.schema.json.");
|
|
115
|
+
const workflowStage = context.workflow?.stages.find((stage) => stage.id === stageId) ?? null;
|
|
116
|
+
checks.stage_present = workflowStage !== null;
|
|
117
|
+
if (!checks.stage_present) {
|
|
118
|
+
errors.push(`Workflow does not declare stage "${stageId}".`);
|
|
119
|
+
}
|
|
120
|
+
const stageRecord = stageRecordFromState(context.state, stageId);
|
|
121
|
+
checks.stage_record_present = stageRecord !== null;
|
|
122
|
+
checks.stage_finished = Boolean(stageRecord?.finished_at);
|
|
123
|
+
checks.stage_succeeded = stageRecord?.status === "succeeded";
|
|
124
|
+
const writeCounts = workflowStage && context.schema
|
|
125
|
+
? zoneWriteCount(dirPath, context.schema, workflowStage)
|
|
126
|
+
: { total: 0, zoneCounts: {} };
|
|
127
|
+
const acceptanceCounts = mergeValidationCounts(context.sourceTotal, stageRecord, writeCounts.zoneCounts);
|
|
128
|
+
const required = stageRequired(context.sourceTotal, writeCounts.total, checks.stage_record_present);
|
|
129
|
+
let acceptanceErrors = [];
|
|
130
|
+
if (workflowStage && context.schema) {
|
|
131
|
+
const acceptanceValidation = validateResolvedStageAcceptance(dirPath, {
|
|
132
|
+
stageId,
|
|
133
|
+
acceptance: workflowStage.acceptance,
|
|
134
|
+
counts: acceptanceCounts,
|
|
135
|
+
});
|
|
136
|
+
checks.acceptance_ok = acceptanceValidation.ok;
|
|
137
|
+
acceptanceErrors = acceptanceValidation.failures;
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
checks.acceptance_ok = false;
|
|
141
|
+
}
|
|
142
|
+
if (required && checks.stage_record_present && !checks.stage_finished) {
|
|
143
|
+
errors.push(`Stage "${stageId}" has no finished_at proof in runtime state.`);
|
|
144
|
+
}
|
|
145
|
+
if (required && checks.stage_record_present && !checks.stage_succeeded) {
|
|
146
|
+
errors.push(`Stage "${stageId}" is not marked succeeded in runtime state.`);
|
|
147
|
+
}
|
|
148
|
+
if (required) {
|
|
149
|
+
errors.push(...acceptanceErrors);
|
|
150
|
+
}
|
|
151
|
+
const ok = required ? errors.length === 0 : errors.length === 0;
|
|
152
|
+
const summary = !required
|
|
153
|
+
? `Stage "${stageId}" is not required yet.`
|
|
154
|
+
: ok
|
|
155
|
+
? `Stage "${stageId}" verified.`
|
|
156
|
+
: `Stage "${stageId}" failed — ${errors[0] ?? "acceptance not satisfied."}`;
|
|
157
|
+
return {
|
|
158
|
+
ok,
|
|
159
|
+
required,
|
|
160
|
+
stage: stageId,
|
|
161
|
+
summary,
|
|
162
|
+
counts: {
|
|
163
|
+
...acceptanceCounts,
|
|
164
|
+
write_artifacts: writeCounts.total,
|
|
165
|
+
declared_write_zones: workflowStage?.writes.length ?? 0,
|
|
166
|
+
},
|
|
167
|
+
checks,
|
|
168
|
+
errors,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
export function validateCompiledWorkflow(dirPath) {
|
|
172
|
+
const context = readWorkflowContext(dirPath);
|
|
173
|
+
const checks = {
|
|
174
|
+
config_present: context.config.present,
|
|
175
|
+
config_valid: context.config.valid,
|
|
176
|
+
config_type_match: context.config.typeMatch(),
|
|
177
|
+
workflow_present: existsSync(join(dirPath, ".interf", "workflow", "workflow.json")),
|
|
178
|
+
workflow_valid: context.workflow !== null,
|
|
179
|
+
schema_present: existsSync(join(dirPath, ".interf", "workflow", "compiled.schema.json")),
|
|
180
|
+
schema_valid: context.schema !== null,
|
|
181
|
+
};
|
|
182
|
+
if (!context.workflow) {
|
|
183
|
+
const errors = ["Could not load the active workflow package."];
|
|
184
|
+
return {
|
|
185
|
+
ok: false,
|
|
186
|
+
required: true,
|
|
187
|
+
stage: "workflow",
|
|
188
|
+
summary: `Compiled workflow failed — ${errors[0]}`,
|
|
189
|
+
counts: { source_total: context.sourceTotal, stage_total: 0, completed_stages: 0 },
|
|
190
|
+
checks,
|
|
191
|
+
errors,
|
|
192
|
+
stage_results: {},
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
const stageResults = {};
|
|
196
|
+
const errors = [];
|
|
197
|
+
let completedStages = 0;
|
|
198
|
+
let failedStage = "compiled";
|
|
199
|
+
for (const stage of context.workflow.stages) {
|
|
200
|
+
const validation = validateCompiledStage(dirPath, stage.id);
|
|
201
|
+
stageResults[stage.id] = validation.ok;
|
|
202
|
+
if (validation.ok) {
|
|
203
|
+
completedStages += 1;
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
failedStage = stage.id;
|
|
207
|
+
errors.push(...validation.errors);
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
const ok = errors.length === 0;
|
|
211
|
+
return {
|
|
212
|
+
ok,
|
|
213
|
+
required: context.sourceTotal > 0,
|
|
214
|
+
stage: failedStage,
|
|
215
|
+
summary: ok
|
|
216
|
+
? `Compiled workflow verified — ${completedStages}/${context.workflow.stages.length} stages satisfied.`
|
|
217
|
+
: `Compiled workflow failed — ${errors[0] ?? "stage acceptance not satisfied."}`,
|
|
218
|
+
counts: {
|
|
219
|
+
source_total: context.sourceTotal,
|
|
220
|
+
stage_total: context.workflow.stages.length,
|
|
221
|
+
completed_stages: completedStages,
|
|
222
|
+
},
|
|
223
|
+
checks,
|
|
224
|
+
errors,
|
|
225
|
+
stage_results: stageResults,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
export function validateCompiledSummarize(dirPath) {
|
|
229
|
+
return validateCompiledStage(dirPath, "summarize");
|
|
230
|
+
}
|
|
231
|
+
export function validateCompiledStructure(dirPath) {
|
|
232
|
+
return validateCompiledStage(dirPath, "structure");
|
|
233
|
+
}
|
|
234
|
+
export function validateCompiledCompile(dirPath) {
|
|
235
|
+
return validateCompiledWorkflow(dirPath);
|
|
236
|
+
}
|
|
@@ -10,11 +10,3 @@ export declare function isSubset(left: Set<string>, right: Set<string>): boolean
|
|
|
10
10
|
export declare function setsEqual(left: Set<string>, right: Set<string>): boolean;
|
|
11
11
|
export declare function setIntersectionSize(left: Set<string>, right: Set<string>): number;
|
|
12
12
|
export declare function dedupeStrings(values: string[]): string[];
|
|
13
|
-
export interface InventoryFiles {
|
|
14
|
-
legacyFiles: Array<Record<string, unknown>>;
|
|
15
|
-
summaryFiles: Array<Record<string, unknown>>;
|
|
16
|
-
entryFiles: Array<Record<string, unknown>>;
|
|
17
|
-
files: Array<Record<string, unknown>>;
|
|
18
|
-
}
|
|
19
|
-
export declare function readInventoryFiles(inventory: Record<string, unknown> | null): InventoryFiles;
|
|
20
|
-
export declare function readInventoryTotal(inventory: Record<string, unknown> | null, inventoryFiles?: InventoryFiles): number;
|
|
@@ -39,33 +39,3 @@ export function setIntersectionSize(left, right) {
|
|
|
39
39
|
export function dedupeStrings(values) {
|
|
40
40
|
return Array.from(new Set(values));
|
|
41
41
|
}
|
|
42
|
-
function asInventoryEntries(value) {
|
|
43
|
-
if (!Array.isArray(value))
|
|
44
|
-
return [];
|
|
45
|
-
return value.filter((item) => !!item && typeof item === "object" && !Array.isArray(item));
|
|
46
|
-
}
|
|
47
|
-
export function readInventoryFiles(inventory) {
|
|
48
|
-
const legacyFiles = asInventoryEntries(inventory?.files);
|
|
49
|
-
const summaryFiles = asInventoryEntries(inventory?.summaries);
|
|
50
|
-
const entryFiles = asInventoryEntries(inventory?.entries);
|
|
51
|
-
const itemFiles = asInventoryEntries(inventory?.items);
|
|
52
|
-
const normalizedEntryFiles = entryFiles.length > 0 ? entryFiles : itemFiles;
|
|
53
|
-
const files = legacyFiles.length > 0
|
|
54
|
-
? legacyFiles
|
|
55
|
-
: summaryFiles.length > 0
|
|
56
|
-
? summaryFiles
|
|
57
|
-
: normalizedEntryFiles;
|
|
58
|
-
return {
|
|
59
|
-
legacyFiles,
|
|
60
|
-
summaryFiles,
|
|
61
|
-
entryFiles: normalizedEntryFiles,
|
|
62
|
-
files,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
export function readInventoryTotal(inventory, inventoryFiles) {
|
|
66
|
-
if (typeof inventory?.total === "number")
|
|
67
|
-
return inventory.total;
|
|
68
|
-
if (typeof inventory?.summary_total === "number")
|
|
69
|
-
return inventory.summary_total;
|
|
70
|
-
return (inventoryFiles ?? readInventoryFiles(inventory)).files.length;
|
|
71
|
-
}
|
package/dist/lib/validate.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { readInterfConfig } from "./interf.js";
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function readCompiledConfig(dirPath: string): {
|
|
3
3
|
present: boolean;
|
|
4
4
|
valid: boolean;
|
|
5
5
|
value: ReturnType<typeof readInterfConfig>;
|
|
@@ -9,9 +9,9 @@ export declare function validateSynthFiles(files: string[]): {
|
|
|
9
9
|
invalid_frontmatter: number;
|
|
10
10
|
short_abstracts: number;
|
|
11
11
|
};
|
|
12
|
-
export declare function countBrokenWikilinks(
|
|
12
|
+
export declare function countBrokenWikilinks(compiledRoot: string, noteIndexRoots: string[], linkScanRoots: string[]): number;
|
|
13
13
|
export declare function asNumber(value: unknown): number;
|
|
14
14
|
export declare function isOutputMarkdownFile(filePath: string): boolean;
|
|
15
15
|
export declare function safeReadText(filePath: string): string | null;
|
|
16
|
-
export {
|
|
17
|
-
export type {
|
|
16
|
+
export { validateCompiled, validateCompiledStage, validateCompiledWorkflow, validateCompiledSummarize, validateCompiledStructure, validateCompiledCompile, } from "./validate-compiled.js";
|
|
17
|
+
export type { CompiledValidationSummary, CompiledStageValidation, CompiledWorkflowValidation, } from "./validate-compiled.js";
|
package/dist/lib/validate.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { existsSync, readFileSync, statSync, } from "node:fs";
|
|
2
2
|
import { basename, extname, join } from "node:path";
|
|
3
|
+
import { readCompiledSchemaFile } from "./compiled-schema.js";
|
|
4
|
+
import { compiledKnowledgeRootPath } from "./compiled-schema.js";
|
|
5
|
+
import { workflowPackagePathForCompiled } from "./compiled-paths.js";
|
|
3
6
|
import { listFilesRecursive } from "./filesystem.js";
|
|
4
7
|
import { readInterfConfig } from "./interf.js";
|
|
5
8
|
import { parseJsonFrontmatter } from "./parse.js";
|
|
6
|
-
import {
|
|
9
|
+
import { compiledInterfConfigPath } from "./compiled-paths.js";
|
|
7
10
|
const REQUIRED_DIGEST_FIELDS = [
|
|
8
11
|
"source_kind",
|
|
9
12
|
"evidence_tier",
|
|
@@ -12,9 +15,8 @@ const REQUIRED_DIGEST_FIELDS = [
|
|
|
12
15
|
];
|
|
13
16
|
const MIN_ABSTRACT_WORDS = 5;
|
|
14
17
|
const WIKILINK_PATTERN = /!?\[\[([^[\]]+)\]\]/g;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const configPath = workspaceInterfConfigPath(dirPath);
|
|
18
|
+
export function readCompiledConfig(dirPath) {
|
|
19
|
+
const configPath = compiledInterfConfigPath(dirPath);
|
|
18
20
|
const value = readInterfConfig(dirPath);
|
|
19
21
|
const present = existsSync(configPath);
|
|
20
22
|
if (!present) {
|
|
@@ -30,7 +32,7 @@ export function readWorkspaceConfig(dirPath) {
|
|
|
30
32
|
valid: value !== null,
|
|
31
33
|
value,
|
|
32
34
|
typeMatch() {
|
|
33
|
-
return value?.type === "
|
|
35
|
+
return value?.type === "compiled" && typeof value?.source?.path === "string";
|
|
34
36
|
},
|
|
35
37
|
};
|
|
36
38
|
}
|
|
@@ -56,7 +58,9 @@ export function validateSynthFiles(files) {
|
|
|
56
58
|
short_abstracts: shortAbstracts,
|
|
57
59
|
};
|
|
58
60
|
}
|
|
59
|
-
export function countBrokenWikilinks(
|
|
61
|
+
export function countBrokenWikilinks(compiledRoot, noteIndexRoots, linkScanRoots) {
|
|
62
|
+
const zonePathById = compiledZoneDirectoryPaths(compiledRoot);
|
|
63
|
+
const knowledgeRelativePrefixes = compiledKnowledgeRelativePrefixes(zonePathById);
|
|
60
64
|
const noteIndex = new Set();
|
|
61
65
|
for (const filePath of dedupeFiles(noteIndexRoots)) {
|
|
62
66
|
for (const target of collectWikilinkTargets(filePath)) {
|
|
@@ -77,12 +81,15 @@ export function countBrokenWikilinks(workspaceRoot, noteIndexRoots, linkScanRoot
|
|
|
77
81
|
if (!target)
|
|
78
82
|
continue;
|
|
79
83
|
if (target.includes("/")) {
|
|
80
|
-
if (!wikilinkPathExists(
|
|
84
|
+
if (!wikilinkPathExists(compiledRoot, target, zonePathById, knowledgeRelativePrefixes)) {
|
|
81
85
|
brokenLinks += 1;
|
|
82
86
|
}
|
|
83
87
|
continue;
|
|
84
88
|
}
|
|
85
|
-
if (!noteIndex.has(target.toLowerCase())
|
|
89
|
+
if (!noteIndex.has(target.toLowerCase()) &&
|
|
90
|
+
!noteIndex.has(noteName(target).toLowerCase()) &&
|
|
91
|
+
!wikilinkPathExists(compiledRoot, target, zonePathById, knowledgeRelativePrefixes) &&
|
|
92
|
+
!wikilinkPathExists(compiledRoot, noteName(target), zonePathById, knowledgeRelativePrefixes)) {
|
|
86
93
|
brokenLinks += 1;
|
|
87
94
|
}
|
|
88
95
|
}
|
|
@@ -157,15 +164,23 @@ function countWords(text) {
|
|
|
157
164
|
function noteName(filePath) {
|
|
158
165
|
return basename(filePath, extname(filePath));
|
|
159
166
|
}
|
|
160
|
-
function wikilinkPathExists(
|
|
161
|
-
return linkPathCandidates(
|
|
167
|
+
function wikilinkPathExists(compiledRoot, target, zonePathById, knowledgeRelativePrefixes) {
|
|
168
|
+
return linkPathCandidates(compiledRoot, target, zonePathById, knowledgeRelativePrefixes)
|
|
169
|
+
.some((candidate) => existsSync(candidate));
|
|
162
170
|
}
|
|
163
|
-
function linkPathCandidates(
|
|
171
|
+
function linkPathCandidates(compiledRoot, target, zonePathById, knowledgeRelativePrefixes) {
|
|
164
172
|
const candidates = new Set();
|
|
165
|
-
addPathCandidate(candidates, join(
|
|
173
|
+
addPathCandidate(candidates, join(compiledRoot, target));
|
|
166
174
|
const [firstSegment] = target.split("/");
|
|
167
|
-
if (firstSegment &&
|
|
168
|
-
addPathCandidate(candidates, join(
|
|
175
|
+
if (firstSegment && knowledgeRelativePrefixes.has(firstSegment)) {
|
|
176
|
+
addPathCandidate(candidates, join(compiledKnowledgeRootPath(compiledRoot), target));
|
|
177
|
+
}
|
|
178
|
+
if (firstSegment) {
|
|
179
|
+
const normalizedPrefix = zonePathById.get(firstSegment);
|
|
180
|
+
if (normalizedPrefix) {
|
|
181
|
+
const remainder = target.slice(firstSegment.length).replace(/^\/+/, "");
|
|
182
|
+
addPathCandidate(candidates, join(compiledRoot, normalizedPrefix, remainder));
|
|
183
|
+
}
|
|
169
184
|
}
|
|
170
185
|
return Array.from(candidates);
|
|
171
186
|
}
|
|
@@ -175,6 +190,25 @@ function addPathCandidate(candidates, absolutePath) {
|
|
|
175
190
|
candidates.add(`${absolutePath}.md`);
|
|
176
191
|
}
|
|
177
192
|
}
|
|
193
|
+
function compiledZoneDirectoryPaths(compiledRoot) {
|
|
194
|
+
const workflowRoot = workflowPackagePathForCompiled(compiledRoot);
|
|
195
|
+
const schema = readCompiledSchemaFile(workflowRoot);
|
|
196
|
+
if (!schema)
|
|
197
|
+
return new Map();
|
|
198
|
+
return new Map(schema.zones
|
|
199
|
+
.filter((zone) => zone.kind === "directory")
|
|
200
|
+
.map((zone) => [zone.id, zone.path]));
|
|
201
|
+
}
|
|
202
|
+
function compiledKnowledgeRelativePrefixes(zonePathById) {
|
|
203
|
+
const prefixes = new Set();
|
|
204
|
+
for (const zonePath of zonePathById.values()) {
|
|
205
|
+
const [root, leaf, ...rest] = zonePath.split("/");
|
|
206
|
+
if (root !== "knowledge" || !leaf || rest.length > 0)
|
|
207
|
+
continue;
|
|
208
|
+
prefixes.add(leaf);
|
|
209
|
+
}
|
|
210
|
+
return prefixes;
|
|
211
|
+
}
|
|
178
212
|
function collectWikilinkTargets(filePath) {
|
|
179
213
|
const targets = new Set();
|
|
180
214
|
targets.add(noteName(filePath));
|
|
@@ -204,4 +238,4 @@ function addFrontmatterLinkTarget(targets, value) {
|
|
|
204
238
|
}
|
|
205
239
|
}
|
|
206
240
|
}
|
|
207
|
-
export {
|
|
241
|
+
export { validateCompiled, validateCompiledStage, validateCompiledWorkflow, validateCompiledSummarize, validateCompiledStructure, validateCompiledCompile, } from "./validate-compiled.js";
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
export type
|
|
3
|
-
export declare const
|
|
4
|
-
export type
|
|
5
|
-
export declare const
|
|
6
|
-
readonly "
|
|
1
|
+
export declare const COMPILED_CONTRACT_TYPES: readonly ["compiled-file-evidence", "compiled-knowledge-structure", "compiled-query-shape"];
|
|
2
|
+
export type CompiledContractType = typeof COMPILED_CONTRACT_TYPES[number];
|
|
3
|
+
export declare const COMPILED_ZONE_KINDS: readonly ["directory", "file", "runtime"];
|
|
4
|
+
export type CompiledZoneKind = typeof COMPILED_ZONE_KINDS[number];
|
|
5
|
+
export declare const COMPILED_CONTRACT_FAMILY_METADATA: {
|
|
6
|
+
readonly "compiled-file-evidence": {
|
|
7
7
|
readonly order: 0;
|
|
8
8
|
readonly bundledSkill: "compile/stages/summarize";
|
|
9
9
|
};
|
|
10
|
-
readonly "
|
|
10
|
+
readonly "compiled-knowledge-structure": {
|
|
11
11
|
readonly order: 1;
|
|
12
12
|
readonly bundledSkill: "compile/stages/structure";
|
|
13
13
|
};
|
|
14
|
-
readonly "
|
|
14
|
+
readonly "compiled-query-shape": {
|
|
15
15
|
readonly order: 2;
|
|
16
16
|
readonly bundledSkill: "compile/stages/shape";
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
|
-
export declare const
|
|
19
|
+
export declare const BUILTIN_COMPILED_STAGE_IDS: {
|
|
20
20
|
readonly SUMMARIZE: "summarize";
|
|
21
21
|
readonly STRUCTURE: "structure";
|
|
22
22
|
readonly SHAPE: "shape";
|
|
23
23
|
};
|
|
24
|
-
export type
|
|
25
|
-
export declare const
|
|
24
|
+
export type BuiltinCompiledStageId = typeof BUILTIN_COMPILED_STAGE_IDS[keyof typeof BUILTIN_COMPILED_STAGE_IDS];
|
|
25
|
+
export declare const BUILTIN_COMPILED_ZONE_IDS: {
|
|
26
26
|
readonly RAW: "raw";
|
|
27
27
|
readonly SUMMARIES: "summaries";
|
|
28
28
|
readonly KNOWLEDGE_ENTITIES: "knowledge-entities";
|
|
@@ -31,20 +31,20 @@ export declare const BUILTIN_WORKSPACE_ZONE_IDS: {
|
|
|
31
31
|
readonly HOME: "home";
|
|
32
32
|
readonly RUNTIME: "runtime";
|
|
33
33
|
};
|
|
34
|
-
export type
|
|
35
|
-
export interface
|
|
36
|
-
id:
|
|
34
|
+
export type BuiltinCompiledZoneId = typeof BUILTIN_COMPILED_ZONE_IDS[keyof typeof BUILTIN_COMPILED_ZONE_IDS];
|
|
35
|
+
export interface BuiltinCompiledZoneSpec {
|
|
36
|
+
id: BuiltinCompiledZoneId;
|
|
37
37
|
path: string;
|
|
38
|
-
kind:
|
|
38
|
+
kind: CompiledZoneKind;
|
|
39
39
|
required: true;
|
|
40
40
|
description: string;
|
|
41
41
|
}
|
|
42
|
-
export declare const
|
|
42
|
+
export declare const BUILTIN_COMPILED_ZONE_SPECS: readonly [{
|
|
43
43
|
readonly id: "raw";
|
|
44
44
|
readonly path: "raw";
|
|
45
45
|
readonly kind: "directory";
|
|
46
46
|
readonly required: true;
|
|
47
|
-
readonly description: "
|
|
47
|
+
readonly description: "Compiled-local raw snapshot copied from the dataset for direct evidence and verification.";
|
|
48
48
|
}, {
|
|
49
49
|
readonly id: "summaries";
|
|
50
50
|
readonly path: "summaries";
|
|
@@ -74,7 +74,7 @@ export declare const BUILTIN_WORKSPACE_ZONE_SPECS: readonly [{
|
|
|
74
74
|
readonly path: "home.md";
|
|
75
75
|
readonly kind: "file";
|
|
76
76
|
readonly required: true;
|
|
77
|
-
readonly description: "Primary entrypoint note for agents using the compiled
|
|
77
|
+
readonly description: "Primary entrypoint note for agents using the compiled dataset.";
|
|
78
78
|
}, {
|
|
79
79
|
readonly id: "runtime";
|
|
80
80
|
readonly path: ".interf/runtime";
|
|
@@ -82,20 +82,20 @@ export declare const BUILTIN_WORKSPACE_ZONE_SPECS: readonly [{
|
|
|
82
82
|
readonly required: true;
|
|
83
83
|
readonly description: "CLI-owned runtime state, health, stage contracts, and proof artifacts.";
|
|
84
84
|
}];
|
|
85
|
-
export interface
|
|
86
|
-
id:
|
|
85
|
+
export interface BuiltinCompiledStageAccessPattern {
|
|
86
|
+
id: BuiltinCompiledStageId;
|
|
87
87
|
label: string;
|
|
88
88
|
description: string;
|
|
89
|
-
contractType:
|
|
89
|
+
contractType: CompiledContractType;
|
|
90
90
|
skillDir: string;
|
|
91
|
-
reads: readonly
|
|
92
|
-
writes: readonly
|
|
91
|
+
reads: readonly BuiltinCompiledZoneId[];
|
|
92
|
+
writes: readonly BuiltinCompiledZoneId[];
|
|
93
93
|
}
|
|
94
|
-
export declare const
|
|
94
|
+
export declare const BUILTIN_COMPILED_STAGE_ACCESS_PATTERNS: readonly [{
|
|
95
95
|
readonly id: "summarize";
|
|
96
96
|
readonly label: "Summarize";
|
|
97
97
|
readonly description: "Turn source files into per-file summaries.";
|
|
98
|
-
readonly contractType: "
|
|
98
|
+
readonly contractType: "compiled-file-evidence";
|
|
99
99
|
readonly skillDir: "summarize";
|
|
100
100
|
readonly reads: readonly ["raw", "runtime"];
|
|
101
101
|
readonly writes: readonly ["summaries"];
|
|
@@ -103,36 +103,27 @@ export declare const BUILTIN_WORKSPACE_STAGE_ACCESS_PATTERNS: readonly [{
|
|
|
103
103
|
readonly id: "structure";
|
|
104
104
|
readonly label: "Structure";
|
|
105
105
|
readonly description: "Build the cross-file knowledge structure from the summaries.";
|
|
106
|
-
readonly contractType: "
|
|
106
|
+
readonly contractType: "compiled-knowledge-structure";
|
|
107
107
|
readonly skillDir: "structure";
|
|
108
108
|
readonly reads: readonly ["summaries", "runtime"];
|
|
109
109
|
readonly writes: readonly ["knowledge-entities", "knowledge-claims", "knowledge-indexes"];
|
|
110
110
|
}, {
|
|
111
111
|
readonly id: "shape";
|
|
112
112
|
readonly label: "Shape";
|
|
113
|
-
readonly description: "Shape the final
|
|
114
|
-
readonly contractType: "
|
|
113
|
+
readonly description: "Shape the final compiled around the saved focus and truth checks.";
|
|
114
|
+
readonly contractType: "compiled-query-shape";
|
|
115
115
|
readonly skillDir: "shape";
|
|
116
116
|
readonly reads: readonly ["raw", "summaries", "knowledge-entities", "knowledge-claims", "knowledge-indexes", "runtime"];
|
|
117
117
|
readonly writes: readonly ["knowledge-indexes", "home"];
|
|
118
118
|
}];
|
|
119
|
-
export declare function
|
|
120
|
-
export declare function
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
orderValid: boolean;
|
|
126
|
-
missing: WorkspaceContractType[];
|
|
127
|
-
};
|
|
128
|
-
export declare function listBuiltinWorkspaceZoneSpecs(): BuiltinWorkspaceZoneSpec[];
|
|
129
|
-
export declare function listBuiltinWorkspaceFallbackStages(): Array<{
|
|
130
|
-
id: BuiltinWorkspaceStageId;
|
|
131
|
-
contract_type: WorkspaceContractType;
|
|
132
|
-
reads: BuiltinWorkspaceZoneId[];
|
|
133
|
-
writes: BuiltinWorkspaceZoneId[];
|
|
119
|
+
export declare function listBuiltinCompiledZoneSpecs(): BuiltinCompiledZoneSpec[];
|
|
120
|
+
export declare function listBuiltinCompiledFallbackStages(): Array<{
|
|
121
|
+
id: BuiltinCompiledStageId;
|
|
122
|
+
contract_type: CompiledContractType;
|
|
123
|
+
reads: BuiltinCompiledZoneId[];
|
|
124
|
+
writes: BuiltinCompiledZoneId[];
|
|
134
125
|
}>;
|
|
135
|
-
export declare function
|
|
126
|
+
export declare function requiredCompiledZoneOwners<TStage extends {
|
|
136
127
|
id: string;
|
|
137
|
-
|
|
138
|
-
}>(stages: readonly TStage[], zoneId:
|
|
128
|
+
writes: readonly string[];
|
|
129
|
+
}>(stages: readonly TStage[], zoneId: BuiltinCompiledZoneId): string[];
|