@interf/compiler 0.4.1 → 0.5.1

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 (162) hide show
  1. package/README.md +70 -66
  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 +274 -65
  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/{workflow-abi.d.ts → builtin-compiled-workflow.d.ts} +37 -46
  44. package/dist/lib/builtin-compiled-workflow.js +153 -0
  45. package/dist/lib/compiled-compile.d.ts +52 -0
  46. package/dist/lib/compiled-compile.js +274 -0
  47. package/dist/lib/compiled-home.d.ts +5 -0
  48. package/dist/lib/compiled-home.js +32 -0
  49. package/dist/lib/compiled-paths.d.ts +39 -0
  50. package/dist/lib/compiled-paths.js +103 -0
  51. package/dist/lib/{workspace-raw.d.ts → compiled-raw.d.ts} +9 -8
  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 +9 -10
  64. package/dist/lib/interf-detect.js +70 -59
  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 +11 -0
  76. package/dist/lib/project-paths.js +32 -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 +7 -6
  85. package/dist/lib/runtime-reconcile.d.ts +2 -3
  86. package/dist/lib/runtime-reconcile.js +94 -184
  87. package/dist/lib/runtime-runs.js +25 -119
  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 +169 -153
  92. package/dist/lib/schema.js +116 -164
  93. package/dist/lib/source-config.d.ts +24 -20
  94. package/dist/lib/source-config.js +159 -122
  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 +110 -126
  99. package/dist/lib/state-io.d.ts +8 -8
  100. package/dist/lib/state-io.js +21 -102
  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 +19 -21
  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 +26 -11
  113. package/dist/lib/test-sandbox.d.ts +1 -1
  114. package/dist/lib/test-sandbox.js +32 -38
  115. package/dist/lib/test-specs.js +1 -1
  116. package/dist/lib/test-targets.d.ts +2 -2
  117. package/dist/lib/test-targets.js +11 -11
  118. package/dist/lib/test-types.d.ts +1 -1
  119. package/dist/lib/test.d.ts +1 -1
  120. package/dist/lib/test.js +1 -1
  121. package/dist/lib/util.d.ts +2 -0
  122. package/dist/lib/util.js +14 -1
  123. package/dist/lib/validate-compiled.d.ts +27 -0
  124. package/dist/lib/validate-compiled.js +238 -0
  125. package/dist/lib/validate-helpers.d.ts +0 -8
  126. package/dist/lib/validate-helpers.js +0 -30
  127. package/dist/lib/validate.d.ts +6 -4
  128. package/dist/lib/validate.js +76 -27
  129. package/dist/lib/workflow-definitions.d.ts +12 -11
  130. package/dist/lib/workflow-definitions.js +45 -55
  131. package/dist/lib/workflow-helpers.d.ts +2 -3
  132. package/dist/lib/workflow-helpers.js +9 -13
  133. package/dist/lib/workflow-improvement.d.ts +3 -3
  134. package/dist/lib/workflow-improvement.js +48 -48
  135. package/dist/lib/workflow-primitives.d.ts +2 -0
  136. package/dist/lib/workflow-primitives.js +5 -0
  137. package/dist/lib/workflow-review-paths.d.ts +3 -3
  138. package/dist/lib/workflow-review-paths.js +11 -11
  139. package/dist/lib/workflow-stage-runner.d.ts +1 -1
  140. package/dist/lib/workflow-stage-runner.js +8 -8
  141. package/dist/lib/workflows.d.ts +9 -9
  142. package/dist/lib/workflows.js +15 -17
  143. package/package.json +13 -12
  144. package/dist/commands/workspace-flow.d.ts +0 -23
  145. package/dist/commands/workspace-flow.js +0 -109
  146. package/dist/lib/registry.d.ts +0 -16
  147. package/dist/lib/registry.js +0 -65
  148. package/dist/lib/validate-workspace.d.ts +0 -121
  149. package/dist/lib/validate-workspace.js +0 -407
  150. package/dist/lib/workflow-abi.js +0 -181
  151. package/dist/lib/workspace-compile.d.ts +0 -54
  152. package/dist/lib/workspace-compile.js +0 -476
  153. package/dist/lib/workspace-home.d.ts +0 -5
  154. package/dist/lib/workspace-home.js +0 -32
  155. package/dist/lib/workspace-layout.d.ts +0 -2
  156. package/dist/lib/workspace-layout.js +0 -60
  157. package/dist/lib/workspace-paths.d.ts +0 -41
  158. package/dist/lib/workspace-paths.js +0 -107
  159. package/dist/lib/workspace-reset.d.ts +0 -1
  160. package/dist/lib/workspace-reset.js +0 -43
  161. package/dist/lib/workspace-schema.d.ts +0 -17
  162. package/dist/lib/workspace-schema.js +0 -74
@@ -1,28 +1,27 @@
1
- export declare const WORKSPACE_CONTRACT_TYPES: readonly ["workspace-file-evidence", "workspace-knowledge-structure", "workspace-query-shape"];
2
- export type WorkspaceContractType = typeof WORKSPACE_CONTRACT_TYPES[number];
3
- export declare const WORKSPACE_ZONE_KINDS: readonly ["directory", "file", "runtime"];
4
- export type WorkspaceZoneKind = typeof WORKSPACE_ZONE_KINDS[number];
5
- export declare const WORKSPACE_CONTRACT_FAMILY_METADATA: {
6
- readonly "workspace-file-evidence": {
1
+ import { COMPILED_ZONE_KINDS, type CompiledZoneKind } from "./workflow-primitives.js";
2
+ export declare const COMPILED_CONTRACT_TYPES: readonly ["compiled-file-evidence", "compiled-knowledge-structure", "compiled-query-shape"];
3
+ export type CompiledContractType = typeof COMPILED_CONTRACT_TYPES[number];
4
+ export declare const COMPILED_CONTRACT_FAMILY_METADATA: {
5
+ readonly "compiled-file-evidence": {
7
6
  readonly order: 0;
8
7
  readonly bundledSkill: "compile/stages/summarize";
9
8
  };
10
- readonly "workspace-knowledge-structure": {
9
+ readonly "compiled-knowledge-structure": {
11
10
  readonly order: 1;
12
11
  readonly bundledSkill: "compile/stages/structure";
13
12
  };
14
- readonly "workspace-query-shape": {
13
+ readonly "compiled-query-shape": {
15
14
  readonly order: 2;
16
15
  readonly bundledSkill: "compile/stages/shape";
17
16
  };
18
17
  };
19
- export declare const BUILTIN_WORKSPACE_STAGE_IDS: {
18
+ export declare const BUILTIN_COMPILED_STAGE_IDS: {
20
19
  readonly SUMMARIZE: "summarize";
21
20
  readonly STRUCTURE: "structure";
22
21
  readonly SHAPE: "shape";
23
22
  };
24
- export type BuiltinWorkspaceStageId = typeof BUILTIN_WORKSPACE_STAGE_IDS[keyof typeof BUILTIN_WORKSPACE_STAGE_IDS];
25
- export declare const BUILTIN_WORKSPACE_ZONE_IDS: {
23
+ export type BuiltinCompiledStageId = typeof BUILTIN_COMPILED_STAGE_IDS[keyof typeof BUILTIN_COMPILED_STAGE_IDS];
24
+ export declare const BUILTIN_COMPILED_ZONE_IDS: {
26
25
  readonly RAW: "raw";
27
26
  readonly SUMMARIES: "summaries";
28
27
  readonly KNOWLEDGE_ENTITIES: "knowledge-entities";
@@ -31,20 +30,20 @@ export declare const BUILTIN_WORKSPACE_ZONE_IDS: {
31
30
  readonly HOME: "home";
32
31
  readonly RUNTIME: "runtime";
33
32
  };
34
- export type BuiltinWorkspaceZoneId = typeof BUILTIN_WORKSPACE_ZONE_IDS[keyof typeof BUILTIN_WORKSPACE_ZONE_IDS];
35
- export interface BuiltinWorkspaceZoneSpec {
36
- id: BuiltinWorkspaceZoneId;
33
+ export type BuiltinCompiledZoneId = typeof BUILTIN_COMPILED_ZONE_IDS[keyof typeof BUILTIN_COMPILED_ZONE_IDS];
34
+ export interface BuiltinCompiledZoneSpec {
35
+ id: BuiltinCompiledZoneId;
37
36
  path: string;
38
- kind: WorkspaceZoneKind;
37
+ kind: CompiledZoneKind;
39
38
  required: true;
40
39
  description: string;
41
40
  }
42
- export declare const BUILTIN_WORKSPACE_ZONE_SPECS: readonly [{
41
+ export declare const BUILTIN_COMPILED_ZONE_SPECS: readonly [{
43
42
  readonly id: "raw";
44
43
  readonly path: "raw";
45
44
  readonly kind: "directory";
46
45
  readonly required: true;
47
- readonly description: "Workspace-local raw snapshot copied from the dataset for direct evidence and verification.";
46
+ readonly description: "Compiled-local raw snapshot copied from the dataset for direct evidence and verification.";
48
47
  }, {
49
48
  readonly id: "summaries";
50
49
  readonly path: "summaries";
@@ -74,7 +73,7 @@ export declare const BUILTIN_WORKSPACE_ZONE_SPECS: readonly [{
74
73
  readonly path: "home.md";
75
74
  readonly kind: "file";
76
75
  readonly required: true;
77
- readonly description: "Primary entrypoint note for agents using the compiled workspace.";
76
+ readonly description: "Primary entrypoint note for agents using the compiled dataset.";
78
77
  }, {
79
78
  readonly id: "runtime";
80
79
  readonly path: ".interf/runtime";
@@ -82,20 +81,20 @@ export declare const BUILTIN_WORKSPACE_ZONE_SPECS: readonly [{
82
81
  readonly required: true;
83
82
  readonly description: "CLI-owned runtime state, health, stage contracts, and proof artifacts.";
84
83
  }];
85
- export interface BuiltinWorkspaceStageAccessPattern {
86
- id: BuiltinWorkspaceStageId;
84
+ export interface BuiltinCompiledStageAccessPattern {
85
+ id: BuiltinCompiledStageId;
87
86
  label: string;
88
87
  description: string;
89
- contractType: WorkspaceContractType;
88
+ contractType: CompiledContractType;
90
89
  skillDir: string;
91
- reads: readonly BuiltinWorkspaceZoneId[];
92
- writes: readonly BuiltinWorkspaceZoneId[];
90
+ reads: readonly BuiltinCompiledZoneId[];
91
+ writes: readonly BuiltinCompiledZoneId[];
93
92
  }
94
- export declare const BUILTIN_WORKSPACE_STAGE_ACCESS_PATTERNS: readonly [{
93
+ export declare const BUILTIN_COMPILED_STAGE_ACCESS_PATTERNS: readonly [{
95
94
  readonly id: "summarize";
96
95
  readonly label: "Summarize";
97
96
  readonly description: "Turn source files into per-file summaries.";
98
- readonly contractType: "workspace-file-evidence";
97
+ readonly contractType: "compiled-file-evidence";
99
98
  readonly skillDir: "summarize";
100
99
  readonly reads: readonly ["raw", "runtime"];
101
100
  readonly writes: readonly ["summaries"];
@@ -103,36 +102,28 @@ export declare const BUILTIN_WORKSPACE_STAGE_ACCESS_PATTERNS: readonly [{
103
102
  readonly id: "structure";
104
103
  readonly label: "Structure";
105
104
  readonly description: "Build the cross-file knowledge structure from the summaries.";
106
- readonly contractType: "workspace-knowledge-structure";
105
+ readonly contractType: "compiled-knowledge-structure";
107
106
  readonly skillDir: "structure";
108
107
  readonly reads: readonly ["summaries", "runtime"];
109
108
  readonly writes: readonly ["knowledge-entities", "knowledge-claims", "knowledge-indexes"];
110
109
  }, {
111
110
  readonly id: "shape";
112
111
  readonly label: "Shape";
113
- readonly description: "Shape the final workspace around the saved focus and truth checks.";
114
- readonly contractType: "workspace-query-shape";
112
+ readonly description: "Shape the final compiled around the saved focus and truth checks.";
113
+ readonly contractType: "compiled-query-shape";
115
114
  readonly skillDir: "shape";
116
115
  readonly reads: readonly ["raw", "summaries", "knowledge-entities", "knowledge-claims", "knowledge-indexes", "runtime"];
117
116
  readonly writes: readonly ["knowledge-indexes", "home"];
118
117
  }];
119
- export declare function workspaceContractOrder(contractType: WorkspaceContractType): number;
120
- export declare function workspaceBundledSkillForContractType(contractType: WorkspaceContractType): string;
121
- export declare function hasValidWorkspaceContractSequence(contractTypes: readonly WorkspaceContractType[]): boolean;
122
- export declare function listMissingWorkspaceContractTypes(contractTypes: readonly string[]): WorkspaceContractType[];
123
- export declare function validateWorkspaceContractSequence(contractTypes: readonly WorkspaceContractType[]): {
124
- ok: boolean;
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[];
118
+ export declare function listBuiltinCompiledZoneSpecs(): BuiltinCompiledZoneSpec[];
119
+ export declare function listBuiltinCompiledFallbackStages(): Array<{
120
+ id: BuiltinCompiledStageId;
121
+ contract_type: CompiledContractType;
122
+ reads: BuiltinCompiledZoneId[];
123
+ writes: BuiltinCompiledZoneId[];
134
124
  }>;
135
- export declare function requiredWorkspaceZoneOwners<TStage extends {
125
+ export declare function requiredCompiledZoneOwners<TStage extends {
136
126
  id: string;
137
- contractType: WorkspaceContractType;
138
- }>(stages: readonly TStage[], zoneId: BuiltinWorkspaceZoneId): string[];
127
+ writes: readonly string[];
128
+ }>(stages: readonly TStage[], zoneId: BuiltinCompiledZoneId): string[];
129
+ export { COMPILED_ZONE_KINDS };
@@ -0,0 +1,153 @@
1
+ import { COMPILED_ZONE_KINDS } from "./workflow-primitives.js";
2
+ export const COMPILED_CONTRACT_TYPES = [
3
+ "compiled-file-evidence",
4
+ "compiled-knowledge-structure",
5
+ "compiled-query-shape",
6
+ ];
7
+ export const COMPILED_CONTRACT_FAMILY_METADATA = {
8
+ "compiled-file-evidence": {
9
+ order: 0,
10
+ bundledSkill: "compile/stages/summarize",
11
+ },
12
+ "compiled-knowledge-structure": {
13
+ order: 1,
14
+ bundledSkill: "compile/stages/structure",
15
+ },
16
+ "compiled-query-shape": {
17
+ order: 2,
18
+ bundledSkill: "compile/stages/shape",
19
+ },
20
+ };
21
+ export const BUILTIN_COMPILED_STAGE_IDS = {
22
+ SUMMARIZE: "summarize",
23
+ STRUCTURE: "structure",
24
+ SHAPE: "shape",
25
+ };
26
+ export const BUILTIN_COMPILED_ZONE_IDS = {
27
+ RAW: "raw",
28
+ SUMMARIES: "summaries",
29
+ KNOWLEDGE_ENTITIES: "knowledge-entities",
30
+ KNOWLEDGE_CLAIMS: "knowledge-claims",
31
+ KNOWLEDGE_INDEXES: "knowledge-indexes",
32
+ HOME: "home",
33
+ RUNTIME: "runtime",
34
+ };
35
+ export const BUILTIN_COMPILED_ZONE_SPECS = [
36
+ {
37
+ id: BUILTIN_COMPILED_ZONE_IDS.RAW,
38
+ path: "raw",
39
+ kind: "directory",
40
+ required: true,
41
+ description: "Compiled-local raw snapshot copied from the dataset for direct evidence and verification.",
42
+ },
43
+ {
44
+ id: BUILTIN_COMPILED_ZONE_IDS.SUMMARIES,
45
+ path: "summaries",
46
+ kind: "directory",
47
+ required: true,
48
+ description: "Per-file evidence notes produced by file-evidence stages.",
49
+ },
50
+ {
51
+ id: BUILTIN_COMPILED_ZONE_IDS.KNOWLEDGE_ENTITIES,
52
+ path: "knowledge/entities",
53
+ kind: "directory",
54
+ required: true,
55
+ description: "Canonical entity notes produced by knowledge-structure stages.",
56
+ },
57
+ {
58
+ id: BUILTIN_COMPILED_ZONE_IDS.KNOWLEDGE_CLAIMS,
59
+ path: "knowledge/claims",
60
+ kind: "directory",
61
+ required: true,
62
+ description: "Claim notes produced by knowledge-structure stages.",
63
+ },
64
+ {
65
+ id: BUILTIN_COMPILED_ZONE_IDS.KNOWLEDGE_INDEXES,
66
+ path: "knowledge/indexes",
67
+ kind: "directory",
68
+ required: true,
69
+ description: "Retrieval indexes and navigation notes produced by structure and shape stages.",
70
+ },
71
+ {
72
+ id: BUILTIN_COMPILED_ZONE_IDS.HOME,
73
+ path: "home.md",
74
+ kind: "file",
75
+ required: true,
76
+ description: "Primary entrypoint note for agents using the compiled dataset.",
77
+ },
78
+ {
79
+ id: BUILTIN_COMPILED_ZONE_IDS.RUNTIME,
80
+ path: ".interf/runtime",
81
+ kind: "runtime",
82
+ required: true,
83
+ description: "CLI-owned runtime state, health, stage contracts, and proof artifacts.",
84
+ },
85
+ ];
86
+ export const BUILTIN_COMPILED_STAGE_ACCESS_PATTERNS = [
87
+ {
88
+ id: BUILTIN_COMPILED_STAGE_IDS.SUMMARIZE,
89
+ label: "Summarize",
90
+ description: "Turn source files into per-file summaries.",
91
+ contractType: "compiled-file-evidence",
92
+ skillDir: "summarize",
93
+ reads: [
94
+ BUILTIN_COMPILED_ZONE_IDS.RAW,
95
+ BUILTIN_COMPILED_ZONE_IDS.RUNTIME,
96
+ ],
97
+ writes: [
98
+ BUILTIN_COMPILED_ZONE_IDS.SUMMARIES,
99
+ ],
100
+ },
101
+ {
102
+ id: BUILTIN_COMPILED_STAGE_IDS.STRUCTURE,
103
+ label: "Structure",
104
+ description: "Build the cross-file knowledge structure from the summaries.",
105
+ contractType: "compiled-knowledge-structure",
106
+ skillDir: "structure",
107
+ reads: [
108
+ BUILTIN_COMPILED_ZONE_IDS.SUMMARIES,
109
+ BUILTIN_COMPILED_ZONE_IDS.RUNTIME,
110
+ ],
111
+ writes: [
112
+ BUILTIN_COMPILED_ZONE_IDS.KNOWLEDGE_ENTITIES,
113
+ BUILTIN_COMPILED_ZONE_IDS.KNOWLEDGE_CLAIMS,
114
+ BUILTIN_COMPILED_ZONE_IDS.KNOWLEDGE_INDEXES,
115
+ ],
116
+ },
117
+ {
118
+ id: BUILTIN_COMPILED_STAGE_IDS.SHAPE,
119
+ label: "Shape",
120
+ description: "Shape the final compiled around the saved focus and truth checks.",
121
+ contractType: "compiled-query-shape",
122
+ skillDir: "shape",
123
+ reads: [
124
+ BUILTIN_COMPILED_ZONE_IDS.RAW,
125
+ BUILTIN_COMPILED_ZONE_IDS.SUMMARIES,
126
+ BUILTIN_COMPILED_ZONE_IDS.KNOWLEDGE_ENTITIES,
127
+ BUILTIN_COMPILED_ZONE_IDS.KNOWLEDGE_CLAIMS,
128
+ BUILTIN_COMPILED_ZONE_IDS.KNOWLEDGE_INDEXES,
129
+ BUILTIN_COMPILED_ZONE_IDS.RUNTIME,
130
+ ],
131
+ writes: [
132
+ BUILTIN_COMPILED_ZONE_IDS.KNOWLEDGE_INDEXES,
133
+ BUILTIN_COMPILED_ZONE_IDS.HOME,
134
+ ],
135
+ },
136
+ ];
137
+ export function listBuiltinCompiledZoneSpecs() {
138
+ return BUILTIN_COMPILED_ZONE_SPECS.map((zone) => ({ ...zone }));
139
+ }
140
+ export function listBuiltinCompiledFallbackStages() {
141
+ return BUILTIN_COMPILED_STAGE_ACCESS_PATTERNS.map((stage) => ({
142
+ id: stage.id,
143
+ contract_type: stage.contractType,
144
+ reads: [...stage.reads],
145
+ writes: [...stage.writes],
146
+ }));
147
+ }
148
+ export function requiredCompiledZoneOwners(stages, zoneId) {
149
+ return Array.from(new Set(stages
150
+ .filter((stage) => stage.writes.includes(zoneId))
151
+ .map((stage) => stage.id)));
152
+ }
153
+ export { COMPILED_ZONE_KINDS };
@@ -0,0 +1,52 @@
1
+ import { type WorkflowExecutor } from "./executors.js";
2
+ import { type CompiledWorkflowId, type WorkflowStageDefinition } from "./workflow-definitions.js";
3
+ import { type WorkflowReporter, type WorkflowStageResult } from "./workflow-helpers.js";
4
+ export interface CompiledStageExecutionDefinition extends WorkflowStageDefinition {
5
+ }
6
+ export interface CompiledSummarizeResult extends WorkflowStageResult {
7
+ skipped: boolean;
8
+ plan: {
9
+ sourceCount: number;
10
+ summaryCount: number;
11
+ targetCount: number;
12
+ };
13
+ }
14
+ export interface CompiledCompileResult {
15
+ ok: boolean;
16
+ stageResults: Record<string, WorkflowStageResult>;
17
+ failedStage: string | null;
18
+ summarize: CompiledSummarizeResult | null;
19
+ structure: WorkflowStageResult | null;
20
+ shape: WorkflowStageResult | null;
21
+ compile: WorkflowStageResult | null;
22
+ }
23
+ export type StageShellRetentionMode = "on-failure" | "always";
24
+ export declare function resolveCompiledContext(compiledPath: string): {
25
+ compiledName: string;
26
+ sourcePath: string;
27
+ controlPath: string;
28
+ workflowId: CompiledWorkflowId;
29
+ };
30
+ export declare function compiledExecutionStages(workflowId: CompiledWorkflowId, compiledPath: string): CompiledStageExecutionDefinition[];
31
+ export declare function runCompiledSummarize(options: {
32
+ executor: WorkflowExecutor;
33
+ compiledPath: string;
34
+ reporter?: WorkflowReporter;
35
+ reportSummary?: boolean;
36
+ reportStep?: boolean;
37
+ stageDefinition?: CompiledStageExecutionDefinition;
38
+ fullPass?: boolean;
39
+ }): Promise<CompiledSummarizeResult>;
40
+ export declare function runCompiledCompile(options: {
41
+ executor: WorkflowExecutor;
42
+ compiledPath: string;
43
+ reporter?: WorkflowReporter;
44
+ reportStep?: boolean;
45
+ preserveStageShells?: StageShellRetentionMode;
46
+ }): Promise<WorkflowStageResult>;
47
+ export declare function compileCompiled(options: {
48
+ executor: WorkflowExecutor;
49
+ compiledPath: string;
50
+ reporter?: WorkflowReporter;
51
+ preserveStageShells?: StageShellRetentionMode;
52
+ }): Promise<CompiledCompileResult>;
@@ -0,0 +1,274 @@
1
+ import { join } from "node:path";
2
+ import { createStageExecutionShell, freezeStageExecutionShell, pruneStageExecutionShells, syncStageExecutionShellWrites, } from "./agent-shells.js";
3
+ import { readInterfConfig, refreshCompiledBootstrapGuidance, resolveSourceFolderPath, resolveSourceControlPath, resolveSourceInputPath, } from "./interf.js";
4
+ import { reconcileCompiledStageRun, } from "./runtime-reconcile.js";
5
+ import { refreshCompiledArtifacts, } from "./state.js";
6
+ import { buildRuntimeStageContract, } from "./runtime.js";
7
+ import { validateWorkflowPackage } from "./local-workflows.js";
8
+ import { formatActiveCompiledWorkflowStageStep, getActiveCompiledStagePolicyNotes, getActiveCompiledWorkflow, resolveRequiredCompiledWorkflowFromConfig, resolveActiveCompiledStageAcceptance, } from "./workflow-definitions.js";
9
+ import { validateCompiledStage, validateCompiledWorkflow, } from "./validate.js";
10
+ import { buildLocalSkillContractExtension, buildStageInstructions, reportBlankLine, reportLine, reportValidationFailure, workflowCompileStageDirectory, } from "./workflow-helpers.js";
11
+ import { executeValidatedStage, } from "./workflow-stage-runner.js";
12
+ import { syncCompiledRawSnapshot } from "./compiled-raw.js";
13
+ import { workflowPackagePathForCompiled, } from "./compiled-paths.js";
14
+ import { compiledContractArtifactPathsForZoneIds, findCompiledSchemaZone, readCompiledSchemaFile, } from "./compiled-schema.js";
15
+ import { discoverSourceFiles } from "./discovery.js";
16
+ import { listFilesRecursive } from "./filesystem.js";
17
+ export function resolveCompiledContext(compiledPath) {
18
+ const config = readInterfConfig(compiledPath);
19
+ const workflowId = resolveRequiredCompiledWorkflowFromConfig(config, `.interf/interf.json for ${compiledPath}`);
20
+ return {
21
+ compiledName: config?.name ?? "compiled",
22
+ sourcePath: resolveSourceFolderPath(compiledPath, config),
23
+ controlPath: resolveSourceControlPath(compiledPath),
24
+ workflowId,
25
+ };
26
+ }
27
+ export function compiledExecutionStages(workflowId, compiledPath) {
28
+ return getActiveCompiledWorkflow(compiledPath, workflowId)
29
+ .stages;
30
+ }
31
+ function zoneArtifactCount(compiledPath, zonePath, kind) {
32
+ const absolutePath = join(compiledPath, zonePath);
33
+ try {
34
+ if (kind === "file") {
35
+ return listFilesRecursive(absolutePath).length > 0 ? 1 : 0;
36
+ }
37
+ }
38
+ catch {
39
+ if (kind === "file")
40
+ return 0;
41
+ }
42
+ return listFilesRecursive(absolutePath).length;
43
+ }
44
+ function resolveStageContractArtifacts(compiledPath, stageDefinition) {
45
+ const schema = readCompiledSchemaFile(workflowPackagePathForCompiled(compiledPath));
46
+ if (!schema) {
47
+ throw new Error(`Missing compiled schema for stage "${stageDefinition.id}" at ${workflowPackagePathForCompiled(compiledPath)}.`);
48
+ }
49
+ return {
50
+ reads: compiledContractArtifactPathsForZoneIds(schema, stageDefinition.reads),
51
+ writes: compiledContractArtifactPathsForZoneIds(schema, stageDefinition.writes),
52
+ };
53
+ }
54
+ function buildStageCounts(compiledPath, stageDefinition) {
55
+ const context = resolveCompiledContext(compiledPath);
56
+ const sourceTotal = discoverSourceFiles(context.sourcePath, compiledPath).totalCount;
57
+ const schema = readCompiledSchemaFile(workflowPackagePathForCompiled(compiledPath));
58
+ const zoneCounts = {};
59
+ if (schema) {
60
+ for (const zoneId of new Set([...stageDefinition.reads, ...stageDefinition.writes])) {
61
+ const zone = findCompiledSchemaZone(schema, zoneId);
62
+ if (!zone)
63
+ continue;
64
+ zoneCounts[zoneId] = zoneArtifactCount(compiledPath, zone.path, zone.kind);
65
+ }
66
+ }
67
+ return {
68
+ source_total: sourceTotal,
69
+ read_zone_total: stageDefinition.reads.length,
70
+ write_zone_total: stageDefinition.writes.length,
71
+ ...zoneCounts,
72
+ };
73
+ }
74
+ function buildStageContract(compiledPath, workflowId, stageDefinition) {
75
+ const config = readInterfConfig(compiledPath);
76
+ const localSkills = buildLocalSkillContractExtension(compiledPath, [workflowCompileStageDirectory(stageDefinition.skillDir)], "Use them to refine this workflow stage while still honoring the declared reads, writes, and proof rules.");
77
+ const instructions = buildStageInstructions(stageDefinition.skillDir, localSkills);
78
+ const stageArtifacts = resolveStageContractArtifacts(compiledPath, stageDefinition);
79
+ return buildRuntimeStageContract({
80
+ compiledName: config?.name ?? "compiled",
81
+ stageId: stageDefinition.id,
82
+ stageLabel: stageDefinition.label,
83
+ counts: buildStageCounts(compiledPath, stageDefinition),
84
+ stageReadArtifacts: stageArtifacts.reads,
85
+ stageWriteArtifacts: stageArtifacts.writes,
86
+ workflowNotes: getActiveCompiledStagePolicyNotes(compiledPath, workflowId, stageDefinition.id),
87
+ localSkillDocs: localSkills.reads,
88
+ instructions,
89
+ acceptance: resolveActiveCompiledStageAcceptance(compiledPath, workflowId, stageDefinition.id),
90
+ });
91
+ }
92
+ async function runCompiledStage(options) {
93
+ const context = resolveCompiledContext(options.compiledPath);
94
+ const stageDefinition = options.stageDefinition;
95
+ const contract = buildStageContract(options.compiledPath, context.workflowId, stageDefinition);
96
+ const localSkills = buildLocalSkillContractExtension(options.compiledPath, [workflowCompileStageDirectory(stageDefinition.skillDir)], "Use them to refine this workflow stage while still honoring the declared reads, writes, and proof rules.");
97
+ const instructions = buildStageInstructions(stageDefinition.skillDir, localSkills);
98
+ if (options.reportStep !== false) {
99
+ reportBlankLine(options.reporter);
100
+ reportLine(options.reporter, `${formatActiveCompiledWorkflowStageStep(options.compiledPath, context.workflowId, stageDefinition.id)} (${stageDefinition.description.toLowerCase()})`);
101
+ }
102
+ const shell = createStageExecutionShell(options.compiledPath, context.compiledName, context.workflowId, stageDefinition, contract.artifacts.writes);
103
+ try {
104
+ return await executeValidatedStage({
105
+ executor: options.executor,
106
+ compiledPath: options.compiledPath,
107
+ executionPath: shell.rootPath,
108
+ targetName: context.compiledName,
109
+ workflow: context.workflowId,
110
+ workflowSourcePath: options.compiledPath,
111
+ stageDefinition,
112
+ instructions,
113
+ summary: `Executing ${stageDefinition.label.toLowerCase()}.`,
114
+ contract,
115
+ statusLines: [
116
+ `Emit exactly one startup line: STATUS: loaded ${stageDefinition.label.toLowerCase()} stage.`,
117
+ "Emit STATUS: reading declared inputs after you confirm the shell contract and local docs.",
118
+ "Emit STATUS: writing declared outputs after the stage starts updating the compiled zones.",
119
+ `Emit DONE: ${stageDefinition.id} complete when the declared outputs and proof are on disk.`,
120
+ ],
121
+ reporter: options.reporter,
122
+ completionCheck: () => validateCompiledStage(options.compiledPath, stageDefinition.id).ok,
123
+ syncWrites: () => syncStageExecutionShellWrites(options.compiledPath, shell.rootPath, stageDefinition, contract.artifacts.writes),
124
+ reconcile: () => reconcileCompiledStageRun(options.compiledPath, stageDefinition),
125
+ refreshArtifacts: () => refreshCompiledArtifacts(options.compiledPath, { ensureViewSpec: true }),
126
+ validate: () => validateCompiledStage(options.compiledPath, stageDefinition.id),
127
+ });
128
+ }
129
+ finally {
130
+ freezeStageExecutionShell(shell.rootPath);
131
+ }
132
+ }
133
+ export async function runCompiledSummarize(options) {
134
+ const context = resolveCompiledContext(options.compiledPath);
135
+ const stageDefinition = options.stageDefinition
136
+ ?? compiledExecutionStages(context.workflowId, options.compiledPath).find((stage) => stage.id === "summarize");
137
+ if (!stageDefinition) {
138
+ return {
139
+ ok: false,
140
+ code: 1,
141
+ skipped: true,
142
+ plan: { sourceCount: 0, summaryCount: 0, targetCount: 0 },
143
+ summary: "Workflow does not declare a summarize stage.",
144
+ };
145
+ }
146
+ const sourceCount = discoverSourceFiles(context.sourcePath, options.compiledPath).totalCount;
147
+ const result = await runCompiledStage({
148
+ executor: options.executor,
149
+ compiledPath: options.compiledPath,
150
+ reporter: options.reporter,
151
+ reportStep: options.reportStep,
152
+ stageDefinition,
153
+ });
154
+ return {
155
+ ...result,
156
+ skipped: false,
157
+ plan: {
158
+ sourceCount,
159
+ summaryCount: 0,
160
+ targetCount: sourceCount,
161
+ },
162
+ };
163
+ }
164
+ export async function runCompiledCompile(options) {
165
+ const preserveMode = options.preserveStageShells ?? "on-failure";
166
+ if (preserveMode !== "always") {
167
+ pruneStageExecutionShells(options.compiledPath);
168
+ }
169
+ let lastResult = { ok: true, code: 0 };
170
+ try {
171
+ const context = resolveCompiledContext(options.compiledPath);
172
+ for (const stageDefinition of compiledExecutionStages(context.workflowId, options.compiledPath)) {
173
+ const result = await runCompiledStage({
174
+ executor: options.executor,
175
+ compiledPath: options.compiledPath,
176
+ reporter: options.reporter,
177
+ reportStep: options.reportStep,
178
+ stageDefinition,
179
+ });
180
+ lastResult = result;
181
+ if (!result.ok)
182
+ return result;
183
+ }
184
+ return lastResult;
185
+ }
186
+ finally {
187
+ if (preserveMode !== "always" && lastResult.ok) {
188
+ pruneStageExecutionShells(options.compiledPath);
189
+ }
190
+ }
191
+ }
192
+ export async function compileCompiled(options) {
193
+ const preserveMode = options.preserveStageShells ?? "on-failure";
194
+ if (preserveMode !== "always") {
195
+ pruneStageExecutionShells(options.compiledPath);
196
+ }
197
+ let result = {
198
+ ok: true,
199
+ stageResults: {},
200
+ failedStage: null,
201
+ summarize: null,
202
+ structure: null,
203
+ shape: null,
204
+ compile: null,
205
+ };
206
+ try {
207
+ const sourceInputPath = resolveSourceInputPath(options.compiledPath);
208
+ syncCompiledRawSnapshot(options.compiledPath, sourceInputPath);
209
+ refreshCompiledBootstrapGuidance(options.compiledPath);
210
+ const workflowValidation = validateWorkflowPackage(join(options.compiledPath, ".interf", "workflow"));
211
+ if (!workflowValidation.ok) {
212
+ reportValidationFailure(options.reporter, workflowValidation.summary, workflowValidation.errors);
213
+ return {
214
+ ...result,
215
+ ok: false,
216
+ failedStage: "workflow",
217
+ compile: {
218
+ ok: false,
219
+ code: 1,
220
+ summary: workflowValidation.summary,
221
+ },
222
+ };
223
+ }
224
+ const context = resolveCompiledContext(options.compiledPath);
225
+ const stages = compiledExecutionStages(context.workflowId, options.compiledPath);
226
+ for (const stageDefinition of stages) {
227
+ const stageResult = await runCompiledStage({
228
+ executor: options.executor,
229
+ compiledPath: options.compiledPath,
230
+ reporter: options.reporter,
231
+ reportStep: true,
232
+ stageDefinition,
233
+ });
234
+ result.stageResults[stageDefinition.id] = stageResult;
235
+ if (stageDefinition.id === "summarize") {
236
+ result.summarize = {
237
+ ...stageResult,
238
+ skipped: false,
239
+ plan: {
240
+ sourceCount: discoverSourceFiles(context.sourcePath, options.compiledPath).totalCount,
241
+ summaryCount: 0,
242
+ targetCount: discoverSourceFiles(context.sourcePath, options.compiledPath).totalCount,
243
+ },
244
+ };
245
+ }
246
+ else if (stageDefinition.id === "structure") {
247
+ result.structure = stageResult;
248
+ }
249
+ else if (stageDefinition.id === "shape") {
250
+ result.shape = stageResult;
251
+ }
252
+ if (!stageResult.ok) {
253
+ result.ok = false;
254
+ result.failedStage = stageDefinition.id;
255
+ result.compile = stageResult;
256
+ return result;
257
+ }
258
+ }
259
+ const workflowValidationResult = validateCompiledWorkflow(options.compiledPath);
260
+ result.ok = workflowValidationResult.ok;
261
+ result.failedStage = workflowValidationResult.ok ? null : workflowValidationResult.stage;
262
+ result.compile = {
263
+ ok: workflowValidationResult.ok,
264
+ code: workflowValidationResult.ok ? 0 : 1,
265
+ summary: workflowValidationResult.summary,
266
+ };
267
+ return result;
268
+ }
269
+ finally {
270
+ if (preserveMode !== "always" && result.ok) {
271
+ pruneStageExecutionShells(options.compiledPath);
272
+ }
273
+ }
274
+ }
@@ -0,0 +1,5 @@
1
+ export declare const UNCOMPILED_COMPILED_HOME_NOTICE = "Not yet compiled. Run `interf compile` to build the compiled dataset.";
2
+ export declare function renderUncompiledCompiledHome(compiledName: string, about?: string): string;
3
+ export declare function compiledHomeHasCompilePlaceholder(content: string): boolean;
4
+ export declare function readCompiledHomeContent(dirPath: string): string | null;
5
+ export declare function compiledHomeIsShaped(dirPath: string): boolean;
@@ -0,0 +1,32 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { compiledHomePath } from "./compiled-schema.js";
3
+ export const UNCOMPILED_COMPILED_HOME_NOTICE = "Not yet compiled. Run `interf compile` to build the compiled dataset.";
4
+ export function renderUncompiledCompiledHome(compiledName, about) {
5
+ return [
6
+ `# ${compiledName} — Home`,
7
+ "",
8
+ UNCOMPILED_COMPILED_HOME_NOTICE,
9
+ ...(about ? ["", `About: ${about}`] : []),
10
+ "",
11
+ ].join("\n");
12
+ }
13
+ export function compiledHomeHasCompilePlaceholder(content) {
14
+ return content.includes(UNCOMPILED_COMPILED_HOME_NOTICE);
15
+ }
16
+ export function readCompiledHomeContent(dirPath) {
17
+ const homePath = compiledHomePath(dirPath);
18
+ if (!existsSync(homePath))
19
+ return null;
20
+ try {
21
+ return readFileSync(homePath, "utf8");
22
+ }
23
+ catch {
24
+ return null;
25
+ }
26
+ }
27
+ export function compiledHomeIsShaped(dirPath) {
28
+ const content = readCompiledHomeContent(dirPath);
29
+ if (content === null)
30
+ return false;
31
+ return !compiledHomeHasCompilePlaceholder(content);
32
+ }