@interf/compiler 0.1.9 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/README.md +37 -28
  2. package/dist/commands/benchmark.d.ts.map +1 -1
  3. package/dist/commands/benchmark.js +1 -8
  4. package/dist/commands/benchmark.js.map +1 -1
  5. package/dist/commands/compile.d.ts.map +1 -1
  6. package/dist/commands/compile.js.map +1 -1
  7. package/dist/commands/create-workflow-wizard.d.ts +65 -0
  8. package/dist/commands/create-workflow-wizard.d.ts.map +1 -0
  9. package/dist/commands/create-workflow-wizard.js +299 -0
  10. package/dist/commands/create-workflow-wizard.js.map +1 -0
  11. package/dist/commands/create.d.ts +1 -37
  12. package/dist/commands/create.d.ts.map +1 -1
  13. package/dist/commands/create.js +11 -313
  14. package/dist/commands/create.js.map +1 -1
  15. package/dist/commands/init.d.ts.map +1 -1
  16. package/dist/commands/init.js +2 -1
  17. package/dist/commands/init.js.map +1 -1
  18. package/dist/commands/reset.js +3 -3
  19. package/dist/commands/reset.js.map +1 -1
  20. package/dist/commands/verify.d.ts.map +1 -1
  21. package/dist/commands/verify.js +9 -0
  22. package/dist/commands/verify.js.map +1 -1
  23. package/dist/index.d.ts +2 -2
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +1 -1
  26. package/dist/index.js.map +1 -1
  27. package/dist/lib/agent-skills.d.ts +21 -0
  28. package/dist/lib/agent-skills.d.ts.map +1 -0
  29. package/dist/lib/agent-skills.js +215 -0
  30. package/dist/lib/agent-skills.js.map +1 -0
  31. package/dist/lib/agents.d.ts +11 -13
  32. package/dist/lib/agents.d.ts.map +1 -1
  33. package/dist/lib/agents.js +12 -212
  34. package/dist/lib/agents.js.map +1 -1
  35. package/dist/lib/filesystem.d.ts +0 -1
  36. package/dist/lib/filesystem.d.ts.map +1 -1
  37. package/dist/lib/filesystem.js +0 -5
  38. package/dist/lib/filesystem.js.map +1 -1
  39. package/dist/lib/interf-bootstrap.d.ts +13 -0
  40. package/dist/lib/interf-bootstrap.d.ts.map +1 -0
  41. package/dist/lib/interf-bootstrap.js +215 -0
  42. package/dist/lib/interf-bootstrap.js.map +1 -0
  43. package/dist/lib/interf-detect.d.ts +31 -0
  44. package/dist/lib/interf-detect.d.ts.map +1 -0
  45. package/dist/lib/interf-detect.js +146 -0
  46. package/dist/lib/interf-detect.js.map +1 -0
  47. package/dist/lib/interf-scaffold.d.ts +15 -0
  48. package/dist/lib/interf-scaffold.d.ts.map +1 -0
  49. package/dist/lib/interf-scaffold.js +592 -0
  50. package/dist/lib/interf-scaffold.js.map +1 -0
  51. package/dist/lib/interf.d.ts +4 -36
  52. package/dist/lib/interf.d.ts.map +1 -1
  53. package/dist/lib/interf.js +5 -1103
  54. package/dist/lib/interf.js.map +1 -1
  55. package/dist/lib/local-workflows.d.ts +7 -0
  56. package/dist/lib/local-workflows.d.ts.map +1 -1
  57. package/dist/lib/local-workflows.js +83 -10
  58. package/dist/lib/local-workflows.js.map +1 -1
  59. package/dist/lib/obsidian.d.ts +6 -0
  60. package/dist/lib/obsidian.d.ts.map +1 -0
  61. package/dist/lib/obsidian.js +166 -0
  62. package/dist/lib/obsidian.js.map +1 -0
  63. package/dist/lib/runtime.d.ts.map +1 -1
  64. package/dist/lib/runtime.js +1 -1
  65. package/dist/lib/runtime.js.map +1 -1
  66. package/dist/lib/schema.d.ts +1 -0
  67. package/dist/lib/schema.d.ts.map +1 -1
  68. package/dist/lib/schema.js +1 -1
  69. package/dist/lib/schema.js.map +1 -1
  70. package/dist/lib/state.d.ts +2 -4
  71. package/dist/lib/state.d.ts.map +1 -1
  72. package/dist/lib/state.js +1 -1
  73. package/dist/lib/state.js.map +1 -1
  74. package/dist/lib/util.d.ts +4 -0
  75. package/dist/lib/util.d.ts.map +1 -0
  76. package/dist/lib/util.js +14 -0
  77. package/dist/lib/util.js.map +1 -0
  78. package/dist/lib/validate.js +5 -8
  79. package/dist/lib/validate.js.map +1 -1
  80. package/dist/lib/workflow-definitions.d.ts.map +1 -1
  81. package/dist/lib/workflow-definitions.js +8 -0
  82. package/dist/lib/workflow-definitions.js.map +1 -1
  83. package/dist/lib/workflow-helpers.d.ts +41 -0
  84. package/dist/lib/workflow-helpers.d.ts.map +1 -0
  85. package/dist/lib/workflow-helpers.js +189 -0
  86. package/dist/lib/workflow-helpers.js.map +1 -0
  87. package/dist/lib/workflows-interface.d.ts +79 -0
  88. package/dist/lib/workflows-interface.d.ts.map +1 -0
  89. package/dist/lib/workflows-interface.js +625 -0
  90. package/dist/lib/workflows-interface.js.map +1 -0
  91. package/dist/lib/workflows-kb.d.ts +50 -0
  92. package/dist/lib/workflows-kb.d.ts.map +1 -0
  93. package/dist/lib/workflows-kb.js +282 -0
  94. package/dist/lib/workflows-kb.js.map +1 -0
  95. package/dist/lib/workflows.d.ts +10 -114
  96. package/dist/lib/workflows.d.ts.map +1 -1
  97. package/dist/lib/workflows.js +14 -1072
  98. package/dist/lib/workflows.js.map +1 -1
  99. package/package.json +8 -3
  100. package/skills/knowledge-base/compile/references/stage-entities.md +2 -2
  101. package/templates/knowledge-base/README.md +1 -1
@@ -0,0 +1,625 @@
1
+ import { existsSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { countFilesRecursive } from "./filesystem.js";
4
+ import { readInterfConfig, refreshWorkspaceBootstrapGuidance, resolveInterfaceKnowledgeBasePath, resolveKnowledgeBaseSourcePath, syncClaudeBootstrap, } from "./interf.js";
5
+ import { loadState, computeInterfaceHealth, refreshInterfaceArtifacts, } from "./state.js";
6
+ import { buildStagePrompt, markRuntimeRunFailedAfterValidation, markRuntimeRunSucceededAfterValidation, runtimeRunStdoutContains, runExecutorStage, validateStageContractAcceptance, } from "./runtime.js";
7
+ import { formatInterfaceWorkflowStageStep, getInterfaceWorkflow, getWorkflowStagePolicyNotes, resolveInterfaceWorkflowFromConfig, } from "./workflow-definitions.js";
8
+ import { validateInterfaceRetrieve, validateInterfacePlan, } from "./validate.js";
9
+ import { reportLine, reportBlankLine, reportValidationFailure, buildLocalSkillContractExtension, buildLocalSkillContractExtensionRelativeTo, mergeLocalSkillContractExtensions, emptyLocalSkillContractExtension, buildStageInstructions, bundledSkillForContractType, resolveStageAcceptance, validateStageOutcome, workflowCreateDirectory, workflowQueryDirectory, workflowCompileStageDirectory, } from "./workflow-helpers.js";
10
+ // ---------------------------------------------------------------------------
11
+ // Interface-specific helpers
12
+ // ---------------------------------------------------------------------------
13
+ export function resolveInterfaceContext(knowledgeBasePath) {
14
+ const config = readInterfConfig(knowledgeBasePath);
15
+ const workflowId = resolveInterfaceWorkflowFromConfig(config);
16
+ const connectedKnowledgeBasePath = resolveInterfaceKnowledgeBasePath(knowledgeBasePath);
17
+ return {
18
+ knowledgeBaseName: config?.name ?? "interface",
19
+ connectedKnowledgeBasePath,
20
+ sourcePath: connectedKnowledgeBasePath ? resolveKnowledgeBaseSourcePath(connectedKnowledgeBasePath) : null,
21
+ workflowId,
22
+ };
23
+ }
24
+ export function interfaceExecutionStages(workflowId, interfacePath) {
25
+ return getInterfaceWorkflow(workflowId, { workspacePath: interfacePath }).stages;
26
+ }
27
+ export function isRetrieveStageComplete(dirPath) {
28
+ const validation = validateInterfaceRetrieve(dirPath);
29
+ return validation.required && validation.ok;
30
+ }
31
+ // ---------------------------------------------------------------------------
32
+ // Interface contract builders
33
+ // ---------------------------------------------------------------------------
34
+ function buildInterfaceCreateContract(options) {
35
+ const connectedKnowledgeBasePath = resolveInterfaceKnowledgeBasePath(options.knowledgeBasePath);
36
+ const workflowSourcePath = connectedKnowledgeBasePath
37
+ ? resolveKnowledgeBaseSourcePath(connectedKnowledgeBasePath)
38
+ : undefined;
39
+ const workflow = getInterfaceWorkflow(options.workflow, {
40
+ sourcePath: workflowSourcePath,
41
+ workspacePath: options.knowledgeBasePath,
42
+ });
43
+ const localSkills = mergeLocalSkillContractExtensions([
44
+ connectedKnowledgeBasePath
45
+ ? buildLocalSkillContractExtensionRelativeTo(connectedKnowledgeBasePath, options.knowledgeBasePath, [workflowQueryDirectory()], "Use the connected knowledge-base workflow docs as higher-level knowledge-base guidance only if they materially improve the interface scaffold.")
46
+ : emptyLocalSkillContractExtension(),
47
+ buildLocalSkillContractExtension(options.knowledgeBasePath, [workflowCreateDirectory()], "Use the interface workflow's local create docs as scaffolding heuristics only if they materially improve the interface setup."),
48
+ ]);
49
+ return {
50
+ instructions: options.instructions,
51
+ counts: {
52
+ workflow_selected: 1,
53
+ local_skill_docs: localSkills.count,
54
+ },
55
+ artifacts: {
56
+ reads: [
57
+ "AGENTS.md",
58
+ "home.md",
59
+ "../../AGENTS.md",
60
+ "../../interf.json",
61
+ "../../home.md",
62
+ "../../knowledge/",
63
+ "../../summaries/",
64
+ ...localSkills.reads,
65
+ ],
66
+ writes: [
67
+ "interf.json",
68
+ "compile-plan.md",
69
+ "AGENTS.md",
70
+ "CLAUDE.md",
71
+ ],
72
+ verifies: [
73
+ "interf verify interface-plan --json",
74
+ ],
75
+ },
76
+ policies: {
77
+ execution_mode: "deterministic",
78
+ status_prefixes: ["STATUS:", "DONE:", "BLOCKED:", "ERROR:"],
79
+ notes: [
80
+ `Interface name: ${options.name}.`,
81
+ `Selected workflow: ${workflow.id} (${workflow.label}).`,
82
+ `Workflow stages: ${workflow.stages.map((stage) => `${stage.label} [${stage.id}]`).join(" -> ")}.`,
83
+ `Use case: ${options.useCase}.`,
84
+ `Connected knowledge-base: ${options.knowledgeBaseName} at ${connectedKnowledgeBasePath ?? "unknown"}.`,
85
+ "The scaffold already exists with home.md, AGENTS.md, CLAUDE.md, interf.json, and the .interf runtime artifacts.",
86
+ "Read the current local AGENTS.md and home.md first. They are the interface workspace bootstrap you are updating.",
87
+ "Then consult ../../AGENTS.md and ../../home.md for parent knowledge-base navigation and evidence structure.",
88
+ "This interface lives inside the parent knowledgeBase. Do not assume it will be opened as a standalone Obsidian vault.",
89
+ "Do not recreate the vault or ask follow-up questions.",
90
+ "Use the selected workflow as the starting point, then adapt it to the knowledge-base data and the use case.",
91
+ "Edit the existing compile-plan.md scaffold in place. Preserve the stage headings and required subsection labels from the starter plan; refine the bullets and narrative instead of replacing the structure.",
92
+ "Preserve the existing AGENTS.md scaffold sections, especially the manual access checklist, raw-source gate, and navigation/router guidance. Update only the interface-specific description and lines that must reflect the use case.",
93
+ "Do not replace AGENTS.md with a shorter template.",
94
+ "Analyze the knowledge-base and update only the interface definition files in this vault: interf.json, compile-plan.md, and AGENTS.md. CLAUDE.md is a generated mirror of AGENTS.md and will be rewritten by the harness.",
95
+ ...localSkills.notes,
96
+ ],
97
+ },
98
+ };
99
+ }
100
+ export function buildInterfaceRetrieveContract(interfacePath, workflowId, summaryCount, instructions, stageId = "retrieve", stageSkillDir = "retrieve") {
101
+ const connectedKnowledgeBasePath = resolveInterfaceKnowledgeBasePath(interfacePath);
102
+ const sourcePath = connectedKnowledgeBasePath ? resolveKnowledgeBaseSourcePath(connectedKnowledgeBasePath) : undefined;
103
+ const acceptance = resolveStageAcceptance("interface", workflowId, stageId, sourcePath, interfacePath);
104
+ const localSkills = mergeLocalSkillContractExtensions([
105
+ connectedKnowledgeBasePath
106
+ ? buildLocalSkillContractExtensionRelativeTo(connectedKnowledgeBasePath, interfacePath, [workflowQueryDirectory()], "Use the connected knowledge-base workflow docs as higher-level knowledge-base guidance before applying interface-local retrieve rules.")
107
+ : emptyLocalSkillContractExtension(),
108
+ buildLocalSkillContractExtension(interfacePath, [workflowCompileStageDirectory(stageSkillDir)], "Use interface-local docs to refine filters, expansion heuristics, ranking, and ontology hints."),
109
+ ]);
110
+ return {
111
+ instructions,
112
+ counts: {
113
+ knowledge_base_summary_total: summaryCount,
114
+ local_skill_docs: localSkills.count,
115
+ },
116
+ ...(acceptance ? { acceptance } : {}),
117
+ artifacts: {
118
+ reads: [
119
+ "AGENTS.md",
120
+ "home.md",
121
+ "../../AGENTS.md",
122
+ "../../home.md",
123
+ "interf.json",
124
+ "compile-plan.md",
125
+ "../../.interf/source-access.json",
126
+ "../../summaries/",
127
+ ".interf/state.json",
128
+ ...localSkills.reads,
129
+ ],
130
+ writes: [
131
+ ".interf/relevant.json",
132
+ ".interf/coverage.json",
133
+ ".interf/state.json",
134
+ ".interf/health.json",
135
+ ],
136
+ verifies: [
137
+ "interf verify retrieve --json",
138
+ ],
139
+ },
140
+ policies: {
141
+ execution_mode: "deterministic",
142
+ status_prefixes: ["STATUS:", "DONE:", "BLOCKED:", "ERROR:"],
143
+ notes: [
144
+ "Read local `AGENTS.md` first, then consult parent knowledge-base `../../AGENTS.md` and `../../home.md` before considering raw-source fallback.",
145
+ "Access hierarchy for this stage is: local interface artifacts -> parent knowledge-base artifacts -> raw source files only when needed.",
146
+ "Treat the interface runtime in compile-plan.md as an initial hypothesis, not a final truth.",
147
+ "Scan ALL knowledge-base summaries frontmatter before making any selection.",
148
+ "Review abstracts for the candidate set, expand through linked summaries when needed, and stop only when the retrieved set is coverage-complete for this interface.",
149
+ "Selection quality is judged by the proof of reviewed, retrieved, and excluded files, not by superficial brevity.",
150
+ "If you need raw-file fallback, inspect `../../.interf/source-access.json` first and verify one suggested path is readable. These are canonical absolute source-file paths shared by the parent knowledge base. If they are not reachable, continue from knowledge-base summaries and report that raw fallback was unavailable.",
151
+ ...getWorkflowStagePolicyNotes("interface", workflowId, stageId, sourcePath, interfacePath),
152
+ ...localSkills.notes,
153
+ ],
154
+ evidence_weighting: {
155
+ required_fields: ["source_kind", "evidence_tier", "truth_mode", "state"],
156
+ preserve_tiers: true,
157
+ },
158
+ working_set: {
159
+ target_context_fraction: 0.15,
160
+ strategy: "Frontmatter scan first, then abstract review, then linked expansion only where coverage proof requires it.",
161
+ },
162
+ },
163
+ };
164
+ }
165
+ export function buildInterfaceAnalyzeContract(interfacePath, workflowId, analyzeCount, instructions, stageId = "analyze", stageSkillDir = "analyze") {
166
+ const connectedKnowledgeBasePath = resolveInterfaceKnowledgeBasePath(interfacePath);
167
+ const sourcePath = connectedKnowledgeBasePath ? resolveKnowledgeBaseSourcePath(connectedKnowledgeBasePath) : undefined;
168
+ const acceptance = resolveStageAcceptance("interface", workflowId, stageId, sourcePath, interfacePath);
169
+ const localSkills = mergeLocalSkillContractExtensions([
170
+ connectedKnowledgeBasePath
171
+ ? buildLocalSkillContractExtensionRelativeTo(connectedKnowledgeBasePath, interfacePath, [workflowQueryDirectory()], "Use the connected knowledge-base workflow docs as higher-level knowledge-base guidance before applying interface-local analyze rules.")
172
+ : emptyLocalSkillContractExtension(),
173
+ buildLocalSkillContractExtension(interfacePath, [workflowCompileStageDirectory(stageSkillDir)], "Use interface-local docs to refine the interface ontology, extraction schema, and evidence grouping."),
174
+ ]);
175
+ return {
176
+ instructions,
177
+ counts: {
178
+ relevant_total: analyzeCount,
179
+ local_skill_docs: localSkills.count,
180
+ },
181
+ ...(acceptance ? { acceptance } : {}),
182
+ artifacts: {
183
+ reads: [
184
+ "AGENTS.md",
185
+ "home.md",
186
+ "../../AGENTS.md",
187
+ "../../home.md",
188
+ "interf.json",
189
+ "compile-plan.md",
190
+ ".interf/relevant.json",
191
+ "../../.interf/source-access.json",
192
+ "../../summaries/",
193
+ ".interf/state.json",
194
+ ...localSkills.reads,
195
+ ],
196
+ writes: [
197
+ ".interf/analysis.json",
198
+ ".interf/state.json",
199
+ ".interf/health.json",
200
+ ],
201
+ verifies: [],
202
+ },
203
+ policies: {
204
+ execution_mode: "deterministic",
205
+ status_prefixes: ["STATUS:", "DONE:", "BLOCKED:", "ERROR:"],
206
+ notes: [
207
+ "Read local `AGENTS.md` first, then consult parent knowledge-base `../../AGENTS.md` and `../../home.md` before considering raw-source fallback.",
208
+ "Access hierarchy for this stage is: local interface artifacts -> parent knowledge-base artifacts -> raw source files only when needed.",
209
+ "This is the deep extraction pass over the relevant set selected by retrieve.",
210
+ "Refine the interface runtime from evidence when the knowledge base clearly demands it.",
211
+ "Keep extraction local to the interface ontology and output goals.",
212
+ "If you need raw-file fallback, inspect `../../.interf/source-access.json` first and verify one suggested path is readable. These are canonical absolute source-file paths shared by the parent knowledge base. If they are not reachable, continue from knowledge-base summaries and report that raw fallback was unavailable.",
213
+ ...getWorkflowStagePolicyNotes("interface", workflowId, stageId, sourcePath, interfacePath),
214
+ ...localSkills.notes,
215
+ ],
216
+ evidence_weighting: {
217
+ required_fields: ["source_kind", "evidence_tier", "truth_mode", "state"],
218
+ preserve_tiers: true,
219
+ },
220
+ working_set: {
221
+ target_context_fraction: 0.3,
222
+ strategy: "Batch relevant summaries into bounded sets, derive local entities/claims, then merge before writing analysis artifacts.",
223
+ },
224
+ },
225
+ };
226
+ }
227
+ export function buildInterfaceCompileContract(interfacePath, workflowId, relevantCount, instructions, stageId = "compile", stageSkillDir = "compile") {
228
+ const connectedKnowledgeBasePath = resolveInterfaceKnowledgeBasePath(interfacePath);
229
+ const sourcePath = connectedKnowledgeBasePath ? resolveKnowledgeBaseSourcePath(connectedKnowledgeBasePath) : undefined;
230
+ const acceptance = resolveStageAcceptance("interface", workflowId, stageId, sourcePath, interfacePath);
231
+ const localSkills = mergeLocalSkillContractExtensions([
232
+ connectedKnowledgeBasePath
233
+ ? buildLocalSkillContractExtensionRelativeTo(connectedKnowledgeBasePath, interfacePath, [workflowQueryDirectory()], "Use the connected knowledge-base workflow docs as higher-level knowledge-base guidance before applying interface-local compile rules.")
234
+ : emptyLocalSkillContractExtension(),
235
+ buildLocalSkillContractExtension(interfacePath, [workflowCompileStageDirectory(stageSkillDir)], "Use interface-local docs to refine the output inventory, navigation, canvases, and final interface shape."),
236
+ ]);
237
+ return {
238
+ instructions,
239
+ counts: {
240
+ relevant_total: relevantCount,
241
+ local_skill_docs: localSkills.count,
242
+ },
243
+ ...(acceptance ? { acceptance } : {}),
244
+ artifacts: {
245
+ reads: [
246
+ "AGENTS.md",
247
+ "home.md",
248
+ "../../AGENTS.md",
249
+ "../../home.md",
250
+ "interf.json",
251
+ "compile-plan.md",
252
+ ".interf/analysis.json",
253
+ ".interf/relevant.json",
254
+ "../../.interf/source-access.json",
255
+ "../../summaries/",
256
+ ...localSkills.reads,
257
+ ],
258
+ writes: [
259
+ "knowledge/",
260
+ "briefs/",
261
+ "summaries/",
262
+ "home.md",
263
+ ".interf/state.json",
264
+ ".interf/health.json",
265
+ ],
266
+ verifies: [],
267
+ },
268
+ policies: {
269
+ execution_mode: "deterministic",
270
+ status_prefixes: ["STATUS:", "DONE:", "BLOCKED:", "ERROR:"],
271
+ notes: [
272
+ "Read local `AGENTS.md` first, then consult parent knowledge-base `../../AGENTS.md` and `../../home.md` before considering raw-source fallback.",
273
+ "Access hierarchy for this stage is: local interface artifacts -> parent knowledge-base artifacts -> raw source files only when needed.",
274
+ "The interface is a local context shell for agents. Build it so an agent can navigate AGENTS.md -> home.md -> local knowledge/briefs/summaries -> knowledge-base summaries -> raw only when needed.",
275
+ "When local outputs cite knowledge-base evidence, point to the parent knowledge-base summary path `../../summaries/...`, not the interface-local `summaries/` folder.",
276
+ "Prefer durable local notes and indexes over monolithic summaries.",
277
+ "Delete stale analysis handoff artifacts once durable outputs and state have been written.",
278
+ "If you need raw-file fallback, inspect `../../.interf/source-access.json` first and verify one suggested path is readable. These are canonical absolute source-file paths shared by the parent knowledge base. If they are not reachable, continue from knowledge-base summaries and report that raw fallback was unavailable.",
279
+ ...getWorkflowStagePolicyNotes("interface", workflowId, stageId, sourcePath, interfacePath),
280
+ ...localSkills.notes,
281
+ ],
282
+ evidence_weighting: {
283
+ required_fields: ["source_kind", "evidence_tier", "truth_mode", "state"],
284
+ preserve_tiers: true,
285
+ },
286
+ working_set: {
287
+ target_context_fraction: 0.25,
288
+ strategy: "Use analysis artifacts as the compile ledger, then write entities, claims, briefs, and navigation in separate local passes.",
289
+ },
290
+ },
291
+ };
292
+ }
293
+ // ---------------------------------------------------------------------------
294
+ // Interface orchestration functions
295
+ // ---------------------------------------------------------------------------
296
+ export async function planInterface(options) {
297
+ const connectedKnowledgeBasePath = resolveInterfaceKnowledgeBasePath(options.knowledgeBasePath);
298
+ const interfaceWorkflow = resolveInterfaceWorkflowFromConfig(readInterfConfig(options.knowledgeBasePath));
299
+ const instructions = buildStageInstructions("interface/create", mergeLocalSkillContractExtensions([
300
+ connectedKnowledgeBasePath
301
+ ? buildLocalSkillContractExtensionRelativeTo(connectedKnowledgeBasePath, options.knowledgeBasePath, [workflowQueryDirectory()], "Use the connected knowledge-base workflow docs as higher-level guidance only if they materially improve the interface scaffold.")
302
+ : emptyLocalSkillContractExtension(),
303
+ buildLocalSkillContractExtension(options.knowledgeBasePath, [workflowCreateDirectory()], "Use the interface workflow's local create docs as scaffolding heuristics only if they materially improve the interface setup."),
304
+ ]));
305
+ const code = await runExecutorStage({
306
+ executor: options.executor,
307
+ knowledgeBasePath: options.knowledgeBasePath,
308
+ targetType: "interface",
309
+ knowledgeBaseName: options.name,
310
+ workflow: interfaceWorkflow,
311
+ workflowSourcePath: connectedKnowledgeBasePath ? resolveKnowledgeBaseSourcePath(connectedKnowledgeBasePath) : undefined,
312
+ stage: "create-interface",
313
+ stageLabel: "Create Interface",
314
+ contractType: "interface-plan",
315
+ summary: `Designing the initial runtime hypothesis for the ${options.name} interface.`,
316
+ contract: buildInterfaceCreateContract({
317
+ name: options.name,
318
+ workflow: options.workflow,
319
+ useCase: options.useCase,
320
+ knowledgeBaseName: options.knowledgeBaseName,
321
+ knowledgeBasePath: options.knowledgeBasePath,
322
+ instructions,
323
+ }),
324
+ buildPrompt: (contractPath) => buildStagePrompt(instructions, contractPath, [
325
+ "Emit exactly one startup line: STATUS: loaded interface creation contract.",
326
+ "Emit STATUS: analyzed knowledge-base when the scaffold inputs and knowledge-base evidence have been reviewed.",
327
+ "Emit STATUS: wrote compile plan after interf.json and compile-plan.md are updated and AGENTS.md still preserves the scaffold router/checklist.",
328
+ "Emit DONE: interface create complete when the scaffold is ready for `interf compile`.",
329
+ ]),
330
+ });
331
+ syncClaudeBootstrap(options.knowledgeBasePath);
332
+ const validation = validateInterfacePlan(options.knowledgeBasePath);
333
+ const emittedDone = runtimeRunStdoutContains(options.knowledgeBasePath, "DONE: interface create complete");
334
+ if (validation.ok && (code === 0 || emittedDone)) {
335
+ if (code !== 0) {
336
+ markRuntimeRunSucceededAfterValidation(options.knowledgeBasePath, "create-interface completed successfully.");
337
+ }
338
+ return {
339
+ ok: true,
340
+ code: 0,
341
+ summary: validation.summary,
342
+ };
343
+ }
344
+ if (!validation.ok) {
345
+ markRuntimeRunFailedAfterValidation(options.knowledgeBasePath, validation.summary);
346
+ }
347
+ return {
348
+ ok: false,
349
+ code,
350
+ summary: validation.summary,
351
+ };
352
+ }
353
+ export async function runInterfaceRetrieve(options) {
354
+ const context = resolveInterfaceContext(options.knowledgeBasePath);
355
+ const sourcePath = options.sourcePath ?? context.sourcePath ?? resolveKnowledgeBaseSourcePath(resolveInterfaceKnowledgeBasePath(options.knowledgeBasePath) ?? options.knowledgeBasePath);
356
+ const workflowId = context.workflowId;
357
+ const connectedKnowledgeBasePath = context.connectedKnowledgeBasePath;
358
+ const stageDefinition = options.stageDefinition ?? interfaceExecutionStages(workflowId, options.knowledgeBasePath).find((stage) => stage.contractType === "interface-retrieval");
359
+ const stageStatusLabel = stageDefinition.label.toLowerCase();
360
+ const knowledgeBaseSummaryTotal = connectedKnowledgeBasePath ? countFilesRecursive(join(connectedKnowledgeBasePath, "summaries")) : 0;
361
+ if (options.reportStep !== false) {
362
+ reportLine(options.reporter, formatInterfaceWorkflowStageStep(workflowId, stageDefinition.id, { sourcePath }));
363
+ }
364
+ const instructions = buildStageInstructions(bundledSkillForContractType(stageDefinition.contractType), mergeLocalSkillContractExtensions([
365
+ connectedKnowledgeBasePath
366
+ ? buildLocalSkillContractExtensionRelativeTo(connectedKnowledgeBasePath, options.knowledgeBasePath, [workflowQueryDirectory()], "Use the connected knowledge-base workflow docs as higher-level knowledge-base guidance before applying interface-local retrieve rules.")
367
+ : emptyLocalSkillContractExtension(),
368
+ buildLocalSkillContractExtension(options.knowledgeBasePath, [workflowCompileStageDirectory(stageDefinition.skillDir)], "Use interface-local docs to refine filters, expansion heuristics, ranking, and ontology hints."),
369
+ ]));
370
+ const code = await runExecutorStage({
371
+ executor: options.executor,
372
+ knowledgeBasePath: options.knowledgeBasePath,
373
+ targetType: "interface",
374
+ knowledgeBaseName: context.knowledgeBaseName,
375
+ workflow: workflowId,
376
+ workflowSourcePath: sourcePath,
377
+ stage: stageDefinition.id,
378
+ stageLabel: stageDefinition.label,
379
+ contractType: stageDefinition.contractType,
380
+ summary: `Preparing ${stageDefinition.label.toLowerCase()} across ${knowledgeBaseSummaryTotal} knowledge-base summaries.`,
381
+ contract: buildInterfaceRetrieveContract(options.knowledgeBasePath, workflowId, knowledgeBaseSummaryTotal, instructions, stageDefinition.id, stageDefinition.skillDir),
382
+ buildPrompt: (contractPath) => buildStagePrompt(instructions, contractPath, [
383
+ `Emit exactly one startup line: STATUS: loaded ${stageStatusLabel} plan ${knowledgeBaseSummaryTotal} summary files.`,
384
+ `Emit STATUS: scanned X/${knowledgeBaseSummaryTotal} after each scan batch or every 250 files, whichever comes first.`,
385
+ "Emit STATUS: reviewed A abstracts, P expansion passes after the candidate-review phase is complete.",
386
+ "Emit STATUS: selected R relevant, J rejected, D delta after filters are applied and the retrieved set is finalized.",
387
+ `Emit DONE: ${stageStatusLabel} complete when \`.interf/relevant.json\`, \`.interf/coverage.json\`, and \`.interf/state.json\` are updated.`,
388
+ ]),
389
+ completionCheck: () => isRetrieveStageComplete(options.knowledgeBasePath) &&
390
+ validateStageContractAcceptance(options.knowledgeBasePath).ok,
391
+ });
392
+ if (code !== 0) {
393
+ return {
394
+ ok: false,
395
+ code,
396
+ knowledgeBaseSummaryTotal,
397
+ relevantCount: 0,
398
+ deltaCount: 0,
399
+ analyzeCount: 0,
400
+ };
401
+ }
402
+ refreshInterfaceArtifacts(options.knowledgeBasePath, { ensureViewSpec: true });
403
+ const validation = validateStageOutcome(options.knowledgeBasePath, validateInterfaceRetrieve(options.knowledgeBasePath));
404
+ if (!validation.ok) {
405
+ reportValidationFailure(options.reporter, validation.summary);
406
+ markRuntimeRunFailedAfterValidation(options.knowledgeBasePath, validation.summary);
407
+ }
408
+ const queryState = loadState(options.knowledgeBasePath);
409
+ const relevantCount = queryState?.relevant_count ?? 0;
410
+ const deltaCount = queryState?.delta_count ?? relevantCount;
411
+ const analyzeCount = deltaCount > 0 ? deltaCount : relevantCount;
412
+ return {
413
+ ok: validation.ok,
414
+ code: validation.ok ? 0 : 1,
415
+ knowledgeBaseSummaryTotal,
416
+ relevantCount,
417
+ deltaCount,
418
+ analyzeCount,
419
+ };
420
+ }
421
+ export async function runInterfaceAnalyze(options) {
422
+ const interfaceConfig = readInterfConfig(options.knowledgeBasePath);
423
+ const knowledgeBaseName = interfaceConfig?.name ?? "interface";
424
+ const workflowId = resolveInterfaceWorkflowFromConfig(interfaceConfig);
425
+ const connectedKnowledgeBasePath = resolveInterfaceKnowledgeBasePath(options.knowledgeBasePath);
426
+ const sourcePath = options.sourcePath ?? (connectedKnowledgeBasePath ? resolveKnowledgeBaseSourcePath(connectedKnowledgeBasePath) : options.knowledgeBasePath);
427
+ const stageDefinition = options.stageDefinition ?? interfaceExecutionStages(workflowId, options.knowledgeBasePath).find((stage) => stage.contractType === "interface-analysis");
428
+ const stageStatusLabel = stageDefinition.label.toLowerCase();
429
+ const queryState = loadState(options.knowledgeBasePath);
430
+ const relevantCount = queryState?.relevant_count ?? 0;
431
+ const deltaCount = queryState?.delta_count ?? relevantCount;
432
+ const analyzeCount = deltaCount > 0 ? deltaCount : relevantCount;
433
+ if (options.reportStep !== false) {
434
+ reportBlankLine(options.reporter);
435
+ reportLine(options.reporter, `${formatInterfaceWorkflowStageStep(workflowId, stageDefinition.id, { sourcePath })}${analyzeCount > 0 ? ` (${analyzeCount} files)` : ""}`);
436
+ }
437
+ const instructions = buildStageInstructions(bundledSkillForContractType(stageDefinition.contractType), mergeLocalSkillContractExtensions([
438
+ connectedKnowledgeBasePath
439
+ ? buildLocalSkillContractExtensionRelativeTo(connectedKnowledgeBasePath, options.knowledgeBasePath, [workflowQueryDirectory()], "Use the connected knowledge-base workflow docs as higher-level knowledge-base guidance before applying interface-local analyze rules.")
440
+ : emptyLocalSkillContractExtension(),
441
+ buildLocalSkillContractExtension(options.knowledgeBasePath, [workflowCompileStageDirectory(stageDefinition.skillDir)], "Use interface-local docs to refine the interface ontology, extraction schema, and evidence grouping."),
442
+ ]));
443
+ const code = await runExecutorStage({
444
+ executor: options.executor,
445
+ knowledgeBasePath: options.knowledgeBasePath,
446
+ targetType: "interface",
447
+ knowledgeBaseName,
448
+ workflow: workflowId,
449
+ workflowSourcePath: sourcePath,
450
+ stage: stageDefinition.id,
451
+ stageLabel: stageDefinition.label,
452
+ contractType: stageDefinition.contractType,
453
+ summary: `Preparing ${stageDefinition.label.toLowerCase()} for ${analyzeCount} interface summaries.`,
454
+ contract: buildInterfaceAnalyzeContract(options.knowledgeBasePath, workflowId, analyzeCount, instructions, stageDefinition.id, stageDefinition.skillDir),
455
+ buildPrompt: (contractPath) => buildStagePrompt(instructions, contractPath, [
456
+ `Emit exactly one startup line: STATUS: loaded ${stageStatusLabel} plan ${analyzeCount} files.`,
457
+ `Emit STATUS: analyzed X/${analyzeCount} after each batch or every 25 files, whichever comes first.`,
458
+ `Emit STATUS: wrote ${stageStatusLabel} outputs after \`.interf/analysis.json\` is updated.`,
459
+ `Emit DONE: ${stageStatusLabel} complete when state reflects the finished extraction pass.`,
460
+ ]),
461
+ completionCheck: () => {
462
+ const state = loadState(options.knowledgeBasePath);
463
+ return Boolean(state?.analyze_complete &&
464
+ existsSync(join(options.knowledgeBasePath, ".interf", "analysis.json")) &&
465
+ validateStageContractAcceptance(options.knowledgeBasePath).ok);
466
+ },
467
+ });
468
+ if (code === 0) {
469
+ refreshInterfaceArtifacts(options.knowledgeBasePath, { ensureViewSpec: true });
470
+ }
471
+ const acceptance = code === 0
472
+ ? validateStageContractAcceptance(options.knowledgeBasePath)
473
+ : { ok: false, summary: "Stage execution failed before acceptance validation." };
474
+ if (code === 0 && !acceptance.ok) {
475
+ reportValidationFailure(options.reporter, acceptance.summary);
476
+ markRuntimeRunFailedAfterValidation(options.knowledgeBasePath, acceptance.summary);
477
+ }
478
+ return {
479
+ ok: code === 0 && acceptance.ok,
480
+ code: code === 0 && acceptance.ok ? 0 : 1,
481
+ relevantCount,
482
+ deltaCount,
483
+ analyzeCount,
484
+ };
485
+ }
486
+ export async function runInterfaceCompileStage(options) {
487
+ const interfaceConfig = readInterfConfig(options.knowledgeBasePath);
488
+ const knowledgeBaseName = interfaceConfig?.name ?? "interface";
489
+ const workflowId = resolveInterfaceWorkflowFromConfig(interfaceConfig);
490
+ const connectedKnowledgeBasePath = resolveInterfaceKnowledgeBasePath(options.knowledgeBasePath);
491
+ const sourcePath = options.sourcePath ?? (connectedKnowledgeBasePath ? resolveKnowledgeBaseSourcePath(connectedKnowledgeBasePath) : options.knowledgeBasePath);
492
+ const stageDefinition = options.stageDefinition ?? interfaceExecutionStages(workflowId, options.knowledgeBasePath).find((stage) => stage.contractType === "interface-output");
493
+ const stageStatusLabel = stageDefinition.label.toLowerCase();
494
+ const relevantCount = loadState(options.knowledgeBasePath)?.relevant_count ?? 0;
495
+ if (options.reportStep !== false) {
496
+ reportBlankLine(options.reporter);
497
+ reportLine(options.reporter, formatInterfaceWorkflowStageStep(workflowId, stageDefinition.id, { sourcePath }));
498
+ }
499
+ const instructions = buildStageInstructions(bundledSkillForContractType(stageDefinition.contractType), mergeLocalSkillContractExtensions([
500
+ connectedKnowledgeBasePath
501
+ ? buildLocalSkillContractExtensionRelativeTo(connectedKnowledgeBasePath, options.knowledgeBasePath, [workflowQueryDirectory()], "Use the connected knowledge-base workflow docs as higher-level knowledge-base guidance before applying interface-local compile rules.")
502
+ : emptyLocalSkillContractExtension(),
503
+ buildLocalSkillContractExtension(options.knowledgeBasePath, [workflowCompileStageDirectory(stageDefinition.skillDir)], "Use interface-local docs to refine the output inventory, navigation, canvases, and final interface shape."),
504
+ ]));
505
+ const code = await runExecutorStage({
506
+ executor: options.executor,
507
+ knowledgeBasePath: options.knowledgeBasePath,
508
+ targetType: "interface",
509
+ knowledgeBaseName,
510
+ workflow: workflowId,
511
+ workflowSourcePath: sourcePath,
512
+ stage: stageDefinition.id,
513
+ stageLabel: stageDefinition.label,
514
+ contractType: stageDefinition.contractType,
515
+ summary: `Preparing ${stageDefinition.label.toLowerCase()} from ${relevantCount} relevant files.`,
516
+ contract: buildInterfaceCompileContract(options.knowledgeBasePath, workflowId, relevantCount, instructions, stageDefinition.id, stageDefinition.skillDir),
517
+ buildPrompt: (contractPath) => buildStagePrompt(instructions, contractPath, [
518
+ `Emit exactly one startup line: STATUS: loaded ${stageStatusLabel} plan ${relevantCount} relevant files.`,
519
+ "Emit STATUS: wrote entities X after the entity pass completes.",
520
+ "Emit STATUS: wrote claims Y after the claim pass completes.",
521
+ `Emit STATUS: wrote ${stageStatusLabel} outputs after local notes and home.md are updated.`,
522
+ `Emit DONE: ${stageStatusLabel} complete when state is updated and temporary analysis artifacts are cleaned up.`,
523
+ ]),
524
+ completionCheck: () => computeInterfaceHealth(options.knowledgeBasePath).status === "compiled" &&
525
+ validateStageContractAcceptance(options.knowledgeBasePath).ok,
526
+ });
527
+ if (code === 0) {
528
+ refreshInterfaceArtifacts(options.knowledgeBasePath, { ensureViewSpec: true });
529
+ }
530
+ const acceptance = code === 0
531
+ ? validateStageContractAcceptance(options.knowledgeBasePath)
532
+ : { ok: false, summary: "Stage execution failed before acceptance validation." };
533
+ if (code === 0 && !acceptance.ok) {
534
+ reportValidationFailure(options.reporter, acceptance.summary);
535
+ markRuntimeRunFailedAfterValidation(options.knowledgeBasePath, acceptance.summary);
536
+ }
537
+ return {
538
+ ok: code === 0 && acceptance.ok,
539
+ code: code === 0 && acceptance.ok ? 0 : 1,
540
+ relevantCount,
541
+ };
542
+ }
543
+ export async function compileInterface(options) {
544
+ refreshWorkspaceBootstrapGuidance(options.knowledgeBasePath);
545
+ const context = resolveInterfaceContext(options.knowledgeBasePath);
546
+ const sourcePath = context.sourcePath ?? (context.connectedKnowledgeBasePath ? resolveKnowledgeBaseSourcePath(context.connectedKnowledgeBasePath) : options.knowledgeBasePath);
547
+ const stages = interfaceExecutionStages(context.workflowId, options.knowledgeBasePath);
548
+ let retrieve = {
549
+ ok: true,
550
+ code: 0,
551
+ knowledgeBaseSummaryTotal: 0,
552
+ relevantCount: 0,
553
+ deltaCount: 0,
554
+ analyzeCount: 0,
555
+ };
556
+ let analyze = null;
557
+ let compile = null;
558
+ for (const stageDefinition of stages) {
559
+ if (stageDefinition.contractType === "interface-retrieval") {
560
+ retrieve = await runInterfaceRetrieve({
561
+ executor: options.executor,
562
+ knowledgeBasePath: options.knowledgeBasePath,
563
+ sourcePath,
564
+ reporter: options.reporter,
565
+ reportStep: true,
566
+ stageDefinition,
567
+ });
568
+ if (!retrieve.ok) {
569
+ return {
570
+ ok: false,
571
+ retrieve,
572
+ analyze: null,
573
+ compile: null,
574
+ failedStage: stageDefinition.id,
575
+ };
576
+ }
577
+ continue;
578
+ }
579
+ if (stageDefinition.contractType === "interface-analysis") {
580
+ analyze = await runInterfaceAnalyze({
581
+ executor: options.executor,
582
+ knowledgeBasePath: options.knowledgeBasePath,
583
+ sourcePath,
584
+ reporter: options.reporter,
585
+ reportStep: true,
586
+ stageDefinition,
587
+ });
588
+ if (!analyze.ok) {
589
+ return {
590
+ ok: false,
591
+ retrieve,
592
+ analyze,
593
+ compile: null,
594
+ failedStage: stageDefinition.id,
595
+ };
596
+ }
597
+ continue;
598
+ }
599
+ compile = await runInterfaceCompileStage({
600
+ executor: options.executor,
601
+ knowledgeBasePath: options.knowledgeBasePath,
602
+ sourcePath,
603
+ reporter: options.reporter,
604
+ reportStep: true,
605
+ stageDefinition,
606
+ });
607
+ if (!compile.ok) {
608
+ return {
609
+ ok: false,
610
+ retrieve,
611
+ analyze,
612
+ compile,
613
+ failedStage: stageDefinition.id,
614
+ };
615
+ }
616
+ }
617
+ return {
618
+ ok: compile?.ok ?? analyze?.ok ?? retrieve.ok,
619
+ retrieve,
620
+ analyze,
621
+ compile,
622
+ failedStage: null,
623
+ };
624
+ }
625
+ //# sourceMappingURL=workflows-interface.js.map