@interf/compiler 0.1.11 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +254 -136
- package/dist/commands/benchmark.d.ts.map +1 -1
- package/dist/commands/benchmark.js +65 -84
- package/dist/commands/benchmark.js.map +1 -1
- package/dist/commands/compile.d.ts.map +1 -1
- package/dist/commands/compile.js +19 -3
- package/dist/commands/compile.js.map +1 -1
- package/dist/commands/create.d.ts +3 -0
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +34 -9
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/default.d.ts.map +1 -1
- package/dist/commands/default.js +2 -0
- package/dist/commands/default.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +3 -2
- package/dist/commands/init.js.map +1 -1
- package/dist/index.d.ts +11 -29
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -16
- package/dist/index.js.map +1 -1
- package/dist/lib/agent-args.d.ts +4 -0
- package/dist/lib/agent-args.d.ts.map +1 -0
- package/dist/lib/agent-args.js +42 -0
- package/dist/lib/agent-args.js.map +1 -0
- package/dist/lib/agent-constants.d.ts +6 -0
- package/dist/lib/agent-constants.d.ts.map +1 -0
- package/dist/lib/agent-constants.js +29 -0
- package/dist/lib/agent-constants.js.map +1 -0
- package/dist/lib/agent-detection.d.ts +8 -0
- package/dist/lib/agent-detection.d.ts.map +1 -0
- package/dist/lib/agent-detection.js +66 -0
- package/dist/lib/agent-detection.js.map +1 -0
- package/dist/lib/agent-execution.d.ts +3 -0
- package/dist/lib/agent-execution.d.ts.map +1 -0
- package/dist/lib/agent-execution.js +207 -0
- package/dist/lib/agent-execution.js.map +1 -0
- package/dist/lib/agent-logs.d.ts +3 -0
- package/dist/lib/agent-logs.d.ts.map +1 -0
- package/dist/lib/agent-logs.js +18 -0
- package/dist/lib/agent-logs.js.map +1 -0
- package/dist/lib/agent-preflight.d.ts +8 -0
- package/dist/lib/agent-preflight.d.ts.map +1 -0
- package/dist/lib/agent-preflight.js +77 -0
- package/dist/lib/agent-preflight.js.map +1 -0
- package/dist/lib/agent-render.d.ts +9 -0
- package/dist/lib/agent-render.d.ts.map +1 -0
- package/dist/lib/agent-render.js +219 -0
- package/dist/lib/agent-render.js.map +1 -0
- package/dist/lib/agent-status.d.ts +4 -0
- package/dist/lib/agent-status.d.ts.map +1 -0
- package/dist/lib/agent-status.js +59 -0
- package/dist/lib/agent-status.js.map +1 -0
- package/dist/lib/agent-types.d.ts +31 -0
- package/dist/lib/agent-types.d.ts.map +1 -0
- package/dist/lib/agent-types.js +2 -0
- package/dist/lib/agent-types.js.map +1 -0
- package/dist/lib/agents.d.ts +7 -49
- package/dist/lib/agents.d.ts.map +1 -1
- package/dist/lib/agents.js +8 -554
- package/dist/lib/agents.js.map +1 -1
- package/dist/lib/benchmark-execution.d.ts +9 -0
- package/dist/lib/benchmark-execution.d.ts.map +1 -0
- package/dist/lib/benchmark-execution.js +488 -0
- package/dist/lib/benchmark-execution.js.map +1 -0
- package/dist/lib/benchmark-paths.d.ts +11 -0
- package/dist/lib/benchmark-paths.d.ts.map +1 -0
- package/dist/lib/benchmark-paths.js +38 -0
- package/dist/lib/benchmark-paths.js.map +1 -0
- package/dist/lib/benchmark-specs.d.ts +8 -0
- package/dist/lib/benchmark-specs.d.ts.map +1 -0
- package/dist/lib/benchmark-specs.js +115 -0
- package/dist/lib/benchmark-specs.js.map +1 -0
- package/dist/lib/benchmark-targets.d.ts +5 -0
- package/dist/lib/benchmark-targets.d.ts.map +1 -0
- package/dist/lib/benchmark-targets.js +72 -0
- package/dist/lib/benchmark-targets.js.map +1 -0
- package/dist/lib/benchmark-types.d.ts +19 -0
- package/dist/lib/benchmark-types.d.ts.map +1 -0
- package/dist/lib/benchmark-types.js +2 -0
- package/dist/lib/benchmark-types.js.map +1 -0
- package/dist/lib/benchmark.d.ts +4 -29
- package/dist/lib/benchmark.d.ts.map +1 -1
- package/dist/lib/benchmark.js +3 -324
- package/dist/lib/benchmark.js.map +1 -1
- package/dist/lib/bundled-templates.d.ts +5 -0
- package/dist/lib/bundled-templates.d.ts.map +1 -0
- package/dist/lib/bundled-templates.js +23 -0
- package/dist/lib/bundled-templates.js.map +1 -0
- package/dist/lib/config.d.ts +1 -0
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +2 -0
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/eval-packs.d.ts +204 -0
- package/dist/lib/eval-packs.d.ts.map +1 -0
- package/dist/lib/eval-packs.js +177 -0
- package/dist/lib/eval-packs.js.map +1 -0
- package/dist/lib/execution-profile.d.ts +18 -0
- package/dist/lib/execution-profile.d.ts.map +1 -0
- package/dist/lib/execution-profile.js +85 -0
- package/dist/lib/execution-profile.js.map +1 -0
- package/dist/lib/interf-bootstrap.d.ts +4 -0
- package/dist/lib/interf-bootstrap.d.ts.map +1 -1
- package/dist/lib/interf-bootstrap.js +71 -68
- package/dist/lib/interf-bootstrap.js.map +1 -1
- package/dist/lib/interf-compile-plan.d.ts +12 -0
- package/dist/lib/interf-compile-plan.d.ts.map +1 -0
- package/dist/lib/interf-compile-plan.js +143 -0
- package/dist/lib/interf-compile-plan.js.map +1 -0
- package/dist/lib/interf-detect.d.ts.map +1 -1
- package/dist/lib/interf-detect.js +11 -10
- package/dist/lib/interf-detect.js.map +1 -1
- package/dist/lib/interf-scaffold.d.ts +1 -10
- package/dist/lib/interf-scaffold.d.ts.map +1 -1
- package/dist/lib/interf-scaffold.js +25 -362
- package/dist/lib/interf-scaffold.js.map +1 -1
- package/dist/lib/interf-workflow-package.d.ts +4 -0
- package/dist/lib/interf-workflow-package.d.ts.map +1 -0
- package/dist/lib/interf-workflow-package.js +131 -0
- package/dist/lib/interf-workflow-package.js.map +1 -0
- package/dist/lib/interf.d.ts +2 -1
- package/dist/lib/interf.d.ts.map +1 -1
- package/dist/lib/interf.js +2 -1
- package/dist/lib/interf.js.map +1 -1
- package/dist/lib/local-workflows.d.ts.map +1 -1
- package/dist/lib/local-workflows.js +8 -12
- package/dist/lib/local-workflows.js.map +1 -1
- package/dist/lib/logger.d.ts +4 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/logger.js +11 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/obsidian.d.ts.map +1 -1
- package/dist/lib/obsidian.js +7 -3
- package/dist/lib/obsidian.js.map +1 -1
- package/dist/lib/parse.d.ts +2 -2
- package/dist/lib/parse.d.ts.map +1 -1
- package/dist/lib/parse.js +11 -7
- package/dist/lib/parse.js.map +1 -1
- package/dist/lib/registry.js +3 -3
- package/dist/lib/registry.js.map +1 -1
- package/dist/lib/runtime-acceptance.d.ts +4 -0
- package/dist/lib/runtime-acceptance.d.ts.map +1 -0
- package/dist/lib/runtime-acceptance.js +123 -0
- package/dist/lib/runtime-acceptance.js.map +1 -0
- package/dist/lib/runtime-contracts.d.ts +4 -0
- package/dist/lib/runtime-contracts.d.ts.map +1 -0
- package/dist/lib/runtime-contracts.js +63 -0
- package/dist/lib/runtime-contracts.js.map +1 -0
- package/dist/lib/runtime-paths.d.ts +8 -0
- package/dist/lib/runtime-paths.d.ts.map +1 -0
- package/dist/lib/runtime-paths.js +28 -0
- package/dist/lib/runtime-paths.js.map +1 -0
- package/dist/lib/runtime-prompt.d.ts +3 -0
- package/dist/lib/runtime-prompt.d.ts.map +1 -0
- package/dist/lib/runtime-prompt.js +59 -0
- package/dist/lib/runtime-prompt.js.map +1 -0
- package/dist/lib/runtime-reconcile.d.ts +6 -0
- package/dist/lib/runtime-reconcile.d.ts.map +1 -0
- package/dist/lib/runtime-reconcile.js +339 -0
- package/dist/lib/runtime-reconcile.js.map +1 -0
- package/dist/lib/runtime-runs.d.ts +12 -0
- package/dist/lib/runtime-runs.d.ts.map +1 -0
- package/dist/lib/runtime-runs.js +337 -0
- package/dist/lib/runtime-runs.js.map +1 -0
- package/dist/lib/runtime-types.d.ts +42 -0
- package/dist/lib/runtime-types.d.ts.map +1 -0
- package/dist/lib/runtime-types.js +2 -0
- package/dist/lib/runtime-types.js.map +1 -0
- package/dist/lib/runtime.d.ts +6 -58
- package/dist/lib/runtime.d.ts.map +1 -1
- package/dist/lib/runtime.js +5 -614
- package/dist/lib/runtime.js.map +1 -1
- package/dist/lib/schema.d.ts +156 -13
- package/dist/lib/schema.d.ts.map +1 -1
- package/dist/lib/schema.js +113 -4
- package/dist/lib/schema.js.map +1 -1
- package/dist/lib/source-config.d.ts +13 -0
- package/dist/lib/source-config.d.ts.map +1 -0
- package/dist/lib/source-config.js +75 -0
- package/dist/lib/source-config.js.map +1 -0
- package/dist/lib/state-artifacts.d.ts +15 -0
- package/dist/lib/state-artifacts.d.ts.map +1 -0
- package/dist/lib/state-artifacts.js +24 -0
- package/dist/lib/state-artifacts.js.map +1 -0
- package/dist/lib/state-health.d.ts +9 -0
- package/dist/lib/state-health.d.ts.map +1 -0
- package/dist/lib/state-health.js +330 -0
- package/dist/lib/state-health.js.map +1 -0
- package/dist/lib/state-io.d.ts +15 -0
- package/dist/lib/state-io.d.ts.map +1 -0
- package/dist/lib/state-io.js +219 -0
- package/dist/lib/state-io.js.map +1 -0
- package/dist/lib/state-paths.d.ts +5 -0
- package/dist/lib/state-paths.d.ts.map +1 -0
- package/dist/lib/state-paths.js +19 -0
- package/dist/lib/state-paths.js.map +1 -0
- package/dist/lib/state-view.d.ts +7 -0
- package/dist/lib/state-view.d.ts.map +1 -0
- package/dist/lib/state-view.js +147 -0
- package/dist/lib/state-view.js.map +1 -0
- package/dist/lib/state.d.ts +6 -46
- package/dist/lib/state.d.ts.map +1 -1
- package/dist/lib/state.js +5 -632
- package/dist/lib/state.js.map +1 -1
- package/dist/lib/summarize-plan.d.ts +1 -0
- package/dist/lib/summarize-plan.d.ts.map +1 -1
- package/dist/lib/summarize-plan.js +10 -0
- package/dist/lib/summarize-plan.js.map +1 -1
- package/dist/lib/user-config.js +2 -2
- package/dist/lib/user-config.js.map +1 -1
- package/dist/lib/validate-helpers.d.ts +21 -0
- package/dist/lib/validate-helpers.d.ts.map +1 -0
- package/dist/lib/validate-helpers.js +72 -0
- package/dist/lib/validate-helpers.js.map +1 -0
- package/dist/lib/validate-interface.d.ts +79 -0
- package/dist/lib/validate-interface.d.ts.map +1 -0
- package/dist/lib/validate-interface.js +535 -0
- package/dist/lib/validate-interface.js.map +1 -0
- package/dist/lib/validate-kb.d.ts +81 -0
- package/dist/lib/validate-kb.d.ts.map +1 -0
- package/dist/lib/validate-kb.js +252 -0
- package/dist/lib/validate-kb.js.map +1 -0
- package/dist/lib/validate.d.ts +17 -146
- package/dist/lib/validate.d.ts.map +1 -1
- package/dist/lib/validate.js +33 -709
- package/dist/lib/validate.js.map +1 -1
- package/dist/lib/workflow-definitions.d.ts +1 -1
- package/dist/lib/workflow-definitions.d.ts.map +1 -1
- package/dist/lib/workflow-definitions.js +90 -166
- package/dist/lib/workflow-definitions.js.map +1 -1
- package/dist/lib/workflow-helpers.d.ts.map +1 -1
- package/dist/lib/workflow-helpers.js +6 -3
- package/dist/lib/workflow-helpers.js.map +1 -1
- package/dist/lib/workflow-stage-runner.d.ts +41 -0
- package/dist/lib/workflow-stage-runner.d.ts.map +1 -0
- package/dist/lib/workflow-stage-runner.js +106 -0
- package/dist/lib/workflow-stage-runner.js.map +1 -0
- package/dist/lib/workflow-starter-docs.d.ts +9 -0
- package/dist/lib/workflow-starter-docs.d.ts.map +1 -0
- package/dist/lib/workflow-starter-docs.js +18 -0
- package/dist/lib/workflow-starter-docs.js.map +1 -0
- package/dist/lib/workflows-interface-contracts.d.ts +24 -0
- package/dist/lib/workflows-interface-contracts.d.ts.map +1 -0
- package/dist/lib/workflows-interface-contracts.js +304 -0
- package/dist/lib/workflows-interface-contracts.js.map +1 -0
- package/dist/lib/workflows-interface.d.ts +3 -10
- package/dist/lib/workflows-interface.d.ts.map +1 -1
- package/dist/lib/workflows-interface.js +117 -365
- package/dist/lib/workflows-interface.js.map +1 -1
- package/dist/lib/workflows-kb.d.ts.map +1 -1
- package/dist/lib/workflows-kb.js +79 -55
- package/dist/lib/workflows-kb.js.map +1 -1
- package/dist/lib/workflows.d.ts +1 -1
- package/dist/lib/workflows.d.ts.map +1 -1
- package/dist/lib/workflows.js +1 -1
- package/dist/lib/workflows.js.map +1 -1
- package/package.json +15 -4
- package/skills/interface/analyze/SKILL.md +79 -28
- package/skills/interface/compile/SKILL.md +27 -28
- package/skills/interface/create/SKILL.md +53 -230
- package/skills/interface/create/references/compile-plan-format.md +31 -31
- package/skills/interface/create/references/workflows.md +17 -32
- package/skills/interface/query/SKILL.md +15 -1
- package/skills/interface/retrieve/SKILL.md +32 -65
- package/skills/knowledge-base/compile/SKILL.md +59 -83
- package/skills/knowledge-base/compile/references/stage-claims.md +1 -1
- package/skills/knowledge-base/compile/references/stage-entities.md +2 -2
- package/skills/knowledge-base/query/SKILL.md +13 -1
- package/skills/knowledge-base/summarize/SKILL.md +54 -24
- package/templates/interface/README.md +13 -12
- package/templates/interface/interfaces.md +14 -11
- package/templates/knowledge-base/README.md +0 -1
- package/templates/knowledge-base/registry.md +15 -15
- package/templates/workflow-package/README.md +16 -0
- package/templates/workflow-package/create/SKILL.md +8 -0
- package/templates/workflow-package/interface-query/SKILL.md +29 -0
- package/templates/workflow-package/interface-stage/SKILL.md +13 -0
- package/templates/workflow-package/knowledge-base-query/SKILL.md +36 -0
- package/templates/workflow-package/knowledge-base-stage/SKILL.md +13 -0
- package/templates/workflow-starters/interface/interf/README.md +13 -0
- package/templates/workflow-starters/interface/interf/create/SKILL.md +15 -0
- package/templates/workflow-starters/knowledge-base/interf/README.md +13 -0
- package/templates/workflow-starters/knowledge-base/karpathy/README.md +13 -0
package/dist/lib/state.js
CHANGED
|
@@ -1,633 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { readInterfConfig, resolveKnowledgeBaseSourcePath } from "./interf.js";
|
|
7
|
-
import { loadRuntimeRun } from "./runtime.js";
|
|
8
|
-
import { InterfaceHealthSchema, InterfaceStateSchema, InterfaceViewSpecSchema, KnowledgeBaseHealthSchema, KnowledgeBaseSourceAccessSchema, KnowledgeBaseStateSchema, KnowledgeBaseViewSpecSchema, } from "./schema.js";
|
|
9
|
-
import { validateKnowledgeBase, validateInterfaceKnowledgeBase, } from "./validate.js";
|
|
10
|
-
import { STATE_DIR } from "./util.js";
|
|
11
|
-
const STATE_FILE = "state.json";
|
|
12
|
-
const HEALTH_FILE = "health.json";
|
|
13
|
-
const VIEW_SPEC_FILE = "view-spec.json";
|
|
14
|
-
const SOURCE_ACCESS_FILE = "source-access.json";
|
|
15
|
-
export function statePath(dirPath) {
|
|
16
|
-
return join(dirPath, STATE_DIR, STATE_FILE);
|
|
17
|
-
}
|
|
18
|
-
export function healthPath(dirPath) {
|
|
19
|
-
return join(dirPath, STATE_DIR, HEALTH_FILE);
|
|
20
|
-
}
|
|
21
|
-
export function viewSpecPath(dirPath) {
|
|
22
|
-
return join(dirPath, STATE_DIR, VIEW_SPEC_FILE);
|
|
23
|
-
}
|
|
24
|
-
export function sourceAccessPath(dirPath) {
|
|
25
|
-
return join(dirPath, STATE_DIR, SOURCE_ACCESS_FILE);
|
|
26
|
-
}
|
|
27
|
-
export function loadState(dirPath) {
|
|
28
|
-
const p = statePath(dirPath);
|
|
29
|
-
if (!existsSync(p))
|
|
30
|
-
return null;
|
|
31
|
-
return safeReadJsonFileWithSchema(p, "runtime state", KnowledgeBaseStateSchema.or(InterfaceStateSchema));
|
|
32
|
-
}
|
|
33
|
-
export function saveState(dirPath, state) {
|
|
34
|
-
const dir = join(dirPath, STATE_DIR);
|
|
35
|
-
mkdirSync(dir, { recursive: true });
|
|
36
|
-
writeFileSync(join(dir, STATE_FILE), JSON.stringify(state, null, 2) + "\n");
|
|
37
|
-
}
|
|
38
|
-
export function loadInterfaceHealth(dirPath) {
|
|
39
|
-
const p = healthPath(dirPath);
|
|
40
|
-
if (!existsSync(p))
|
|
41
|
-
return null;
|
|
42
|
-
return safeReadJsonFileWithSchema(p, "interface health", InterfaceHealthSchema);
|
|
43
|
-
}
|
|
44
|
-
export function loadKnowledgeBaseHealth(dirPath) {
|
|
45
|
-
const p = healthPath(dirPath);
|
|
46
|
-
if (!existsSync(p))
|
|
47
|
-
return null;
|
|
48
|
-
return safeReadJsonFileWithSchema(p, "knowledge-base health", KnowledgeBaseHealthSchema);
|
|
49
|
-
}
|
|
50
|
-
export function saveInterfaceHealth(dirPath, health) {
|
|
51
|
-
const dir = join(dirPath, STATE_DIR);
|
|
52
|
-
mkdirSync(dir, { recursive: true });
|
|
53
|
-
writeFileSync(healthPath(dirPath), JSON.stringify(health, null, 2) + "\n");
|
|
54
|
-
}
|
|
55
|
-
export function saveKnowledgeBaseHealth(dirPath, health) {
|
|
56
|
-
const dir = join(dirPath, STATE_DIR);
|
|
57
|
-
mkdirSync(dir, { recursive: true });
|
|
58
|
-
writeFileSync(healthPath(dirPath), JSON.stringify(health, null, 2) + "\n");
|
|
59
|
-
}
|
|
60
|
-
export function loadInterfaceViewSpec(dirPath) {
|
|
61
|
-
const p = viewSpecPath(dirPath);
|
|
62
|
-
if (!existsSync(p))
|
|
63
|
-
return null;
|
|
64
|
-
return loadViewSpec(p, InterfaceViewSpecSchema);
|
|
65
|
-
}
|
|
66
|
-
export function loadKnowledgeBaseViewSpec(dirPath) {
|
|
67
|
-
const p = viewSpecPath(dirPath);
|
|
68
|
-
if (!existsSync(p))
|
|
69
|
-
return null;
|
|
70
|
-
return loadViewSpec(p, KnowledgeBaseViewSpecSchema);
|
|
71
|
-
}
|
|
72
|
-
export function loadKnowledgeBaseSourceAccess(dirPath) {
|
|
73
|
-
const p = sourceAccessPath(dirPath);
|
|
74
|
-
if (!existsSync(p))
|
|
75
|
-
return null;
|
|
76
|
-
return safeReadJsonFileWithSchema(p, "knowledge-base source access", KnowledgeBaseSourceAccessSchema);
|
|
77
|
-
}
|
|
78
|
-
export function saveInterfaceViewSpec(dirPath, viewSpec) {
|
|
79
|
-
const dir = join(dirPath, STATE_DIR);
|
|
80
|
-
mkdirSync(dir, { recursive: true });
|
|
81
|
-
writeFileSync(viewSpecPath(dirPath), JSON.stringify(viewSpec, null, 2) + "\n");
|
|
82
|
-
}
|
|
83
|
-
export function saveKnowledgeBaseViewSpec(dirPath, viewSpec) {
|
|
84
|
-
const dir = join(dirPath, STATE_DIR);
|
|
85
|
-
mkdirSync(dir, { recursive: true });
|
|
86
|
-
writeFileSync(viewSpecPath(dirPath), JSON.stringify(viewSpec, null, 2) + "\n");
|
|
87
|
-
}
|
|
88
|
-
export function initKnowledgeBaseState() {
|
|
89
|
-
return {
|
|
90
|
-
version: 1,
|
|
91
|
-
pending: [],
|
|
92
|
-
summarized: 0,
|
|
93
|
-
compiled: 0,
|
|
94
|
-
last_add: null,
|
|
95
|
-
last_summarize: null,
|
|
96
|
-
last_compile: null,
|
|
97
|
-
inventory_complete: false,
|
|
98
|
-
abstracts_read: 0,
|
|
99
|
-
full_reads: 0,
|
|
100
|
-
entity_count: 0,
|
|
101
|
-
claim_count: 0,
|
|
102
|
-
warning_count: 0,
|
|
103
|
-
error_count: 0,
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
export function initInterfaceState() {
|
|
107
|
-
return {
|
|
108
|
-
version: 1,
|
|
109
|
-
retrieve_complete: false,
|
|
110
|
-
analyze_complete: false,
|
|
111
|
-
compile_complete: false,
|
|
112
|
-
coverage_complete: false,
|
|
113
|
-
frontmatter_scanned: 0,
|
|
114
|
-
candidate_count: 0,
|
|
115
|
-
abstracts_read: 0,
|
|
116
|
-
expansion_passes: 0,
|
|
117
|
-
relevant_count: 0,
|
|
118
|
-
rejected_count: 0,
|
|
119
|
-
delta_count: 0,
|
|
120
|
-
delta_files: [],
|
|
121
|
-
last_retrieve: null,
|
|
122
|
-
last_analyze: null,
|
|
123
|
-
last_compile: null,
|
|
124
|
-
knowledge_base_summary_count_at_last_compile: 0,
|
|
125
|
-
extracted_entities: 0,
|
|
126
|
-
extracted_claims: 0,
|
|
127
|
-
entity_count: 0,
|
|
128
|
-
claim_count: 0,
|
|
129
|
-
output_count: 0,
|
|
130
|
-
warning_count: 0,
|
|
131
|
-
error_count: 0,
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
export function refreshInterfaceArtifacts(dirPath, options) {
|
|
135
|
-
normalizeInterfaceCompileState(dirPath);
|
|
136
|
-
const health = computeInterfaceHealth(dirPath);
|
|
137
|
-
saveInterfaceHealth(dirPath, health);
|
|
138
|
-
let viewSpec;
|
|
139
|
-
if (options?.ensureViewSpec) {
|
|
140
|
-
viewSpec = ensureInterfaceViewSpec(dirPath);
|
|
141
|
-
}
|
|
142
|
-
return { health, viewSpec };
|
|
143
|
-
}
|
|
144
|
-
function normalizeInterfaceCompileState(dirPath) {
|
|
145
|
-
const state = {
|
|
146
|
-
...initInterfaceState(),
|
|
147
|
-
...(loadState(dirPath) ?? {}),
|
|
148
|
-
};
|
|
149
|
-
const config = readInterfConfig(dirPath);
|
|
150
|
-
const knowledgeBasePath = config?.type === "interface" && config.knowledge_base?.path
|
|
151
|
-
? resolve(dirPath, config.knowledge_base.path)
|
|
152
|
-
: null;
|
|
153
|
-
const knowledgeBaseTotal = knowledgeBasePath !== null && existsSync(join(knowledgeBasePath, "summaries"))
|
|
154
|
-
? countFilesRecursive(join(knowledgeBasePath, "summaries"))
|
|
155
|
-
: 0;
|
|
156
|
-
if (state.compile_complete === true &&
|
|
157
|
-
typeof state.last_compile === "string" &&
|
|
158
|
-
knowledgeBaseTotal > 0 &&
|
|
159
|
-
(state.knowledge_base_summary_count_at_last_compile ?? 0) <= 0) {
|
|
160
|
-
state.knowledge_base_summary_count_at_last_compile = knowledgeBaseTotal;
|
|
161
|
-
saveState(dirPath, state);
|
|
162
|
-
}
|
|
163
|
-
return state;
|
|
164
|
-
}
|
|
165
|
-
function resolveInterfaceCompileReferenceCount(state, knowledgeBaseTotal) {
|
|
166
|
-
const explicitCount = state.knowledge_base_summary_count_at_last_compile ?? 0;
|
|
167
|
-
if (explicitCount > 0)
|
|
168
|
-
return explicitCount;
|
|
169
|
-
if (state.compile_complete === true && typeof state.last_compile === "string") {
|
|
170
|
-
return knowledgeBaseTotal;
|
|
171
|
-
}
|
|
172
|
-
return 0;
|
|
173
|
-
}
|
|
174
|
-
export function refreshKnowledgeBaseArtifacts(dirPath, options) {
|
|
175
|
-
const health = computeKnowledgeBaseHealth(dirPath);
|
|
176
|
-
saveKnowledgeBaseHealth(dirPath, health);
|
|
177
|
-
const sourceAccess = ensureKnowledgeBaseSourceAccess(dirPath);
|
|
178
|
-
let viewSpec;
|
|
179
|
-
if (options?.ensureViewSpec) {
|
|
180
|
-
viewSpec = ensureKnowledgeBaseViewSpec(dirPath);
|
|
181
|
-
}
|
|
182
|
-
return { health, viewSpec, sourceAccess };
|
|
183
|
-
}
|
|
184
|
-
export function computeKnowledgeBaseHealth(dirPath) {
|
|
185
|
-
const state = {
|
|
186
|
-
...initKnowledgeBaseState(),
|
|
187
|
-
...(loadState(dirPath) ?? {}),
|
|
188
|
-
};
|
|
189
|
-
const validation = validateKnowledgeBase(dirPath);
|
|
190
|
-
const now = new Date().toISOString();
|
|
191
|
-
const config = readInterfConfig(dirPath);
|
|
192
|
-
const knowledgeBaseName = config?.name ?? basename(dirPath);
|
|
193
|
-
const sourcePath = resolveKnowledgeBaseSourcePath(dirPath, config);
|
|
194
|
-
const discovery = discoverSourceFiles(sourcePath, dirPath);
|
|
195
|
-
const summariesPresent = existsSync(join(dirPath, "summaries"));
|
|
196
|
-
const inventoryPresent = existsSync(join(dirPath, STATE_DIR, "inventory.json"));
|
|
197
|
-
const homePresent = existsSync(join(dirPath, "home.md"));
|
|
198
|
-
const outputs = countKnowledgeBaseOutputFiles(dirPath);
|
|
199
|
-
const outputsPresent = outputs > 0;
|
|
200
|
-
const sourceTotal = discovery.totalCount;
|
|
201
|
-
const summarized = summariesPresent ? countFilesRecursive(join(dirPath, "summaries")) : 0;
|
|
202
|
-
const sourceCovered = Math.min(sourceTotal, summarized);
|
|
203
|
-
const compiled = Math.min(summarized, state.compiled ?? 0);
|
|
204
|
-
const toSummarize = Math.max(0, sourceTotal - sourceCovered);
|
|
205
|
-
const toCompile = Math.max(0, summarized - compiled);
|
|
206
|
-
const warnings = (toSummarize > 0 ? 1 : 0) +
|
|
207
|
-
(toCompile > 0 ? 1 : 0) +
|
|
208
|
-
(summarized > sourceTotal && sourceTotal > 0 ? 1 : 0) +
|
|
209
|
-
(!outputsPresent && state.last_compile ? 1 : 0) +
|
|
210
|
-
validation.invalid_frontmatter +
|
|
211
|
-
validation.short_abstracts +
|
|
212
|
-
validation.broken_links;
|
|
213
|
-
const errors = (!validation.config_present ? 1 : 0) +
|
|
214
|
-
(!validation.config_valid && validation.config_present ? 1 : 0) +
|
|
215
|
-
(!validation.config_type_match && validation.config_valid ? 1 : 0) +
|
|
216
|
-
(state.error_count ?? 0);
|
|
217
|
-
const activeRun = loadRuntimeRun(dirPath);
|
|
218
|
-
const inferredStage = resolveKnowledgeBaseStage(state, sourceTotal, summarized, toSummarize, toCompile, errors);
|
|
219
|
-
const inferredStatus = resolveKnowledgeBaseStatus(sourceTotal, summarized, toSummarize, toCompile, errors, state);
|
|
220
|
-
const stage = activeRun?.status === "running"
|
|
221
|
-
? activeRun.contract_type === "kb-knowledge-layer"
|
|
222
|
-
? "compile"
|
|
223
|
-
: activeRun.contract_type === "kb-file-evidence"
|
|
224
|
-
? "summarize"
|
|
225
|
-
: inferredStage
|
|
226
|
-
: inferredStage;
|
|
227
|
-
const status = activeRun?.status === "running" ? "running" : inferredStatus;
|
|
228
|
-
return {
|
|
229
|
-
kind: "knowledge-base-health",
|
|
230
|
-
version: 1,
|
|
231
|
-
generated_at: now,
|
|
232
|
-
target_name: knowledgeBaseName,
|
|
233
|
-
status,
|
|
234
|
-
stage,
|
|
235
|
-
summary: activeRun?.status === "running"
|
|
236
|
-
? `Running — ${activeRun.stage_label} via ${activeRun.executor.display_name}. ${activeRun.summary}`
|
|
237
|
-
: buildKnowledgeBaseSummary(status, stage, { rawTotal: sourceTotal, rawCovered: sourceCovered, summarized, toSummarize, compiled, toCompile }),
|
|
238
|
-
metrics: {
|
|
239
|
-
source_total: sourceTotal,
|
|
240
|
-
source_covered: sourceCovered,
|
|
241
|
-
summarized,
|
|
242
|
-
to_summarize: toSummarize,
|
|
243
|
-
compiled,
|
|
244
|
-
to_compile: toCompile,
|
|
245
|
-
entities: state.entity_count ?? countFilesRecursive(join(dirPath, "knowledge", "entities")),
|
|
246
|
-
claims: state.claim_count ?? countFilesRecursive(join(dirPath, "knowledge", "claims")),
|
|
247
|
-
outputs,
|
|
248
|
-
invalid_frontmatter: validation.invalid_frontmatter,
|
|
249
|
-
short_abstracts: validation.short_abstracts,
|
|
250
|
-
broken_links: validation.broken_links,
|
|
251
|
-
warnings: (state.warning_count ?? 0) + warnings,
|
|
252
|
-
errors,
|
|
253
|
-
},
|
|
254
|
-
checks: {
|
|
255
|
-
config_present: validation.config_present,
|
|
256
|
-
config_valid: validation.config_valid,
|
|
257
|
-
config_type_match: validation.config_type_match,
|
|
258
|
-
summaries_present: summariesPresent,
|
|
259
|
-
inventory_present: inventoryPresent,
|
|
260
|
-
outputs_present: outputsPresent,
|
|
261
|
-
home_present: homePresent,
|
|
262
|
-
summary_frontmatter_valid: validation.summary_frontmatter_valid,
|
|
263
|
-
abstracts_valid: validation.abstracts_valid,
|
|
264
|
-
links_valid: validation.broken_links === 0,
|
|
265
|
-
},
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
export function computeInterfaceHealth(dirPath) {
|
|
269
|
-
const state = {
|
|
270
|
-
...initInterfaceState(),
|
|
271
|
-
...(loadState(dirPath) ?? {}),
|
|
272
|
-
};
|
|
273
|
-
const validation = validateInterfaceKnowledgeBase(dirPath);
|
|
274
|
-
const now = new Date().toISOString();
|
|
275
|
-
const config = readInterfConfig(dirPath);
|
|
276
|
-
const interfaceName = config?.name ?? basename(dirPath);
|
|
277
|
-
const knowledgeBasePath = config?.type === "interface" && config.knowledge_base?.path
|
|
278
|
-
? resolve(dirPath, config.knowledge_base.path)
|
|
279
|
-
: null;
|
|
280
|
-
const knowledgeBasePathValid = knowledgeBasePath !== null && existsSync(join(knowledgeBasePath, "summaries"));
|
|
281
|
-
const coverageProof = existsSync(join(dirPath, STATE_DIR, "coverage.json"));
|
|
282
|
-
const retrievedSet = existsSync(join(dirPath, STATE_DIR, "relevant.json"));
|
|
283
|
-
const analysisPending = existsSync(join(dirPath, STATE_DIR, "analysis.json"));
|
|
284
|
-
const homePresent = existsSync(join(dirPath, "home.md"));
|
|
285
|
-
const outputs = countOutputFiles(dirPath);
|
|
286
|
-
const outputsPresent = outputs > 0;
|
|
287
|
-
const knowledgeBaseTotal = knowledgeBasePathValid ? countFilesRecursive(join(knowledgeBasePath, "summaries")) : 0;
|
|
288
|
-
const knowledgeBaseCompiled = Math.min(knowledgeBaseTotal, resolveInterfaceCompileReferenceCount(state, knowledgeBaseTotal));
|
|
289
|
-
const toSync = Math.max(0, knowledgeBaseTotal - knowledgeBaseCompiled);
|
|
290
|
-
const warnings = (toSync > 0 ? 1 : 0) +
|
|
291
|
-
((state.frontmatter_scanned ?? 0) > 0 && (state.frontmatter_scanned ?? 0) < knowledgeBaseTotal ? 1 : 0) +
|
|
292
|
-
(state.retrieve_complete && !coverageProof ? 1 : 0) +
|
|
293
|
-
(state.retrieve_complete && !(state.coverage_complete ?? false) ? 1 : 0) +
|
|
294
|
-
(!outputsPresent && state.last_compile ? 1 : 0) +
|
|
295
|
-
(analysisPending ? 1 : 0) +
|
|
296
|
-
validation.broken_links;
|
|
297
|
-
const errors = (!validation.config_present ? 1 : 0) +
|
|
298
|
-
(!validation.config_valid && validation.config_present ? 1 : 0) +
|
|
299
|
-
(!validation.config_type_match && validation.config_valid ? 1 : 0) +
|
|
300
|
-
(!knowledgeBasePathValid ? 1 : 0) +
|
|
301
|
-
(state.error_count ?? 0);
|
|
302
|
-
const activeRun = loadRuntimeRun(dirPath);
|
|
303
|
-
const inferredStage = resolveInterfaceStage(state, errors);
|
|
304
|
-
const inferredStatus = resolveInterfaceStatus(state, toSync, errors);
|
|
305
|
-
const stage = activeRun?.status === "running"
|
|
306
|
-
? activeRun.contract_type === "interface-plan"
|
|
307
|
-
? "create"
|
|
308
|
-
: activeRun.contract_type === "interface-retrieval"
|
|
309
|
-
? "retrieve"
|
|
310
|
-
: activeRun.contract_type === "interface-analysis"
|
|
311
|
-
? "analyze"
|
|
312
|
-
: activeRun.contract_type === "interface-output"
|
|
313
|
-
? "compile"
|
|
314
|
-
: inferredStage
|
|
315
|
-
: inferredStage;
|
|
316
|
-
const status = activeRun?.status === "running" ? "running" : inferredStatus;
|
|
317
|
-
return {
|
|
318
|
-
kind: "interface-health",
|
|
319
|
-
version: 1,
|
|
320
|
-
generated_at: now,
|
|
321
|
-
interface_name: interfaceName,
|
|
322
|
-
status,
|
|
323
|
-
stage,
|
|
324
|
-
summary: activeRun?.status === "running"
|
|
325
|
-
? `Running — ${activeRun.stage_label} via ${activeRun.executor.display_name}. ${activeRun.summary}`
|
|
326
|
-
: buildInterfaceSummary(status, stage, {
|
|
327
|
-
knowledgeBaseTotal,
|
|
328
|
-
knowledgeBaseCompiled,
|
|
329
|
-
toSync,
|
|
330
|
-
frontmatterScanned: state.frontmatter_scanned ?? 0,
|
|
331
|
-
abstractsRead: state.abstracts_read ?? 0,
|
|
332
|
-
relevant: state.relevant_count ?? 0,
|
|
333
|
-
delta: state.delta_count ?? 0,
|
|
334
|
-
}),
|
|
335
|
-
metrics: {
|
|
336
|
-
knowledge_base_total: knowledgeBaseTotal,
|
|
337
|
-
knowledge_base_compiled: knowledgeBaseCompiled,
|
|
338
|
-
to_compile: toSync,
|
|
339
|
-
frontmatter_scanned: state.frontmatter_scanned ?? 0,
|
|
340
|
-
candidate_count: state.candidate_count ?? 0,
|
|
341
|
-
abstracts_read: state.abstracts_read ?? 0,
|
|
342
|
-
expansion_passes: state.expansion_passes ?? 0,
|
|
343
|
-
relevant: state.relevant_count ?? 0,
|
|
344
|
-
rejected: state.rejected_count ?? 0,
|
|
345
|
-
delta: state.delta_count ?? 0,
|
|
346
|
-
entities: state.entity_count ??
|
|
347
|
-
state.extracted_entities ??
|
|
348
|
-
countFilesRecursive(join(dirPath, "knowledge", "entities")),
|
|
349
|
-
claims: state.claim_count ??
|
|
350
|
-
state.extracted_claims ??
|
|
351
|
-
countFilesRecursive(join(dirPath, "knowledge", "claims")),
|
|
352
|
-
outputs,
|
|
353
|
-
broken_links: validation.broken_links,
|
|
354
|
-
warnings: (state.warning_count ?? 0) + warnings,
|
|
355
|
-
errors,
|
|
356
|
-
},
|
|
357
|
-
checks: {
|
|
358
|
-
config_present: validation.config_present,
|
|
359
|
-
config_valid: validation.config_valid,
|
|
360
|
-
config_type_match: validation.config_type_match,
|
|
361
|
-
knowledge_base_path_valid: knowledgeBasePathValid,
|
|
362
|
-
coverage_proof: coverageProof,
|
|
363
|
-
coverage_complete: state.coverage_complete ?? false,
|
|
364
|
-
retrieved_set: retrievedSet,
|
|
365
|
-
analysis_pending: analysisPending,
|
|
366
|
-
outputs_present: outputsPresent,
|
|
367
|
-
home_present: homePresent,
|
|
368
|
-
links_valid: validation.broken_links === 0,
|
|
369
|
-
},
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
export function ensureInterfaceViewSpec(dirPath) {
|
|
373
|
-
const existing = loadInterfaceViewSpec(dirPath);
|
|
374
|
-
const now = new Date().toISOString();
|
|
375
|
-
const interfaceName = readInterfConfig(dirPath)?.name ?? basename(dirPath);
|
|
376
|
-
const defaults = {
|
|
377
|
-
kind: "interface-view-spec",
|
|
378
|
-
version: 1,
|
|
379
|
-
generated_at: now,
|
|
380
|
-
interface_name: interfaceName,
|
|
381
|
-
health_source: ".interf/health.json",
|
|
382
|
-
state_source: ".interf/state.json",
|
|
383
|
-
default_note: "home.md",
|
|
384
|
-
graph_scope: ["knowledge", "briefs", "summaries"],
|
|
385
|
-
cards: [
|
|
386
|
-
{ id: "compile", label: "Knowledge Base Compiled", metric: "knowledge_base_compiled", denominator_metric: "knowledge_base_total", format: "fraction" },
|
|
387
|
-
{
|
|
388
|
-
id: "scanned",
|
|
389
|
-
label: "Scanned",
|
|
390
|
-
metric: "frontmatter_scanned",
|
|
391
|
-
denominator_metric: "knowledge_base_total",
|
|
392
|
-
format: "fraction",
|
|
393
|
-
},
|
|
394
|
-
{ id: "abstracts", label: "Abstracts Read", metric: "abstracts_read", format: "number" },
|
|
395
|
-
{ id: "to-compile", label: "To Compile", metric: "to_compile", format: "number" },
|
|
396
|
-
{ id: "relevant", label: "Relevant", metric: "relevant", format: "number" },
|
|
397
|
-
{ id: "entities", label: "Entities", metric: "entities", format: "number" },
|
|
398
|
-
{ id: "outputs", label: "Outputs", metric: "outputs", format: "number" },
|
|
399
|
-
],
|
|
400
|
-
sections: [
|
|
401
|
-
{ id: "status", type: "status", title: "Compile Status", path: ".interf/health.json" },
|
|
402
|
-
{ id: "cards", type: "cards", title: "Key Metrics", path: ".interf/health.json" },
|
|
403
|
-
{ id: "graph", type: "graph", title: "Knowledge Graph", paths: ["knowledge", "briefs", "summaries"] },
|
|
404
|
-
{
|
|
405
|
-
id: "core-docs",
|
|
406
|
-
type: "documents",
|
|
407
|
-
title: "Core Docs",
|
|
408
|
-
paths: ["home.md", "briefs", "summaries", "knowledge/claims", "knowledge/entities"],
|
|
409
|
-
},
|
|
410
|
-
{ id: "claims", type: "table", title: "Claims", path: "knowledge/claims" },
|
|
411
|
-
],
|
|
412
|
-
};
|
|
413
|
-
if (existing) {
|
|
414
|
-
const normalized = normalizeInterfaceViewSpec(existing, defaults);
|
|
415
|
-
if (JSON.stringify(normalized) !== JSON.stringify(existing)) {
|
|
416
|
-
saveInterfaceViewSpec(dirPath, normalized);
|
|
417
|
-
}
|
|
418
|
-
return normalized;
|
|
419
|
-
}
|
|
420
|
-
saveInterfaceViewSpec(dirPath, defaults);
|
|
421
|
-
return defaults;
|
|
422
|
-
}
|
|
423
|
-
export function ensureKnowledgeBaseViewSpec(dirPath) {
|
|
424
|
-
const existing = loadKnowledgeBaseViewSpec(dirPath);
|
|
425
|
-
const now = new Date().toISOString();
|
|
426
|
-
const knowledgeBaseName = readInterfConfig(dirPath)?.name ?? basename(dirPath);
|
|
427
|
-
const defaults = {
|
|
428
|
-
kind: "knowledge-base-view-spec",
|
|
429
|
-
version: 1,
|
|
430
|
-
generated_at: now,
|
|
431
|
-
target_name: knowledgeBaseName,
|
|
432
|
-
health_source: ".interf/health.json",
|
|
433
|
-
state_source: ".interf/state.json",
|
|
434
|
-
default_note: "home.md",
|
|
435
|
-
graph_scope: ["summaries", "knowledge"],
|
|
436
|
-
cards: [
|
|
437
|
-
{ id: "source-total", label: "Source Files", metric: "source_total", format: "number" },
|
|
438
|
-
{ id: "summarized", label: "Summarized", metric: "source_covered", denominator_metric: "source_total", format: "fraction" },
|
|
439
|
-
{ id: "to-summarize", label: "To Summarize", metric: "to_summarize", format: "number" },
|
|
440
|
-
{ id: "compiled", label: "Compiled", metric: "compiled", denominator_metric: "summarized", format: "fraction" },
|
|
441
|
-
{ id: "entities", label: "Entities", metric: "entities", format: "number" },
|
|
442
|
-
{ id: "claims", label: "Claims", metric: "claims", format: "number" },
|
|
443
|
-
],
|
|
444
|
-
sections: [
|
|
445
|
-
{ id: "status", type: "status", title: "Compile Status", path: ".interf/health.json" },
|
|
446
|
-
{ id: "cards", type: "cards", title: "Key Metrics", path: ".interf/health.json" },
|
|
447
|
-
{ id: "graph", type: "graph", title: "Knowledge Graph", paths: ["summaries", "knowledge"] },
|
|
448
|
-
{
|
|
449
|
-
id: "core-docs",
|
|
450
|
-
type: "documents",
|
|
451
|
-
title: "Core Docs",
|
|
452
|
-
paths: ["home.md", "knowledge/indexes", "knowledge/entities", "knowledge/claims", "summaries"],
|
|
453
|
-
},
|
|
454
|
-
{ id: "claims", type: "table", title: "Claims", path: "knowledge/claims" },
|
|
455
|
-
],
|
|
456
|
-
};
|
|
457
|
-
if (existing) {
|
|
458
|
-
const normalized = normalizeKnowledgeBaseViewSpec(existing, defaults);
|
|
459
|
-
if (JSON.stringify(normalized) !== JSON.stringify(existing)) {
|
|
460
|
-
saveKnowledgeBaseViewSpec(dirPath, normalized);
|
|
461
|
-
}
|
|
462
|
-
return normalized;
|
|
463
|
-
}
|
|
464
|
-
saveKnowledgeBaseViewSpec(dirPath, defaults);
|
|
465
|
-
return defaults;
|
|
466
|
-
}
|
|
467
|
-
export function ensureKnowledgeBaseSourceAccess(dirPath) {
|
|
468
|
-
const now = new Date().toISOString();
|
|
469
|
-
const config = readInterfConfig(dirPath);
|
|
470
|
-
const knowledgeBaseName = config?.name ?? basename(dirPath);
|
|
471
|
-
const sourcePath = resolveKnowledgeBaseSourcePath(dirPath, config);
|
|
472
|
-
const discovery = discoverSourceFiles(sourcePath, dirPath);
|
|
473
|
-
const sampleFiles = [...discovery.sourceFiles]
|
|
474
|
-
.sort((a, b) => a.length - b.length || a.localeCompare(b))
|
|
475
|
-
.slice(0, 10);
|
|
476
|
-
const sourceRoot = relative(dirPath, sourcePath) || ".";
|
|
477
|
-
const suggestedChecks = sampleFiles.slice(0, 3).map((file) => resolve(sourcePath, file));
|
|
478
|
-
const artifact = {
|
|
479
|
-
kind: "knowledge-base-source-access",
|
|
480
|
-
version: 1,
|
|
481
|
-
generated_at: now,
|
|
482
|
-
target_name: knowledgeBaseName,
|
|
483
|
-
source_root: sourceRoot,
|
|
484
|
-
source_total: discovery.totalCount,
|
|
485
|
-
sample_files: sampleFiles,
|
|
486
|
-
suggested_checks: suggestedChecks,
|
|
487
|
-
};
|
|
488
|
-
mkdirSync(join(dirPath, STATE_DIR), { recursive: true });
|
|
489
|
-
writeFileSync(sourceAccessPath(dirPath), JSON.stringify(artifact, null, 2) + "\n");
|
|
490
|
-
return artifact;
|
|
491
|
-
}
|
|
492
|
-
export function resolveKnowledgeBaseStatus(rawTotal, summarized, toSummarize, toCompile, errors, state) {
|
|
493
|
-
if (errors > 0)
|
|
494
|
-
return "failed";
|
|
495
|
-
if (rawTotal === 0 && summarized === 0 && state.last_summarize === null && state.last_compile === null)
|
|
496
|
-
return "idle";
|
|
497
|
-
if (toSummarize > 0 || toCompile > 0)
|
|
498
|
-
return "stale";
|
|
499
|
-
return "compiled";
|
|
500
|
-
}
|
|
501
|
-
export function resolveKnowledgeBaseStage(state, rawTotal, summarized, toSummarize, toCompile, errors) {
|
|
502
|
-
if (errors > 0)
|
|
503
|
-
return "failed";
|
|
504
|
-
if (rawTotal === 0 && summarized === 0 && state.last_summarize === null && state.last_compile === null)
|
|
505
|
-
return "idle";
|
|
506
|
-
if (toSummarize > 0)
|
|
507
|
-
return "summarize";
|
|
508
|
-
if (toCompile > 0)
|
|
509
|
-
return "compile";
|
|
510
|
-
return "compiled";
|
|
511
|
-
}
|
|
512
|
-
function buildKnowledgeBaseSummary(status, stage, metrics) {
|
|
513
|
-
if (status === "failed")
|
|
514
|
-
return "Failed — required knowledge-base inputs are missing.";
|
|
515
|
-
if (status === "idle")
|
|
516
|
-
return "Idle — no raw files have been ingested yet.";
|
|
517
|
-
if (stage === "summarize") {
|
|
518
|
-
return `Stale — ${metrics.toSummarize} raw files still need summaries (${metrics.rawCovered}/${metrics.rawTotal} summarized).`;
|
|
519
|
-
}
|
|
520
|
-
if (stage === "compile") {
|
|
521
|
-
return `Stale — ${metrics.toCompile} summaries still need graph compile (${metrics.compiled}/${metrics.summarized} compiled).`;
|
|
522
|
-
}
|
|
523
|
-
return `Compiled — ${metrics.compiled}/${metrics.summarized} summaries compiled, ${metrics.rawCovered}/${metrics.rawTotal} raw files summarized.`;
|
|
524
|
-
}
|
|
525
|
-
export function normalizeInterfaceViewSpec(existing, defaults) {
|
|
526
|
-
const existingCards = Array.isArray(existing.cards) ? existing.cards : defaults.cards;
|
|
527
|
-
const cards = existingCards.map((card) => {
|
|
528
|
-
if (card.id === "compile" && card.format === "fraction" && !card.denominator_metric) {
|
|
529
|
-
return {
|
|
530
|
-
...card,
|
|
531
|
-
metric: "knowledge_base_compiled",
|
|
532
|
-
denominator_metric: "knowledge_base_total",
|
|
533
|
-
};
|
|
534
|
-
}
|
|
535
|
-
return card;
|
|
536
|
-
});
|
|
537
|
-
return {
|
|
538
|
-
...defaults,
|
|
539
|
-
...existing,
|
|
540
|
-
cards,
|
|
541
|
-
sections: Array.isArray(existing.sections) && existing.sections.length > 0 ? existing.sections : defaults.sections,
|
|
542
|
-
graph_scope: Array.isArray(existing.graph_scope) && existing.graph_scope.length > 0
|
|
543
|
-
? existing.graph_scope
|
|
544
|
-
: defaults.graph_scope,
|
|
545
|
-
};
|
|
546
|
-
}
|
|
547
|
-
export function normalizeKnowledgeBaseViewSpec(existing, defaults) {
|
|
548
|
-
const existingCards = Array.isArray(existing.cards) ? existing.cards : defaults.cards;
|
|
549
|
-
const cards = existingCards.map((card) => card);
|
|
550
|
-
return {
|
|
551
|
-
...defaults,
|
|
552
|
-
...existing,
|
|
553
|
-
cards,
|
|
554
|
-
sections: Array.isArray(existing.sections) && existing.sections.length > 0 ? existing.sections : defaults.sections,
|
|
555
|
-
graph_scope: Array.isArray(existing.graph_scope) && existing.graph_scope.length > 0
|
|
556
|
-
? existing.graph_scope
|
|
557
|
-
: defaults.graph_scope,
|
|
558
|
-
};
|
|
559
|
-
}
|
|
560
|
-
function loadViewSpec(filePath, schema) {
|
|
561
|
-
try {
|
|
562
|
-
const raw = JSON.parse(readFileSync(filePath, "utf8"));
|
|
563
|
-
const parsed = schema.safeParse(raw);
|
|
564
|
-
return parsed.success ? (parsed.data ?? null) : null;
|
|
565
|
-
}
|
|
566
|
-
catch {
|
|
567
|
-
return null;
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
export function resolveInterfaceStatus(state, toSync, errors) {
|
|
571
|
-
if (errors > 0)
|
|
572
|
-
return "failed";
|
|
573
|
-
if (hasInterfaceStagePrepared(state, "analyze") || hasInterfaceStagePrepared(state, "retrieve"))
|
|
574
|
-
return "running";
|
|
575
|
-
if (state.last_compile === null)
|
|
576
|
-
return "idle";
|
|
577
|
-
if (toSync > 0)
|
|
578
|
-
return "stale";
|
|
579
|
-
return "compiled";
|
|
580
|
-
}
|
|
581
|
-
export function resolveInterfaceStage(state, errors) {
|
|
582
|
-
if (errors > 0)
|
|
583
|
-
return "failed";
|
|
584
|
-
if (hasInterfaceStagePrepared(state, "analyze"))
|
|
585
|
-
return "compile";
|
|
586
|
-
if (hasInterfaceStagePrepared(state, "retrieve"))
|
|
587
|
-
return "analyze";
|
|
588
|
-
if (state.compile_complete || state.last_compile)
|
|
589
|
-
return "compiled";
|
|
590
|
-
return "idle";
|
|
591
|
-
}
|
|
592
|
-
function buildInterfaceSummary(status, stage, metrics) {
|
|
593
|
-
if (status === "failed")
|
|
594
|
-
return "Failed — required interface inputs are missing.";
|
|
595
|
-
if (status === "running") {
|
|
596
|
-
return stage === "create"
|
|
597
|
-
? "Runtime design in progress."
|
|
598
|
-
: `Compile in progress — ${stage} stage active.`;
|
|
599
|
-
}
|
|
600
|
-
if (status === "idle")
|
|
601
|
-
return "Idle — interface has not been compiled yet.";
|
|
602
|
-
if (status === "stale") {
|
|
603
|
-
return `Stale — ${metrics.toSync} new summary files since last compile (${metrics.knowledgeBaseCompiled}/${metrics.knowledgeBaseTotal} covered).`;
|
|
604
|
-
}
|
|
605
|
-
return `Compiled — scanned ${metrics.frontmatterScanned}/${metrics.knowledgeBaseTotal} summaries, reviewed ${metrics.abstractsRead} abstracts, selected ${metrics.relevant} relevant, ${metrics.toSync} to compile.`;
|
|
606
|
-
}
|
|
607
|
-
function countOutputFiles(dirPath) {
|
|
608
|
-
return [
|
|
609
|
-
join(dirPath, "knowledge", "entities"),
|
|
610
|
-
join(dirPath, "knowledge", "claims"),
|
|
611
|
-
join(dirPath, "briefs"),
|
|
612
|
-
join(dirPath, "summaries"),
|
|
613
|
-
].reduce((total, dir) => total + countFilesRecursive(dir), 0);
|
|
614
|
-
}
|
|
615
|
-
function countKnowledgeBaseOutputFiles(dirPath) {
|
|
616
|
-
return [
|
|
617
|
-
join(dirPath, "knowledge", "entities"),
|
|
618
|
-
join(dirPath, "knowledge", "claims"),
|
|
619
|
-
join(dirPath, "knowledge", "indexes"),
|
|
620
|
-
].reduce((total, dir) => total + countFilesRecursive(dir), 0);
|
|
621
|
-
}
|
|
622
|
-
function hasInterfaceStagePrepared(state, stage) {
|
|
623
|
-
const stageComplete = stage === "retrieve" ? state.retrieve_complete : state.analyze_complete;
|
|
624
|
-
const stageAt = stage === "retrieve" ? state.last_retrieve : state.last_analyze;
|
|
625
|
-
if (!stageComplete)
|
|
626
|
-
return false;
|
|
627
|
-
if (stageAt === null)
|
|
628
|
-
return true;
|
|
629
|
-
if (state.last_compile === null)
|
|
630
|
-
return true;
|
|
631
|
-
return stageAt > state.last_compile;
|
|
632
|
-
}
|
|
1
|
+
export { statePath, healthPath, viewSpecPath, sourceAccessPath, } from "./state-paths.js";
|
|
2
|
+
export { loadState, saveState, loadInterfaceHealth, loadKnowledgeBaseHealth, saveInterfaceHealth, saveKnowledgeBaseHealth, loadInterfaceViewSpec, loadKnowledgeBaseViewSpec, loadKnowledgeBaseSourceAccess, saveInterfaceViewSpec, saveKnowledgeBaseViewSpec, initKnowledgeBaseState, initInterfaceState, } from "./state-io.js";
|
|
3
|
+
export { refreshInterfaceArtifacts, refreshKnowledgeBaseArtifacts, } from "./state-artifacts.js";
|
|
4
|
+
export { computeKnowledgeBaseHealth, computeInterfaceHealth, resolveKnowledgeBaseStatus, resolveKnowledgeBaseStage, resolveInterfaceStatus, resolveInterfaceStage, } from "./state-health.js";
|
|
5
|
+
export { ensureInterfaceViewSpec, ensureKnowledgeBaseViewSpec, ensureKnowledgeBaseSourceAccess, normalizeInterfaceViewSpec, normalizeKnowledgeBaseViewSpec, } from "./state-view.js";
|
|
633
6
|
//# sourceMappingURL=state.js.map
|