@interf/compiler 0.4.0 → 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.
Files changed (160) hide show
  1. package/README.md +71 -69
  2. package/builtin-workflows/interf/README.md +6 -6
  3. package/builtin-workflows/interf/compile/stages/shape/SKILL.md +7 -7
  4. package/builtin-workflows/interf/compile/stages/structure/SKILL.md +2 -2
  5. package/builtin-workflows/interf/compile/stages/summarize/SKILL.md +1 -1
  6. package/builtin-workflows/interf/{workspace.schema.json → compiled.schema.json} +5 -5
  7. package/builtin-workflows/interf/improve/SKILL.md +3 -3
  8. package/builtin-workflows/interf/use/query/SKILL.md +2 -2
  9. package/builtin-workflows/interf/workflow.json +42 -31
  10. package/dist/commands/check-draft.d.ts +19 -0
  11. package/dist/commands/check-draft.js +110 -0
  12. package/dist/commands/compile-controller.d.ts +4 -4
  13. package/dist/commands/compile-controller.js +117 -81
  14. package/dist/commands/compile.d.ts +5 -5
  15. package/dist/commands/compile.js +61 -62
  16. package/dist/commands/compiled-flow.d.ts +23 -0
  17. package/dist/commands/compiled-flow.js +112 -0
  18. package/dist/commands/create-workflow-wizard.d.ts +3 -3
  19. package/dist/commands/create-workflow-wizard.js +11 -11
  20. package/dist/commands/create.d.ts +2 -2
  21. package/dist/commands/create.js +50 -57
  22. package/dist/commands/default.js +2 -2
  23. package/dist/commands/executor-flow.d.ts +20 -1
  24. package/dist/commands/executor-flow.js +67 -7
  25. package/dist/commands/init.js +242 -289
  26. package/dist/commands/list.js +14 -10
  27. package/dist/commands/reset.js +6 -6
  28. package/dist/commands/source-config-wizard.d.ts +12 -8
  29. package/dist/commands/source-config-wizard.js +356 -119
  30. package/dist/commands/status.js +49 -26
  31. package/dist/commands/test-flow.d.ts +23 -10
  32. package/dist/commands/test-flow.js +278 -58
  33. package/dist/commands/test.d.ts +7 -1
  34. package/dist/commands/test.js +264 -65
  35. package/dist/commands/verify.js +23 -14
  36. package/dist/index.d.ts +7 -7
  37. package/dist/index.js +4 -4
  38. package/dist/lib/agent-args.js +2 -1
  39. package/dist/lib/agent-constants.js +1 -1
  40. package/dist/lib/agent-render.js +4 -4
  41. package/dist/lib/agent-shells.d.ts +8 -8
  42. package/dist/lib/agent-shells.js +231 -142
  43. package/dist/lib/compiled-compile.d.ts +52 -0
  44. package/dist/lib/compiled-compile.js +274 -0
  45. package/dist/lib/compiled-home.d.ts +5 -0
  46. package/dist/lib/compiled-home.js +32 -0
  47. package/dist/lib/compiled-layout.d.ts +2 -0
  48. package/dist/lib/compiled-layout.js +60 -0
  49. package/dist/lib/compiled-paths.d.ts +41 -0
  50. package/dist/lib/compiled-paths.js +111 -0
  51. package/dist/lib/{workspace-raw.d.ts → compiled-raw.d.ts} +8 -7
  52. package/dist/lib/{workspace-raw.js → compiled-raw.js} +16 -14
  53. package/dist/lib/compiled-reset.d.ts +1 -0
  54. package/dist/lib/compiled-reset.js +44 -0
  55. package/dist/lib/compiled-schema.d.ts +27 -0
  56. package/dist/lib/compiled-schema.js +110 -0
  57. package/dist/lib/config.d.ts +0 -1
  58. package/dist/lib/config.js +0 -1
  59. package/dist/lib/discovery.d.ts +1 -1
  60. package/dist/lib/discovery.js +3 -3
  61. package/dist/lib/interf-bootstrap.d.ts +1 -1
  62. package/dist/lib/interf-bootstrap.js +4 -4
  63. package/dist/lib/interf-detect.d.ts +10 -10
  64. package/dist/lib/interf-detect.js +78 -56
  65. package/dist/lib/interf-scaffold.d.ts +2 -2
  66. package/dist/lib/interf-scaffold.js +90 -57
  67. package/dist/lib/interf-workflow-package.d.ts +3 -3
  68. package/dist/lib/interf-workflow-package.js +30 -30
  69. package/dist/lib/interf.d.ts +5 -5
  70. package/dist/lib/interf.js +4 -4
  71. package/dist/lib/local-workflows.d.ts +4 -4
  72. package/dist/lib/local-workflows.js +35 -70
  73. package/dist/lib/obsidian.d.ts +1 -1
  74. package/dist/lib/parse.js +92 -1
  75. package/dist/lib/project-paths.d.ts +13 -0
  76. package/dist/lib/project-paths.js +29 -0
  77. package/dist/lib/runtime-acceptance.d.ts +7 -1
  78. package/dist/lib/runtime-acceptance.js +194 -59
  79. package/dist/lib/runtime-contracts.d.ts +2 -4
  80. package/dist/lib/runtime-contracts.js +17 -161
  81. package/dist/lib/runtime-inventory.d.ts +7 -0
  82. package/dist/lib/runtime-inventory.js +29 -0
  83. package/dist/lib/runtime-paths.js +5 -5
  84. package/dist/lib/runtime-prompt.js +9 -6
  85. package/dist/lib/runtime-reconcile.d.ts +2 -3
  86. package/dist/lib/runtime-reconcile.js +92 -171
  87. package/dist/lib/runtime-runs.js +30 -39
  88. package/dist/lib/runtime-types.d.ts +10 -19
  89. package/dist/lib/runtime.d.ts +2 -2
  90. package/dist/lib/runtime.js +1 -1
  91. package/dist/lib/schema.d.ts +163 -140
  92. package/dist/lib/schema.js +163 -124
  93. package/dist/lib/source-config.d.ts +24 -20
  94. package/dist/lib/source-config.js +154 -116
  95. package/dist/lib/state-artifacts.d.ts +5 -5
  96. package/dist/lib/state-artifacts.js +8 -8
  97. package/dist/lib/state-health.d.ts +4 -4
  98. package/dist/lib/state-health.js +108 -126
  99. package/dist/lib/state-io.d.ts +8 -8
  100. package/dist/lib/state-io.js +77 -50
  101. package/dist/lib/state-paths.js +5 -5
  102. package/dist/lib/state-view.d.ts +4 -4
  103. package/dist/lib/state-view.js +52 -55
  104. package/dist/lib/state.d.ts +5 -5
  105. package/dist/lib/state.js +4 -4
  106. package/dist/lib/summarize-plan.d.ts +3 -2
  107. package/dist/lib/summarize-plan.js +18 -16
  108. package/dist/lib/test-execution.js +9 -9
  109. package/dist/lib/test-matrices.d.ts +3 -3
  110. package/dist/lib/test-matrices.js +6 -6
  111. package/dist/lib/test-paths.d.ts +4 -4
  112. package/dist/lib/test-paths.js +16 -10
  113. package/dist/lib/test-sandbox.d.ts +1 -1
  114. package/dist/lib/test-sandbox.js +38 -31
  115. package/dist/lib/test-targets.d.ts +2 -2
  116. package/dist/lib/test-targets.js +11 -11
  117. package/dist/lib/test-types.d.ts +1 -1
  118. package/dist/lib/test.d.ts +1 -1
  119. package/dist/lib/test.js +1 -1
  120. package/dist/lib/util.d.ts +2 -0
  121. package/dist/lib/util.js +14 -1
  122. package/dist/lib/validate-compiled.d.ts +27 -0
  123. package/dist/lib/validate-compiled.js +236 -0
  124. package/dist/lib/validate-helpers.d.ts +0 -8
  125. package/dist/lib/validate-helpers.js +0 -30
  126. package/dist/lib/validate.d.ts +4 -4
  127. package/dist/lib/validate.js +49 -15
  128. package/dist/lib/workflow-abi.d.ts +37 -46
  129. package/dist/lib/workflow-abi.js +51 -76
  130. package/dist/lib/workflow-definitions.d.ts +11 -11
  131. package/dist/lib/workflow-definitions.js +36 -53
  132. package/dist/lib/workflow-helpers.d.ts +2 -3
  133. package/dist/lib/workflow-helpers.js +9 -13
  134. package/dist/lib/workflow-improvement.d.ts +3 -3
  135. package/dist/lib/workflow-improvement.js +48 -48
  136. package/dist/lib/workflow-review-paths.d.ts +3 -3
  137. package/dist/lib/workflow-review-paths.js +11 -11
  138. package/dist/lib/workflow-stage-runner.d.ts +1 -1
  139. package/dist/lib/workflow-stage-runner.js +8 -8
  140. package/dist/lib/workflows.d.ts +9 -9
  141. package/dist/lib/workflows.js +15 -17
  142. package/package.json +10 -9
  143. package/dist/commands/workspace-flow.d.ts +0 -23
  144. package/dist/commands/workspace-flow.js +0 -109
  145. package/dist/lib/registry.d.ts +0 -16
  146. package/dist/lib/registry.js +0 -65
  147. package/dist/lib/validate-workspace.d.ts +0 -121
  148. package/dist/lib/validate-workspace.js +0 -407
  149. package/dist/lib/workspace-compile.d.ts +0 -54
  150. package/dist/lib/workspace-compile.js +0 -476
  151. package/dist/lib/workspace-home.d.ts +0 -5
  152. package/dist/lib/workspace-home.js +0 -32
  153. package/dist/lib/workspace-layout.d.ts +0 -2
  154. package/dist/lib/workspace-layout.js +0 -60
  155. package/dist/lib/workspace-paths.d.ts +0 -41
  156. package/dist/lib/workspace-paths.js +0 -107
  157. package/dist/lib/workspace-reset.d.ts +0 -1
  158. package/dist/lib/workspace-reset.js +0 -43
  159. package/dist/lib/workspace-schema.d.ts +0 -17
  160. package/dist/lib/workspace-schema.js +0 -74
@@ -1,76 +1,94 @@
1
1
  import chalk from "chalk";
2
2
  import * as p from "@clack/prompts";
3
3
  import { detectInterf, readInterfConfig, resolveSourceControlPath, } from "../lib/interf.js";
4
- import { SOURCE_FOLDER_CONFIG_FILE, resolveWorkspaceCompileMaxAttempts, resolveWorkspaceCompileMaxLoops, syncWorkspaceInterfConfigFromSourceWorkspaceConfig, upsertSourceWorkspaceConfig, } from "../lib/source-config.js";
5
- import { DEFAULT_WORKSPACE_NAME, describeCompileLoopSelection, promptSingleWorkspaceConfig, } from "./source-config-wizard.js";
6
- import { buildWorkspaceWorkflowOptions, chooseWorkspaceWorkflow, createWorkflowWizard, } from "./create-workflow-wizard.js";
7
- import { findBuiltWorkspacePath, findSavedWorkspaceConfig, listSavedWorkspaceEntries, ensureWorkspaceFromConfig, } from "./workspace-flow.js";
8
- import { printSavedTestOutcome, printSavedTestComparison, questionPassRate, runSavedRawTest, runSavedWorkspaceTest, } from "./test-flow.js";
4
+ import { SOURCE_FOLDER_CONFIG_FILE, resolveDatasetCompileMaxAttempts, resolveDatasetCompileMaxLoops, syncCompiledInterfConfigFromSourceDatasetConfig, upsertSourceDatasetConfig, } from "../lib/source-config.js";
5
+ import { DEFAULT_COMPILED_NAME, describeCompileLoopSelection, promptSingleCompiledConfig, } from "./source-config-wizard.js";
6
+ import { buildCompiledWorkflowOptions, chooseCompiledWorkflow, createWorkflowWizard, } from "./create-workflow-wizard.js";
7
+ import { findBuiltCompiledPath, findSavedCompiledConfig, listSavedCompiledEntries, ensureCompiledFromConfig, } from "./compiled-flow.js";
8
+ import { readSavedTestComparison } from "./test-flow.js";
9
9
  import { resolveOrConfigureLocalExecutor } from "./executor-flow.js";
10
- import { runConfiguredWorkspaceCompile } from "./compile.js";
11
- function describeSavedQuestions(workspace) {
12
- const count = workspace.checks.length;
10
+ import { runConfiguredCompiledCompile } from "./compile.js";
11
+ import { runTestCommand } from "./test.js";
12
+ function describeSavedQuestions(dataset) {
13
+ const count = dataset.checks.length;
13
14
  if (count === 0)
14
15
  return "No saved truth checks yet";
15
16
  return `${count} saved truth check${count === 1 ? "" : "s"}`;
16
17
  }
17
- function compileModeAlreadyRanSavedTests(workspace) {
18
- if (workspace.checks.length === 0)
18
+ function compileModeAlreadyRanSavedTests(dataset) {
19
+ if (dataset.checks.length === 0)
19
20
  return false;
20
- return (resolveWorkspaceCompileMaxAttempts(workspace) != null ||
21
- resolveWorkspaceCompileMaxLoops(workspace) != null);
21
+ return (resolveDatasetCompileMaxAttempts(dataset) != null ||
22
+ resolveDatasetCompileMaxLoops(dataset) != null);
22
23
  }
23
- function printWorkspaceSummary(options) {
24
- const workspaceConfig = options.builtWorkspacePath
25
- ? readInterfConfig(options.builtWorkspacePath)
24
+ function printDatasetSummary(options) {
25
+ const compiledConfig = options.builtCompiledPath
26
+ ? readInterfConfig(options.builtCompiledPath)
26
27
  : null;
27
- const workflowLabel = `${options.workspace.workflow ?? "interf"}${workspaceConfig?.workflow_origin?.local_draft === true ? " (local draft)" : ""}`;
28
- p.log.info(`Workspace: ${options.workspace.name}`);
29
- if (options.workspace.about) {
30
- p.log.info(`Focus: ${options.workspace.about}`);
28
+ const workflowLabel = `${options.dataset.workflow ?? "interf"}${compiledConfig?.workflow_origin?.local_draft === true ? " (local draft)" : ""}`;
29
+ p.log.info(`Dataset: ${options.dataset.name}`);
30
+ p.log.info(`Path: ${options.dataset.path === "." ? "project root" : options.dataset.path}`);
31
+ if (options.dataset.about) {
32
+ p.log.info(`About: ${options.dataset.about}`);
31
33
  }
32
34
  p.log.info(`Workflow: ${workflowLabel}`);
33
35
  p.log.info(describeCompileLoopSelection({
34
- maxAttempts: options.workspace.max_attempts,
35
- maxLoops: options.workspace.max_loops,
36
+ maxAttempts: options.dataset.max_attempts,
37
+ maxLoops: options.dataset.max_loops,
36
38
  }));
37
- p.log.info(describeSavedQuestions(options.workspace));
38
- p.log.info(options.built ? "Compiled workspace is available." : "Compiled workspace has not been built yet.");
39
+ p.log.info(describeSavedQuestions(options.dataset));
40
+ p.log.info(options.built ? "Compiled dataset is available." : "Compiled dataset has not been built yet.");
41
+ if (options.latestComparison?.raw && options.latestComparison?.compiled) {
42
+ p.log.info(`Latest saved comparison: files-as-is ${options.latestComparison.raw.passed_cases}/${options.latestComparison.raw.total_cases}, compiled ${options.latestComparison.compiled.passed_cases}/${options.latestComparison.compiled.total_cases}.`);
43
+ }
44
+ else if (options.latestComparison?.raw) {
45
+ p.log.info(`Latest files-as-is baseline: ${options.latestComparison.raw.passed_cases}/${options.latestComparison.raw.total_cases}.`);
46
+ }
47
+ else if (options.latestComparison?.compiled) {
48
+ p.log.info(`Latest compiled run: ${options.latestComparison.compiled.passed_cases}/${options.latestComparison.compiled.total_cases}.`);
49
+ }
39
50
  if (options.sourcePath !== process.cwd()) {
40
51
  p.log.info(`Source folder: ${options.sourcePath}`);
41
52
  }
42
53
  }
43
- async function promptWorkspaceAction(workspace, built) {
44
- const options = [
45
- {
46
- value: "edit",
47
- label: "Edit workflow, truth checks, and compile mode",
48
- hint: "Update this workspace setup",
49
- },
50
- ];
51
- if (workspace.checks.length > 0) {
52
- options.push({
53
- value: "raw",
54
- label: "Run a baseline test on the raw files",
55
- hint: "Measure current performance before compilation",
56
- });
57
- }
58
- options.push({
59
- value: "compile",
60
- label: built ? "Refresh the compiled workspace" : "Compile the workspace",
61
- hint: built ? "Rebuild it from the current files" : "Build it for the first time",
62
- });
63
- if (workspace.checks.length > 0 && built) {
54
+ async function promptDatasetAction(dataset, built, latestComparison) {
55
+ const options = [];
56
+ const hasSavedRawBaseline = Boolean(latestComparison?.raw);
57
+ const rawAlreadyPasses = latestComparison?.raw &&
58
+ latestComparison.raw.passed_cases === latestComparison.raw.total_cases;
59
+ if (dataset.checks.length > 0) {
64
60
  options.push({
65
61
  value: "test",
66
- label: "Run the saved test on the compiled workspace",
67
- hint: "Score this workspace on its saved truth checks",
62
+ label: built
63
+ ? "Measure files-as-is and compiled accuracy (Recommended)"
64
+ : hasSavedRawBaseline
65
+ ? "Rerun the files-as-is baseline"
66
+ : "Measure the files-as-is baseline (Recommended)",
67
+ hint: built
68
+ ? "Compare whether the compiled dataset is actually better on the saved checks"
69
+ : hasSavedRawBaseline
70
+ ? "Refresh the saved raw baseline on the current checks"
71
+ : "See whether the raw dataset is already good enough before compiling",
68
72
  });
69
73
  }
70
74
  options.push({
71
- value: "workspace",
72
- label: "Create another workspace",
73
- hint: "Add a separate focus or question set",
75
+ value: "compile",
76
+ label: built ? "Rebuild the compiled dataset" : "Build the compiled dataset",
77
+ hint: built
78
+ ? "Refresh it from the current dataset files"
79
+ : dataset.checks.length > 0
80
+ ? rawAlreadyPasses
81
+ ? "Optional: compare a compiled dataset against the already-passing baseline"
82
+ : "Compile only if the baseline is not good enough"
83
+ : "Build it first, then measure it later",
84
+ }, {
85
+ value: "dataset",
86
+ label: "Add another dataset",
87
+ hint: "Add a separate folder, focus, or question set",
88
+ }, {
89
+ value: "edit",
90
+ label: "Edit truth checks and settings",
91
+ hint: "Update checks, focus, workflow, or compile mode",
74
92
  }, {
75
93
  value: "workflow",
76
94
  label: "Create workflow",
@@ -88,22 +106,42 @@ async function promptWorkspaceAction(workspace, built) {
88
106
  return null;
89
107
  return selected;
90
108
  }
91
- async function chooseWorkspaceForWizard(options) {
92
- if (options.fixedWorkspaceName) {
93
- return findSavedWorkspaceConfig(options.sourcePath, options.fixedWorkspaceName);
109
+ function printDatasetRecommendation(dataset, built, latestComparison) {
110
+ if (dataset.checks.length === 0) {
111
+ p.log.info("Recommended first step: save a few truth checks for this dataset.");
112
+ return;
113
+ }
114
+ if (!built) {
115
+ if (latestComparison?.raw) {
116
+ if (latestComparison.raw.passed_cases === latestComparison.raw.total_cases) {
117
+ p.log.info("Files-as-is already passes the saved checks. Compile only if you want a side-by-side comparison or a stronger compiled surface.");
118
+ return;
119
+ }
120
+ p.log.info(`Latest files-as-is baseline: ${latestComparison.raw.passed_cases}/${latestComparison.raw.total_cases}. Compile if you want to improve it.`);
121
+ return;
122
+ }
123
+ p.log.info("Recommended first step: measure the files-as-is baseline before compiling.");
124
+ return;
125
+ }
126
+ p.log.info("Recommended first step: compare the files-as-is baseline and the compiled dataset.");
127
+ }
128
+ async function chooseCompiledForWizard(options) {
129
+ if (options.fixedCompiledName) {
130
+ return findSavedCompiledConfig(options.sourcePath, options.fixedCompiledName);
94
131
  }
95
- const savedEntries = listSavedWorkspaceEntries(options.sourcePath);
132
+ const savedEntries = listSavedCompiledEntries(options.sourcePath);
96
133
  if (savedEntries.length === 0)
97
134
  return null;
98
135
  if (savedEntries.length === 1)
99
136
  return savedEntries[0]?.config ?? null;
100
137
  const selected = await p.select({
101
- message: "Which workspace do you want to work with?",
138
+ message: "Which dataset do you want to work with?",
102
139
  options: [
103
140
  ...savedEntries.map((entry) => ({
104
141
  value: entry.config.name,
105
142
  label: entry.config.name,
106
143
  hint: [
144
+ `path ${entry.config.path}`,
107
145
  entry.config.about ?? describeSavedQuestions(entry.config),
108
146
  `workflow ${entry.config.workflow ?? "interf"}${entry.localDraft ? " (local draft)" : ""}`,
109
147
  entry.path ? "built" : "not built yet",
@@ -111,8 +149,8 @@ async function chooseWorkspaceForWizard(options) {
111
149
  })),
112
150
  {
113
151
  value: "__new__",
114
- label: "Create another workspace",
115
- hint: "Add a separate focus or question set",
152
+ label: "Add another dataset",
153
+ hint: "Add a separate folder, focus, or question set",
116
154
  },
117
155
  ],
118
156
  });
@@ -120,52 +158,55 @@ async function chooseWorkspaceForWizard(options) {
120
158
  return null;
121
159
  if (selected === "__new__")
122
160
  return "__new__";
123
- return findSavedWorkspaceConfig(options.sourcePath, String(selected));
161
+ return findSavedCompiledConfig(options.sourcePath, String(selected));
124
162
  }
125
- async function promptWorkspaceSetup(options) {
126
- const workflowChoice = await chooseWorkspaceWorkflow(options.sourcePath, {
127
- currentWorkflowId: options.initial?.workflow ?? "interf",
128
- message: options.introStyle === "edit"
129
- ? "Which workflow should this workspace use?"
130
- : "Which workflow should this workspace start from?",
131
- });
132
- if (p.isCancel(workflowChoice))
133
- return null;
134
- const workflowId = workflowChoice;
135
- const workflowLabel = buildWorkspaceWorkflowOptions(options.sourcePath)
163
+ async function promptCompiledSetup(options) {
164
+ let workflowId = options.initial?.workflow ?? "interf";
165
+ if (options.introStyle === "edit") {
166
+ const workflowChoice = await chooseCompiledWorkflow(options.sourcePath, {
167
+ currentWorkflowId: workflowId,
168
+ message: "Which workflow should this dataset use?",
169
+ });
170
+ if (p.isCancel(workflowChoice))
171
+ return null;
172
+ workflowId = workflowChoice;
173
+ }
174
+ const workflowLabel = buildCompiledWorkflowOptions(options.sourcePath)
136
175
  .find((option) => option.value === workflowId)?.label ?? workflowId;
137
- const workspaceConfig = await promptSingleWorkspaceConfig({
176
+ const compiledConfig = await promptSingleCompiledConfig({
177
+ projectPath: options.sourcePath,
138
178
  initial: options.initial,
139
179
  ...(options.fixedName ? { fixedName: options.fixedName } : {}),
140
180
  skipNamePrompt: !options.fixedName && options.introStyle === "first",
141
181
  introStyle: options.introStyle,
142
182
  selectedWorkflowLabel: workflowLabel,
143
183
  });
144
- if (!workspaceConfig)
184
+ if (!compiledConfig)
145
185
  return null;
146
- const workspaceConfigWithWorkflow = {
147
- ...workspaceConfig,
186
+ const compiledConfigWithWorkflow = {
187
+ ...compiledConfig,
148
188
  workflow: workflowId,
149
189
  };
150
- upsertSourceWorkspaceConfig(options.sourcePath, workspaceConfigWithWorkflow, {
190
+ upsertSourceDatasetConfig(options.sourcePath, compiledConfigWithWorkflow, {
151
191
  ...(options.fixedName ? { matchName: options.fixedName } : {}),
152
192
  });
153
- const builtWorkspacePath = findBuiltWorkspacePath(options.sourcePath, workspaceConfigWithWorkflow.name);
154
- if (builtWorkspacePath) {
155
- syncWorkspaceInterfConfigFromSourceWorkspaceConfig(builtWorkspacePath, workspaceConfigWithWorkflow);
193
+ const builtCompiledPath = findBuiltCompiledPath(options.sourcePath, compiledConfigWithWorkflow.name);
194
+ if (builtCompiledPath) {
195
+ syncCompiledInterfConfigFromSourceDatasetConfig(builtCompiledPath, compiledConfigWithWorkflow);
156
196
  }
157
197
  console.log();
158
- console.log(chalk.green(` ✓ Saved workspace setup in ${SOURCE_FOLDER_CONFIG_FILE}`));
198
+ console.log(chalk.green(` ✓ Saved dataset setup in ${SOURCE_FOLDER_CONFIG_FILE}`));
159
199
  console.log(chalk.dim(` Source folder: ${options.sourcePath}`));
160
- console.log(chalk.dim(` Workspace: ${workspaceConfigWithWorkflow.name}`));
200
+ console.log(chalk.dim(` Dataset: ${compiledConfigWithWorkflow.name}`));
201
+ console.log(chalk.dim(` Path: ${compiledConfigWithWorkflow.path}`));
161
202
  console.log(chalk.dim(` Workflow: ${workflowLabel}`));
162
203
  console.log(chalk.dim(` Compile mode: ${describeCompileLoopSelection({
163
- maxAttempts: workspaceConfigWithWorkflow.max_attempts,
164
- maxLoops: workspaceConfigWithWorkflow.max_loops,
204
+ maxAttempts: compiledConfigWithWorkflow.max_attempts,
205
+ maxLoops: compiledConfigWithWorkflow.max_loops,
165
206
  })}`));
166
- return workspaceConfigWithWorkflow;
207
+ return compiledConfigWithWorkflow;
167
208
  }
168
- async function compileSelectedWorkspace(sourcePath, workspaceConfig) {
209
+ async function compileSelectedCompiled(sourcePath, compiledConfig) {
169
210
  const { executor, error } = await resolveOrConfigureLocalExecutor({
170
211
  purpose: "compile",
171
212
  });
@@ -177,274 +218,186 @@ async function compileSelectedWorkspace(sourcePath, workspaceConfig) {
177
218
  console.log(chalk.red(error ?? "No coding agent detected."));
178
219
  return null;
179
220
  }
180
- const workspacePath = ensureWorkspaceFromConfig(sourcePath, workspaceConfig);
181
- const compiled = await runConfiguredWorkspaceCompile({
221
+ const compiledPath = ensureCompiledFromConfig(sourcePath, compiledConfig);
222
+ const compiled = await runConfiguredCompiledCompile({
182
223
  executor,
183
- workspacePath,
224
+ compiledPath,
184
225
  sourcePath,
185
- workspaceConfig,
226
+ compiledConfig,
186
227
  maxAttemptsOverride: null,
187
228
  maxLoopsOverride: null,
188
229
  });
189
230
  if (!compiled) {
190
231
  return null;
191
232
  }
192
- return workspacePath;
193
- }
194
- async function runFirstWorkspaceFlow(sourcePath, workspaceConfig) {
195
- let rawOutcome = null;
196
- let workspaceOutcome = null;
197
- let rawOutcomeShown = false;
198
- if (workspaceConfig.checks.length > 0) {
199
- const runRawFirst = await p.confirm({
200
- message: "Run a baseline test on the raw files now? (Recommended)",
201
- initialValue: true,
202
- });
203
- if (p.isCancel(runRawFirst))
204
- return;
205
- if (runRawFirst) {
206
- rawOutcome = await runSavedRawTest({
207
- sourcePath,
208
- workspaceConfig,
209
- });
210
- if (rawOutcome) {
211
- console.log();
212
- printSavedTestOutcome("Raw files", rawOutcome);
213
- rawOutcomeShown = true;
214
- }
215
- }
216
- }
217
- else {
218
- p.log.info("You can compile this workspace now and add questions later when you want to test it.");
219
- }
220
- const compileAndTest = workspaceConfig.checks.length > 0 && rawOutcome
221
- ? await p.confirm({
222
- message: "Compile the workspace with this workflow and run the same test now? (Recommended)",
223
- initialValue: true,
224
- })
225
- : await p.confirm({
226
- message: "Compile the workspace with this workflow now? (Recommended)",
227
- initialValue: true,
228
- });
229
- if (p.isCancel(compileAndTest) || !compileAndTest) {
230
- if (rawOutcome && !rawOutcomeShown) {
231
- printSavedTestOutcome("Raw files", rawOutcome);
232
- }
233
- console.log();
234
- console.log(chalk.dim(" Next:"));
235
- console.log(chalk.dim(" interf compile"));
236
- if (workspaceConfig.checks.length > 0) {
237
- console.log(chalk.dim(" interf test"));
238
- }
239
- return;
240
- }
241
- const workspacePath = await compileSelectedWorkspace(sourcePath, workspaceConfig);
242
- if (!workspacePath) {
243
- if (rawOutcome && !rawOutcomeShown) {
244
- printSavedTestOutcome("Raw files", rawOutcome);
245
- }
246
- return;
247
- }
248
- if (workspaceConfig.checks.length === 0) {
249
- return;
250
- }
251
- if (compileModeAlreadyRanSavedTests(workspaceConfig)) {
252
- p.log.info("Saved compile mode already ran the workspace test.");
253
- return;
254
- }
255
- if (!rawOutcome) {
256
- const runWorkspaceTest = await p.confirm({
257
- message: "Run the saved test on the compiled workspace now? (Recommended)",
258
- initialValue: true,
259
- });
260
- if (p.isCancel(runWorkspaceTest) || !runWorkspaceTest)
261
- return;
262
- }
263
- workspaceOutcome = await runSavedWorkspaceTest({
264
- sourcePath,
265
- workspaceConfig,
266
- workspacePath,
267
- });
268
- if (rawOutcomeShown) {
269
- if (workspaceOutcome) {
270
- console.log();
271
- printSavedTestOutcome("Compiled workspace", workspaceOutcome);
272
- if (rawOutcome) {
273
- const rawQuestions = questionPassRate(rawOutcome);
274
- const workspaceQuestions = questionPassRate(workspaceOutcome);
275
- const delta = workspaceQuestions - rawQuestions;
276
- const color = delta >= 0 ? chalk.green : chalk.red;
277
- const direction = delta >= 0 ? "improved" : "decreased";
278
- console.log();
279
- console.log(color(` Truth-check pass rate ${direction} from ${rawQuestions}% to ${workspaceQuestions}%.`));
280
- }
281
- }
282
- }
283
- else {
284
- printSavedTestComparison(rawOutcome, workspaceOutcome);
285
- }
233
+ return compiledPath;
286
234
  }
287
- export const initCommand = {
288
- command: "init",
289
- describe: "Open the root-folder wizard for this folder",
290
- handler: async () => {
291
- await runInitCommand();
292
- },
293
- };
294
- export async function runInitCommand() {
295
- p.intro(chalk.bold("Interf Compiler"));
296
- p.log.info("Measure and improve how accurately your local agent answers questions from the dataset in this folder.");
297
- const cwd = process.cwd();
298
- const detected = detectInterf(cwd);
299
- const sourcePath = detected ? resolveSourceControlPath(detected.path) : cwd;
300
- if (detected) {
301
- p.log.info(`Working from the dataset control plane: ${sourcePath}`);
302
- }
303
- const savedEntries = listSavedWorkspaceEntries(sourcePath);
304
- if (savedEntries.length === 0) {
305
- const workspaceConfig = await promptWorkspaceSetup({
306
- sourcePath,
307
- initial: { name: DEFAULT_WORKSPACE_NAME },
308
- introStyle: "first",
309
- });
310
- if (!workspaceConfig)
311
- return;
312
- await runFirstWorkspaceFlow(sourcePath, workspaceConfig);
313
- return;
314
- }
315
- const selectedWorkspace = await chooseWorkspaceForWizard({
316
- sourcePath,
317
- fixedWorkspaceName: detected?.config.name ?? null,
318
- });
319
- if (!selectedWorkspace)
320
- return;
321
- if (selectedWorkspace === "__new__") {
322
- const workspaceConfig = await promptWorkspaceSetup({
323
- sourcePath,
324
- initial: { name: DEFAULT_WORKSPACE_NAME },
325
- introStyle: "additional",
326
- });
327
- if (!workspaceConfig)
328
- return;
329
- await runFirstWorkspaceFlow(sourcePath, workspaceConfig);
330
- return;
331
- }
332
- const builtWorkspacePath = findBuiltWorkspacePath(sourcePath, selectedWorkspace.name);
333
- printWorkspaceSummary({
235
+ async function runCompiledActionMenu(sourcePath, compiledConfig, options = {}) {
236
+ const builtCompiledPath = findBuiltCompiledPath(sourcePath, compiledConfig.name);
237
+ const latestComparison = readSavedTestComparison(sourcePath, compiledConfig.name);
238
+ printDatasetSummary({
334
239
  sourcePath,
335
- workspace: selectedWorkspace,
336
- built: Boolean(builtWorkspacePath),
337
- builtWorkspacePath,
240
+ dataset: compiledConfig,
241
+ built: Boolean(builtCompiledPath),
242
+ builtCompiledPath,
243
+ latestComparison,
338
244
  });
339
- const action = await promptWorkspaceAction(selectedWorkspace, Boolean(builtWorkspacePath));
245
+ printDatasetRecommendation(compiledConfig, Boolean(builtCompiledPath), latestComparison);
246
+ const action = await promptDatasetAction(compiledConfig, Boolean(builtCompiledPath), latestComparison);
340
247
  if (!action)
341
248
  return;
342
249
  if (action === "done") {
343
- p.outro("Nothing changed.");
250
+ p.outro(options.justConfigured ? "Saved dataset setup." : "Nothing changed.");
344
251
  return;
345
252
  }
346
253
  if (action === "workflow") {
347
254
  await createWorkflowWizard({ sourcePath });
348
255
  return;
349
256
  }
350
- if (action === "workspace") {
351
- const workspaceConfig = await promptWorkspaceSetup({
257
+ if (action === "dataset") {
258
+ const nextCompiled = await promptCompiledSetup({
352
259
  sourcePath,
353
- initial: { name: DEFAULT_WORKSPACE_NAME },
260
+ initial: { name: DEFAULT_COMPILED_NAME },
354
261
  introStyle: "additional",
355
262
  });
356
- if (!workspaceConfig)
263
+ if (!nextCompiled)
357
264
  return;
358
- await runFirstWorkspaceFlow(sourcePath, workspaceConfig);
265
+ await runCompiledActionMenu(sourcePath, nextCompiled, { justConfigured: true });
359
266
  return;
360
267
  }
361
268
  if (action === "edit") {
362
- const workspaceConfig = await promptWorkspaceSetup({
269
+ const nextCompiled = await promptCompiledSetup({
363
270
  sourcePath,
364
- initial: selectedWorkspace,
365
- fixedName: selectedWorkspace.name,
271
+ initial: compiledConfig,
272
+ fixedName: compiledConfig.name,
366
273
  introStyle: "edit",
367
274
  });
368
- if (!workspaceConfig)
275
+ if (!nextCompiled)
369
276
  return;
370
- const refreshedBuiltWorkspacePath = findBuiltWorkspacePath(sourcePath, workspaceConfig.name);
371
- printWorkspaceSummary({
372
- sourcePath,
373
- workspace: workspaceConfig,
374
- built: Boolean(refreshedBuiltWorkspacePath),
375
- builtWorkspacePath: refreshedBuiltWorkspacePath,
376
- });
377
- p.log.info("Saved workspace setup updated.");
277
+ await runCompiledActionMenu(sourcePath, nextCompiled, { justConfigured: true });
378
278
  return;
379
279
  }
380
- if (action === "raw") {
381
- if (selectedWorkspace.checks.length === 0) {
280
+ if (action === "test") {
281
+ if (compiledConfig.checks.length === 0) {
382
282
  process.exitCode = 1;
383
- console.log(chalk.red(` Workspace "${selectedWorkspace.name}" does not have any saved truth checks yet.`));
384
- console.log(chalk.dim(" Run `interf` or `interf init` to add a few first."));
283
+ console.log(chalk.red(` Dataset "${compiledConfig.name}" does not have any saved truth checks yet.`));
284
+ console.log(chalk.dim(" Run `interf`, edit this dataset, and add a few truth checks first."));
285
+ console.log(chalk.dim(" Then rerun `interf test`."));
385
286
  return;
386
287
  }
387
- const rawOutcome = await runSavedRawTest({
288
+ const baselineRan = await runTestCommand({
388
289
  sourcePath,
389
- workspaceConfig: selectedWorkspace,
290
+ dataset: compiledConfig.name,
291
+ datasetConfig: compiledConfig,
292
+ ...(builtCompiledPath ? {} : { target: "raw" }),
390
293
  });
391
- if (!rawOutcome)
294
+ if (!baselineRan) {
392
295
  return;
393
- const compileAndCompare = await p.confirm({
394
- message: "Compile the workspace and run the same test now? (Recommended)",
395
- initialValue: true,
396
- });
397
- if (p.isCancel(compileAndCompare) || !compileAndCompare) {
398
- printSavedTestComparison(rawOutcome, null);
296
+ }
297
+ if (builtCompiledPath) {
399
298
  return;
400
299
  }
401
- const workspacePath = await compileSelectedWorkspace(sourcePath, selectedWorkspace);
402
- if (!workspacePath) {
403
- printSavedTestComparison(rawOutcome, null);
300
+ const latestComparison = readSavedTestComparison(sourcePath, compiledConfig.name);
301
+ if (latestComparison?.raw?.passed_cases === latestComparison?.raw?.total_cases) {
302
+ const compileAnyway = await p.confirm({
303
+ message: "The files-as-is baseline already passed. Compile this dataset anyway?",
304
+ initialValue: false,
305
+ });
306
+ if (p.isCancel(compileAnyway) || !compileAnyway) {
307
+ return;
308
+ }
309
+ }
310
+ else {
311
+ const compileAndCompare = await p.confirm({
312
+ message: "Compile this dataset now and compare it on the same checks? (Recommended)",
313
+ initialValue: true,
314
+ });
315
+ if (p.isCancel(compileAndCompare) || !compileAndCompare) {
316
+ return;
317
+ }
318
+ }
319
+ const compiledPath = await compileSelectedCompiled(sourcePath, compiledConfig);
320
+ if (!compiledPath) {
404
321
  return;
405
322
  }
406
- const workspaceOutcome = await runSavedWorkspaceTest({
323
+ await runTestCommand({
407
324
  sourcePath,
408
- workspaceConfig: selectedWorkspace,
409
- workspacePath,
325
+ dataset: compiledConfig.name,
326
+ datasetConfig: compiledConfig,
327
+ target: "both",
410
328
  });
411
- printSavedTestComparison(rawOutcome, workspaceOutcome);
412
329
  return;
413
330
  }
414
331
  if (action === "compile") {
415
- const workspacePath = await compileSelectedWorkspace(sourcePath, selectedWorkspace);
416
- if (!workspacePath)
332
+ if (!await compileSelectedCompiled(sourcePath, compiledConfig))
417
333
  return;
418
- if (selectedWorkspace.checks.length === 0)
334
+ if (compiledConfig.checks.length === 0)
419
335
  return;
420
- if (compileModeAlreadyRanSavedTests(selectedWorkspace)) {
421
- p.log.info("Saved compile mode already ran the workspace test.");
336
+ if (compileModeAlreadyRanSavedTests(compiledConfig)) {
337
+ p.log.info("Saved compile mode already ran the compiled-dataset test.");
422
338
  return;
423
339
  }
424
- const runWorkspaceTest = await p.confirm({
425
- message: "Run the saved test on the compiled workspace now?",
340
+ const runCompiledTest = await p.confirm({
341
+ message: builtCompiledPath
342
+ ? "Run files-as-is and compiled on the saved checks now?"
343
+ : "Compare files-as-is and compiled on the saved checks now?",
426
344
  initialValue: true,
427
345
  });
428
- if (p.isCancel(runWorkspaceTest) || !runWorkspaceTest)
346
+ if (p.isCancel(runCompiledTest) || !runCompiledTest)
429
347
  return;
430
- const workspaceOutcome = await runSavedWorkspaceTest({
348
+ await runTestCommand({
431
349
  sourcePath,
432
- workspaceConfig: selectedWorkspace,
433
- workspacePath,
350
+ dataset: compiledConfig.name,
351
+ datasetConfig: compiledConfig,
352
+ target: "both",
434
353
  });
435
- printSavedTestComparison(null, workspaceOutcome);
436
354
  return;
437
355
  }
438
- if (!builtWorkspacePath) {
439
- process.exitCode = 1;
440
- console.log(chalk.red(` Workspace "${selectedWorkspace.name}" is not compiled yet.`));
441
- console.log(chalk.dim(" Run `interf compile` first."));
356
+ }
357
+ export const initCommand = {
358
+ command: "init",
359
+ describe: "Open the root-folder wizard for this folder",
360
+ handler: async () => {
361
+ await runInitCommand();
362
+ },
363
+ };
364
+ export async function runInitCommand() {
365
+ p.intro(chalk.bold("Interf Compiler"));
366
+ p.log.info("Measure how accurately your local agents answer from the dataset in this folder, then compile only if it helps.");
367
+ const cwd = process.cwd();
368
+ const detected = detectInterf(cwd);
369
+ const sourcePath = detected ? resolveSourceControlPath(detected.path) : cwd;
370
+ if (detected) {
371
+ p.log.info(`Working from the dataset control plane: ${sourcePath}`);
372
+ }
373
+ const savedEntries = listSavedCompiledEntries(sourcePath);
374
+ if (savedEntries.length === 0) {
375
+ const compiledConfig = await promptCompiledSetup({
376
+ sourcePath,
377
+ initial: { name: DEFAULT_COMPILED_NAME },
378
+ introStyle: "first",
379
+ });
380
+ if (!compiledConfig)
381
+ return;
382
+ await runCompiledActionMenu(sourcePath, compiledConfig, { justConfigured: true });
442
383
  return;
443
384
  }
444
- const workspaceOutcome = await runSavedWorkspaceTest({
385
+ const selectedCompiled = await chooseCompiledForWizard({
445
386
  sourcePath,
446
- workspaceConfig: selectedWorkspace,
447
- workspacePath: builtWorkspacePath,
387
+ fixedCompiledName: detected?.config.name ?? null,
448
388
  });
449
- printSavedTestComparison(null, workspaceOutcome);
389
+ if (!selectedCompiled)
390
+ return;
391
+ if (selectedCompiled === "__new__") {
392
+ const compiledConfig = await promptCompiledSetup({
393
+ sourcePath,
394
+ initial: { name: DEFAULT_COMPILED_NAME },
395
+ introStyle: "additional",
396
+ });
397
+ if (!compiledConfig)
398
+ return;
399
+ await runCompiledActionMenu(sourcePath, compiledConfig, { justConfigured: true });
400
+ return;
401
+ }
402
+ await runCompiledActionMenu(sourcePath, selectedCompiled);
450
403
  }