weavatrix 0.3.13 → 1.0.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 (303) hide show
  1. package/LICENSE +1 -0
  2. package/README.md +231 -199
  3. package/bin/native/darwin-arm64/weavatrix +0 -0
  4. package/bin/native/darwin-x64/weavatrix +0 -0
  5. package/bin/native/linux-arm64/weavatrix +0 -0
  6. package/bin/native/linux-x64/weavatrix +0 -0
  7. package/bin/native/win32-arm64/weavatrix.exe +0 -0
  8. package/bin/native/win32-x64/weavatrix.exe +0 -0
  9. package/bin/resolve-binary.mjs +73 -0
  10. package/bin/run-native.mjs +26 -0
  11. package/bin/weavatrix-mcp.mjs +7 -6
  12. package/bin/weavatrix.mjs +5 -0
  13. package/package.json +8 -65
  14. package/skill/SKILL.md +62 -374
  15. package/skill/agents/openai.yaml +4 -0
  16. package/skill/references/tool-routing.md +45 -0
  17. package/SECURITY.md +0 -101
  18. package/docs/adr/0001-v0.3-offline-online-split.md +0 -60
  19. package/docs/agent-task-benchmark.md +0 -58
  20. package/docs/releases/v0.2.19.md +0 -33
  21. package/docs/releases/v0.3.0.md +0 -43
  22. package/docs/releases/v0.3.1.md +0 -30
  23. package/docs/releases/v0.3.10.md +0 -76
  24. package/docs/releases/v0.3.11.md +0 -55
  25. package/docs/releases/v0.3.12.md +0 -44
  26. package/docs/releases/v0.3.13.md +0 -34
  27. package/docs/releases/v0.3.2.md +0 -15
  28. package/docs/releases/v0.3.3.md +0 -25
  29. package/docs/releases/v0.3.4.md +0 -40
  30. package/docs/releases/v0.3.5.md +0 -50
  31. package/docs/releases/v0.3.6.md +0 -44
  32. package/docs/releases/v0.3.7.md +0 -37
  33. package/docs/releases/v0.3.8.md +0 -21
  34. package/docs/releases/v0.3.9.md +0 -36
  35. package/scripts/run-agent-task-benchmark.mjs +0 -118
  36. package/src/analysis/allowed-test-runner.js +0 -70
  37. package/src/analysis/architecture/contract-graph.js +0 -119
  38. package/src/analysis/architecture/contract-schema.js +0 -110
  39. package/src/analysis/architecture/contract-storage.js +0 -35
  40. package/src/analysis/architecture/contract-verification.js +0 -168
  41. package/src/analysis/architecture-contract.js +0 -16
  42. package/src/analysis/audit-debt.js +0 -94
  43. package/src/analysis/audit-extensions.js +0 -60
  44. package/src/analysis/cargo-dependency-evidence.js +0 -108
  45. package/src/analysis/cargo-manifests.js +0 -81
  46. package/src/analysis/change-classification/diff-parser.js +0 -103
  47. package/src/analysis/change-classification/options.js +0 -40
  48. package/src/analysis/change-classification/symbol-classifier.js +0 -177
  49. package/src/analysis/change-classification.js +0 -188
  50. package/src/analysis/coverage-reports.js +0 -235
  51. package/src/analysis/cycle-route.js +0 -14
  52. package/src/analysis/data-flow-evidence.js +0 -114
  53. package/src/analysis/dead-check.js +0 -300
  54. package/src/analysis/dead-code-review/candidates.js +0 -194
  55. package/src/analysis/dead-code-review/policy.js +0 -23
  56. package/src/analysis/dead-code-review.js +0 -119
  57. package/src/analysis/dep-check-ecosystems.js +0 -205
  58. package/src/analysis/dep-check.js +0 -290
  59. package/src/analysis/dep-rules.js +0 -10
  60. package/src/analysis/dependency/conventions.js +0 -16
  61. package/src/analysis/dependency/scoped-dependencies.js +0 -51
  62. package/src/analysis/dependency/source-references.js +0 -21
  63. package/src/analysis/duplicate-groups.js +0 -104
  64. package/src/analysis/duplicates-worker.js +0 -11
  65. package/src/analysis/duplicates.compute.js +0 -269
  66. package/src/analysis/duplicates.js +0 -15
  67. package/src/analysis/duplicates.run.js +0 -52
  68. package/src/analysis/duplicates.tokenize.js +0 -199
  69. package/src/analysis/endpoints/common.js +0 -62
  70. package/src/analysis/endpoints/extract.js +0 -107
  71. package/src/analysis/endpoints/inventory.js +0 -84
  72. package/src/analysis/endpoints/mounts.js +0 -129
  73. package/src/analysis/endpoints-java.js +0 -260
  74. package/src/analysis/endpoints-rust.js +0 -124
  75. package/src/analysis/endpoints.js +0 -3
  76. package/src/analysis/findings.js +0 -70
  77. package/src/analysis/git-history/analytics.js +0 -177
  78. package/src/analysis/git-history/collector.js +0 -67
  79. package/src/analysis/git-history/options.js +0 -66
  80. package/src/analysis/git-history.js +0 -143
  81. package/src/analysis/git-ref-graph.js +0 -76
  82. package/src/analysis/go-dependency-evidence.js +0 -62
  83. package/src/analysis/graph-analysis.aggregate.js +0 -295
  84. package/src/analysis/graph-analysis.edges.js +0 -24
  85. package/src/analysis/graph-analysis.js +0 -7
  86. package/src/analysis/graph-analysis.refs.js +0 -154
  87. package/src/analysis/graph-analysis.summaries.js +0 -65
  88. package/src/analysis/health-capabilities.js +0 -83
  89. package/src/analysis/hot-path-review.js +0 -266
  90. package/src/analysis/http-contract-wrappers.js +0 -241
  91. package/src/analysis/http-contracts/analysis.js +0 -179
  92. package/src/analysis/http-contracts/client-call-detection.js +0 -82
  93. package/src/analysis/http-contracts/client-call-parser.js +0 -273
  94. package/src/analysis/http-contracts/graph-context.js +0 -143
  95. package/src/analysis/http-contracts/matching.js +0 -61
  96. package/src/analysis/http-contracts/shared.js +0 -85
  97. package/src/analysis/http-contracts.js +0 -6
  98. package/src/analysis/internal-audit/dependency-health.js +0 -113
  99. package/src/analysis/internal-audit/python-manifests.js +0 -78
  100. package/src/analysis/internal-audit/repo-files.js +0 -50
  101. package/src/analysis/internal-audit/supply-chain.js +0 -149
  102. package/src/analysis/internal-audit.collect.js +0 -213
  103. package/src/analysis/internal-audit.js +0 -9
  104. package/src/analysis/internal-audit.reach.js +0 -173
  105. package/src/analysis/internal-audit.run.js +0 -256
  106. package/src/analysis/java-source.js +0 -36
  107. package/src/analysis/jvm-artifact-index.js +0 -87
  108. package/src/analysis/jvm-dependency-evidence.js +0 -138
  109. package/src/analysis/jvm-manifests.js +0 -114
  110. package/src/analysis/manifests.js +0 -123
  111. package/src/analysis/package-reachability.js +0 -39
  112. package/src/analysis/source-complexity.ast.js +0 -97
  113. package/src/analysis/source-complexity.constants.js +0 -55
  114. package/src/analysis/source-complexity.js +0 -14
  115. package/src/analysis/source-complexity.report.js +0 -81
  116. package/src/analysis/source-complexity.walk.js +0 -228
  117. package/src/analysis/source-correctness/retry-patterns.js +0 -93
  118. package/src/analysis/source-correctness.js +0 -222
  119. package/src/analysis/static-test-reachability.js +0 -150
  120. package/src/analysis/structure/dependency-graph.js +0 -151
  121. package/src/analysis/structure/findings.js +0 -162
  122. package/src/analysis/task-retrieval.js +0 -107
  123. package/src/analysis/transport-contracts.js +0 -224
  124. package/src/analysis/transport-runtime-evidence.js +0 -155
  125. package/src/analysis-kit.mjs +0 -17
  126. package/src/bounds.js +0 -4
  127. package/src/build-graph.js +0 -209
  128. package/src/child-env.js +0 -7
  129. package/src/config.js +0 -5
  130. package/src/extension/local-services.mjs +0 -75
  131. package/src/git-exec.js +0 -67
  132. package/src/graph/build-worker.js +0 -49
  133. package/src/graph/builder/go-receiver-resolution.js +0 -112
  134. package/src/graph/builder/js/dynamic-import.js +0 -26
  135. package/src/graph/builder/js/queries.js +0 -48
  136. package/src/graph/builder/lang-csharp.js +0 -40
  137. package/src/graph/builder/lang-css.js +0 -29
  138. package/src/graph/builder/lang-go.js +0 -140
  139. package/src/graph/builder/lang-html.js +0 -29
  140. package/src/graph/builder/lang-java-calls.js +0 -142
  141. package/src/graph/builder/lang-java.js +0 -215
  142. package/src/graph/builder/lang-js.js +0 -291
  143. package/src/graph/builder/lang-python.js +0 -235
  144. package/src/graph/builder/lang-rust-calls.js +0 -63
  145. package/src/graph/builder/lang-rust.js +0 -299
  146. package/src/graph/builder/lang-solidity.js +0 -126
  147. package/src/graph/builder/lang-sql.js +0 -263
  148. package/src/graph/builder/pass2-resolution.js +0 -81
  149. package/src/graph/builder/spec-pkg.js +0 -87
  150. package/src/graph/community.js +0 -27
  151. package/src/graph/edge-provenance.js +0 -31
  152. package/src/graph/file-lock.js +0 -69
  153. package/src/graph/freshness-probe.js +0 -142
  154. package/src/graph/graph-filter.js +0 -63
  155. package/src/graph/incremental-refresh.js +0 -235
  156. package/src/graph/internal-builder.barrels.js +0 -235
  157. package/src/graph/internal-builder.build.js +0 -300
  158. package/src/graph/internal-builder.java.js +0 -33
  159. package/src/graph/internal-builder.js +0 -12
  160. package/src/graph/internal-builder.langs.js +0 -157
  161. package/src/graph/internal-builder.pass2.js +0 -163
  162. package/src/graph/internal-builder.resolvers.js +0 -286
  163. package/src/graph/layout.js +0 -51
  164. package/src/graph/node-id.js +0 -7
  165. package/src/graph/parser-artifact-boundary.js +0 -55
  166. package/src/graph/relations.js +0 -4
  167. package/src/graph/repo-registry.js +0 -124
  168. package/src/graph/resolvers/rust.js +0 -117
  169. package/src/infra/infra-items.js +0 -255
  170. package/src/infra/infra-registry.js +0 -184
  171. package/src/infra/infra.detect.js +0 -119
  172. package/src/infra/infra.js +0 -38
  173. package/src/infra/infra.match.js +0 -102
  174. package/src/infra/infra.scan.js +0 -93
  175. package/src/mcp/actions/graph-lifecycle.mjs +0 -148
  176. package/src/mcp/architecture-bootstrap.mjs +0 -168
  177. package/src/mcp/architecture-starter.mjs +0 -234
  178. package/src/mcp/catalog.mjs +0 -233
  179. package/src/mcp/company-contract-page.mjs +0 -142
  180. package/src/mcp/company-contract-reconcile.mjs +0 -87
  181. package/src/mcp/company-contract-verdict.mjs +0 -42
  182. package/src/mcp/evidence/bun-lock-graph.mjs +0 -209
  183. package/src/mcp/evidence/duplicate-member-order.mjs +0 -8
  184. package/src/mcp/evidence/package-graph-common.mjs +0 -115
  185. package/src/mcp/evidence/package-lock-graph.mjs +0 -92
  186. package/src/mcp/evidence-snapshot.architecture.mjs +0 -80
  187. package/src/mcp/evidence-snapshot.common.mjs +0 -158
  188. package/src/mcp/evidence-snapshot.duplicates.mjs +0 -213
  189. package/src/mcp/evidence-snapshot.health.mjs +0 -102
  190. package/src/mcp/evidence-snapshot.inventory.mjs +0 -148
  191. package/src/mcp/evidence-snapshot.mjs +0 -50
  192. package/src/mcp/evidence-snapshot.package-graph.mjs +0 -34
  193. package/src/mcp/evidence-snapshot.structure.mjs +0 -84
  194. package/src/mcp/extension-api.mjs +0 -77
  195. package/src/mcp/git-output.mjs +0 -7
  196. package/src/mcp/graph/context-core.mjs +0 -111
  197. package/src/mcp/graph/context-seeds.mjs +0 -207
  198. package/src/mcp/graph/context-state.mjs +0 -85
  199. package/src/mcp/graph/reverse-reach.mjs +0 -42
  200. package/src/mcp/graph/tools-core.mjs +0 -143
  201. package/src/mcp/graph/tools-query.mjs +0 -276
  202. package/src/mcp/graph-context.mjs +0 -5
  203. package/src/mcp/graph-diff.mjs +0 -218
  204. package/src/mcp/health/audit-format.mjs +0 -199
  205. package/src/mcp/health/audit.mjs +0 -174
  206. package/src/mcp/health/dead-code.mjs +0 -110
  207. package/src/mcp/health/duplicates.mjs +0 -85
  208. package/src/mcp/health/endpoints.mjs +0 -71
  209. package/src/mcp/health/structure.mjs +0 -219
  210. package/src/mcp/runtime-version.mjs +0 -31
  211. package/src/mcp/server/auto-refresh.mjs +0 -66
  212. package/src/mcp/server/runtime-config.mjs +0 -43
  213. package/src/mcp/server/shutdown.mjs +0 -40
  214. package/src/mcp/staleness-notice.mjs +0 -20
  215. package/src/mcp/sync/evidence-architecture.mjs +0 -54
  216. package/src/mcp/sync/evidence-common.mjs +0 -88
  217. package/src/mcp/sync/evidence-duplicates.mjs +0 -97
  218. package/src/mcp/sync/evidence-health.mjs +0 -56
  219. package/src/mcp/sync/evidence-packages.mjs +0 -95
  220. package/src/mcp/sync/payload-common.mjs +0 -97
  221. package/src/mcp/sync/payload-v2.mjs +0 -54
  222. package/src/mcp/sync/payload-v3.mjs +0 -79
  223. package/src/mcp/sync-evidence.mjs +0 -23
  224. package/src/mcp/sync-payload.mjs +0 -70
  225. package/src/mcp/tool-result.mjs +0 -54
  226. package/src/mcp/tools-actions.mjs +0 -11
  227. package/src/mcp/tools-architecture.mjs +0 -177
  228. package/src/mcp/tools-company.mjs +0 -251
  229. package/src/mcp/tools-context.mjs +0 -222
  230. package/src/mcp/tools-endpoints.mjs +0 -207
  231. package/src/mcp/tools-graph-hubs.mjs +0 -78
  232. package/src/mcp/tools-graph.mjs +0 -17
  233. package/src/mcp/tools-health.mjs +0 -24
  234. package/src/mcp/tools-history.mjs +0 -28
  235. package/src/mcp/tools-impact-change.mjs +0 -220
  236. package/src/mcp/tools-impact-precision.mjs +0 -89
  237. package/src/mcp/tools-impact.mjs +0 -169
  238. package/src/mcp/tools-source.mjs +0 -238
  239. package/src/mcp/tools-verified-change.mjs +0 -200
  240. package/src/mcp-rg.mjs +0 -50
  241. package/src/mcp-runtime.mjs +0 -2
  242. package/src/mcp-server.mjs +0 -298
  243. package/src/mcp-source-tools.mjs +0 -163
  244. package/src/path-classification.js +0 -220
  245. package/src/path-ignore.js +0 -69
  246. package/src/precision/lsp-client/constants.js +0 -12
  247. package/src/precision/lsp-client/environment.js +0 -20
  248. package/src/precision/lsp-client/errors.js +0 -15
  249. package/src/precision/lsp-client/lifecycle.js +0 -114
  250. package/src/precision/lsp-client/message-parser.js +0 -81
  251. package/src/precision/lsp-client/protocol.js +0 -212
  252. package/src/precision/lsp-client/registry.js +0 -59
  253. package/src/precision/lsp-client/repo-uri.js +0 -60
  254. package/src/precision/lsp-client/stdio-client.js +0 -140
  255. package/src/precision/lsp-client.js +0 -10
  256. package/src/precision/lsp-overlay/budget-policy.js +0 -78
  257. package/src/precision/lsp-overlay/build.js +0 -261
  258. package/src/precision/lsp-overlay/contract.js +0 -61
  259. package/src/precision/lsp-overlay/reference-results.js +0 -108
  260. package/src/precision/lsp-overlay/semantic-inputs.js +0 -62
  261. package/src/precision/lsp-overlay/source-session.js +0 -142
  262. package/src/precision/lsp-overlay/store.js +0 -150
  263. package/src/precision/lsp-overlay/target-index.js +0 -152
  264. package/src/precision/lsp-overlay/target-query.js +0 -55
  265. package/src/precision/lsp-overlay.js +0 -11
  266. package/src/precision/symbol-query.js +0 -224
  267. package/src/precision/typescript-lsp-provider.js +0 -12
  268. package/src/precision/typescript-provider/client.js +0 -89
  269. package/src/precision/typescript-provider/discovery.js +0 -124
  270. package/src/precision/typescript-provider/isolated-runtime.js +0 -39
  271. package/src/precision/typescript-provider/project-host.js +0 -254
  272. package/src/precision/typescript-provider/project-safety.js +0 -166
  273. package/src/precision/typescript-provider/reference-usage.js +0 -53
  274. package/src/process.js +0 -95
  275. package/src/repo-path.js +0 -53
  276. package/src/scan/discover.inventory.js +0 -78
  277. package/src/scan/discover.js +0 -5
  278. package/src/scan/discover.list.js +0 -79
  279. package/src/scan/discover.stack.js +0 -227
  280. package/src/scan/search.core.js +0 -24
  281. package/src/scan/search.git.js +0 -102
  282. package/src/scan/search.js +0 -9
  283. package/src/scan/search.node.js +0 -83
  284. package/src/scan/search.preview.js +0 -49
  285. package/src/scan/search.rg.js +0 -145
  286. package/src/security/advisory-store.js +0 -172
  287. package/src/security/installed-jvm-rust.js +0 -46
  288. package/src/security/installed.js +0 -280
  289. package/src/security/malware-file-heuristics.js +0 -121
  290. package/src/security/malware-heuristics.exclusions.js +0 -134
  291. package/src/security/malware-heuristics.js +0 -15
  292. package/src/security/malware-heuristics.roots.js +0 -145
  293. package/src/security/malware-heuristics.scan.js +0 -89
  294. package/src/security/malware-heuristics.sweep.js +0 -122
  295. package/src/security/malware-scoring.js +0 -105
  296. package/src/security/match.js +0 -85
  297. package/src/security/registry-sig.classify.js +0 -137
  298. package/src/security/registry-sig.js +0 -18
  299. package/src/security/registry-sig.rules.js +0 -192
  300. package/src/security/rust-advisory-report.js +0 -60
  301. package/src/security/typosquat.js +0 -81
  302. package/src/util.js +0 -40
  303. package/src/version.js +0 -7
@@ -1,148 +0,0 @@
1
- import {existsSync, readFileSync, realpathSync, statSync, writeFileSync} from 'node:fs'
2
- import {dirname, isAbsolute, join} from 'node:path'
3
- import {diffGraphs, formatGraphDiff, prevGraphPathFor} from '../graph-context.mjs'
4
- import {buildGraphForRepo, defaultPrecisionMode, precisionStatusLine} from '../../build-graph.js'
5
- import {graphHomeDir, graphOutDirForModule, graphOutDirForRepo} from '../../graph/layout.js'
6
- import {liveRepositoryRecords, registerRepository} from '../../graph/repo-registry.js'
7
- import {precisionSemanticInputsMatch, readPrecisionOverlay} from '../../precision/lsp-overlay.js'
8
-
9
- export async function tRebuildGraph(g, args, ctx) {
10
- if (!ctx.repoRoot) return 'Rebuild needs the repo root (not provided to this server).'
11
- const mode = ['no-tests', 'tests-only', 'full'].includes(args.mode)
12
- ? args.mode
13
- : ['no-tests', 'tests-only', 'full'].includes(g?.graphBuildMode) ? g.graphBuildMode : 'full'
14
- const precision = args.precision === 'off' ? 'off' : args.precision === 'lsp' ? 'lsp' : (g?.graphPrecisionMode || defaultPrecisionMode())
15
- const scope = String(args.scope || '').replace(/\\/g, '/').replace(/^\/+|\/+$/g, '')
16
- if (scope) {
17
- const scopedDir = graphOutDirForModule(ctx.repoRoot, scope)
18
- const scoped = await buildGraphForRepo(ctx.repoRoot, {mode, scope, precision, outDir: scopedDir})
19
- if (!scoped || !scoped.ok) return `Scoped graph build failed: ${(scoped && scoped.error) || 'unknown error'}`
20
- return [
21
- `Built an isolated scoped graph for ${scope} (${mode}). ${scoped.log || ''}.`,
22
- `The active full-repository graph was not replaced, so this operation cannot report a false full→scope structural delta.`,
23
- `Scoped graph: ${join(scopedDir, 'graph.json')}`,
24
- ].join('\n')
25
- }
26
- // snapshot the outgoing state: bytes → graph.prev.json (for graph_diff later), struct → inline delta
27
- let prevBytes = null
28
- try { prevBytes = readFileSync(ctx.graphPath) } catch { /* first build — nothing to diff against */ }
29
- let before = null
30
- try { before = prevBytes ? JSON.parse(prevBytes.toString('utf8')) : null } catch { before = null }
31
- const res = await buildGraphForRepo(ctx.repoRoot, {mode, scope: '', precision, outDir: ctx.graphPath ? dirname(ctx.graphPath) : undefined})
32
- if (!res || !res.ok) return `Graph rebuild failed: ${(res && res.error) || 'unknown error'}`
33
- if (prevBytes) { try { writeFileSync(prevGraphPathFor(ctx.graphPath), prevBytes) } catch { /* snapshot is best-effort */ } }
34
- const fresh = ctx.reload() // refresh THIS server's in-memory graph so subsequent tool calls see the new graph
35
- let afterStatic = null
36
- try { afterStatic = JSON.parse(readFileSync(ctx.graphPath, 'utf8')) } catch { /* reload already reports the failure */ }
37
- const beforeMode = ['full', 'no-tests', 'tests-only'].includes(before?.graphBuildMode) ? before.graphBuildMode : 'full'
38
- const afterMode = ['full', 'no-tests', 'tests-only'].includes(afterStatic?.graphBuildMode) ? afterStatic.graphBuildMode : 'full'
39
- const delta = before && afterStatic
40
- ? beforeMode === afterMode
41
- ? formatGraphDiff(diffGraphs(before, afterStatic))
42
- : `Structural delta not computed: build mode changed from ${beforeMode} to ${afterMode}, so the node/edge universes are not comparable.`
43
- : null
44
- return [
45
- `Rebuilt the graph (${mode}). ${res.log || ''}. In-memory graph reloaded — graph tools now reflect it.`,
46
- delta
47
- ].filter(Boolean).join('\n\n')
48
- }
49
-
50
- // Retarget this server at ANOTHER local repository at runtime — one weavatrix registration serves any
51
- // repo. Loads <parent>/weavatrix-graphs/<name>/graph.json (the central layout graphs
52
- // always live in), building it first when missing. On a failed load the previous repo stays active.
53
- export async function tOpenRepo(g, args, ctx) {
54
-
55
- const requestedPath = String(args.path || '').trim()
56
- if (!requestedPath) return 'Provide "path" — an absolute path to a local repository folder.'
57
- if (!isAbsolute(requestedPath)) return 'open_repo requires an absolute repository path.'
58
- let repoPath
59
- try { repoPath = realpathSync.native(requestedPath) } catch { return `Path not found: ${requestedPath}` }
60
- try { if (!statSync(repoPath).isDirectory()) return `Not a directory: ${requestedPath}` } catch { return `Path not found: ${requestedPath}` }
61
- if (!existsSync(join(repoPath, '.git'))) return `Not a Git repository: ${requestedPath}`
62
- const graphPath = join(graphOutDirForRepo(repoPath), 'graph.json')
63
- const graphExists = existsSync(graphPath)
64
- const requestedMode = ['no-tests', 'tests-only', 'full'].includes(args.mode) ? args.mode : null
65
- const requestedPrecision = ['lsp', 'off'].includes(args.precision) ? args.precision : null
66
- let built = false
67
- let upgrade = false
68
- let schemaUpgrade = false
69
- let precisionUpgrade = false
70
- let savedMode = 'full'
71
- let savedPrecision = defaultPrecisionMode()
72
- if (graphExists) {
73
- try {
74
- const saved = JSON.parse(readFileSync(graphPath, 'utf8'))
75
- savedMode = ['no-tests', 'tests-only', 'full'].includes(saved.graphBuildMode) ? saved.graphBuildMode : 'full'
76
- savedPrecision = ['lsp', 'off'].includes(saved.graphPrecisionMode) ? saved.graphPrecisionMode : defaultPrecisionMode()
77
- schemaUpgrade = !Number.isInteger(saved.edgeTypesV) || saved.edgeTypesV < 2
78
- || !Number.isInteger(saved.edgeProvenanceV) || saved.edgeProvenanceV < 1
79
- || !Number.isInteger(saved.extractorSchemaV) || saved.extractorSchemaV < 7
80
- || !Number.isInteger(saved.reExportOccurrencesV) || saved.reExportOccurrencesV < 1
81
- || !Number.isInteger(saved.symbolSpacesV) || saved.symbolSpacesV < 1
82
- || !Number.isInteger(saved.physicalFileLocV) || saved.physicalFileLocV < 1
83
- if (savedPrecision === 'lsp') {
84
- const overlay = readPrecisionOverlay(graphPath, saved)
85
- precisionUpgrade = !overlay || (typeof overlay.semanticInputFingerprint === 'string'
86
- && !precisionSemanticInputsMatch(overlay, repoPath, saved))
87
- }
88
- upgrade = schemaUpgrade || precisionUpgrade
89
- } catch {
90
- upgrade = true
91
- }
92
- }
93
- const modeMismatch = graphExists && requestedMode != null && requestedMode !== savedMode
94
- const precisionMismatch = graphExists && requestedPrecision != null && requestedPrecision !== savedPrecision
95
- if (!graphExists || upgrade || modeMismatch || precisionMismatch) {
96
- if (args.build === false) {
97
- if (modeMismatch && !upgrade) {
98
- return `The existing graph for ${repoPath} was built in ${savedMode}, but ${requestedMode} was requested. Re-call without build:false to rebuild it before switching.`
99
- }
100
- if (precisionMismatch && !upgrade) {
101
- return `The existing graph for ${repoPath} uses semantic precision ${savedPrecision}, but ${requestedPrecision} was requested. Re-call without build:false to rebuild it before switching.`
102
- }
103
- return upgrade
104
- ? precisionUpgrade && !schemaUpgrade
105
- ? `The existing graph for ${repoPath} lacks current revision-matched semantic precision evidence. Re-call without build:false to refresh it before switching.`
106
- : `The existing graph for ${repoPath} predates current graph metadata (typed edges, provenance, or physical file LOC). Re-call without build:false to upgrade it before switching.`
107
- : `No graph yet for ${repoPath} (expected at ${graphPath}). Re-call without build:false to build one — large repos can take minutes.`
108
- }
109
- const mode = requestedMode || (graphExists ? savedMode : 'full')
110
- const precision = requestedPrecision || (graphExists ? savedPrecision : defaultPrecisionMode())
111
- const res = await buildGraphForRepo(repoPath, {mode, scope: '', precision})
112
- if (!res || !res.ok) return `Graph build failed for ${repoPath}: ${(res && res.error) || 'unknown error'}`
113
- built = true
114
- }
115
- const prev = {graphPath: ctx.graphPath, repoRoot: ctx.repoRoot}
116
- ctx.graphPath = graphPath
117
- ctx.repoRoot = repoPath
118
- const loaded = ctx.reload()
119
- if (!loaded) {
120
- ctx.graphPath = prev.graphPath
121
- ctx.repoRoot = prev.repoRoot
122
- ctx.reload()
123
- return `Failed to load ${graphPath} — still targeting the previous repo (${prev.repoRoot || 'none'}).`
124
- }
125
- registerRepository({repoPath, graphDir: graphOutDirForRepo(repoPath), graphHome: graphHomeDir()})
126
- const buildNote = built ? (upgrade ? ' (graph upgraded to current edge/precision metadata)' : modeMismatch ? ' (graph rebuilt in the requested mode)' : precisionMismatch ? ' (semantic precision mode updated)' : ' (graph built fresh)') : ''
127
- return [
128
- `Opened ${repoPath}${buildNote}: ${loaded.nodes.length} nodes / ${loaded.links.length} edges. All tools now target this repo.`,
129
- `Graph: ${graphPath}`,
130
- `Build mode: ${loaded.graphBuildMode || 'full'}`,
131
- precisionStatusLine(loaded.precision),
132
- ].join('\n')
133
- }
134
-
135
- // Sibling repos that already have a built graph in the central weavatrix-graphs folder — open_repo candidates.
136
- export function tListKnownRepos(g, args, ctx) {
137
- const root = graphHomeDir()
138
- const norm = (p) => String(p).replace(/[\\/]+/g, '/').toLowerCase()
139
- const rows = liveRepositoryRecords(root).map((record) => ({
140
- ...record,
141
- builtAt: statSync(join(record.graphDir, 'graph.json')).mtime.toISOString(),
142
- }))
143
- if (!rows.length) return `No registered graphs under ${root}. Build a repository once with open_repo or rebuild_graph.`
144
- return [
145
- `Known repositories (${rows.length}) in ${root}:`,
146
- ...rows.map((r) => ` ${norm(r.repoPath) === norm(ctx.repoRoot) ? '»' : ' '} ${r.label} [${r.repositoryId}] — graph built ${r.builtAt} (${r.repoPath})`),
147
- ].join('\n')
148
- }
@@ -1,168 +0,0 @@
1
- // Explicit two-step local architecture bootstrap. Preview is pure; approval writes only the exact
2
- // previewed contract with a short-lived one-time token and never overwrites an active policy.
3
- import {createHash, randomBytes} from 'node:crypto'
4
- import {existsSync, mkdirSync, writeFileSync} from 'node:fs'
5
- import {join} from 'node:path'
6
- import {
7
- loadArchitectureContract, normalizeArchitectureContract, verifyArchitecture,
8
- } from '../analysis/architecture-contract.js'
9
- import {createRepoBoundary} from '../repo-path.js'
10
- import {detectRepoStack} from '../scan/discover.js'
11
- import {toolResult} from './tool-result.mjs'
12
-
13
- const version = new URL(import.meta.url).search
14
- const starter = await import(new URL(`./architecture-starter.mjs${version}`, import.meta.url).href)
15
- const {createArchitectureStarter, proposeObservedDependencyDirections} = starter
16
-
17
- const PREVIEW_TTL_MS = 5 * 60_000
18
- const previews = new Map()
19
-
20
- const stackIds = (repoRoot) => {
21
- try {
22
- const stack = detectRepoStack(repoRoot)
23
- return ['languages', 'runtimes', 'tests', 'infra', 'deploy']
24
- .flatMap((category) => Array.isArray(stack?.[category]) ? stack[category] : [])
25
- .map((item) => String(item?.id || '')).filter(Boolean)
26
- } catch { return [] }
27
- }
28
- const sha256 = (value) => createHash('sha256').update(value).digest('hex')
29
-
30
- function currentFingerprints(verification) {
31
- return [...verification.new, ...verification.existing]
32
- .map((item) => item.fingerprint).sort((a, b) => a.localeCompare(b))
33
- }
34
-
35
- function baselineMetrics(verification) {
36
- return Object.fromEntries(['runtimeCycles', 'violations', 'componentDependencies', 'mappedComponents']
37
- .map((key) => [key, verification.metrics?.[key]])
38
- .filter(([, value]) => Number.isFinite(value)))
39
- }
40
-
41
- function materializeCandidate(candidate, verification, baselineMode) {
42
- if (baselineMode !== 'accept-current') return normalizeArchitectureContract(candidate)
43
- return normalizeArchitectureContract({
44
- ...candidate,
45
- ratchet: {baseline: {
46
- fingerprints: currentFingerprints(verification),
47
- metrics: baselineMetrics(verification),
48
- }},
49
- })
50
- }
51
-
52
- export function activeArchitectureContract(ctx) {
53
- if (!ctx?.repoRoot) return {contract: null, source: null, error: 'no repository root is active'}
54
- return loadArchitectureContract(ctx.repoRoot, ctx.graphPath)
55
- }
56
-
57
- function preview(g, args, ctx) {
58
- const active = activeArchitectureContract(ctx)
59
- if (active.contract) return toolResult(
60
- `Architecture bootstrap refused: an active contract already exists at ${active.source}.`,
61
- {state: 'ALREADY_CONFIGURED', source: active.source, contractHash: active.contract.contractHash},
62
- )
63
- if (active.error) return toolResult(
64
- `Architecture bootstrap refused: ${active.source || 'contract'} is invalid (${active.error}).`,
65
- {state: 'ERROR', source: active.source, error: active.error},
66
- )
67
- const baselineMode = args?.baseline_mode === 'accept-current' ? 'accept-current' : 'none'
68
- let candidate, starterProposal = null
69
- try {
70
- starterProposal = args?.candidate_contract ? null : createArchitectureStarter(g, ctx?.repoRoot)
71
- candidate = args?.candidate_contract
72
- ? normalizeArchitectureContract(args.candidate_contract)
73
- : starterProposal.contract
74
- } catch (error) {
75
- return toolResult(`Candidate architecture contract is invalid: ${error.message}`, {state: 'INVALID', error: error.message})
76
- }
77
- const technologies = stackIds(ctx?.repoRoot)
78
- const candidateVerification = verifyArchitecture({graph: g, contract: candidate, technologies})
79
- const materializedContract = materializeCandidate(candidate, candidateVerification, baselineMode)
80
- const materializedVerification = verifyArchitecture({graph: g, contract: materializedContract, technologies})
81
- const contents = `${JSON.stringify(materializedContract, null, 2)}\n`
82
- const contentHash = sha256(contents)
83
- const token = randomBytes(12).toString('hex')
84
- const expiresAt = new Date(Date.now() + PREVIEW_TTL_MS).toISOString()
85
- previews.set(token, {
86
- repoRoot: String(ctx?.repoRoot || ''), graphPath: String(ctx?.graphPath || ''),
87
- contract: materializedContract, contents, contentHash,
88
- verificationHash: materializedVerification.verificationHash,
89
- expiresAt: Date.parse(expiresAt),
90
- })
91
- return toolResult([
92
- `Architecture bootstrap PREVIEW only; no file was written. Candidate verification: ${candidateVerification.status}.`,
93
- baselineMode === 'accept-current'
94
- ? `Explicit accept-current baseline would record ${currentFingerprints(candidateVerification).length} current finding fingerprint(s).`
95
- : 'No current findings were added to the baseline.',
96
- `Review the materialized contract and then approve with confirm_token "${token}" before ${expiresAt}.`,
97
- ].join('\n'), {
98
- state: 'PREVIEW', wrote: false, baselineMode,
99
- candidateVerification, materializedVerification, materializedContract,
100
- observedDependencyProposals: proposeObservedDependencyDirections(g, materializedContract.components),
101
- budgetProposals: starterProposal?.budgetProposals || [],
102
- starterMethodology: starterProposal?.methodology,
103
- patch: {operation: 'create', path: '.weavatrix/architecture.json', contentHash, contents},
104
- confirmToken: token, expiresAt,
105
- })
106
- }
107
-
108
- function approve(g, args, ctx) {
109
- const token = String(args?.confirm_token || '')
110
- const pending = previews.get(token)
111
- if (!pending) return toolResult(
112
- 'Architecture approval refused: run a fresh preview and provide its exact confirm_token.',
113
- {state: 'CONFIRMATION_REQUIRED', wrote: false},
114
- )
115
- previews.delete(token)
116
- if (pending.expiresAt < Date.now()) return toolResult(
117
- 'Architecture approval refused: the preview expired; run preview again.',
118
- {state: 'PREVIEW_EXPIRED', wrote: false},
119
- )
120
- if (pending.repoRoot !== String(ctx?.repoRoot || '') || pending.graphPath !== String(ctx?.graphPath || '')) {
121
- return toolResult('Architecture approval refused: the active repository changed after preview.', {
122
- state: 'REPOSITORY_CHANGED', wrote: false,
123
- })
124
- }
125
- const active = activeArchitectureContract(ctx)
126
- if (active.contract || active.error) return toolResult(
127
- `Architecture approval refused: ${active.source || 'a contract'} appeared or changed after preview.`,
128
- {state: active.error ? 'ERROR' : 'ALREADY_CONFIGURED', wrote: false, source: active.source, error: active.error || undefined},
129
- )
130
- const verification = verifyArchitecture({
131
- graph: g, contract: pending.contract, technologies: stackIds(ctx?.repoRoot),
132
- })
133
- if (verification.verificationHash !== pending.verificationHash) return toolResult(
134
- 'Architecture approval refused: graph evidence changed after preview; review a fresh preview.',
135
- {state: 'GRAPH_CHANGED', wrote: false, previewVerificationHash: pending.verificationHash, currentVerificationHash: verification.verificationHash},
136
- )
137
- const boundary = createRepoBoundary(ctx?.repoRoot)
138
- if (!boundary.root) return toolResult('Architecture approval refused: the repository boundary is unavailable.', {
139
- state: 'PATH_REFUSED', wrote: false,
140
- })
141
- try { mkdirSync(join(boundary.root, '.weavatrix'), {recursive: true}) }
142
- catch (error) { return toolResult(`Architecture approval could not create its policy directory: ${error.message}`, {
143
- state: 'WRITE_FAILED', wrote: false, error: error.message,
144
- }) }
145
- const policyDirectory = boundary.resolve('.weavatrix')
146
- if (!policyDirectory.ok) return toolResult('Architecture approval refused: the policy directory resolves outside the active repository.', {
147
- state: 'PATH_REFUSED', wrote: false,
148
- })
149
- const targetPath = join(policyDirectory.path, 'architecture.json')
150
- if (existsSync(targetPath)) return toolResult('Architecture approval refused: the target contract already exists.', {
151
- state: 'ALREADY_CONFIGURED', wrote: false, source: '.weavatrix/architecture.json',
152
- })
153
- try {
154
- writeFileSync(targetPath, pending.contents, {encoding: 'utf8', flag: 'wx'})
155
- } catch (error) {
156
- return toolResult(`Architecture approval failed without overwriting policy: ${error.message}`, {
157
- state: 'WRITE_FAILED', wrote: false, error: error.message,
158
- })
159
- }
160
- return toolResult(
161
- `Architecture contract approved and created at .weavatrix/architecture.json (${pending.contentHash.slice(0, 12)}).`,
162
- {state: 'APPROVED', wrote: true, source: '.weavatrix/architecture.json', contentHash: pending.contentHash, contract: pending.contract, verification},
163
- )
164
- }
165
-
166
- export function tBootstrapArchitecture(g, args = {}, ctx) {
167
- return args.action === 'approve' ? approve(g, args, ctx) : preview(g, args, ctx)
168
- }
@@ -1,234 +0,0 @@
1
- // Adaptive, source-free architecture starter. It proposes component territories and separately
2
- // reports observed dependency directions; observations never become enforceable policy implicitly.
3
- import {normalizeArchitectureContract} from '../analysis/architecture-contract.js'
4
- import {createPathClassifier, hasPathClass} from '../path-classification.js'
5
-
6
- export const PROVISIONAL_BUDGETS = Object.freeze({
7
- runtimeCycles: 0,
8
- maxFileLoc: 300,
9
- maxFunctionLoc: 120,
10
- maxCyclomatic: 15,
11
- maxModuleFiles: 80,
12
- minModuleCohesion: .5,
13
- maxModuleBoundaryRatio: .65,
14
- })
15
-
16
- const STARTER_BUDGETS = Object.freeze({
17
- runtimeCycles: PROVISIONAL_BUDGETS.runtimeCycles,
18
- maxFileLoc: PROVISIONAL_BUDGETS.maxFileLoc,
19
- })
20
-
21
- const BUDGET_PROPOSALS = Object.freeze(Object.entries(PROVISIONAL_BUDGETS)
22
- .filter(([key]) => !(key in STARTER_BUDGETS))
23
- .map(([key, value]) => ({
24
- key, value, state: 'CANDIDATE_NOT_ENFORCED',
25
- reason: 'Generic review threshold; adopt only after inspecting repository-specific evidence.',
26
- })))
27
-
28
- const SOURCE_ROOTS = new Set(['src', 'app', 'lib', 'packages', 'services'])
29
- const CODE_EXTENSIONS = new Set([
30
- '.cjs', '.cs', '.css', '.go', '.htm', '.html', '.java', '.js', '.jsx', '.less', '.mjs', '.py', '.pyi',
31
- '.rs', '.scss', '.sol', '.sql', '.ts', '.tsx',
32
- ])
33
- const CLASSIFIED = ['test', 'e2e', 'generated', 'mock', 'story', 'docs', 'benchmark', 'temp']
34
- const EDGE_RELATIONS = new Set(['imports', 're_exports', 'calls', 'references'])
35
-
36
- const slash = (value) => String(value || '').replace(/\\/g, '/').replace(/^\.\//, '')
37
- const extension = (file) => {
38
- const name = slash(file).split('/').at(-1) || ''
39
- const dot = name.lastIndexOf('.')
40
- return dot >= 0 ? name.slice(dot).toLowerCase() : ''
41
- }
42
- const safeId = (value, fallback) => String(value || '').toLowerCase()
43
- .replace(/[^a-z0-9._:-]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 100) || fallback
44
-
45
- function productFiles(graph, repoRoot) {
46
- const classifier = createPathClassifier(repoRoot)
47
- return [...new Set((graph?.nodes || [])
48
- .filter((node) => !String(node.id).includes('#'))
49
- .map((node) => slash(node.source_file || node.id))
50
- .filter((file) => file && CODE_EXTENSIONS.has(extension(file))))]
51
- .filter((file) => {
52
- const explanation = classifier.explain(file)
53
- return !explanation.excluded && !hasPathClass(explanation, ...CLASSIFIED)
54
- })
55
- .sort((a, b) => a.localeCompare(b))
56
- }
57
-
58
- function commonDirectoryPrefix(entries) {
59
- if (!entries.length) return []
60
- const first = entries[0].directories
61
- let length = first.length
62
- for (const entry of entries.slice(1)) {
63
- let index = 0
64
- while (index < length && index < entry.directories.length && first[index] === entry.directories[index]) index++
65
- length = index
66
- }
67
- // Keep at least one package segment available as an actual component territory.
68
- const shortest = Math.min(...entries.map((entry) => entry.directories.length))
69
- return first.slice(0, Math.min(length, Math.max(0, shortest - 1)))
70
- }
71
-
72
- function javaTerritories(files) {
73
- const byRoot = new Map()
74
- for (const file of files) {
75
- const match = /^(.*?)(?:\/)?src\/main\/java\/(.+\.java)$/i.exec(file)
76
- if (!match) continue
77
- const root = `${match[1] ? `${match[1]}/` : ''}src/main/java`
78
- const tail = match[2].split('/')
79
- const entry = {file, root, directories: tail.slice(0, -1)}
80
- const entries = byRoot.get(root) || []
81
- entries.push(entry)
82
- byRoot.set(root, entries)
83
- }
84
- const paths = new Map()
85
- for (const [root, entries] of byRoot) {
86
- const common = commonDirectoryPrefix(entries)
87
- for (const entry of entries) {
88
- const next = entry.directories[common.length]
89
- const path = next ? `${root}/${[...common, next].join('/')}` : entry.file
90
- paths.set(entry.file, {key: path, name: path, path})
91
- }
92
- }
93
- let refined = true
94
- while (refined) {
95
- refined = false
96
- const groups = new Map()
97
- for (const [file, territory] of paths) {
98
- const entries = groups.get(territory.key) || []
99
- entries.push({file, territory})
100
- groups.set(territory.key, entries)
101
- }
102
- for (const entries of groups.values()) {
103
- if (entries.length <= PROVISIONAL_BUDGETS.maxModuleFiles) continue
104
- const base = entries[0].territory.path
105
- if (!entries.every((entry) => entry.territory.path === base)) continue
106
- const nested = entries.map((entry) => ({...entry, rest: entry.file.slice(base.length + 1).split('/')}))
107
- const childDirectories = new Set(nested.filter((entry) => entry.rest.length > 1).map((entry) => entry.rest[0]))
108
- if (childDirectories.size < 2) continue
109
- for (const entry of nested) {
110
- if (entry.rest.length > 1) {
111
- const path = `${base}/${entry.rest[0]}`
112
- paths.set(entry.file, {key: path, name: path, path})
113
- } else {
114
- paths.set(entry.file, {key: `${base}::root`, name: `${base} (root files)`, path: entry.file})
115
- }
116
- }
117
- refined = true
118
- }
119
- }
120
- return paths
121
- }
122
-
123
- function nestedSourceTerritory(file) {
124
- const match = /^(.*?)\/src\/(.+)$/.exec(file)
125
- if (!match || !match[1]) return null
126
- const tail = match[2].split('/')
127
- // Java's src/main/java package tree is handled with a package-aware common prefix above.
128
- if (tail[0] === 'main' && tail[1] === 'java') return null
129
- return tail.length > 1 ? `${match[1]}/src/${tail[0]}` : file
130
- }
131
-
132
- function genericTerritory(file) {
133
- const parts = file.split('/').filter(Boolean)
134
- if (parts.length === 1) return {key: 'root-code', name: 'root code', path: file}
135
- if (SOURCE_ROOTS.has(parts[0]) && parts.length === 2) {
136
- return {key: `${parts[0]}-root`, name: `${parts[0]} (root files)`, path: file}
137
- }
138
- const path = parts.slice(0, SOURCE_ROOTS.has(parts[0]) ? 2 : 1).join('/')
139
- return {key: path, name: path, path}
140
- }
141
-
142
- function componentsFor(graph, repoRoot) {
143
- const files = productFiles(graph, repoRoot)
144
- const java = javaTerritories(files)
145
- const groups = new Map()
146
- for (const file of files) {
147
- const adaptive = java.get(file) || nestedSourceTerritory(file)
148
- const territory = adaptive
149
- ? typeof adaptive === 'string' ? {key: adaptive, name: adaptive, path: adaptive} : adaptive
150
- : genericTerritory(file)
151
- const group = groups.get(territory.key) || {name: territory.name, paths: new Set(), files: 0}
152
- group.paths.add(territory.path)
153
- group.files++
154
- groups.set(territory.key, group)
155
- }
156
- return [...groups]
157
- .sort((a, b) => b[1].files - a[1].files || a[0].localeCompare(b[0]))
158
- .slice(0, 200)
159
- .map(([key, group], index) => ({
160
- id: safeId(key, `component-${index + 1}`),
161
- name: group.name,
162
- paths: [...group.paths].sort((a, b) => a.localeCompare(b)),
163
- }))
164
- }
165
-
166
- function componentFor(file, components) {
167
- const normalized = slash(file)
168
- let best = null
169
- for (const component of components) for (const prefix of component.paths) {
170
- if (normalized !== prefix && !normalized.startsWith(`${prefix}/`)) continue
171
- if (!best || prefix.length > best.prefix.length) best = {id: component.id, prefix}
172
- }
173
- return best?.id || null
174
- }
175
-
176
- const endpoint = (value) => value && typeof value === 'object' ? String(value.id) : String(value || '')
177
- function fileOf(id, byId) {
178
- const node = byId.get(id)
179
- return slash(node?.source_file || id.split('#')[0])
180
- }
181
- function edgeKind(link) {
182
- return link.typeOnly === true ? 'type-only' : link.compileOnly === true ? 'compile-only' : 'runtime'
183
- }
184
-
185
- function observedDirections(graph, components) {
186
- const byId = new Map((graph?.nodes || []).map((node) => [String(node.id), node]))
187
- const pairs = new Set(), directions = new Map()
188
- for (const link of graph?.links || []) {
189
- if (!EDGE_RELATIONS.has(link.relation) || link.barrelProxy === true) continue
190
- const fromFile = fileOf(endpoint(link.source), byId), toFile = fileOf(endpoint(link.target), byId)
191
- const from = componentFor(fromFile, components), to = componentFor(toFile, components)
192
- if (!from || !to || from === to) continue
193
- const kind = edgeKind(link), pair = `${fromFile}\0${toFile}\0${kind}`
194
- if (pairs.has(pair)) continue
195
- pairs.add(pair)
196
- const key = `${from}\0${to}\0${kind}`
197
- const item = directions.get(key) || {from, to, kind, count: 0, samples: []}
198
- item.count++
199
- if (item.samples.length < 3) item.samples.push(`${fromFile} -> ${toFile}`)
200
- directions.set(key, item)
201
- }
202
- return [...directions.values()]
203
- .sort((a, b) => b.count - a.count || a.from.localeCompare(b.from) || a.to.localeCompare(b.to))
204
- .slice(0, 100)
205
- .map((item, index) => ({
206
- ...item,
207
- state: 'OBSERVED_NOT_ENFORCED',
208
- suggestedRule: {
209
- id: safeId(`observed-${item.from}-to-${item.to}-${item.kind}`, `observed-${index + 1}`),
210
- action: 'allow', kinds: [item.kind], from: [item.from], to: [item.to],
211
- reason: `Observed in ${item.count} unique file dependency pair(s); review before adopting as policy.`,
212
- },
213
- }))
214
- }
215
-
216
- export function proposeObservedDependencyDirections(graph, components) {
217
- return observedDirections(graph, components)
218
- }
219
-
220
- export function createArchitectureStarter(graph, repoRoot) {
221
- const components = componentsFor(graph, repoRoot)
222
- const contract = normalizeArchitectureContract({
223
- name: 'Proposed no-regressions baseline', style: 'custom', enforcement: 'ratchet', components,
224
- dependencyRules: [], budgets: STARTER_BUDGETS,
225
- technologies: {required: [], forbidden: []}, exceptions: [],
226
- ratchet: {baseline: {fingerprints: [], metrics: {}}},
227
- })
228
- return {
229
- contract,
230
- observedDependencyProposals: proposeObservedDependencyDirections(graph, contract.components),
231
- budgetProposals: BUDGET_PROPOSALS,
232
- methodology: 'adaptive product territories; only universal runtime-cycle/file-size guards are active; observed directions and generic quality thresholds are review-only',
233
- }
234
- }