@interf/compiler 0.33.0 → 0.50.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 (234) hide show
  1. package/README.md +122 -226
  2. package/dist/cli/commands/agents.js +1 -32
  3. package/dist/cli/commands/benchmark.d.ts +2 -3
  4. package/dist/cli/commands/benchmark.js +1 -31
  5. package/dist/cli/commands/build-plan.js +26 -50
  6. package/dist/cli/commands/build.d.ts +2 -3
  7. package/dist/cli/commands/build.js +1 -31
  8. package/dist/cli/commands/graphs.js +177 -32
  9. package/dist/cli/commands/mcp.d.ts +1 -0
  10. package/dist/cli/commands/mcp.js +223 -126
  11. package/dist/cli/commands/project.js +10 -36
  12. package/dist/cli/commands/reset.d.ts +2 -3
  13. package/dist/cli/commands/reset.js +1 -22
  14. package/dist/cli/commands/runs.js +86 -33
  15. package/dist/cli/commands/status.js +3 -24
  16. package/dist/cli/commands/traces.js +1 -29
  17. package/dist/cli/commands/wizard.js +17 -29
  18. package/dist/cli/lib/http-client.d.ts +39 -0
  19. package/dist/cli/lib/http-client.js +73 -0
  20. package/dist/packages/build-plans/authoring/brief.d.ts +25 -4
  21. package/dist/packages/build-plans/authoring/build-plan-authoring.d.ts +42 -1
  22. package/dist/packages/build-plans/authoring/build-plan-authoring.js +470 -63
  23. package/dist/packages/build-plans/authoring/build-plan-edit-session.d.ts +9 -0
  24. package/dist/packages/build-plans/authoring/build-plan-edit-session.js +27 -10
  25. package/dist/packages/build-plans/authoring/build-plan-improvement.js +62 -8
  26. package/dist/packages/build-plans/authoring/lib/build-plan-edit-utils.d.ts +1 -0
  27. package/dist/packages/build-plans/package/build-plan-definitions.d.ts +0 -1
  28. package/dist/packages/build-plans/package/build-plan-definitions.js +5 -3
  29. package/dist/packages/build-plans/package/build-plan-stage-runner.d.ts +1 -0
  30. package/dist/packages/build-plans/package/build-plan-stage-runner.js +2 -1
  31. package/dist/packages/build-plans/package/builtin-build-plan.d.ts +2 -2
  32. package/dist/packages/build-plans/package/builtin-build-plan.js +3 -3
  33. package/dist/packages/build-plans/package/context-interface.d.ts +3 -0
  34. package/dist/packages/build-plans/package/context-interface.js +5 -5
  35. package/dist/packages/build-plans/package/interf-build-plan-package.js +22 -22
  36. package/dist/packages/build-plans/package/local-build-plans.d.ts +10 -5
  37. package/dist/packages/build-plans/package/local-build-plans.js +57 -32
  38. package/dist/packages/contracts/index.d.ts +4 -3
  39. package/dist/packages/contracts/index.js +2 -1
  40. package/dist/packages/contracts/lib/context-graph-layer.d.ts +161 -0
  41. package/dist/packages/contracts/lib/context-graph-layer.js +216 -0
  42. package/dist/packages/contracts/lib/project-paths.d.ts +7 -0
  43. package/dist/packages/contracts/lib/project-paths.js +9 -0
  44. package/dist/packages/contracts/lib/project-schema.d.ts +264 -1
  45. package/dist/packages/contracts/lib/project-schema.js +38 -13
  46. package/dist/packages/contracts/lib/schema.d.ts +556 -23
  47. package/dist/packages/contracts/lib/schema.js +279 -18
  48. package/dist/packages/contracts/utils/filesystem.d.ts +1 -0
  49. package/dist/packages/contracts/utils/filesystem.js +29 -1
  50. package/dist/packages/projects/lib/schema.d.ts +6 -8
  51. package/dist/packages/projects/lib/schema.js +3 -1
  52. package/dist/packages/projects/source-config.d.ts +0 -5
  53. package/dist/packages/projects/source-config.js +9 -22
  54. package/dist/packages/runtime/actions/fields.d.ts +4 -0
  55. package/dist/packages/runtime/actions/form-builders.js +79 -31
  56. package/dist/packages/runtime/actions/form-validators.js +9 -3
  57. package/dist/packages/runtime/actions/helpers.js +3 -3
  58. package/dist/packages/runtime/actions/registry.d.ts +1 -1
  59. package/dist/packages/runtime/actions/registry.js +1 -1
  60. package/dist/packages/runtime/actions/requests.d.ts +1 -1
  61. package/dist/packages/runtime/actions/requests.js +12 -6
  62. package/dist/packages/runtime/actions/schemas.d.ts +7 -0
  63. package/dist/packages/runtime/actions/schemas.js +1 -0
  64. package/dist/packages/runtime/agent-handoff.js +8 -7
  65. package/dist/packages/runtime/agents/lib/execution-profile.d.ts +14 -0
  66. package/dist/packages/runtime/agents/lib/execution-profile.js +23 -0
  67. package/dist/packages/runtime/agents/lib/execution.js +14 -8
  68. package/dist/packages/runtime/agents/lib/executors.d.ts +1 -0
  69. package/dist/packages/runtime/agents/lib/executors.js +11 -2
  70. package/dist/packages/runtime/agents/lib/logs.d.ts +10 -0
  71. package/dist/packages/runtime/agents/lib/logs.js +32 -8
  72. package/dist/packages/runtime/agents/lib/preflight.js +4 -1
  73. package/dist/packages/runtime/agents/lib/render.d.ts +18 -0
  74. package/dist/packages/runtime/agents/lib/render.js +44 -18
  75. package/dist/packages/runtime/agents/lib/shell-templates.js +105 -63
  76. package/dist/packages/runtime/agents/lib/shells.d.ts +29 -0
  77. package/dist/packages/runtime/agents/lib/shells.js +158 -32
  78. package/dist/packages/runtime/agents/lib/source-context-scan.d.ts +10 -0
  79. package/dist/packages/runtime/agents/lib/source-context-scan.js +388 -0
  80. package/dist/packages/runtime/agents/lib/status.js +1 -14
  81. package/dist/packages/runtime/agents/lib/string-utils.d.ts +16 -0
  82. package/dist/packages/runtime/agents/lib/string-utils.js +36 -0
  83. package/dist/packages/runtime/agents/lib/types.d.ts +1 -0
  84. package/dist/packages/runtime/agents/providers/codex.js +2 -0
  85. package/dist/packages/runtime/agents/role-executors.js +2 -1
  86. package/dist/packages/runtime/auth/session-store.js +11 -3
  87. package/dist/packages/runtime/benchmark-question-draft.d.ts +3 -0
  88. package/dist/packages/runtime/benchmark-question-draft.js +57 -28
  89. package/dist/packages/runtime/build/artifact-status.d.ts +1 -1
  90. package/dist/packages/runtime/build/artifact-status.js +1 -1
  91. package/dist/packages/runtime/build/build-evidence.d.ts +2 -1
  92. package/dist/packages/runtime/build/build-evidence.js +11 -5
  93. package/dist/packages/runtime/build/build-pipeline.js +89 -5
  94. package/dist/packages/runtime/build/build-stage-plan.js +3 -1
  95. package/dist/packages/runtime/build/build-stage-runner.js +169 -32
  96. package/dist/packages/runtime/build/build-target.d.ts +3 -0
  97. package/dist/packages/runtime/build/build-target.js +25 -1
  98. package/dist/packages/runtime/build/check-evaluator.d.ts +1 -1
  99. package/dist/packages/runtime/build/check-evaluator.js +655 -4
  100. package/dist/packages/runtime/build/context-graph-paths.d.ts +13 -0
  101. package/dist/packages/runtime/build/context-graph-paths.js +27 -0
  102. package/dist/packages/runtime/build/index.d.ts +2 -2
  103. package/dist/packages/runtime/build/index.js +2 -2
  104. package/dist/packages/runtime/build/inspect-map.d.ts +10 -0
  105. package/dist/packages/runtime/build/inspect-map.js +270 -0
  106. package/dist/packages/runtime/build/lib/schema.d.ts +246 -53
  107. package/dist/packages/runtime/build/lib/schema.js +173 -15
  108. package/dist/packages/runtime/build/native-entrypoint.d.ts +2 -0
  109. package/dist/packages/runtime/build/native-entrypoint.js +286 -0
  110. package/dist/packages/runtime/build/runtime-contracts.js +9 -3
  111. package/dist/packages/runtime/build/runtime-log-paths.d.ts +3 -0
  112. package/dist/packages/runtime/build/runtime-log-paths.js +16 -0
  113. package/dist/packages/runtime/build/runtime-prompt.js +6 -4
  114. package/dist/packages/runtime/build/runtime-runs.js +63 -10
  115. package/dist/packages/runtime/build/runtime-types.d.ts +4 -1
  116. package/dist/packages/runtime/build/runtime.d.ts +3 -1
  117. package/dist/packages/runtime/build/runtime.js +3 -1
  118. package/dist/packages/runtime/build/source-files.js +11 -2
  119. package/dist/packages/runtime/build/source-inventory.d.ts +1 -0
  120. package/dist/packages/runtime/build/source-inventory.js +246 -7
  121. package/dist/packages/runtime/build/source-manifest.d.ts +11 -0
  122. package/dist/packages/runtime/build/source-manifest.js +30 -2
  123. package/dist/packages/runtime/build/stage-evidence.js +80 -11
  124. package/dist/packages/runtime/build/stage-manifest.d.ts +45 -0
  125. package/dist/packages/runtime/build/stage-manifest.js +1125 -0
  126. package/dist/packages/runtime/build/stage-reuse.js +12 -0
  127. package/dist/packages/runtime/build/stage-session.d.ts +81 -0
  128. package/dist/packages/runtime/build/stage-session.js +308 -0
  129. package/dist/packages/runtime/build/state-io.js +10 -11
  130. package/dist/packages/runtime/build/state-view.js +1 -1
  131. package/dist/packages/runtime/build/state.d.ts +1 -1
  132. package/dist/packages/runtime/build/state.js +1 -1
  133. package/dist/packages/runtime/build/summary-coverage-index.d.ts +21 -0
  134. package/dist/packages/runtime/build/summary-coverage-index.js +189 -0
  135. package/dist/packages/runtime/build/traces.js +3 -3
  136. package/dist/packages/runtime/build/validate-context-graph.d.ts +1 -1
  137. package/dist/packages/runtime/build/validate-context-graph.js +5 -5
  138. package/dist/packages/runtime/build/validate.d.ts +1 -1
  139. package/dist/packages/runtime/build/validate.js +1 -1
  140. package/dist/packages/runtime/client.d.ts +3 -3
  141. package/dist/packages/runtime/client.js +8 -13
  142. package/dist/packages/runtime/context-checks.js +13 -0
  143. package/dist/packages/runtime/context-graph-scaffold.js +2 -1
  144. package/dist/packages/runtime/context-graph-semantic-graph.d.ts +9 -0
  145. package/dist/packages/runtime/context-graph-semantic-graph.js +416 -0
  146. package/dist/packages/runtime/execution/lib/schema.d.ts +34 -31
  147. package/dist/packages/runtime/index.d.ts +2 -2
  148. package/dist/packages/runtime/index.js +1 -1
  149. package/dist/packages/runtime/native-run-handlers.d.ts +38 -0
  150. package/dist/packages/runtime/native-run-handlers.js +52 -33
  151. package/dist/packages/runtime/plan-artifact-contract.js +1 -1
  152. package/dist/packages/runtime/project-source-state.d.ts +4 -4
  153. package/dist/packages/runtime/project-source-state.js +5 -2
  154. package/dist/packages/runtime/project-store.d.ts +5 -0
  155. package/dist/packages/runtime/project-store.js +30 -3
  156. package/dist/packages/runtime/requested-artifacts.js +1 -1
  157. package/dist/packages/runtime/run-observability.js +9 -4
  158. package/dist/packages/runtime/runtime-action-proposals.js +3 -3
  159. package/dist/packages/runtime/runtime-build-plans.js +47 -3
  160. package/dist/packages/runtime/runtime-build-runs.js +9 -16
  161. package/dist/packages/runtime/runtime-caches.d.ts +26 -0
  162. package/dist/packages/runtime/runtime-caches.js +47 -0
  163. package/dist/packages/runtime/runtime-jobs.js +6 -6
  164. package/dist/packages/runtime/runtime-project-mutations.js +1 -0
  165. package/dist/packages/runtime/runtime-project-reads.d.ts +4 -1
  166. package/dist/packages/runtime/runtime-project-reads.js +229 -36
  167. package/dist/packages/runtime/runtime-proposal-helpers.js +6 -6
  168. package/dist/packages/runtime/runtime-resource-builders.d.ts +4 -2
  169. package/dist/packages/runtime/runtime-resource-builders.js +16 -14
  170. package/dist/packages/runtime/runtime-status.d.ts +14 -0
  171. package/dist/packages/runtime/runtime-status.js +15 -0
  172. package/dist/packages/runtime/runtime-verify-runs.js +6 -5
  173. package/dist/packages/runtime/runtime.d.ts +439 -22
  174. package/dist/packages/runtime/runtime.js +16 -2
  175. package/dist/packages/runtime/schemas/actions.d.ts +24 -0
  176. package/dist/packages/runtime/schemas/agents.d.ts +28 -0
  177. package/dist/packages/runtime/schemas/agents.js +33 -0
  178. package/dist/packages/runtime/schemas/build-plans.d.ts +181 -8
  179. package/dist/packages/runtime/schemas/build-plans.js +36 -2
  180. package/dist/packages/runtime/schemas/context-graphs.d.ts +1522 -0
  181. package/dist/packages/runtime/schemas/context-graphs.js +110 -0
  182. package/dist/packages/runtime/schemas/files.d.ts +7 -347
  183. package/dist/packages/runtime/schemas/files.js +1 -24
  184. package/dist/packages/runtime/schemas/index.d.ts +1 -0
  185. package/dist/packages/runtime/schemas/index.js +1 -0
  186. package/dist/packages/runtime/schemas/jobs.js +4 -0
  187. package/dist/packages/runtime/schemas/projects.d.ts +48 -21
  188. package/dist/packages/runtime/schemas/projects.js +34 -10
  189. package/dist/packages/runtime/schemas/runs.d.ts +1009 -240
  190. package/dist/packages/runtime/schemas/runs.js +17 -0
  191. package/dist/packages/runtime/service/openapi.js +1 -0
  192. package/dist/packages/runtime/service/operations.d.ts +1666 -145
  193. package/dist/packages/runtime/service/operations.js +147 -17
  194. package/dist/packages/runtime/service/routes.d.ts +11 -3
  195. package/dist/packages/runtime/service/routes.js +11 -3
  196. package/dist/packages/runtime/service/server-app-boot.js +2 -2
  197. package/dist/packages/runtime/service/server-helpers.d.ts +11 -0
  198. package/dist/packages/runtime/service/server-helpers.js +19 -0
  199. package/dist/packages/runtime/service/server-routes-action-proposals.js +4 -2
  200. package/dist/packages/runtime/service/server-routes-agents.js +19 -85
  201. package/dist/packages/runtime/service/server-routes-build-plans.js +14 -11
  202. package/dist/packages/runtime/service/server-routes-project-context.js +102 -7
  203. package/dist/packages/runtime/service/server-routes-project-jobs.js +19 -12
  204. package/dist/packages/runtime/service/server-routes-project-runs.js +5 -2
  205. package/dist/packages/runtime/service/server-routes-projects.js +6 -2
  206. package/dist/packages/runtime/service/server-routes-runs.js +11 -4
  207. package/dist/packages/runtime/verify/lib/schema.js +12 -0
  208. package/dist/packages/runtime/verify/test-file-guard.d.ts +2 -0
  209. package/dist/packages/runtime/verify/test-file-guard.js +29 -0
  210. package/dist/packages/runtime/verify/verify-execution.d.ts +7 -0
  211. package/dist/packages/runtime/verify/verify-execution.js +109 -35
  212. package/dist/packages/runtime/verify/verify-paths.d.ts +1 -0
  213. package/dist/packages/runtime/verify/verify-paths.js +4 -0
  214. package/dist/packages/runtime/verify/verify-specs.js +49 -39
  215. package/dist/packages/runtime/wire-schemas.d.ts +1 -1
  216. package/dist/packages/runtime/wire-schemas.js +1 -1
  217. package/package.json +2 -8
  218. package/public-repo/CONTRIBUTING.md +10 -3
  219. package/public-repo/README.md +122 -226
  220. package/public-repo/build-plans/interf-default/README.md +15 -12
  221. package/public-repo/build-plans/interf-default/build/stages/entrypoint/SKILL.md +74 -0
  222. package/public-repo/build-plans/interf-default/build/stages/knowledge/SKILL.md +95 -0
  223. package/public-repo/build-plans/interf-default/build/stages/summarize/SKILL.md +38 -5
  224. package/public-repo/build-plans/interf-default/build-plan.json +27 -23
  225. package/public-repo/build-plans/interf-default/build-plan.schema.json +24 -20
  226. package/public-repo/build-plans/interf-default/use/query/SKILL.md +8 -7
  227. package/public-repo/openapi/local-service.openapi.json +11637 -4213
  228. package/public-repo/skills/interf/SKILL.md +174 -134
  229. package/dist/packages/runtime/build/runtime-paths.d.ts +0 -8
  230. package/dist/packages/runtime/build/runtime-paths.js +0 -26
  231. package/dist/packages/runtime/build/state-paths.d.ts +0 -7
  232. package/dist/packages/runtime/build/state-paths.js +0 -22
  233. package/public-repo/build-plans/interf-default/build/stages/shape/SKILL.md +0 -34
  234. package/public-repo/build-plans/interf-default/build/stages/structure/SKILL.md +0 -28
@@ -0,0 +1,416 @@
1
+ import { createHash } from "node:crypto";
2
+ import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
3
+ import { basename, extname, join, posix } from "node:path";
4
+ import { parseJsonFrontmatter } from "../contracts/utils/parse.js";
5
+ import { knowledgeNoteKind, layerForPath, normalizeLayerPath, } from "../contracts/lib/context-graph-layer.js";
6
+ import { ContextGraphSemanticGraphSchema, } from "./schemas/index.js";
7
+ // Upper bound on markdown notes rendered into the semantic graph. This is a
8
+ // pathological-input guard, NOT a display budget: it must comfortably exceed a
9
+ // realistic Context Graph's note count so the canvas renders the WHOLE graph and
10
+ // agrees with the GraphManifest node count, instead of truncating to the first
11
+ // N alphabetical notes and showing a different, smaller graph than readiness
12
+ // counted. The old value (180) silently dropped the bulk of a ~500-note graph —
13
+ // turning real, connected content into off-canvas "islands". A real Context
14
+ // Graph stays well under this ceiling; only a runaway build approaches it.
15
+ const MAX_MARKDOWN_NOTES = 5000;
16
+ const WIKILINK_PATTERN = /\[\[([^\]\n]+)\]\]/g;
17
+ const MARKDOWN_LINK_PATTERN = /!?\[[^\]\n]*\]\(([^)\n]+)\)/g;
18
+ function shortHash(value, length = 16) {
19
+ return createHash("sha256")
20
+ .update(value)
21
+ .digest("hex")
22
+ .slice(0, length);
23
+ }
24
+ function noteKey(value) {
25
+ return normalizeLayerPath(value)
26
+ .replace(/\.md$/i, "")
27
+ .trim()
28
+ .toLowerCase();
29
+ }
30
+ function slugKey(value) {
31
+ return value
32
+ .trim()
33
+ .toLowerCase()
34
+ .replace(/['"]/g, "")
35
+ .replace(/[^a-z0-9]+/g, "-")
36
+ .replace(/^-+|-+$/g, "");
37
+ }
38
+ function withoutMarkdownExtension(path) {
39
+ return path.replace(/\.md$/i, "");
40
+ }
41
+ function markdownBasename(path) {
42
+ return basename(path, extname(path));
43
+ }
44
+ function addGraphFile(files, contextGraphPath, relativePath) {
45
+ const absolutePath = join(contextGraphPath, relativePath);
46
+ if (!existsSync(absolutePath) || !statSync(absolutePath).isFile())
47
+ return;
48
+ if (!relativePath.toLowerCase().endsWith(".md"))
49
+ return;
50
+ files.push(normalizeLayerPath(relativePath));
51
+ }
52
+ function collectMarkdownFiles(files, contextGraphPath, relativeDir) {
53
+ const absoluteDir = join(contextGraphPath, relativeDir);
54
+ if (!existsSync(absoluteDir) || !statSync(absoluteDir).isDirectory())
55
+ return;
56
+ const entries = readdirSync(absoluteDir, { withFileTypes: true })
57
+ .sort((left, right) => left.name.localeCompare(right.name));
58
+ for (const entry of entries) {
59
+ if (entry.name.startsWith("."))
60
+ continue;
61
+ const relativePath = normalizeLayerPath(join(relativeDir, entry.name));
62
+ if (entry.isDirectory()) {
63
+ collectMarkdownFiles(files, contextGraphPath, relativePath);
64
+ continue;
65
+ }
66
+ if (entry.isFile())
67
+ addGraphFile(files, contextGraphPath, relativePath);
68
+ }
69
+ }
70
+ function listMarkdownFiles(contextGraphPath) {
71
+ const files = [];
72
+ collectMarkdownFiles(files, contextGraphPath, ".");
73
+ return Array.from(new Set(files)).slice(0, MAX_MARKDOWN_NOTES);
74
+ }
75
+ function stringValue(value) {
76
+ return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
77
+ }
78
+ function stringValues(value) {
79
+ if (Array.isArray(value))
80
+ return value.flatMap((item) => stringValues(item));
81
+ if (typeof value === "string")
82
+ return value.trim().length > 0 ? [value.trim()] : [];
83
+ if (value && typeof value === "object") {
84
+ const record = value;
85
+ return [
86
+ stringValue(record.path),
87
+ stringValue(record.locator),
88
+ stringValue(record.source_path),
89
+ stringValue(record.ref),
90
+ stringValue(record.summary),
91
+ ].filter((item) => Boolean(item));
92
+ }
93
+ return [];
94
+ }
95
+ function sourceRefsFromFrontmatter(frontmatter) {
96
+ return Array.from(new Set([
97
+ ...stringValues(frontmatter.source_refs),
98
+ ...stringValues(frontmatter.source_ref),
99
+ ...stringValues(frontmatter.source_path),
100
+ ]));
101
+ }
102
+ function aliasesFromFrontmatter(frontmatter) {
103
+ return Array.from(new Set([
104
+ stringValue(frontmatter.title),
105
+ stringValue(frontmatter.label),
106
+ stringValue(frontmatter.alias),
107
+ ...stringValues(frontmatter.aliases),
108
+ ].filter((item) => Boolean(item))));
109
+ }
110
+ function firstHeading(body) {
111
+ const heading = body.split("\n").find((line) => /^#{1,3}\s+\S/.test(line));
112
+ return heading ? heading.replace(/^#{1,3}\s+/, "").trim() : null;
113
+ }
114
+ function firstParagraph(body) {
115
+ const paragraph = body
116
+ .split(/\n\s*\n/)
117
+ .map((block) => block.replace(/\s+/g, " ").trim())
118
+ .find((block) => block.length > 0 && !block.startsWith("#"));
119
+ if (!paragraph)
120
+ return null;
121
+ return paragraph.length > 180 ? `${paragraph.slice(0, 177)}...` : paragraph;
122
+ }
123
+ function inferNoteKind(path) {
124
+ // Layer (home / artifact / summary / knowledge) and the knowledge
125
+ // claim·entity·index sub-kind come from the central `context-graph-layer`
126
+ // module, the single owner of the `knowledge/claims/` / `claim-` conventions,
127
+ // so this classifier and the StageManifest one can never drift. The only
128
+ // semantic-graph-specific refinement kept local is the loose "leaf merely
129
+ // contains `index`" nicety; the central module deliberately excludes it.
130
+ const layer = layerForPath(path);
131
+ if (layer === "home")
132
+ return "home";
133
+ if (layer === "artifacts")
134
+ return "artifact";
135
+ if (layer === "summaries")
136
+ return "summary";
137
+ const knowledgeKind = knowledgeNoteKind(path);
138
+ if (knowledgeKind === "claim")
139
+ return "claim";
140
+ if (knowledgeKind === "entity")
141
+ return "entity";
142
+ if (knowledgeKind === "index" || markdownBasename(normalizeLayerPath(path)).includes("index"))
143
+ return "index";
144
+ if (layer === "knowledge")
145
+ return "knowledge";
146
+ return "note";
147
+ }
148
+ function noteLabel(path, frontmatter, body) {
149
+ const leaf = markdownBasename(path);
150
+ const title = stringValue(frontmatter.title) ?? stringValue(frontmatter.label) ?? firstHeading(body);
151
+ return title && title.length <= 48 ? title : leaf;
152
+ }
153
+ function noteSummary(label, frontmatter, body) {
154
+ const explicit = stringValue(frontmatter.summary) ?? stringValue(frontmatter.abstract) ?? stringValue(frontmatter.description);
155
+ if (explicit)
156
+ return explicit.length > 220 ? `${explicit.slice(0, 217)}...` : explicit;
157
+ const title = stringValue(frontmatter.title) ?? firstHeading(body);
158
+ if (title && title !== label)
159
+ return title;
160
+ return firstParagraph(body);
161
+ }
162
+ function parseWikilinks(content) {
163
+ const links = [];
164
+ for (const match of content.matchAll(WIKILINK_PATTERN)) {
165
+ const raw = match[1]?.split("|")[0]?.split("#")[0]?.trim();
166
+ if (raw)
167
+ links.push(raw);
168
+ }
169
+ return Array.from(new Set(links));
170
+ }
171
+ function parseMarkdownLinks(content) {
172
+ const links = [];
173
+ for (const match of content.matchAll(MARKDOWN_LINK_PATTERN)) {
174
+ const raw = match[1]?.split("#")[0]?.trim();
175
+ if (!raw || /^https?:\/\//i.test(raw))
176
+ continue;
177
+ if (!raw.toLowerCase().endsWith(".md"))
178
+ continue;
179
+ try {
180
+ links.push(decodeURIComponent(raw));
181
+ }
182
+ catch {
183
+ links.push(raw);
184
+ }
185
+ }
186
+ return Array.from(new Set(links));
187
+ }
188
+ function parseNote(contextGraphPath, path) {
189
+ const content = readFileSync(join(contextGraphPath, path), "utf8");
190
+ const parsed = parseJsonFrontmatter(content);
191
+ const frontmatter = parsed?.frontmatter ?? {};
192
+ const body = parsed?.body ?? content;
193
+ const label = noteLabel(path, frontmatter, body);
194
+ return {
195
+ body,
196
+ id: `note:${path}`,
197
+ kind: inferNoteKind(path),
198
+ label,
199
+ path,
200
+ sourceRefs: sourceRefsFromFrontmatter(frontmatter),
201
+ summary: noteSummary(label, frontmatter, body),
202
+ aliases: aliasesFromFrontmatter(frontmatter),
203
+ wikilinks: Array.from(new Set([
204
+ ...parseWikilinks(content),
205
+ ...parseMarkdownLinks(content),
206
+ ])),
207
+ };
208
+ }
209
+ function addIndexTarget(index, key, nodeId) {
210
+ const normalized = noteKey(key);
211
+ if (normalized.length > 0 && !index.has(normalized))
212
+ index.set(normalized, nodeId);
213
+ const slug = slugKey(key);
214
+ if (slug.length > 0 && !index.has(slug))
215
+ index.set(slug, nodeId);
216
+ }
217
+ function buildNoteIndex(notes) {
218
+ const index = new Map();
219
+ for (const note of notes) {
220
+ addIndexTarget(index, note.path, note.id);
221
+ addIndexTarget(index, withoutMarkdownExtension(note.path), note.id);
222
+ addIndexTarget(index, markdownBasename(note.path), note.id);
223
+ if (note.path.endsWith("/summary.md")) {
224
+ addIndexTarget(index, withoutMarkdownExtension(note.path), note.id);
225
+ }
226
+ for (const alias of note.aliases)
227
+ addIndexTarget(index, alias, note.id);
228
+ }
229
+ return index;
230
+ }
231
+ function resolveWikilink(sourcePath, rawTarget, index) {
232
+ const clean = normalizeLayerPath(rawTarget);
233
+ const sourceDir = normalizeLayerPath(posix.dirname(sourcePath));
234
+ const relativeCandidate = normalizeLayerPath(posix.normalize(posix.join(sourceDir, clean)));
235
+ const candidates = [
236
+ clean,
237
+ withoutMarkdownExtension(clean),
238
+ relativeCandidate,
239
+ withoutMarkdownExtension(relativeCandidate),
240
+ markdownBasename(clean),
241
+ ];
242
+ for (const candidate of candidates) {
243
+ const match = index.get(noteKey(candidate)) ?? index.get(slugKey(candidate));
244
+ if (match)
245
+ return match;
246
+ }
247
+ return null;
248
+ }
249
+ function sourceLabel(ref, matchedFile) {
250
+ if (matchedFile)
251
+ return matchedFile.path;
252
+ const firstSegment = ref.split("›")[0]?.split("#")[0]?.trim() ?? ref;
253
+ if (/^https?:\/\//i.test(firstSegment)) {
254
+ try {
255
+ return new URL(firstSegment).hostname;
256
+ }
257
+ catch {
258
+ return firstSegment;
259
+ }
260
+ }
261
+ return firstSegment.length > 64 ? `${firstSegment.slice(0, 61)}...` : firstSegment;
262
+ }
263
+ function findSourceFile(ref, sourceManifest) {
264
+ const files = sourceManifest?.files ?? [];
265
+ const lowerRef = ref.toLowerCase();
266
+ return files.find((file) => {
267
+ const path = file.path.toLowerCase();
268
+ const leaf = basename(file.path).toLowerCase();
269
+ return lowerRef === path || lowerRef.startsWith(path) || lowerRef.includes(path) || lowerRef.includes(leaf);
270
+ }) ?? null;
271
+ }
272
+ function addNode(nodes, node) {
273
+ if (!nodes.has(node.id))
274
+ nodes.set(node.id, node);
275
+ }
276
+ function addEdge(edges, edge) {
277
+ if (!edges.has(edge.id))
278
+ edges.set(edge.id, edge);
279
+ }
280
+ function sourceNodeId(ref, matchedFile) {
281
+ return `source:${shortHash(matchedFile?.path ?? ref)}`;
282
+ }
283
+ function degreeCounts(edges) {
284
+ const links = new Map();
285
+ const backlinks = new Map();
286
+ for (const edge of edges) {
287
+ links.set(edge.source, (links.get(edge.source) ?? 0) + 1);
288
+ backlinks.set(edge.target, (backlinks.get(edge.target) ?? 0) + 1);
289
+ }
290
+ return { backlinks, links };
291
+ }
292
+ export function buildContextGraphSemanticGraph(options) {
293
+ const generatedAt = options.generatedAt ?? new Date().toISOString();
294
+ if (!existsSync(options.contextGraphPath)) {
295
+ return ContextGraphSemanticGraphSchema.parse({
296
+ kind: "interf-context-graph-semantic-graph",
297
+ version: 1,
298
+ generated_at: generatedAt,
299
+ nodes: [],
300
+ edges: [],
301
+ stats: { notes: 0, links: 0, source_refs: 0, unresolved_links: 0 },
302
+ });
303
+ }
304
+ const notes = listMarkdownFiles(options.contextGraphPath).map((path) => parseNote(options.contextGraphPath, path));
305
+ const noteIndex = buildNoteIndex(notes);
306
+ const nodes = new Map();
307
+ const edges = new Map();
308
+ const projectNodeId = `project:${options.projectId}`;
309
+ addNode(nodes, {
310
+ id: projectNodeId,
311
+ kind: "project",
312
+ label: options.projectId,
313
+ path: options.contextGraphPath,
314
+ summary: "Latest Context Graph root.",
315
+ source_refs: [],
316
+ link_count: 0,
317
+ backlink_count: 0,
318
+ });
319
+ for (const note of notes) {
320
+ addNode(nodes, {
321
+ id: note.id,
322
+ kind: note.kind,
323
+ label: note.label,
324
+ path: note.path,
325
+ summary: note.summary,
326
+ source_refs: note.sourceRefs,
327
+ link_count: 0,
328
+ backlink_count: 0,
329
+ });
330
+ }
331
+ const home = notes.find((note) => note.kind === "home");
332
+ if (home) {
333
+ addEdge(edges, {
334
+ id: `${projectNodeId}->${home.id}:contains`,
335
+ kind: "contains",
336
+ source: projectNodeId,
337
+ target: home.id,
338
+ label: "contains",
339
+ detail: `${options.projectId} starts at ${home.path}.`,
340
+ });
341
+ }
342
+ if (options.entrypointPath) {
343
+ const entrypointId = noteIndex.get(noteKey(options.entrypointPath)) ?? noteIndex.get(noteKey(withoutMarkdownExtension(options.entrypointPath)));
344
+ if (entrypointId) {
345
+ addEdge(edges, {
346
+ id: `${projectNodeId}->${entrypointId}:handoff`,
347
+ kind: "handoff",
348
+ source: projectNodeId,
349
+ target: entrypointId,
350
+ label: "handoff",
351
+ detail: `${options.entrypointPath} is the primary downstream agent entrypoint.`,
352
+ });
353
+ }
354
+ }
355
+ let unresolvedLinks = 0;
356
+ for (const note of notes) {
357
+ for (const rawTarget of note.wikilinks) {
358
+ const targetId = resolveWikilink(note.path, rawTarget, noteIndex);
359
+ if (!targetId) {
360
+ unresolvedLinks += 1;
361
+ continue;
362
+ }
363
+ addEdge(edges, {
364
+ id: `${note.id}->${targetId}:links-to`,
365
+ kind: "links-to",
366
+ source: note.id,
367
+ target: targetId,
368
+ label: "links to",
369
+ detail: `${note.path} links to ${rawTarget}.`,
370
+ });
371
+ }
372
+ for (const ref of note.sourceRefs) {
373
+ const matchedFile = findSourceFile(ref, options.sourceManifest);
374
+ const id = sourceNodeId(ref, matchedFile);
375
+ const label = sourceLabel(ref, matchedFile);
376
+ addNode(nodes, {
377
+ id,
378
+ kind: "source",
379
+ label,
380
+ path: matchedFile?.locator ?? matchedFile?.path ?? null,
381
+ summary: ref,
382
+ source_refs: [ref],
383
+ link_count: 0,
384
+ backlink_count: 0,
385
+ });
386
+ addEdge(edges, {
387
+ id: `${note.id}->${id}:source-ref:${shortHash(ref, 10)}`,
388
+ kind: "source-ref",
389
+ source: note.id,
390
+ target: id,
391
+ label: "source ref",
392
+ detail: `${note.path} cites ${label}.`,
393
+ });
394
+ }
395
+ }
396
+ const edgeList = [...edges.values()];
397
+ const counts = degreeCounts(edgeList);
398
+ const nodeList = [...nodes.values()].map((node) => ({
399
+ ...node,
400
+ link_count: counts.links.get(node.id) ?? 0,
401
+ backlink_count: counts.backlinks.get(node.id) ?? 0,
402
+ }));
403
+ return ContextGraphSemanticGraphSchema.parse({
404
+ kind: "interf-context-graph-semantic-graph",
405
+ version: 1,
406
+ generated_at: generatedAt,
407
+ nodes: nodeList,
408
+ edges: edgeList,
409
+ stats: {
410
+ notes: notes.length,
411
+ links: edgeList.filter((edge) => edge.kind === "links-to").length,
412
+ source_refs: edgeList.filter((edge) => edge.kind === "source-ref").length,
413
+ unresolved_links: unresolvedLinks,
414
+ },
415
+ });
416
+ }
@@ -307,14 +307,14 @@ export declare const RunObservabilitySchema: z.ZodObject<{
307
307
  generated_at: z.ZodString;
308
308
  project: z.ZodString;
309
309
  status: z.ZodEnum<{
310
- failed: "failed";
311
310
  ready: "ready";
311
+ "not-ready": "not-ready";
312
+ failed: "failed";
312
313
  "not-configured": "not-configured";
313
314
  "not-built": "not-built";
314
315
  building: "building";
315
316
  built: "built";
316
317
  checking: "checking";
317
- "not-ready": "not-ready";
318
318
  stale: "stale";
319
319
  }>;
320
320
  ready: z.ZodBoolean;
@@ -334,14 +334,14 @@ export declare const RunObservabilitySchema: z.ZodObject<{
334
334
  }>;
335
335
  ok: z.ZodBoolean;
336
336
  status: z.ZodOptional<z.ZodEnum<{
337
- failed: "failed";
338
337
  ready: "ready";
338
+ "not-ready": "not-ready";
339
+ failed: "failed";
339
340
  "not-configured": "not-configured";
340
341
  "not-built": "not-built";
341
342
  building: "building";
342
343
  built: "built";
343
344
  checking: "checking";
344
- "not-ready": "not-ready";
345
345
  stale: "stale";
346
346
  }>>;
347
347
  summary: z.ZodString;
@@ -383,14 +383,14 @@ export declare const RunObservabilitySchema: z.ZodObject<{
383
383
  }>;
384
384
  ok: z.ZodBoolean;
385
385
  status: z.ZodOptional<z.ZodEnum<{
386
- failed: "failed";
387
386
  ready: "ready";
387
+ "not-ready": "not-ready";
388
+ failed: "failed";
388
389
  "not-configured": "not-configured";
389
390
  "not-built": "not-built";
390
391
  building: "building";
391
392
  built: "built";
392
393
  checking: "checking";
393
- "not-ready": "not-ready";
394
394
  stale: "stale";
395
395
  }>>;
396
396
  summary: z.ZodString;
@@ -670,14 +670,14 @@ export declare const ReadinessUpdatedEventSchema: z.ZodObject<{
670
670
  generated_at: z.ZodString;
671
671
  project: z.ZodString;
672
672
  status: z.ZodEnum<{
673
- failed: "failed";
674
673
  ready: "ready";
674
+ "not-ready": "not-ready";
675
+ failed: "failed";
675
676
  "not-configured": "not-configured";
676
677
  "not-built": "not-built";
677
678
  building: "building";
678
679
  built: "built";
679
680
  checking: "checking";
680
- "not-ready": "not-ready";
681
681
  stale: "stale";
682
682
  }>;
683
683
  ready: z.ZodBoolean;
@@ -697,14 +697,14 @@ export declare const ReadinessUpdatedEventSchema: z.ZodObject<{
697
697
  }>;
698
698
  ok: z.ZodBoolean;
699
699
  status: z.ZodOptional<z.ZodEnum<{
700
- failed: "failed";
701
700
  ready: "ready";
701
+ "not-ready": "not-ready";
702
+ failed: "failed";
702
703
  "not-configured": "not-configured";
703
704
  "not-built": "not-built";
704
705
  building: "building";
705
706
  built: "built";
706
707
  checking: "checking";
707
- "not-ready": "not-ready";
708
708
  stale: "stale";
709
709
  }>>;
710
710
  summary: z.ZodString;
@@ -746,14 +746,14 @@ export declare const ReadinessUpdatedEventSchema: z.ZodObject<{
746
746
  }>;
747
747
  ok: z.ZodBoolean;
748
748
  status: z.ZodOptional<z.ZodEnum<{
749
- failed: "failed";
750
749
  ready: "ready";
750
+ "not-ready": "not-ready";
751
+ failed: "failed";
751
752
  "not-configured": "not-configured";
752
753
  "not-built": "not-built";
753
754
  building: "building";
754
755
  built: "built";
755
756
  checking: "checking";
756
- "not-ready": "not-ready";
757
757
  stale: "stale";
758
758
  }>>;
759
759
  summary: z.ZodString;
@@ -918,14 +918,14 @@ export declare const InterfRunEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<
918
918
  generated_at: z.ZodString;
919
919
  project: z.ZodString;
920
920
  status: z.ZodEnum<{
921
- failed: "failed";
922
921
  ready: "ready";
922
+ "not-ready": "not-ready";
923
+ failed: "failed";
923
924
  "not-configured": "not-configured";
924
925
  "not-built": "not-built";
925
926
  building: "building";
926
927
  built: "built";
927
928
  checking: "checking";
928
- "not-ready": "not-ready";
929
929
  stale: "stale";
930
930
  }>;
931
931
  ready: z.ZodBoolean;
@@ -945,14 +945,14 @@ export declare const InterfRunEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<
945
945
  }>;
946
946
  ok: z.ZodBoolean;
947
947
  status: z.ZodOptional<z.ZodEnum<{
948
- failed: "failed";
949
948
  ready: "ready";
949
+ "not-ready": "not-ready";
950
+ failed: "failed";
950
951
  "not-configured": "not-configured";
951
952
  "not-built": "not-built";
952
953
  building: "building";
953
954
  built: "built";
954
955
  checking: "checking";
955
- "not-ready": "not-ready";
956
956
  stale: "stale";
957
957
  }>>;
958
958
  summary: z.ZodString;
@@ -994,14 +994,14 @@ export declare const InterfRunEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<
994
994
  }>;
995
995
  ok: z.ZodBoolean;
996
996
  status: z.ZodOptional<z.ZodEnum<{
997
- failed: "failed";
998
997
  ready: "ready";
998
+ "not-ready": "not-ready";
999
+ failed: "failed";
999
1000
  "not-configured": "not-configured";
1000
1001
  "not-built": "not-built";
1001
1002
  building: "building";
1002
1003
  built: "built";
1003
1004
  checking: "checking";
1004
- "not-ready": "not-ready";
1005
1005
  stale: "stale";
1006
1006
  }>>;
1007
1007
  summary: z.ZodString;
@@ -1357,14 +1357,14 @@ export declare const BuildRunSchema: z.ZodObject<{
1357
1357
  generated_at: z.ZodString;
1358
1358
  project: z.ZodString;
1359
1359
  status: z.ZodEnum<{
1360
- failed: "failed";
1361
1360
  ready: "ready";
1361
+ "not-ready": "not-ready";
1362
+ failed: "failed";
1362
1363
  "not-configured": "not-configured";
1363
1364
  "not-built": "not-built";
1364
1365
  building: "building";
1365
1366
  built: "built";
1366
1367
  checking: "checking";
1367
- "not-ready": "not-ready";
1368
1368
  stale: "stale";
1369
1369
  }>;
1370
1370
  ready: z.ZodBoolean;
@@ -1384,14 +1384,14 @@ export declare const BuildRunSchema: z.ZodObject<{
1384
1384
  }>;
1385
1385
  ok: z.ZodBoolean;
1386
1386
  status: z.ZodOptional<z.ZodEnum<{
1387
- failed: "failed";
1388
1387
  ready: "ready";
1388
+ "not-ready": "not-ready";
1389
+ failed: "failed";
1389
1390
  "not-configured": "not-configured";
1390
1391
  "not-built": "not-built";
1391
1392
  building: "building";
1392
1393
  built: "built";
1393
1394
  checking: "checking";
1394
- "not-ready": "not-ready";
1395
1395
  stale: "stale";
1396
1396
  }>>;
1397
1397
  summary: z.ZodString;
@@ -1433,14 +1433,14 @@ export declare const BuildRunSchema: z.ZodObject<{
1433
1433
  }>;
1434
1434
  ok: z.ZodBoolean;
1435
1435
  status: z.ZodOptional<z.ZodEnum<{
1436
- failed: "failed";
1437
1436
  ready: "ready";
1437
+ "not-ready": "not-ready";
1438
+ failed: "failed";
1438
1439
  "not-configured": "not-configured";
1439
1440
  "not-built": "not-built";
1440
1441
  building: "building";
1441
1442
  built: "built";
1442
1443
  checking: "checking";
1443
- "not-ready": "not-ready";
1444
1444
  stale: "stale";
1445
1445
  }>>;
1446
1446
  summary: z.ZodString;
@@ -1483,14 +1483,14 @@ export declare const BuildRunSchema: z.ZodObject<{
1483
1483
  generated_at: z.ZodString;
1484
1484
  project: z.ZodString;
1485
1485
  status: z.ZodEnum<{
1486
- failed: "failed";
1487
1486
  ready: "ready";
1487
+ "not-ready": "not-ready";
1488
+ failed: "failed";
1488
1489
  "not-configured": "not-configured";
1489
1490
  "not-built": "not-built";
1490
1491
  building: "building";
1491
1492
  built: "built";
1492
1493
  checking: "checking";
1493
- "not-ready": "not-ready";
1494
1494
  stale: "stale";
1495
1495
  }>;
1496
1496
  ready: z.ZodBoolean;
@@ -1510,14 +1510,14 @@ export declare const BuildRunSchema: z.ZodObject<{
1510
1510
  }>;
1511
1511
  ok: z.ZodBoolean;
1512
1512
  status: z.ZodOptional<z.ZodEnum<{
1513
- failed: "failed";
1514
1513
  ready: "ready";
1514
+ "not-ready": "not-ready";
1515
+ failed: "failed";
1515
1516
  "not-configured": "not-configured";
1516
1517
  "not-built": "not-built";
1517
1518
  building: "building";
1518
1519
  built: "built";
1519
1520
  checking: "checking";
1520
- "not-ready": "not-ready";
1521
1521
  stale: "stale";
1522
1522
  }>>;
1523
1523
  summary: z.ZodString;
@@ -1559,14 +1559,14 @@ export declare const BuildRunSchema: z.ZodObject<{
1559
1559
  }>;
1560
1560
  ok: z.ZodBoolean;
1561
1561
  status: z.ZodOptional<z.ZodEnum<{
1562
- failed: "failed";
1563
1562
  ready: "ready";
1563
+ "not-ready": "not-ready";
1564
+ failed: "failed";
1564
1565
  "not-configured": "not-configured";
1565
1566
  "not-built": "not-built";
1566
1567
  building: "building";
1567
1568
  built: "built";
1568
1569
  checking: "checking";
1569
- "not-ready": "not-ready";
1570
1570
  stale: "stale";
1571
1571
  }>>;
1572
1572
  summary: z.ZodString;
@@ -1595,9 +1595,9 @@ export declare const BuildRunSchema: z.ZodObject<{
1595
1595
  artifacts: z.ZodDefault<z.ZodArray<z.ZodObject<{
1596
1596
  artifact_id: z.ZodString;
1597
1597
  status: z.ZodEnum<{
1598
+ ready: "ready";
1598
1599
  failed: "failed";
1599
1600
  skipped: "skipped";
1600
- ready: "ready";
1601
1601
  not_ready: "not_ready";
1602
1602
  }>;
1603
1603
  built_by_stages: z.ZodDefault<z.ZodArray<z.ZodString>>;
@@ -1614,6 +1614,9 @@ export declare const BuildRunSchema: z.ZodObject<{
1614
1614
  frontmatter_required_keys: "frontmatter_required_keys";
1615
1615
  frontmatter_nonempty_keys: "frontmatter_nonempty_keys";
1616
1616
  source_refs_required: "source_refs_required";
1617
+ summary_backlinks_present: "summary_backlinks_present";
1618
+ knowledge_web_connectivity: "knowledge_web_connectivity";
1619
+ graph_notes_connected: "graph_notes_connected";
1617
1620
  wikilinks_valid: "wikilinks_valid";
1618
1621
  must_not_contain: "must_not_contain";
1619
1622
  must_contain: "must_contain";