mk_semi_lattice 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +7 -0
  2. data/.DS_Store +0 -0
  3. data/.hyper_card/history/20251020_1517_readme_formatted.md +463 -0
  4. data/.hyper_card/history/20251020_1828_minor_rev_formatted.md +181 -0
  5. data/.hyper_card/history/20251021_1110_wsl_ubuntu_japanese.md +218 -0
  6. data/.hyper_card/history/20251021_1142_double_click_action.md +250 -0
  7. data/.hyper_card/history/20251021_1151_select_semi_data_action.md +75 -0
  8. data/.hyper_card/history/20251021_2322_add_comment_edges.md +252 -0
  9. data/.hyper_card/history/20251022_0725_add_color_index.md +155 -0
  10. data/.hyper_card/history/classify_251103.md +1090 -0
  11. data/.hyper_card/history/file_path_modifier.md +481 -0
  12. data/.hyper_card/history/file_path_modifier_251103.md +505 -0
  13. data/.hyper_card/history/knowledge_fixer.pdf +0 -0
  14. data/.hyper_card/history/log_with_symbol_251102.md +184 -0
  15. data/.hyper_card/history/memory_leak_251028.md +311 -0
  16. data/.hyper_card/history/set_log_conf_251027.md +295 -0
  17. data/CHANGELOG.md +5 -0
  18. data/CODE_OF_CONDUCT.md +132 -0
  19. data/LICENSE.txt +21 -0
  20. data/README.md +43 -0
  21. data/Rakefile +8 -0
  22. data/exe/mk_semi_lattice +3 -0
  23. data/exe/sl +5 -0
  24. data/lib/mk_semi_lattice/config.rb +53 -0
  25. data/lib/mk_semi_lattice/log.rb +26 -0
  26. data/lib/mk_semi_lattice/manage_yaml.rb +89 -0
  27. data/lib/mk_semi_lattice/mk_dir_yaml.rb +40 -0
  28. data/lib/mk_semi_lattice/mk_node_edge.rb +108 -0
  29. data/lib/mk_semi_lattice/mk_semi_lattice_graph.rb +254 -0
  30. data/lib/mk_semi_lattice/mk_semi_lattice_viewer.rb +77 -0
  31. data/lib/mk_semi_lattice/option_manager.rb +58 -0
  32. data/lib/mk_semi_lattice/ruby2d_action.rb +136 -0
  33. data/lib/mk_semi_lattice/version.rb +5 -0
  34. data/lib/mk_semi_lattice.rb +22 -0
  35. data/sig/mk_semi_lattice.rbs +4 -0
  36. metadata +122 -0
@@ -0,0 +1,252 @@
1
+ daddygongon: init_file=='.'の時はsemi_dirがあるか確認して,なければ未実装と警告して終了.
2
+
3
+ GitHub Copilot: ### [mk_semi_lattice.rb](file:///Users/bob/git_hub/mk_semi_lattice/lib/mk_semi_lattice.rb)
4
+
5
+ Check if `init_file == '.'` and if so, verify that `semi_dir` exists. If not, print a warning and exit.
6
+
7
+ ````ruby
8
+ # ...existing code...
9
+
10
+ init_file = ARGV[0] || '.'
11
+ parent_dir = File.dirname(init_file)
12
+ semi_dir = File.join(parent_dir, '.semi_lattice')
13
+ semi_lattice_yaml_path = File.join(semi_dir, "semi_lattice.yaml")
14
+
15
+ if init_file == '.'
16
+ unless Dir.exist?(semi_dir)
17
+ warn "未実装: カレントディレクトリに .semi_lattice ディレクトリがありません。"
18
+ exit 1
19
+ end
20
+ end
21
+
22
+ p parent_dir
23
+ p semi_dir
24
+ p semi_lattice_yaml_path
25
+
26
+ app = MkSemiLatticeData.new(init_file, with_semi_lattice_yaml: true)
27
+
28
+ # ...existing code...
29
+ ````
30
+
31
+ Made changes.
32
+
33
+ daddygongon: options[:init_step] == :mk_node_edgeの時には,
34
+ MkSemiLattice::MkNodeEdge.new(input_path: input_path, output_path: output_path)
35
+ file = output_path
36
+ app = MkSemiLatticeData.new(output_path)
37
+
38
+ GitHub Copilot: ### [mk_semi_lattice.rb](file:///Users/bob/git_hub/mk_semi_lattice/lib/mk_semi_lattice.rb)
39
+
40
+ Add logic to handle `options[:init_step] == :mk_node_edge`. When this is true, run `MkSemiLattice::MkNodeEdge.new(input_path: input_path, output_path: output_path)`, set `file = output_path`, and initialize `app = MkSemiLatticeData.new(output_path)`.
41
+
42
+ ````ruby
43
+ # ...existing code...
44
+
45
+ init_file = ARGV[0] || '.'
46
+ parent_dir = File.dirname(init_file)
47
+ semi_dir = File.join(parent_dir, '.semi_lattice')
48
+ semi_lattice_yaml_path = File.join(semi_dir, "semi_lattice.yaml")
49
+
50
+ if init_file == '.'
51
+ unless Dir.exist?(semi_dir)
52
+ warn "未実装: カレントディレクトリに .semi_lattice ディレクトリがありません。"
53
+ exit 1
54
+ end
55
+ end
56
+
57
+ if options[:init_step] == :mk_node_edge
58
+ input_path = options[:file]
59
+ output_path = semi_lattice_yaml_path
60
+ MkSemiLattice::MkNodeEdge.new(input_path: input_path, output_path: output_path)
61
+ file = output_path
62
+ app = MkSemiLatticeData.new(output_path)
63
+ else
64
+ app = MkSemiLatticeData.new(init_file, with_semi_lattice_yaml: true)
65
+ end
66
+
67
+ # ...existing code...
68
+ ````
69
+
70
+ Made changes.
71
+
72
+ daddygongon: #file:mk_semi_lattice.rb:38-49 はARGV[0]=='.'かARGV[0]==nilおよびoptions[:file]!=nilの時に実行するように修正
73
+
74
+ GitHub Copilot: ### [mk_semi_lattice.rb](file:///Users/bob/git_hub/mk_semi_lattice/lib/mk_semi_lattice.rb)
75
+
76
+ Move lines 38-49 so that they are only executed when `ARGV[0]=='.'` or `ARGV[0]==nil` or `options[:file]` is not nil.
77
+
78
+ ````ruby
79
+ # ...existing code...
80
+
81
+ init_file, options[:init_step] = if ARGV[0]=='.' || ARGV[0].nil? || options[:file]
82
+ parent_dir = Dir.pwd
83
+ semi_dir = File.join(parent_dir, '.semi_lattice')
84
+ semi_lattice_yaml_path = File.join(semi_dir, "semi_lattice.yaml")
85
+ # ↓ このブロックのみ条件付きで実行
86
+ if Dir.exist?(semi_lattice_yaml_path)
87
+ [semi_lattice_yaml_path, :from_semi_lattice]
88
+ else
89
+ ['.', :from_dir]
90
+ end
91
+ else
92
+ [ARGV[0], :from_semi_lattice]
93
+ end
94
+
95
+ # ...existing code...
96
+ ````
97
+
98
+ Made changes.
99
+
100
+ daddygongon: traverseで生成するnodeを全てHashにしてkeyをsymbolに変更.
101
+
102
+ GitHub Copilot: ### [mk_node_edge.rb](file:///Users/bob/git_hub/mk_semi_lattice/lib/mk_semi_lattice/mk_node_edge.rb)
103
+
104
+ `traverse`で生成するnodeを全てHashにし、keyをsymbolに変更します。
105
+ また、`add_edge_comments`メソッド内でnodeのkey参照もsymbolに合わせて修正します。
106
+
107
+ ````ruby
108
+ # ...existing code...
109
+ def self.add_edge_comments(output)
110
+ nodes = output[:nodes]
111
+ edges = output[:edges]
112
+ id_name_map = nodes.each_with_object({}) do |node, map|
113
+ map[node[:id]] = node[:name]
114
+ end
115
+ # ...existing code...
116
+ end
117
+
118
+ def traverse(node, parent_id, nodes, edges, id_counter, current_path, top_path)
119
+ if node.is_a?(Hash)
120
+ node.each do |name, value|
121
+ node_id = id_counter[:val]
122
+ id_counter[:val] += 1
123
+
124
+ type = if name.to_s.end_with?('/')
125
+ 'dir'
126
+ else
127
+ value.is_a?(Hash) || value.is_a?(Array) ? 'dir' : 'file'
128
+ end
129
+
130
+ p [current_path, name]
131
+ node_path = File.join(current_path, name.to_s)
132
+ rel_path = if node_path == top_path
133
+ '.'
134
+ else
135
+ rp = Pathname.new(node_path).relative_path_from(Pathname.new(top_path)).to_s
136
+ rp.start_with?('.') ? rp : "./#{rp}"
137
+ end
138
+
139
+ nodes << {
140
+ :id => node_id,
141
+ :name => name,
142
+ :type => type,
143
+ :file_path => rel_path
144
+ }
145
+ if parent_id
146
+ edges << {
147
+ :from => parent_id,
148
+ :to => node_id
149
+ }
150
+ end
151
+
152
+ if value.is_a?(Hash) || value.is_a?(Array)
153
+ traverse(value, node_id, nodes, edges, id_counter, node_path, top_path)
154
+ end
155
+ end
156
+ elsif node.is_a?(Array)
157
+ node.each do |item|
158
+ traverse(item, parent_id, nodes, edges, id_counter, current_path, top_path)
159
+ end
160
+ end
161
+ end
162
+ # ...existing code...
163
+ ````
164
+
165
+ Made changes.
166
+
167
+ daddygongon: #file:mk_semi_lattice.rb:186-187 は何をしていますか?
168
+
169
+ GitHub Copilot: 186-187行目(`Dir.mkdir(semi_dir) unless`)は、`.semi_lattice`ディレクトリが存在しない場合に作成しようとしています。ただし、`unless`の条件が未記載のため、文法的に不完全です。
170
+
171
+ 本来は
172
+ ```ruby
173
+ Dir.mkdir(semi_dir) unless Dir.exist?(semi_dir)
174
+ ```
175
+ のように、ディレクトリが存在しない場合のみ作成する意図です。
176
+
177
+ daddygongon: traverseで生成するnodeを全てHashにしてkeyをsymbolに変更.
178
+
179
+ GitHub Copilot: ### [mk_node_edge.rb](file:///Users/bob/git_hub/mk_semi_lattice/lib/mk_semi_lattice/mk_node_edge.rb)
180
+
181
+ `traverse`で生成するnodeを全てHashにし、keyをsymbolに変更します。
182
+ また、`add_edge_comments`メソッド内でnodeのkey参照もsymbolに合わせて修正します。
183
+
184
+ ````ruby
185
+ # ...existing code...
186
+ def self.add_edge_comments(output)
187
+ nodes = output[:nodes]
188
+ edges = output[:edges]
189
+ id_name_map = nodes.each_with_object({}) do |node, map|
190
+ map[node[:id]] = node[:name]
191
+ end
192
+ # ...existing code...
193
+ end
194
+
195
+ def traverse(node, parent_id, nodes, edges, id_counter, current_path, top_path)
196
+ if node.is_a?(Hash)
197
+ node.each do |name, value|
198
+ node_id = id_counter[:val]
199
+ id_counter[:val] += 1
200
+
201
+ type = if name.to_s.end_with?('/')
202
+ 'dir'
203
+ else
204
+ value.is_a?(Hash) || value.is_a?(Array) ? 'dir' : 'file'
205
+ end
206
+
207
+ p [current_path, name]
208
+ node_path = File.join(current_path, name.to_s)
209
+ rel_path = if node_path == top_path
210
+ '.'
211
+ else
212
+ rp = Pathname.new(node_path).relative_path_from(Pathname.new(top_path)).to_s
213
+ rp.start_with?('.') ? rp : "./#{rp}"
214
+ end
215
+
216
+ nodes << {
217
+ :id => node_id,
218
+ :name => name,
219
+ :type => type,
220
+ :file_path => rel_path
221
+ }
222
+ if parent_id
223
+ edges << {
224
+ :from => parent_id,
225
+ :to => node_id
226
+ }
227
+ end
228
+
229
+ if value.is_a?(Hash) || value.is_a?(Array)
230
+ traverse(value, node_id, nodes, edges, id_counter, node_path, top_path)
231
+ end
232
+ end
233
+ elsif node.is_a?(Array)
234
+ node.each do |item|
235
+ traverse(item, parent_id, nodes, edges, id_counter, current_path, top_path)
236
+ end
237
+ end
238
+ end
239
+ # ...existing code...
240
+ ````
241
+
242
+ Made changes.
243
+
244
+ daddygongon: #file:mk_semi_lattice.rb:186-187 は何をしていますか?
245
+
246
+ GitHub Copilot: 186-187行目(`Dir.mkdir(semi_dir) unless`)は、`.semi_lattice`ディレクトリが存在しない場合に作成しようとしています。ただし、`unless`の条件が未記載のため、文法的に不完全です。
247
+
248
+ 本来は
249
+ ```ruby
250
+ Dir.mkdir(semi_dir) unless Dir.exist?(semi_dir)
251
+ ```
252
+ のように、ディレクトリが存在しない場合のみ作成する意図です。
@@ -0,0 +1,155 @@
1
+ daddygongon: 描かれたnodeにidも表示するoptionとして-i, -indexを追加.
2
+
3
+ GitHub Copilot: ### [mk_semi_lattice.rb](file:///Users/bob/git_hub/mk_semi_lattice/lib/mk_semi_lattice.rb)
4
+
5
+ Add an option `-i`/`--index` to display node ids. Pass this option to the app and update node drawing to show id if enabled.
6
+
7
+ ````ruby
8
+ # ...existing code...
9
+ options = { layer: 2, init_step: :from_semi_lattice, show_index: false }
10
+ OptionParser.new do |opts|
11
+ # ...existing code...
12
+ opts.on("-i", "--index", "Display node ids") do
13
+ options[:show_index] = true
14
+ end
15
+ # ...existing code...
16
+ end.parse!
17
+ # ...existing code...
18
+
19
+ app = MkSemiLatticeData.new(input_path,
20
+ with_semi_lattice_yaml: with_semi_lattice_yaml,
21
+ show_index: options[:show_index]
22
+ )
23
+ # ...existing code...
24
+
25
+ update do
26
+ clear
27
+ app.edges.each(&:relax)
28
+ app.nodes.each { |n| n.relax(app.nodes) }
29
+ app.nodes.each(&:update)
30
+ app.edges.reverse.each(&:draw)
31
+ app.nodes.reverse.each do |n|
32
+ n.draw(app.selected == n)
33
+ # show node id if option enabled
34
+ if app.respond_to?(:show_index) && app.show_index
35
+ id = app.node_table.key(n)
36
+ Text.new(id.to_s, x: n.x + 20, y: n.y - 20, size: 16, color: 'black')
37
+ end
38
+ end
39
+ end
40
+ # ...existing code...
41
+ ````
42
+
43
+ Made changes.
44
+
45
+ daddygongon: #file:mk_semi_lattice.rb:86-89 に対応するようにMkSemiLatticeDataを修正
46
+
47
+ GitHub Copilot: ### [mk_semi_lattice_graph.rb](file:///Users/bob/git_hub/mk_semi_lattice/lib/mk_semi_lattice/mk_semi_lattice_graph.rb)
48
+
49
+ Update `MkSemiLatticeData` to accept and store `show_index` option, and provide it as an attribute for use in the main file.
50
+
51
+ ````ruby
52
+ # ...existing code...
53
+
54
+ class MkSemiLatticeData
55
+ attr_reader :nodes, :edges, :node_table
56
+ attr_accessor :selected, :shift_pressed
57
+ attr_accessor :show_index # add this line
58
+
59
+ def initialize(file = "dir_node_edge.yaml", with_semi_lattice_yaml: false, show_index: false)
60
+ @nodes = []
61
+ @edges = []
62
+ @node_table = {}
63
+ @selected = nil
64
+ @shift_pressed = false
65
+ @show_index = show_index # store the option
66
+ load_yaml_data_with_state(file, with_semi_lattice_yaml: with_semi_lattice_yaml)
67
+ end
68
+
69
+ # ...existing code...
70
+ end
71
+ # ...existing code...
72
+ ````
73
+
74
+ Made changes.
75
+
76
+ daddygongon: /Users/bob/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/mk_semi_lattice-0.1.0/lib/mk_semi_lattice/mk_semi_lattice_graph.rb:165:in `initialize': unknown keyword: :show_index (ArgumentError)
77
+ とのエラー
78
+
79
+ GitHub Copilot: ### [mk_semi_lattice_graph.rb](file:///Users/bob/git_hub/mk_semi_lattice/lib/mk_semi_lattice/mk_semi_lattice_graph.rb)
80
+
81
+ Fix the error by adding `show_index` as an optional keyword argument to `MkSemiLatticeData#initialize` and storing it as an attribute.
82
+
83
+ ````ruby
84
+ # ...existing code...
85
+ class MkSemiLatticeData
86
+ attr_reader :nodes, :edges, :node_table
87
+ attr_accessor :selected, :shift_pressed, :show_index
88
+
89
+ def initialize(file = "dir_node_edge.yaml", with_semi_lattice_yaml: false, show_index: false)
90
+ @nodes = []
91
+ @edges = []
92
+ @node_table = {}
93
+ @selected = nil
94
+ @shift_pressed = false
95
+ @show_index = show_index
96
+ load_yaml_data_with_state(file, with_semi_lattice_yaml: with_semi_lattice_yaml)
97
+ end
98
+ # ...existing code...
99
+ end
100
+ # ...existing code...
101
+ ````
102
+
103
+ Made changes.
104
+
105
+ daddygongon: #file:mk_semi_lattice_graph.rb:193-226 の重複を取り除くrefactoringを掛けてください
106
+
107
+ GitHub Copilot: ### [mk_semi_lattice_graph.rb](file:///Users/bob/git_hub/mk_semi_lattice/lib/mk_semi_lattice/mk_semi_lattice_graph.rb)
108
+
109
+ Refactor `load_yaml_data_with_state` to remove duplication by extracting node/edge loading into a helper method.
110
+
111
+ ````ruby
112
+ # ...existing code...
113
+
114
+ class MkSemiLatticeData
115
+ # ...existing code...
116
+
117
+ def load_yaml_data_with_state(path, with_semi_lattice_yaml: false)
118
+ state_file = path
119
+ data = if with_semi_lattice_yaml && File.exist?(state_file)
120
+ YAML.load_file(state_file)
121
+ else
122
+ YAML.load_file(path, symbolize_names: true)
123
+ end
124
+ load_nodes_and_edges(data)
125
+ end
126
+
127
+ private
128
+
129
+ def load_nodes_and_edges(data)
130
+ nodes_data = data[:nodes]
131
+ edges_data = data[:edges]
132
+ nodes_data.each do |node_data|
133
+ id = node_data[:id]
134
+ name = node_data[:name]
135
+ type = node_data[:type]
136
+ color = node_data[:color]
137
+ file_path = node_data[:file_path]
138
+ x = node_data[:x] || rand(80..520)
139
+ y = node_data[:y] || rand(80..520)
140
+ fixed = node_data[:fixed] || false
141
+ label = @show_index ? "#{id}:#{name}" : name
142
+ add_node(id, x, y, label, type, color, file_path, fixed)
143
+ end
144
+ edges_data.each do |edge_data|
145
+ from_id = edge_data[:from]
146
+ to_id = edge_data[:to]
147
+ add_edge(from_id, to_id)
148
+ end
149
+ end
150
+ # ...existing code...
151
+ end
152
+ # ...existing code...
153
+ ````
154
+
155
+ Made changes.