archsight 0.5.2 → 0.5.4
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.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/docs/archimate.md +1 -1
- data/docs/configuration.md +1 -1
- data/docs/diagram.md +12 -2
- data/docs/import.md +27 -2
- data/docs/modeling.md +17 -6
- data/docs/pages.md +1 -1
- data/docs/search.md +19 -0
- data/lib/archsight/annotations/capacity_annotations.rb +15 -0
- data/lib/archsight/database.rb +1 -1
- data/lib/archsight/diagram/graph/attributes.rb +11 -3
- data/lib/archsight/diagram/graph/builder.rb +1 -0
- data/lib/archsight/diagram/graph/node.rb +26 -2
- data/lib/archsight/diagram/layout/expander.rb +39 -0
- data/lib/archsight/diagram/layout.rb +11 -0
- data/lib/archsight/diagram/legend/inventory.rb +6 -2
- data/lib/archsight/diagram/parser.rb +1 -1
- data/lib/archsight/diagram/renderer/node_renderer.rb +6 -1
- data/lib/archsight/diagram/renderer/stylesheet.rb +2 -0
- data/lib/archsight/diagram/style/representers.rb +14 -0
- data/lib/archsight/diagram/support/text_metrics.rb +38 -0
- data/lib/archsight/git_source.rb +5 -3
- data/lib/archsight/helpers.rb +3 -1
- data/lib/archsight/import/handlers/gitea.rb +195 -0
- data/lib/archsight/import/handlers/github.rb +1 -0
- data/lib/archsight/import/handlers/gitlab.rb +1 -0
- data/lib/archsight/import/handlers/repository.rb +32 -4
- data/lib/archsight/linter.rb +13 -2
- data/lib/archsight/mcp/analyze_resource_tool.rb +145 -43
- data/lib/archsight/mcp/base.rb +112 -5
- data/lib/archsight/mcp/execute_analysis_tool.rb +11 -1
- data/lib/archsight/mcp/query_hints.rb +119 -0
- data/lib/archsight/mcp/query_tool.rb +90 -5
- data/lib/archsight/mcp/relations_tool.rb +89 -0
- data/lib/archsight/mcp/resource_doc_tool.rb +39 -20
- data/lib/archsight/mcp/summary_tool.rb +106 -0
- data/lib/archsight/mcp.rb +2 -0
- data/lib/archsight/query/ast.rb +28 -0
- data/lib/archsight/query/evaluator.rb +2 -0
- data/lib/archsight/query/lexer.rb +2 -2
- data/lib/archsight/query/parser.rb +45 -0
- data/lib/archsight/query/text_search.rb +38 -0
- data/lib/archsight/query.rb +1 -0
- data/lib/archsight/reading_time.rb +66 -0
- data/lib/archsight/resources/base.rb +12 -0
- data/lib/archsight/resources/business_contract.rb +8 -1
- data/lib/archsight/resources/config.rb +28 -0
- data/lib/archsight/resources/implementation_work_package.rb +2 -0
- data/lib/archsight/resources/motivation_requirement.rb +10 -0
- data/lib/archsight/resources/technology_device.rb +14 -0
- data/lib/archsight/resources/technology_equipment.rb +3 -1
- data/lib/archsight/resources/technology_node.rb +8 -1
- data/lib/archsight/summary/builder.rb +204 -0
- data/lib/archsight/summary/lens.rb +224 -0
- data/lib/archsight/summary.rb +11 -0
- data/lib/archsight/version.rb +1 -1
- data/lib/archsight/web/api/openapi/spec.yaml +20 -1
- data/lib/archsight/web/api/page_helpers.rb +5 -1
- data/lib/archsight/web/application.rb +2 -0
- data/lib/archsight/web/public/vue/{DocPage-B2AVspsD.js → DocPage-BHffBQ3u.js} +1 -1
- data/lib/archsight/web/public/vue/{EditorPage-BYSZG_O0.js → EditorPage-BHZtvtnN.js} +1 -1
- data/lib/archsight/web/public/vue/{ErrorPage-eL_Woec4.js → ErrorPage-BQARAwF8.js} +1 -1
- data/lib/archsight/web/public/vue/{GraphView-YEiPBxPd.js → GraphView-D84CH00D.js} +1 -1
- data/lib/archsight/web/public/vue/{HomePage-BeLTwv2y.js → HomePage-BJpTPWFz.js} +2 -2
- data/lib/archsight/web/public/vue/{InstanceRouter-DgvdUouW.js → InstanceRouter-C1Da3nWo.js} +1 -1
- data/lib/archsight/web/public/vue/{KindList-BkYvYpnh.js → KindList-DNRUVuEJ.js} +1 -1
- data/lib/archsight/web/public/vue/PageView-DzKj212I.js +1 -0
- data/lib/archsight/web/public/vue/{QueryError-DzGMgvyb.js → QueryError-CTVAL1Tm.js} +1 -1
- data/lib/archsight/web/public/vue/{ResourceList-Cr9ExUDn.js → ResourceList-CRt_FpfS.js} +1 -1
- data/lib/archsight/web/public/vue/{SearchResults-D6tx3Atc.js → SearchResults-BMwBz4BB.js} +1 -1
- data/lib/archsight/web/public/vue/{WikiPage-BhaaveRq.js → WikiPage-DSEL2gmd.js} +1 -1
- data/lib/archsight/web/public/vue/{index-le1guGp1.js → index-JZkWwfYg.js} +2 -2
- data/lib/archsight/web/public/vue.html +1 -1
- metadata +24 -14
- data/lib/archsight/web/public/vue/PageView-B3SnDw9S.js +0 -1
data/lib/archsight/git_source.rb
CHANGED
|
@@ -11,7 +11,7 @@ module Archsight
|
|
|
11
11
|
# file, its `origin` remote, the checked out branch), nothing goes over the network.
|
|
12
12
|
#
|
|
13
13
|
# The web URL is `https://<host>/<owner>/<repo>` of the remote, without the user, password or token a remote URL
|
|
14
|
-
# may carry. GitHub files are `/blob/<ref>/<path>`, GitLab files `/-/blob/<ref>/<path
|
|
14
|
+
# may carry. GitHub files are `/blob/<ref>/<path>`, GitLab files `/-/blob/<ref>/<path>`, Gitea/Forgejo files `/src/branch/<ref>/<path>` (`/src/commit/<sha>/<path>`); on other hosts, and for a
|
|
15
15
|
# file git does not track, only the repository is linked. The ref is the checked out branch, the commit when the
|
|
16
16
|
# HEAD is detached (CI).
|
|
17
17
|
module GitSource
|
|
@@ -58,8 +58,10 @@ module Archsight
|
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
def file_url(host, repository_url, ref, path)
|
|
61
|
-
blob =
|
|
62
|
-
|
|
61
|
+
blob = case host
|
|
62
|
+
when /(\A|\.)github\./ then "blob"
|
|
63
|
+
when /(\A|\.)gitlab\./ then "-/blob"
|
|
64
|
+
when /(\A|\.)(gitea|forgejo|codeberg)\./ then ref&.match?(/\A\h{40,64}\z/) ? "src/commit" : "src/branch"
|
|
63
65
|
end
|
|
64
66
|
return nil unless blob && ref
|
|
65
67
|
|
data/lib/archsight/helpers.rb
CHANGED
|
@@ -83,6 +83,8 @@ module Archsight
|
|
|
83
83
|
"iconoir-github"
|
|
84
84
|
when /gitlab/
|
|
85
85
|
"iconoir-git-fork"
|
|
86
|
+
when /gitea|forgejo|codeberg/
|
|
87
|
+
"iconoir-git-fork"
|
|
86
88
|
when /confluence\.|atlassian\.net/
|
|
87
89
|
"iconoir-page-edit"
|
|
88
90
|
when /jira\.|atlassian\.net.*jira/
|
|
@@ -138,7 +140,7 @@ module Archsight
|
|
|
138
140
|
case url
|
|
139
141
|
when %r{docs\.google\.com/(document|spreadsheets|presentation)}
|
|
140
142
|
"Documentation"
|
|
141
|
-
when /github\.com|gitlab/
|
|
143
|
+
when /github\.com|gitlab|gitea|forgejo|codeberg/
|
|
142
144
|
"Code Repository"
|
|
143
145
|
when /confluence\.|atlassian\.net/
|
|
144
146
|
"Documentation"
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "fileutils"
|
|
4
|
+
require "net/http"
|
|
5
|
+
require "json"
|
|
6
|
+
require "uri"
|
|
7
|
+
require "openssl"
|
|
8
|
+
require_relative "../handler"
|
|
9
|
+
require_relative "../registry"
|
|
10
|
+
require_relative "cache_pruner"
|
|
11
|
+
|
|
12
|
+
# Gitea handler - lists repositories of a Gitea (or Forgejo) server and generates child Import resources
|
|
13
|
+
#
|
|
14
|
+
# Configuration:
|
|
15
|
+
# import/config/host - Gitea host, e.g. "gitea.example.com" (required)
|
|
16
|
+
# import/config/org - Organization (or user) to list; without it every repository the token can see is listed
|
|
17
|
+
# import/config/scheme - "https" (default) or "http"
|
|
18
|
+
# import/config/verifySSL - "false" to skip certificate verification (default: true)
|
|
19
|
+
# import/config/rateLimitMs - Pause between API requests in milliseconds (default: 0)
|
|
20
|
+
# import/config/repoOutputPath - Output path for repository handler results (e.g., "generated/repositories.yaml")
|
|
21
|
+
# import/config/childCacheTime - Cache time for generated child imports (e.g., "1h", "30m")
|
|
22
|
+
# import/config/fallbackTeam - Default team when no contributor match found (propagated to child imports)
|
|
23
|
+
# import/config/botTeam - Team for bot-only repositories (propagated to child imports)
|
|
24
|
+
# import/config/corporateAffixes - Comma-separated corporate username affixes for team matching (propagated to child imports)
|
|
25
|
+
# import/config/defaultVisibility - Default visibility for non-public repos (default: "internal")
|
|
26
|
+
# import/config/cacheRoot - Override for the local git cache root (default: ~/.cache/archsight/git)
|
|
27
|
+
#
|
|
28
|
+
# Environment:
|
|
29
|
+
# GITEA_TOKEN - Gitea access token (required)
|
|
30
|
+
# Create at: <host>/user/settings/applications (scope read:repository, plus read:organization for `org`)
|
|
31
|
+
#
|
|
32
|
+
# Output:
|
|
33
|
+
# Generates Import:Repo:* resources for each repository
|
|
34
|
+
# The repository handler will clone/sync the actual git repositories (over SSH, so the SSH keys must work)
|
|
35
|
+
#
|
|
36
|
+
# Before generating imports, prunes any cache subdirectory under
|
|
37
|
+
# cacheRoot/gitea/<host>/<owner> that no longer corresponds to a repo returned by
|
|
38
|
+
# the API (e.g. a repo that was renamed or deleted), so stale clones don't
|
|
39
|
+
# linger and get picked up by later importers.
|
|
40
|
+
class Archsight::Import::Handlers::Gitea < Archsight::Import::Handler
|
|
41
|
+
# generates child imports (see Handler.generates_imports?)
|
|
42
|
+
def self.generates_imports? = true
|
|
43
|
+
|
|
44
|
+
include Archsight::Import::Handlers::CachePruner
|
|
45
|
+
|
|
46
|
+
# Gitea caps the page size (50 by default), so the listing runs until an empty page
|
|
47
|
+
PER_PAGE = 50
|
|
48
|
+
|
|
49
|
+
def execute
|
|
50
|
+
@host = config("host")
|
|
51
|
+
raise "Missing required config: host" unless @host
|
|
52
|
+
|
|
53
|
+
@token = ENV.fetch("GITEA_TOKEN", nil)
|
|
54
|
+
raise "Missing required environment variable: GITEA_TOKEN" unless @token
|
|
55
|
+
|
|
56
|
+
@org = config("org")
|
|
57
|
+
@scheme = config("scheme", default: "https")
|
|
58
|
+
@verify_ssl = config("verifySSL", default: "true").to_s != "false"
|
|
59
|
+
@rate_limit_ms = config("rateLimitMs", default: "0").to_i
|
|
60
|
+
@repo_output_path = config("repoOutputPath")
|
|
61
|
+
@child_cache_time = config("childCacheTime")
|
|
62
|
+
@default_visibility = config("defaultVisibility", default: "internal")
|
|
63
|
+
@host_dir = File.join(Archsight::Import.cache_root(config("cacheRoot")), "gitea", @host)
|
|
64
|
+
|
|
65
|
+
progress.update("Fetching repositories from #{@org || @host}")
|
|
66
|
+
repos = fetch_all_repos
|
|
67
|
+
|
|
68
|
+
if repos.empty?
|
|
69
|
+
progress.warn("No repositories found in #{@org || @host}")
|
|
70
|
+
return
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
prune_stale_cache(repos)
|
|
74
|
+
|
|
75
|
+
progress.update("Generating #{repos.size} import resources")
|
|
76
|
+
generate_repository_imports(repos)
|
|
77
|
+
|
|
78
|
+
write_generates_meta
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
private
|
|
82
|
+
|
|
83
|
+
def fetch_all_repos
|
|
84
|
+
repos = {}
|
|
85
|
+
page = 1
|
|
86
|
+
|
|
87
|
+
loop do
|
|
88
|
+
progress.update("Fetching repositories (page #{page})")
|
|
89
|
+
batch = fetch_repos_page(page)
|
|
90
|
+
break if batch.empty?
|
|
91
|
+
|
|
92
|
+
before = repos.size
|
|
93
|
+
batch.each { |repo| repos[repo["id"] || repo["fullName"]] = repo }
|
|
94
|
+
break if repos.size == before # a server that ignores `page` would repeat the first one forever
|
|
95
|
+
|
|
96
|
+
progress.update("Fetched #{repos.size} repositories")
|
|
97
|
+
page += 1
|
|
98
|
+
sleep(@rate_limit_ms / 1000.0) if @rate_limit_ms.positive?
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
repos.values
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def fetch_repos_page(page)
|
|
105
|
+
data = if @org
|
|
106
|
+
make_request("/orgs/#{URI.encode_www_form_component(@org)}/repos", page: page, limit: PER_PAGE)
|
|
107
|
+
else
|
|
108
|
+
# the search wraps the repositories: { ok: true, data: [...] }
|
|
109
|
+
make_request("/repos/search", page: page, limit: PER_PAGE)["data"]
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
Array(data).map do |repo|
|
|
113
|
+
{
|
|
114
|
+
"id" => repo["id"],
|
|
115
|
+
"name" => repo["name"],
|
|
116
|
+
"fullName" => repo["full_name"],
|
|
117
|
+
"owner" => repo.dig("owner", "login") || repo["full_name"].to_s.split("/").first,
|
|
118
|
+
"isArchived" => repo["archived"],
|
|
119
|
+
"private" => repo["private"],
|
|
120
|
+
"sshUrl" => repo["ssh_url"],
|
|
121
|
+
"url" => repo["clone_url"] || repo["html_url"]
|
|
122
|
+
}
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def make_request(path, params = {})
|
|
127
|
+
uri = URI("#{@scheme}://#{@host}/api/v1#{path}")
|
|
128
|
+
uri.query = URI.encode_www_form(params) unless params.empty?
|
|
129
|
+
|
|
130
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
131
|
+
http.use_ssl = uri.scheme == "https"
|
|
132
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl? && !@verify_ssl
|
|
133
|
+
|
|
134
|
+
request = Net::HTTP::Get.new(uri)
|
|
135
|
+
request["Authorization"] = "token #{@token}"
|
|
136
|
+
request["Accept"] = "application/json"
|
|
137
|
+
|
|
138
|
+
handle_response(http.request(request))
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def handle_response(response)
|
|
142
|
+
case response
|
|
143
|
+
when Net::HTTPSuccess
|
|
144
|
+
JSON.parse(response.body)
|
|
145
|
+
when Net::HTTPUnauthorized
|
|
146
|
+
raise "Gitea API error: 401 Unauthorized - Invalid or expired GITEA_TOKEN"
|
|
147
|
+
when Net::HTTPForbidden
|
|
148
|
+
raise "Gitea API error: 403 Forbidden - Check token permissions"
|
|
149
|
+
when Net::HTTPNotFound
|
|
150
|
+
raise "Gitea API error: 404 Not Found - #{@org ? "Organization '#{@org}'" : "API"} not found or not accessible on #{@host}"
|
|
151
|
+
else
|
|
152
|
+
raise "Gitea API error: #{response.code} #{response.message}"
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
# Each owner has its own directory; owners that are not listed are left alone
|
|
157
|
+
def prune_stale_cache(repos)
|
|
158
|
+
repos.group_by { |repo| repo["owner"] }.each do |owner, owned|
|
|
159
|
+
prune_stale_cache_entries(File.join(@host_dir, owner), owned.map { |repo| repo["name"] })
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def generate_repository_imports(repos)
|
|
164
|
+
yaml_documents = repos.map do |repo|
|
|
165
|
+
child_annotations = {}
|
|
166
|
+
child_annotations["import/outputPath"] = @repo_output_path if @repo_output_path
|
|
167
|
+
child_annotations["import/cacheTime"] = @child_cache_time if @child_cache_time
|
|
168
|
+
|
|
169
|
+
child_config = {
|
|
170
|
+
"path" => File.join(@host_dir, repo["owner"], repo["name"]),
|
|
171
|
+
"gitUrl" => repo["sshUrl"] || repo["url"],
|
|
172
|
+
"archived" => repo["isArchived"].to_s,
|
|
173
|
+
"visibility" => repo["private"] == false ? "open-source" : @default_visibility
|
|
174
|
+
}
|
|
175
|
+
child_config["fallbackTeam"] = config("fallbackTeam") if config("fallbackTeam")
|
|
176
|
+
child_config["botTeam"] = config("botTeam") if config("botTeam")
|
|
177
|
+
child_config["corporateAffixes"] = config("corporateAffixes") if config("corporateAffixes")
|
|
178
|
+
child_config["gitService"] = config("gitService", default: "Git:Gitea")
|
|
179
|
+
|
|
180
|
+
import_yaml(
|
|
181
|
+
name: "Import:Repo:gitea:#{repo["owner"]}:#{repo["name"]}",
|
|
182
|
+
handler: "repository",
|
|
183
|
+
config: child_config,
|
|
184
|
+
annotations: child_annotations
|
|
185
|
+
)
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# Add self-marker with generated/at for caching
|
|
189
|
+
yaml_documents << self_marker
|
|
190
|
+
|
|
191
|
+
write_yaml(yaml_documents.map { |doc| YAML.dump(doc) }.join("\n"))
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
Archsight::Import::Registry.register("gitea", Archsight::Import::Handlers::Gitea)
|
|
@@ -165,6 +165,7 @@ class Archsight::Import::Handlers::Github < Archsight::Import::Handler
|
|
|
165
165
|
child_config["fallbackTeam"] = config("fallbackTeam") if config("fallbackTeam")
|
|
166
166
|
child_config["botTeam"] = config("botTeam") if config("botTeam")
|
|
167
167
|
child_config["corporateAffixes"] = config("corporateAffixes") if config("corporateAffixes")
|
|
168
|
+
child_config["gitService"] = config("gitService", default: "Git:Github")
|
|
168
169
|
|
|
169
170
|
import_yaml(
|
|
170
171
|
name: "Import:Repo:github:#{@org}:#{repo_name}",
|
|
@@ -214,6 +214,7 @@ class Archsight::Import::Handlers::Gitlab < Archsight::Import::Handler
|
|
|
214
214
|
child_config["fallbackTeam"] = config("fallbackTeam") if config("fallbackTeam")
|
|
215
215
|
child_config["botTeam"] = config("botTeam") if config("botTeam")
|
|
216
216
|
child_config["corporateAffixes"] = config("corporateAffixes") if config("corporateAffixes")
|
|
217
|
+
child_config["gitService"] = config("gitService", default: "Git:Gitlab")
|
|
217
218
|
|
|
218
219
|
import_yaml(
|
|
219
220
|
name: "Import:Repo:gitlab:#{dir_name}",
|
|
@@ -116,6 +116,7 @@ class Archsight::Import::Handlers::Repository < Archsight::Import::Handler
|
|
|
116
116
|
|
|
117
117
|
def update_repository
|
|
118
118
|
run_git(%w[git fetch --quiet], @path)
|
|
119
|
+
repair_unborn_head if empty_repository?
|
|
119
120
|
return if empty_repository? # Skip merge for empty repos
|
|
120
121
|
|
|
121
122
|
# FETCH_HEAD may be absent when git fetch brings nothing new (e.g. no
|
|
@@ -133,6 +134,30 @@ class Archsight::Import::Handlers::Repository < Archsight::Import::Handler
|
|
|
133
134
|
run_git(%w[git reset --hard FETCH_HEAD], @path)
|
|
134
135
|
end
|
|
135
136
|
|
|
137
|
+
# A clone made while the remote was empty keeps an unborn local branch: later fetches only
|
|
138
|
+
# advance the origin/* refs, so HEAD never gets a commit and the repository would be
|
|
139
|
+
# reported as empty. Point the local default branch at the remote one.
|
|
140
|
+
def repair_unborn_head
|
|
141
|
+
remote_ref = remote_default_ref
|
|
142
|
+
return unless remote_ref
|
|
143
|
+
|
|
144
|
+
progress.warn("Local HEAD has no commits but #{remote_ref} does, checking it out")
|
|
145
|
+
run_git(["git", "checkout", "--quiet", "-B", remote_ref.delete_prefix("origin/"), remote_ref], @path)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# The remote-tracking ref of the remote's default branch (`origin/main`), or nil when the
|
|
149
|
+
# remote has no commits.
|
|
150
|
+
def remote_default_ref
|
|
151
|
+
Open3.capture3("git", "remote", "set-head", "origin", "--auto", chdir: @path) # origin/HEAD is unset after an empty clone
|
|
152
|
+
out, _, status = Open3.capture3("git", "symbolic-ref", "--short", "refs/remotes/origin/HEAD", chdir: @path)
|
|
153
|
+
return out.strip if status.success? && resolve_ref(out.strip)
|
|
154
|
+
|
|
155
|
+
# the remote did not name a default branch: fall back to the branch the clone started on
|
|
156
|
+
branch, _, status = Open3.capture3("git", "symbolic-ref", "--short", "HEAD", chdir: @path)
|
|
157
|
+
candidate = "origin/#{branch.strip}"
|
|
158
|
+
candidate if status.success? && resolve_ref(candidate)
|
|
159
|
+
end
|
|
160
|
+
|
|
136
161
|
def empty_repository?
|
|
137
162
|
# Check if HEAD exists (empty repos have no commits)
|
|
138
163
|
_, _, status = Open3.capture3("git", "rev-parse", "HEAD", chdir: @path)
|
|
@@ -331,10 +356,7 @@ class Archsight::Import::Handlers::Repository < Archsight::Import::Handler
|
|
|
331
356
|
spec = {}
|
|
332
357
|
|
|
333
358
|
# Technology component (Git provider)
|
|
334
|
-
if git_url
|
|
335
|
-
provider = git_url.include?("github") ? "Git:Github" : "Git:Gitlab"
|
|
336
|
-
spec["suppliedBy"] = { "technologyComponents" => [provider] }
|
|
337
|
-
end
|
|
359
|
+
spec["suppliedBy"] = { "technologyComponents" => [git_service(git_url)] } if git_url
|
|
338
360
|
|
|
339
361
|
# Team relations from contributor matching
|
|
340
362
|
if team_result
|
|
@@ -361,6 +383,12 @@ class Archsight::Import::Handlers::Repository < Archsight::Import::Handler
|
|
|
361
383
|
url_line.split("=").last.strip
|
|
362
384
|
end
|
|
363
385
|
|
|
386
|
+
# The TechnologyService that supplies the repository: `gitService` as passed by the listing import
|
|
387
|
+
# (github, gitlab, gitea), else guessed from the clone URL for repository imports written by hand
|
|
388
|
+
def git_service(git_url)
|
|
389
|
+
config("gitService") || (git_url.include?("github") ? "Git:Github" : "Git:Gitlab")
|
|
390
|
+
end
|
|
391
|
+
|
|
364
392
|
def repository_name(git_url_or_path)
|
|
365
393
|
if git_url_or_path.include?(":")
|
|
366
394
|
# Git URL format
|
data/lib/archsight/linter.rb
CHANGED
|
@@ -20,7 +20,7 @@ module Archsight
|
|
|
20
20
|
# Structure relations between elements of one kind (specialization, composition, aggregation). Each verb is
|
|
21
21
|
# checked on its own: a chain of one of them must not lead back to where it started. They stay out of the
|
|
22
22
|
# general check above so that a cycle is reported once.
|
|
23
|
-
HIERARCHY_VERBS = %i[specializes composedOf aggregates].freeze
|
|
23
|
+
HIERARCHY_VERBS = %i[specializes composedOf aggregates refinedBy].freeze
|
|
24
24
|
|
|
25
25
|
def initialize(database)
|
|
26
26
|
@database = database
|
|
@@ -192,7 +192,7 @@ module Archsight
|
|
|
192
192
|
report_cycles(graph) { |start, path| "#{start.path_ref}: #{start.klass} '#{start.name}' is part of a relation cycle (#{path})" }
|
|
193
193
|
end
|
|
194
194
|
|
|
195
|
-
# `specializes`, `composedOf` and `
|
|
195
|
+
# `specializes`, `composedOf`, `aggregates` and `refinedBy` (one chain per verb) must not lead back to where they started
|
|
196
196
|
def validate_hierarchy_cycles
|
|
197
197
|
HIERARCHY_VERBS.each do |hierarchy_verb|
|
|
198
198
|
graph = relation_graph { |verb| verb == hierarchy_verb }
|
|
@@ -306,6 +306,8 @@ module Archsight
|
|
|
306
306
|
next
|
|
307
307
|
end
|
|
308
308
|
|
|
309
|
+
validate_summary_lens_key(instance, key)
|
|
310
|
+
|
|
309
311
|
# Content checks don't depend on enum/type constraints
|
|
310
312
|
validate_markdown(instance, key, value) if annotation.markdown?
|
|
311
313
|
validate_diagram(instance, key, value) if annotation.diagram?
|
|
@@ -320,6 +322,15 @@ module Archsight
|
|
|
320
322
|
end
|
|
321
323
|
end
|
|
322
324
|
|
|
325
|
+
# `summary/lens-<layer or Kind>`: a suffix that names neither would be ignored silently
|
|
326
|
+
def validate_summary_lens_key(instance, key)
|
|
327
|
+
suffix = key[%r{\Asummary/lens-(.+)\z}, 1]
|
|
328
|
+
return unless suffix && instance.klass == "Config"
|
|
329
|
+
|
|
330
|
+
problem = Archsight::Summary::Lens.key_error(suffix)
|
|
331
|
+
@errors << "#{instance.path_ref}: Annotation '#{key}' #{problem}" if problem
|
|
332
|
+
end
|
|
333
|
+
|
|
323
334
|
# The resource a `Name` / `Kind/Name` annotation points to must exist; a bare `Name` means the same kind
|
|
324
335
|
def validate_resource_reference(instance, key, value)
|
|
325
336
|
return if Archsight::Helpers::ResourceResolver.new(@database).find_annotated(value, instance.klass).is_a?(Array)
|
|
@@ -23,6 +23,22 @@ class Archsight::MCP::AnalyzeResourceTool < FastMcp::Tool
|
|
|
23
23
|
kind/verb/depth with summary statistics. Essential for change impact assessment.
|
|
24
24
|
Example: kind="ApplicationInterface", name="Kubernetes:RestAPI", impact=true
|
|
25
25
|
|
|
26
|
+
EXAMPLES:
|
|
27
|
+
kind="ApplicationComponent", name="X", depth=2 - what X depends on and what depends on X, two levels
|
|
28
|
+
kind="ApplicationComponent", name="X", impact=true, exclude_kinds=["Page","PageMenu"], depth=2, limit=50 -
|
|
29
|
+
a small, filtered impact list; direction="out" turns it around (what X relies on)
|
|
30
|
+
|
|
31
|
+
TYPICAL FLOW: find the exact name with query (output='brief'), call this tool in basic mode, and go to
|
|
32
|
+
depth or impact only for the question that needs it. For just the direct relations of one verb use the
|
|
33
|
+
relations tool instead.
|
|
34
|
+
|
|
35
|
+
PITFALLS:
|
|
36
|
+
• kind and name are exact and case-sensitive; a wrong name returns 'did you mean' suggestions across all kinds.
|
|
37
|
+
• impact=true on a hub resource can list hundreds of entries: set limit, depth and exclude_kinds first.
|
|
38
|
+
The summary (counts by kind) always covers everything, even when the list is cut.
|
|
39
|
+
• depth > 0 returns the whole tree both ways and grows fast; keep it at 1 to 3.
|
|
40
|
+
• The response is cut when it exceeds the size budget; a 'truncated' note says how to narrow it.
|
|
41
|
+
|
|
26
42
|
RESOURCE KINDS: TechnologyArtifact, ApplicationComponent, ApplicationInterface,
|
|
27
43
|
ApplicationService, MotivationRequirement, ComplianceEvidence, and more.
|
|
28
44
|
DESC
|
|
@@ -46,6 +62,22 @@ class Archsight::MCP::AnalyzeResourceTool < FastMcp::Tool
|
|
|
46
62
|
"if this resource is deprecated or removed. Returns grouped results with statistics. " \
|
|
47
63
|
"Useful for change management and deprecation planning."
|
|
48
64
|
)
|
|
65
|
+
optional(:kinds).array(:string).description(
|
|
66
|
+
"Impact mode: only follow and report these kinds (e.g. ['ApplicationComponent']). Default: all kinds."
|
|
67
|
+
)
|
|
68
|
+
optional(:exclude_kinds).array(:string).description(
|
|
69
|
+
"Impact mode: skip these kinds and do not follow through them (e.g. ['Page', 'PageMenu'])."
|
|
70
|
+
)
|
|
71
|
+
optional(:verbs).array(:string).description(
|
|
72
|
+
"Impact mode: only follow these relation verbs (e.g. ['realizedThrough', 'servedBy'])."
|
|
73
|
+
)
|
|
74
|
+
optional(:direction).filled(:string).description(
|
|
75
|
+
"Impact mode: 'in' = what depends on this resource (default), 'out' = what this resource depends on."
|
|
76
|
+
)
|
|
77
|
+
optional(:limit).filled(:integer).description(
|
|
78
|
+
"Impact mode: maximum entries listed (nearest first). The summary (counts by kind) always covers all of " \
|
|
79
|
+
"them and says how many were left out."
|
|
80
|
+
)
|
|
49
81
|
optional(:group_by).filled(:string).description(
|
|
50
82
|
"How to group impact analysis results: " \
|
|
51
83
|
"'kind' = group by resource type (default, good for understanding scope), " \
|
|
@@ -54,19 +86,21 @@ class Archsight::MCP::AnalyzeResourceTool < FastMcp::Tool
|
|
|
54
86
|
)
|
|
55
87
|
end
|
|
56
88
|
|
|
57
|
-
def call(kind:, name:, depth: 0, impact: false, group_by: "kind"
|
|
89
|
+
def call(kind:, name:, depth: 0, impact: false, group_by: "kind", kinds: nil, exclude_kinds: nil, verbs: nil,
|
|
90
|
+
direction: "in", limit: nil)
|
|
58
91
|
db = Archsight::MCP.db
|
|
59
92
|
|
|
60
93
|
klass = Archsight::Resources[kind]
|
|
61
94
|
return error_response("Unknown resource kind: #{kind}") unless klass
|
|
62
95
|
|
|
63
96
|
instance = db.instance_by_kind(kind, name)
|
|
64
|
-
return
|
|
97
|
+
return not_found_response(kind, name) unless instance
|
|
65
98
|
|
|
66
99
|
depth = [[depth.to_i, 0].max, 10].min # Clamp to 0-10
|
|
67
100
|
|
|
68
101
|
if impact
|
|
69
|
-
|
|
102
|
+
filter = { kinds: kinds, exclude_kinds: exclude_kinds, verbs: verbs&.map(&:to_s), direction: direction.to_s }
|
|
103
|
+
build_impact_analysis(db, instance, kind, name, depth, group_by, filter, limit)
|
|
70
104
|
else
|
|
71
105
|
build_resource_analysis(db, instance, kind, name, depth)
|
|
72
106
|
end
|
|
@@ -76,6 +110,13 @@ class Archsight::MCP::AnalyzeResourceTool < FastMcp::Tool
|
|
|
76
110
|
|
|
77
111
|
private
|
|
78
112
|
|
|
113
|
+
# Not found: the closest names across all kinds, so a typo or a wrong kind is one call away from the answer
|
|
114
|
+
def not_found_response(kind, name)
|
|
115
|
+
suggestions = Archsight::MCP.suggest(name, kind: kind)
|
|
116
|
+
message = ["Resource not found: #{kind}/#{name}", Archsight::MCP.did_you_mean(suggestions)].compact.join(". ")
|
|
117
|
+
JSON.pretty_generate({ error: "Error", message: message, suggestions: suggestions })
|
|
118
|
+
end
|
|
119
|
+
|
|
79
120
|
def error_response(message, error_type = "Error", backtrace = nil)
|
|
80
121
|
result = {
|
|
81
122
|
error: error_type,
|
|
@@ -91,7 +132,7 @@ class Archsight::MCP::AnalyzeResourceTool < FastMcp::Tool
|
|
|
91
132
|
name: name,
|
|
92
133
|
spec: instance.spec,
|
|
93
134
|
annotations: instance.annotations
|
|
94
|
-
}
|
|
135
|
+
}.merge(Archsight::MCP.source_info(instance))
|
|
95
136
|
|
|
96
137
|
if depth.positive?
|
|
97
138
|
# Include dependency trees
|
|
@@ -101,33 +142,22 @@ class Archsight::MCP::AnalyzeResourceTool < FastMcp::Tool
|
|
|
101
142
|
else
|
|
102
143
|
# Just direct relations
|
|
103
144
|
result[:relations] = Archsight::MCP.extract_relations(instance)
|
|
145
|
+
result[:related] = Archsight::MCP.related_sources(instance)
|
|
104
146
|
result[:has_relations] = instance.has_relations?
|
|
105
147
|
end
|
|
106
148
|
|
|
107
149
|
JSON.pretty_generate(result)
|
|
108
150
|
end
|
|
109
151
|
|
|
110
|
-
def build_impact_analysis(db, instance, kind, name, max_depth, group_by)
|
|
152
|
+
def build_impact_analysis(db, instance, kind, name, max_depth, group_by, filter, limit)
|
|
111
153
|
max_depth = 5 if max_depth.zero? # Default depth for impact analysis
|
|
154
|
+
limit = [limit.to_i, 1].max if limit
|
|
112
155
|
|
|
113
|
-
# Collect all impacted resources
|
|
114
156
|
impacted = []
|
|
115
|
-
|
|
116
|
-
collect_impact(
|
|
117
|
-
|
|
118
|
-
#
|
|
119
|
-
grouped = case group_by
|
|
120
|
-
when "verb"
|
|
121
|
-
impacted.group_by { |i| i[:verb].to_s }
|
|
122
|
-
when "kind"
|
|
123
|
-
impacted.group_by { |i| i[:kind] }
|
|
124
|
-
when "depth"
|
|
125
|
-
impacted.group_by { |i| i[:depth] }
|
|
126
|
-
else
|
|
127
|
-
{ "all" => impacted }
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
# Calculate summary statistics
|
|
157
|
+
edges = ImpactEdges.new(db, filter)
|
|
158
|
+
collect_impact(edges, instance, 0, max_depth, Set.new, impacted)
|
|
159
|
+
|
|
160
|
+
# Summary statistics always cover everything found, whatever is listed
|
|
131
161
|
summary = {
|
|
132
162
|
total_impacted: impacted.length,
|
|
133
163
|
unique_resources: impacted.map { |i| "#{i[:kind]}/#{i[:name]}" }.uniq.length,
|
|
@@ -138,44 +168,116 @@ class Archsight::MCP::AnalyzeResourceTool < FastMcp::Tool
|
|
|
138
168
|
result = {
|
|
139
169
|
target: { kind: kind, name: name },
|
|
140
170
|
analysis: "impact",
|
|
171
|
+
direction: filter[:direction],
|
|
141
172
|
max_depth: max_depth,
|
|
142
173
|
group_by: group_by,
|
|
143
|
-
summary: summary
|
|
144
|
-
impacted_resources: grouped
|
|
174
|
+
summary: summary
|
|
145
175
|
}
|
|
176
|
+
result[:filters] = filter.slice(:kinds, :exclude_kinds, :verbs).compact unless filter.slice(:kinds, :exclude_kinds, :verbs).compact.empty?
|
|
146
177
|
|
|
147
|
-
|
|
178
|
+
ordered = impacted.each_with_index.sort_by { |entry, index| [entry[:depth], index] }.map(&:first)
|
|
179
|
+
shown = limit ? ordered.take(limit) : ordered
|
|
180
|
+
result[:impacted_resources] = group_impacted(shown, group_by)
|
|
181
|
+
|
|
182
|
+
Archsight::MCP.fit(truncation_note(result, impacted.length, shown.length)) do |attempt|
|
|
183
|
+
keep = [shown.length / (2**attempt), 1].max
|
|
184
|
+
result[:impacted_resources] = group_impacted(ordered.take(keep), group_by)
|
|
185
|
+
truncation_note(result, impacted.length, keep, budget: true)
|
|
186
|
+
end
|
|
148
187
|
end
|
|
149
188
|
|
|
150
|
-
def
|
|
151
|
-
|
|
189
|
+
def group_impacted(entries, group_by)
|
|
190
|
+
case group_by
|
|
191
|
+
when "verb" then entries.group_by { |i| i[:verb].to_s }
|
|
192
|
+
when "kind" then entries.group_by { |i| i[:kind] }
|
|
193
|
+
when "depth" then entries.group_by { |i| i[:depth] }
|
|
194
|
+
else { "all" => entries }
|
|
195
|
+
end
|
|
196
|
+
end
|
|
152
197
|
|
|
153
|
-
|
|
154
|
-
|
|
198
|
+
# Says how many entries are left out and how to narrow the request
|
|
199
|
+
def truncation_note(result, total, shown, budget: false)
|
|
200
|
+
return result if shown >= total
|
|
155
201
|
|
|
156
|
-
|
|
202
|
+
reason = budget ? "size budget" : "limit"
|
|
203
|
+
result.merge(
|
|
204
|
+
truncated: "#{total - shown} more entries not listed (#{reason}); #{shown} of #{total} shown, nearest first. " \
|
|
205
|
+
"Narrow with exclude_kinds, kinds, verbs, a smaller depth or direction."
|
|
206
|
+
)
|
|
207
|
+
end
|
|
157
208
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
209
|
+
# The relations to follow from a resource, filtered by kind and verb. `in` finds the resources that point at it
|
|
210
|
+
# (via an index over all relations, built once), `out` the ones it points at.
|
|
211
|
+
class ImpactEdges
|
|
212
|
+
def initialize(db, filter)
|
|
213
|
+
@db = db
|
|
214
|
+
@filter = filter
|
|
215
|
+
@incoming = nil
|
|
216
|
+
end
|
|
161
217
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
218
|
+
# [[resource, verb], ...]
|
|
219
|
+
def next_from(resource)
|
|
220
|
+
pairs = @filter[:direction] == "out" ? outgoing(resource) : incoming(resource)
|
|
221
|
+
pairs.select { |other, verb| allowed?(other, verb) }
|
|
222
|
+
end
|
|
165
223
|
|
|
166
|
-
|
|
167
|
-
kind: other.class.to_s.split("::").last,
|
|
168
|
-
name: other.name,
|
|
169
|
-
verb: verb,
|
|
170
|
-
depth: current_depth + 1
|
|
171
|
-
}
|
|
224
|
+
private
|
|
172
225
|
|
|
173
|
-
|
|
226
|
+
def allowed?(other, verb)
|
|
227
|
+
kind = other.class.to_s.split("::").last
|
|
228
|
+
return false if @filter[:kinds] && !@filter[:kinds].empty? && !@filter[:kinds].include?(kind)
|
|
229
|
+
return false if @filter[:exclude_kinds]&.include?(kind)
|
|
230
|
+
|
|
231
|
+
@filter[:verbs].nil? || @filter[:verbs].empty? || @filter[:verbs].include?(verb.to_s)
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def outgoing(resource)
|
|
235
|
+
resource.class.relations.flat_map do |verb, kind_name, _|
|
|
236
|
+
resource.relations(verb, kind_name).map { |target| [target, verb] }
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
def incoming(resource)
|
|
241
|
+
build_index unless @incoming
|
|
242
|
+
@incoming[resource] || []
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
def build_index
|
|
246
|
+
@incoming = {}
|
|
247
|
+
@db.instances.each_value do |instances_hash|
|
|
248
|
+
instances_hash.each_value do |other|
|
|
249
|
+
other.class.relations.each do |verb, kind_name, _|
|
|
250
|
+
other.relations(verb, kind_name).each do |target|
|
|
251
|
+
next if target == other
|
|
252
|
+
|
|
253
|
+
(@incoming[target] ||= []) << [other, verb]
|
|
254
|
+
end
|
|
255
|
+
end
|
|
174
256
|
end
|
|
175
257
|
end
|
|
176
258
|
end
|
|
177
259
|
end
|
|
178
260
|
|
|
261
|
+
def collect_impact(edges, resource, current_depth, max_depth, visited, collector)
|
|
262
|
+
return if current_depth >= max_depth
|
|
263
|
+
|
|
264
|
+
key = "#{resource.class.to_s.split("::").last}/#{resource.name}"
|
|
265
|
+
return if visited.include?(key)
|
|
266
|
+
|
|
267
|
+
visited.add(key)
|
|
268
|
+
|
|
269
|
+
edges.next_from(resource).each do |other, verb|
|
|
270
|
+
collector << {
|
|
271
|
+
kind: other.class.to_s.split("::").last,
|
|
272
|
+
name: other.name,
|
|
273
|
+
verb: verb,
|
|
274
|
+
depth: current_depth + 1
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
collect_impact(edges, other, current_depth + 1, max_depth, visited.dup, collector)
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
|
|
179
281
|
def build_dependency_tree(db, resource, direction, current_depth, max_depth, visited)
|
|
180
282
|
return [] if current_depth >= max_depth
|
|
181
283
|
|