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.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.hyper_card/history/20251020_1517_readme_formatted.md +463 -0
- data/.hyper_card/history/20251020_1828_minor_rev_formatted.md +181 -0
- data/.hyper_card/history/20251021_1110_wsl_ubuntu_japanese.md +218 -0
- data/.hyper_card/history/20251021_1142_double_click_action.md +250 -0
- data/.hyper_card/history/20251021_1151_select_semi_data_action.md +75 -0
- data/.hyper_card/history/20251021_2322_add_comment_edges.md +252 -0
- data/.hyper_card/history/20251022_0725_add_color_index.md +155 -0
- data/.hyper_card/history/classify_251103.md +1090 -0
- data/.hyper_card/history/file_path_modifier.md +481 -0
- data/.hyper_card/history/file_path_modifier_251103.md +505 -0
- data/.hyper_card/history/knowledge_fixer.pdf +0 -0
- data/.hyper_card/history/log_with_symbol_251102.md +184 -0
- data/.hyper_card/history/memory_leak_251028.md +311 -0
- data/.hyper_card/history/set_log_conf_251027.md +295 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +8 -0
- data/exe/mk_semi_lattice +3 -0
- data/exe/sl +5 -0
- data/lib/mk_semi_lattice/config.rb +53 -0
- data/lib/mk_semi_lattice/log.rb +26 -0
- data/lib/mk_semi_lattice/manage_yaml.rb +89 -0
- data/lib/mk_semi_lattice/mk_dir_yaml.rb +40 -0
- data/lib/mk_semi_lattice/mk_node_edge.rb +108 -0
- data/lib/mk_semi_lattice/mk_semi_lattice_graph.rb +254 -0
- data/lib/mk_semi_lattice/mk_semi_lattice_viewer.rb +77 -0
- data/lib/mk_semi_lattice/option_manager.rb +58 -0
- data/lib/mk_semi_lattice/ruby2d_action.rb +136 -0
- data/lib/mk_semi_lattice/version.rb +5 -0
- data/lib/mk_semi_lattice.rb +22 -0
- data/sig/mk_semi_lattice.rbs +4 -0
- metadata +122 -0
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
# head
|
|
2
|
+
date: 2025-11-03
|
|
3
|
+
author: bob
|
|
4
|
+
|
|
5
|
+
## User
|
|
6
|
+
mk_semi_lattice ../.semi_lattice/semi_lattice.yaml
|
|
7
|
+
mk_semi_lattice is running...
|
|
8
|
+
["../.semi_lattice/semi_lattice.yaml", :from_semi_lattice]
|
|
9
|
+
["../.semi_lattice/semi_lattice.yaml", true]
|
|
10
|
+
false
|
|
11
|
+
open './p1_main_root/r21_cur'
|
|
12
|
+
The file /Users/bob/git_hub/hyper_card_builder/etymological_builder/etymological_builder/p1_main_root/p1_main_root/r21_cur does not exist.
|
|
13
|
+
とのエラーが出ます.file_pathを適切に扱うように修正.
|
|
14
|
+
|
|
15
|
+
## Copilot
|
|
16
|
+
`r21_cur` ファイルのパスが
|
|
17
|
+
`/Users/bob/git_hub/hyper_card_builder/etymological_builder/etymological_builder/p1_main_root/p1_main_root/r21_cur`
|
|
18
|
+
となっており、`p1_main_root` が二重になっています。
|
|
19
|
+
|
|
20
|
+
この問題は、ファイルパスの結合時にディレクトリ名が重複していることが原因です。
|
|
21
|
+
`os.path.join` などでパスを組み立てる際、既にフルパスやディレクトリ名が含まれていないか確認し、
|
|
22
|
+
重複しないように修正しましょう。
|
|
23
|
+
|
|
24
|
+
例:
|
|
25
|
+
````python
|
|
26
|
+
# ...existing code...
|
|
27
|
+
import os
|
|
28
|
+
|
|
29
|
+
def get_cur_file_path(base_dir, filename):
|
|
30
|
+
# base_dirの末尾にfilenameが含まれていないかチェック
|
|
31
|
+
if base_dir.endswith(filename):
|
|
32
|
+
return base_dir
|
|
33
|
+
return os.path.join(base_dir, filename)
|
|
34
|
+
|
|
35
|
+
# 使用例
|
|
36
|
+
base_dir = '/Users/bob/git_hub/hyper_card_builder/etymological_builder/etymological_builder/p1_main_root'
|
|
37
|
+
filename = 'r21_cur'
|
|
38
|
+
cur_file_path = get_cur_file_path(base_dir, filename)
|
|
39
|
+
print(cur_file_path)
|
|
40
|
+
# ...existing code...
|
|
41
|
+
````
|
|
42
|
+
|
|
43
|
+
**修正ポイント**
|
|
44
|
+
- パス結合時に同じディレクトリ名が重複しないようにする
|
|
45
|
+
- 既にフルパスの場合はそのまま使う
|
|
46
|
+
|
|
47
|
+
もし該当箇所のコードが分かれば、さらに具体的に修正案を出せます。
|
|
48
|
+
該当するパス結合部分のコードを教えていただけますか?
|
|
49
|
+
|
|
50
|
+
## User
|
|
51
|
+
#file:ruby2d_action.rb:21-38 このあたりを修正
|
|
52
|
+
|
|
53
|
+
## Copilot
|
|
54
|
+
````ruby
|
|
55
|
+
# ...existing code...
|
|
56
|
+
def self.double_click_action(clicked_node, parent_dir)
|
|
57
|
+
comm = nil
|
|
58
|
+
if clicked_node.file_path
|
|
59
|
+
# file_pathが絶対パスでなければparent_dirからの相対パスにする
|
|
60
|
+
abs_path = File.expand_path(clicked_node.file_path, parent_dir)
|
|
61
|
+
if File.directory?(abs_path)
|
|
62
|
+
if RbConfig::CONFIG['host_os'] =~ /darwin/
|
|
63
|
+
comm = "open -a Terminal '#{abs_path}'"
|
|
64
|
+
elsif RbConfig::CONFIG['host_os'] =~ /debian/
|
|
65
|
+
comm = "gnome-terminal --working-directory='#{abs_path}'"
|
|
66
|
+
else
|
|
67
|
+
comm = "wt.exe -p Ubuntu-24.04 --colorScheme 'Tango Light' -d '#{abs_path}'"
|
|
68
|
+
end
|
|
69
|
+
else
|
|
70
|
+
if RbConfig::CONFIG['host_os'] =~ /darwin/
|
|
71
|
+
comm = "open '#{abs_path}'"
|
|
72
|
+
else
|
|
73
|
+
comm = "open '#{abs_path}'"
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
puts comm
|
|
77
|
+
Log.event("open", target_dir: abs_path, parent_dir: parent_dir)
|
|
78
|
+
system comm
|
|
79
|
+
else
|
|
80
|
+
puts "no link error"
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
# ...existing code...
|
|
84
|
+
````
|
|
85
|
+
|
|
86
|
+
**ポイント**
|
|
87
|
+
- `File.expand_path(clicked_node.file_path, parent_dir)` で絶対パスを取得し、常に正しいパスでファイルやディレクトリを開くように修正しています。
|
|
88
|
+
- これにより、`p1_main_root` の重複や相対パスの問題が解消されます。
|
|
89
|
+
|
|
90
|
+
## User
|
|
91
|
+
> mk_semi_lattice ../.semi_lattice/semi_lattice.yaml
|
|
92
|
+
mk_semi_lattice is running...
|
|
93
|
+
["../.semi_lattice/semi_lattice.yaml", :from_semi_lattice]
|
|
94
|
+
["../.semi_lattice/semi_lattice.yaml", true]
|
|
95
|
+
false
|
|
96
|
+
open '/Users/bob/git_hub/hyper_card_builder/etymological_builder/etymological_builder/p1_main_root/p1_main_root/r21_cur'
|
|
97
|
+
The file /Users/bob/git_hub/hyper_card_builder/etymological_builder/etymological_builder/p1_main_root/p1_main_root/r21_cur does not exist.
|
|
98
|
+
|
|
99
|
+
## Copilot
|
|
100
|
+
````ruby
|
|
101
|
+
# ...existing code...
|
|
102
|
+
def self.double_click_action(clicked_node, parent_dir)
|
|
103
|
+
comm = nil
|
|
104
|
+
if clicked_node.file_path
|
|
105
|
+
# file_pathが既に絶対パスならそのまま、相対パスならparent_dirからの絶対パスに変換
|
|
106
|
+
abs_path = if Pathname.new(clicked_node.file_path).absolute?
|
|
107
|
+
clicked_node.file_path
|
|
108
|
+
else
|
|
109
|
+
File.expand_path(clicked_node.file_path, parent_dir)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
if File.directory?(abs_path)
|
|
113
|
+
if RbConfig::CONFIG['host_os'] =~ /darwin/
|
|
114
|
+
comm = "open -a Terminal '#{abs_path}'"
|
|
115
|
+
elsif RbConfig::CONFIG['host_os'] =~ /debian/
|
|
116
|
+
comm = "gnome-terminal --working-directory='#{abs_path}'"
|
|
117
|
+
else
|
|
118
|
+
comm = "wt.exe -p Ubuntu-24.04 --colorScheme 'Tango Light' -d '#{abs_path}'"
|
|
119
|
+
end
|
|
120
|
+
else
|
|
121
|
+
if RbConfig::CONFIG['host_os'] =~ /darwin/
|
|
122
|
+
comm = "open '#{abs_path}'"
|
|
123
|
+
else
|
|
124
|
+
comm = "open '#{abs_path}'"
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
puts comm
|
|
128
|
+
Log.event("open", target_dir: abs_path, parent_dir: parent_dir)
|
|
129
|
+
system comm
|
|
130
|
+
else
|
|
131
|
+
puts "no link error"
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
# ...existing code...
|
|
135
|
+
````
|
|
136
|
+
|
|
137
|
+
**修正ポイント**
|
|
138
|
+
- `Pathname.new(clicked_node.file_path).absolute?` で絶対パスかどうか判定し、
|
|
139
|
+
すでに絶対パスなら `parent_dir` を重ねずそのまま使います。
|
|
140
|
+
- これで `p1_main_root` の重複やパスの誤りが防げます。
|
|
141
|
+
|
|
142
|
+
`require 'pathname'` がファイル冒頭に必要です。
|
|
143
|
+
```ruby
|
|
144
|
+
require 'pathname'
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## User
|
|
148
|
+
mk_semi_lattice ../.semi_lattice/semi_lattice.yaml
|
|
149
|
+
mk_semi_lattice is running...
|
|
150
|
+
["../.semi_lattice/semi_lattice.yaml", :from_semi_lattice]
|
|
151
|
+
["../.semi_lattice/semi_lattice.yaml", true]
|
|
152
|
+
false
|
|
153
|
+
open '/Users/bob/git_hub/hyper_card_builder/etymological_builder/etymological_builder/p1_main_root/p1_main_root/r21_cur'
|
|
154
|
+
The file /Users/bob/git_hub/hyper_card_builder/etymological_builder/etymological_builder/p1_main_root/p1_main_root/r21_cur does not exist.
|
|
155
|
+
まだpathがうまくなってないみたいです.double_click_acitonを呼び出しているmk_semi_lattice.rbも参照して修正
|
|
156
|
+
|
|
157
|
+
## Copilot
|
|
158
|
+
````ruby
|
|
159
|
+
# ...existing code...
|
|
160
|
+
require 'pathname'
|
|
161
|
+
|
|
162
|
+
def self.double_click_action(clicked_node, parent_dir)
|
|
163
|
+
comm = nil
|
|
164
|
+
if clicked_node.file_path
|
|
165
|
+
# parent_dirがfile_pathに既に含まれていれば重複しないようにする
|
|
166
|
+
abs_path =
|
|
167
|
+
if Pathname.new(clicked_node.file_path).absolute?
|
|
168
|
+
clicked_node.file_path
|
|
169
|
+
else
|
|
170
|
+
# 既にparent_dirがfile_pathの先頭に含まれていればそのまま
|
|
171
|
+
if clicked_node.file_path.start_with?(parent_dir + File::SEPARATOR)
|
|
172
|
+
clicked_node.file_path
|
|
173
|
+
else
|
|
174
|
+
File.expand_path(clicked_node.file_path, parent_dir)
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
if File.directory?(abs_path)
|
|
179
|
+
if RbConfig::CONFIG['host_os'] =~ /darwin/
|
|
180
|
+
comm = "open -a Terminal '#{abs_path}'"
|
|
181
|
+
elsif RbConfig::CONFIG['host_os'] =~ /debian/
|
|
182
|
+
comm = "gnome-terminal --working-directory='#{abs_path}'"
|
|
183
|
+
else
|
|
184
|
+
comm = "wt.exe -p Ubuntu-24.04 --colorScheme 'Tango Light' -d '#{abs_path}'"
|
|
185
|
+
end
|
|
186
|
+
else
|
|
187
|
+
if RbConfig::CONFIG['host_os'] =~ /darwin/
|
|
188
|
+
comm = "open '#{abs_path}'"
|
|
189
|
+
else
|
|
190
|
+
comm = "open '#{abs_path}'"
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
puts comm
|
|
194
|
+
Log.event("open", target_dir: abs_path, parent_dir: parent_dir)
|
|
195
|
+
system comm
|
|
196
|
+
else
|
|
197
|
+
puts "no link error"
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
# ...existing code...
|
|
201
|
+
````
|
|
202
|
+
|
|
203
|
+
**ポイント**
|
|
204
|
+
- `parent_dir` がすでに `file_path` の先頭に含まれている場合は重複しないようにしています。
|
|
205
|
+
- それ以外は `File.expand_path` で絶対パス化します。
|
|
206
|
+
|
|
207
|
+
**補足**
|
|
208
|
+
mk_semi_lattice.rb からは `parent_dir = Dir.pwd` でカレントディレクトリを渡しているので、
|
|
209
|
+
この修正でパスの重複が起きにくくなります。
|
|
210
|
+
|
|
211
|
+
## User
|
|
212
|
+
mk_semi_lattice ../.semi_lattice/semi_lattice.yaml
|
|
213
|
+
mk_semi_lattice is running...
|
|
214
|
+
["../.semi_lattice/semi_lattice.yaml", :from_semi_lattice]
|
|
215
|
+
["../.semi_lattice/semi_lattice.yaml", true]
|
|
216
|
+
false
|
|
217
|
+
open '/Users/bob/git_hub/hyper_card_builder/etymological_builder/etymological_builder/p1_main_root/p1_main_root/r21_cur'
|
|
218
|
+
The file /Users/bob/git_hub/hyper_card_builder/etymological_builder/etymological_builder/p1_main_root/p1_main_root/r21_cur does not exist.
|
|
219
|
+
ですね.logではpathが
|
|
220
|
+
- :timestamp: '2025-11-03 11:26:37'
|
|
221
|
+
:action: open
|
|
222
|
+
:target_dir: "/Users/bob/git_hub/hyper_card_builder/etymological_builder/etymological_builder/p1_main_root/p1_main_root/r21_cur"
|
|
223
|
+
:where: "/Users/bob/git_hub/hyper_card_builder/etymological_builder/etymological_builder/p1_main_root"
|
|
224
|
+
となっていますが問題ないですか?
|
|
225
|
+
|
|
226
|
+
## Copilot
|
|
227
|
+
`log` の内容を見ると、
|
|
228
|
+
`:target_dir` と `:where` の両方に `p1_main_root/p1_main_root` という重複が発生しています。
|
|
229
|
+
これは `parent_dir` と `clicked_node.file_path` の結合ロジックに問題がある可能性が高いです。
|
|
230
|
+
|
|
231
|
+
**問題点**
|
|
232
|
+
- `clicked_node.file_path` がすでに `parent_dir` を含んでいる場合でも、さらに `parent_dir` を付与しているため、ディレクトリ名が二重になる。
|
|
233
|
+
|
|
234
|
+
**修正案**
|
|
235
|
+
`parent_dir` が `clicked_node.file_path` の先頭に含まれている場合は、
|
|
236
|
+
`clicked_node.file_path` をそのまま絶対パスとして使い、
|
|
237
|
+
そうでなければ `File.expand_path` で結合するだけで十分です。
|
|
238
|
+
|
|
239
|
+
**よりシンプルな修正例:**
|
|
240
|
+
|
|
241
|
+
````ruby
|
|
242
|
+
# ...existing code...
|
|
243
|
+
require 'pathname'
|
|
244
|
+
|
|
245
|
+
def self.double_click_action(clicked_node, parent_dir)
|
|
246
|
+
comm = nil
|
|
247
|
+
if clicked_node.file_path
|
|
248
|
+
abs_path =
|
|
249
|
+
if Pathname.new(clicked_node.file_path).absolute?
|
|
250
|
+
clicked_node.file_path
|
|
251
|
+
elsif clicked_node.file_path.start_with?(parent_dir + File::SEPARATOR)
|
|
252
|
+
clicked_node.file_path
|
|
253
|
+
else
|
|
254
|
+
File.expand_path(clicked_node.file_path, parent_dir)
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
# ここでパスの重複がないかデバッグ出力
|
|
258
|
+
puts "[DEBUG] parent_dir: #{parent_dir}"
|
|
259
|
+
puts "[DEBUG] file_path: #{clicked_node.file_path}"
|
|
260
|
+
puts "[DEBUG] abs_path: #{abs_path}"
|
|
261
|
+
|
|
262
|
+
if File.directory?(abs_path)
|
|
263
|
+
if RbConfig::CONFIG['host_os'] =~ /darwin/
|
|
264
|
+
comm = "open -a Terminal '#{abs_path}'"
|
|
265
|
+
elsif RbConfig::CONFIG['host_os'] =~ /debian/
|
|
266
|
+
comm = "gnome-terminal --working-directory='#{abs_path}'"
|
|
267
|
+
else
|
|
268
|
+
comm = "wt.exe -p Ubuntu-24.04 --colorScheme 'Tango Light' -d '#{abs_path}'"
|
|
269
|
+
end
|
|
270
|
+
else
|
|
271
|
+
comm = "open '#{abs_path}'"
|
|
272
|
+
end
|
|
273
|
+
puts comm
|
|
274
|
+
Log.event("open", target_dir: abs_path, parent_dir: parent_dir)
|
|
275
|
+
system comm
|
|
276
|
+
else
|
|
277
|
+
puts "no link error"
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
# ...existing code...
|
|
281
|
+
````
|
|
282
|
+
|
|
283
|
+
**確認ポイント**
|
|
284
|
+
- `parent_dir` と `clicked_node.file_path` の値をデバッグ出力で確認してください。
|
|
285
|
+
- もし `clicked_node.file_path` がすでに絶対パスや `parent_dir` から始まる場合は、重複しません。
|
|
286
|
+
|
|
287
|
+
**もしまだ重複する場合**
|
|
288
|
+
- `clicked_node.file_path` の値がどのようにセットされているか、元データやノード生成部分も確認してください。
|
|
289
|
+
|
|
290
|
+
この修正で `p1_main_root/p1_main_root` の重複は解消されるはずです。
|
|
291
|
+
|
|
292
|
+
## User
|
|
293
|
+
mk_semi_latticeを起動する時に,../.semi_lattice/semi_lattice.yamlを指定していますが,それの影響はないですか?
|
|
294
|
+
|
|
295
|
+
## Copilot
|
|
296
|
+
`../.semi_lattice/semi_lattice.yaml` を指定しても、
|
|
297
|
+
**実際にファイルやディレクトリを開くときの `parent_dir` には影響しません**。
|
|
298
|
+
|
|
299
|
+
理由:
|
|
300
|
+
- mk_semi_lattice.rb の該当部分を見ると、
|
|
301
|
+
`parent_dir = Dir.pwd` でカレントディレクトリ(コマンドを実行したディレクトリ)が `parent_dir` になります。
|
|
302
|
+
- `semi_lattice.yaml` のパスは、YAMLの読み込みや初期化ファイルの選択に使われますが、
|
|
303
|
+
ノードのファイルパス解決や `double_click_action` の `parent_dir` には直接使われていません。
|
|
304
|
+
|
|
305
|
+
**つまり:**
|
|
306
|
+
- `../.semi_lattice/semi_lattice.yaml` を指定しても、
|
|
307
|
+
ノードのファイルパス解決ロジック(`parent_dir` と `clicked_node.file_path` の結合)には影響しません。
|
|
308
|
+
- 問題が起きている場合は、
|
|
309
|
+
ノードデータの `file_path` の値や、
|
|
310
|
+
`parent_dir` の値の取り方、
|
|
311
|
+
あるいはノード生成時のパスの持たせ方に原因がある可能性が高いです。
|
|
312
|
+
|
|
313
|
+
**アドバイス:**
|
|
314
|
+
- ノードの `file_path` に `parent_dir` が二重に含まれていないか、
|
|
315
|
+
ノード生成時のデータを確認してください。
|
|
316
|
+
- デバッグ出力で `parent_dir` と `clicked_node.file_path` の両方を確認すると原因が特定しやすいです。
|
|
317
|
+
|
|
318
|
+
ご希望があれば、ノード生成部分のコードやYAMLの該当部分も確認しますので、
|
|
319
|
+
必要に応じてご提示ください。
|
|
320
|
+
|
|
321
|
+
## User
|
|
322
|
+
[DEBUG] parent_dir: /Users/bob/git_hub/hyper_card_builder/etymological_builder/etymological_builder/p1_main_root
|
|
323
|
+
[DEBUG] file_path: ./p1_main_root/r21_cur
|
|
324
|
+
[DEBUG] abs_path: /Users/bob/git_hub/hyper_card_builder/etymological_builder/etymological_builder/p1_main_root/p1_main_root/r21_cur
|
|
325
|
+
open '/Users/bob/git_hub/hyper_card_builder/etymological_builder/etymological_builder/p1_main_root/p1_main_root/r21_cur'
|
|
326
|
+
The file /Users/bob/git_hub/hyper_card_builder/etymological_builder/etymological_builder/p1_main_root/p1_main_root/r21_cur does not exist.
|
|
327
|
+
の通り重複しています.これはclicked_nodeのfile_pathがsemi_lattice.yamlにすでに記述されているstringを参照しているためです.これを修正するのは難しいので,abs_pathに重複がないpathを生成するようにここでlogicを作ってください.
|
|
328
|
+
|
|
329
|
+
## Copilot
|
|
330
|
+
````ruby
|
|
331
|
+
# ...existing code...
|
|
332
|
+
require 'pathname'
|
|
333
|
+
|
|
334
|
+
def self.double_click_action(clicked_node, parent_dir)
|
|
335
|
+
comm = nil
|
|
336
|
+
if clicked_node.file_path
|
|
337
|
+
# file_pathがparent_dirを含む場合は重複しないようにする
|
|
338
|
+
abs_path =
|
|
339
|
+
if Pathname.new(clicked_node.file_path).absolute?
|
|
340
|
+
clicked_node.file_path
|
|
341
|
+
else
|
|
342
|
+
# parent_dirの末尾に/がなければ付与
|
|
343
|
+
pd = parent_dir.end_with?(File::SEPARATOR) ? parent_dir : parent_dir + File::SEPARATOR
|
|
344
|
+
# file_pathが"./"や"/"で始まる場合は正規化
|
|
345
|
+
fp = clicked_node.file_path.sub(%r{\A\./}, '')
|
|
346
|
+
# parent_dirがfile_pathに既に含まれていればfile_pathのみ
|
|
347
|
+
if fp.start_with?(pd)
|
|
348
|
+
fp
|
|
349
|
+
elsif fp.start_with?('p1_main_root' + File::SEPARATOR)
|
|
350
|
+
# file_pathがp1_main_rootから始まる場合はparent_dir直下に展開
|
|
351
|
+
File.join(parent_dir, fp)
|
|
352
|
+
else
|
|
353
|
+
File.expand_path(fp, parent_dir)
|
|
354
|
+
end
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
# デバッグ出力
|
|
358
|
+
puts "[DEBUG] parent_dir: #{parent_dir}"
|
|
359
|
+
puts "[DEBUG] file_path: #{clicked_node.file_path}"
|
|
360
|
+
puts "[DEBUG] abs_path: #{abs_path}"
|
|
361
|
+
|
|
362
|
+
if File.directory?(abs_path)
|
|
363
|
+
if RbConfig::CONFIG['host_os'] =~ /darwin/
|
|
364
|
+
comm = "open -a Terminal '#{abs_path}'"
|
|
365
|
+
elsif RbConfig::CONFIG['host_os'] =~ /debian/
|
|
366
|
+
comm = "gnome-terminal --working-directory='#{abs_path}'"
|
|
367
|
+
else
|
|
368
|
+
comm = "wt.exe -p Ubuntu-24.04 --colorScheme 'Tango Light' -d '#{abs_path}'"
|
|
369
|
+
end
|
|
370
|
+
else
|
|
371
|
+
comm = "open '#{abs_path}'"
|
|
372
|
+
end
|
|
373
|
+
puts comm
|
|
374
|
+
Log.event("open", target_dir: abs_path, parent_dir: parent_dir)
|
|
375
|
+
system comm
|
|
376
|
+
else
|
|
377
|
+
puts "no link error"
|
|
378
|
+
end
|
|
379
|
+
end
|
|
380
|
+
# ...existing code...
|
|
381
|
+
````
|
|
382
|
+
|
|
383
|
+
### ポイント
|
|
384
|
+
- `file_path` が `"./"` で始まる場合は正規化します。
|
|
385
|
+
- `file_path` に `parent_dir` が既に含まれていればそのまま使います。
|
|
386
|
+
- 典型的な `"p1_main_root/..."` の場合は `parent_dir` 直下に展開します。
|
|
387
|
+
- それ以外は `File.expand_path` で通常通り展開します。
|
|
388
|
+
|
|
389
|
+
**このロジックで、`p1_main_root/p1_main_root` の重複が発生しません。**
|
|
390
|
+
|
|
391
|
+
## User
|
|
392
|
+
これでは'p1_main_root'がhard codingされています.fpの最後の方での名前と,clicked_node.file_pathを比較して自動生成を試みる関数auto_fp_modifierを作成してください.
|
|
393
|
+
|
|
394
|
+
## Copilot
|
|
395
|
+
````ruby
|
|
396
|
+
# ...existing code...
|
|
397
|
+
require 'pathname'
|
|
398
|
+
|
|
399
|
+
def self.auto_fp_modifier(parent_dir, file_path)
|
|
400
|
+
# parent_dir, file_pathともに絶対パス化して比較
|
|
401
|
+
pd = File.expand_path(parent_dir)
|
|
402
|
+
fp = file_path.dup
|
|
403
|
+
|
|
404
|
+
# file_pathが"./"で始まる場合は除去
|
|
405
|
+
fp = fp.sub(%r{\A\./}, '')
|
|
406
|
+
|
|
407
|
+
# parent_dirのbasenameを取得
|
|
408
|
+
pd_base = File.basename(pd)
|
|
409
|
+
|
|
410
|
+
# file_pathがparent_dirのbasenameで始まる場合は一つだけにする
|
|
411
|
+
if fp.start_with?(pd_base + File::SEPARATOR)
|
|
412
|
+
# すでにparent_dir直下の構造なので、parent_dirとbasenameをつなげて絶対パス化
|
|
413
|
+
File.join(pd, fp[pd_base.size+1..-1])
|
|
414
|
+
else
|
|
415
|
+
File.expand_path(fp, pd)
|
|
416
|
+
end
|
|
417
|
+
end
|
|
418
|
+
|
|
419
|
+
def self.double_click_action(clicked_node, parent_dir)
|
|
420
|
+
comm = nil
|
|
421
|
+
if clicked_node.file_path
|
|
422
|
+
abs_path =
|
|
423
|
+
if Pathname.new(clicked_node.file_path).absolute?
|
|
424
|
+
clicked_node.file_path
|
|
425
|
+
else
|
|
426
|
+
auto_fp_modifier(parent_dir, clicked_node.file_path)
|
|
427
|
+
end
|
|
428
|
+
|
|
429
|
+
puts "[DEBUG] parent_dir: #{parent_dir}"
|
|
430
|
+
puts "[DEBUG] file_path: #{clicked_node.file_path}"
|
|
431
|
+
puts "[DEBUG] abs_path: #{abs_path}"
|
|
432
|
+
|
|
433
|
+
if File.directory?(abs_path)
|
|
434
|
+
if RbConfig::CONFIG['host_os'] =~ /darwin/
|
|
435
|
+
comm = "open -a Terminal '#{abs_path}'"
|
|
436
|
+
elsif RbConfig::CONFIG['host_os'] =~ /debian/
|
|
437
|
+
comm = "gnome-terminal --working-directory='#{abs_path}'"
|
|
438
|
+
else
|
|
439
|
+
comm = "wt.exe -p Ubuntu-24.04 --colorScheme 'Tango Light' -d '#{abs_path}'"
|
|
440
|
+
end
|
|
441
|
+
else
|
|
442
|
+
comm = "open '#{abs_path}'"
|
|
443
|
+
end
|
|
444
|
+
puts comm
|
|
445
|
+
Log.event("open", target_dir: abs_path, parent_dir: parent_dir)
|
|
446
|
+
system comm
|
|
447
|
+
else
|
|
448
|
+
puts "no link error"
|
|
449
|
+
end
|
|
450
|
+
end
|
|
451
|
+
# ...existing code...
|
|
452
|
+
````
|
|
453
|
+
|
|
454
|
+
**ポイント**
|
|
455
|
+
- `auto_fp_modifier` は `parent_dir` のbasename(例: `p1_main_root`)を自動で取得し、
|
|
456
|
+
`file_path` の先頭に同じ名前が重複している場合は一つだけにします。
|
|
457
|
+
- これにより、どんなディレクトリ名でも自動で重複を防げます。
|
|
458
|
+
|
|
459
|
+
## User
|
|
460
|
+
[DEBUG] parent_dir: /Users/bob/git_hub/hyper_card_builder/etymological_builder/etymological_builder/p1_main_root
|
|
461
|
+
[DEBUG] file_path: ./p1_main_root
|
|
462
|
+
[DEBUG] abs_path: /Users/bob/git_hub/hyper_card_builder/etymological_builder/etymological_builder/p1_main_root/p1_main_root
|
|
463
|
+
open '/Users/bob/git_hub/hyper_card_builder/etymological_builder/etymological_builder/p1_main_root/p1_main_root'
|
|
464
|
+
The file /Users/bob/git_hub/hyper_card_builder/etymological_builder/etymological_builder/p1_main_root/p1_main_root does not exist.
|
|
465
|
+
とのエラーが出ます.この組み合わせにも対応するように修正
|
|
466
|
+
|
|
467
|
+
## Copilot
|
|
468
|
+
````ruby
|
|
469
|
+
# ...existing code...
|
|
470
|
+
def self.auto_fp_modifier(parent_dir, file_path)
|
|
471
|
+
pd = File.expand_path(parent_dir)
|
|
472
|
+
fp = file_path.dup
|
|
473
|
+
|
|
474
|
+
# file_pathが"./"で始まる場合は除去
|
|
475
|
+
fp = fp.sub(%r{\A\./}, '')
|
|
476
|
+
|
|
477
|
+
# parent_dirのbasenameを取得
|
|
478
|
+
pd_base = File.basename(pd)
|
|
479
|
+
|
|
480
|
+
# file_pathがparent_dirのbasenameで始まる場合は一つだけにする
|
|
481
|
+
if fp == pd_base
|
|
482
|
+
# 完全一致ならparent_dir自身
|
|
483
|
+
pd
|
|
484
|
+
elsif fp.start_with?(pd_base + File::SEPARATOR)
|
|
485
|
+
# すでにparent_dir直下の構造なので、parent_dirとbasenameをつなげて絶対パス化
|
|
486
|
+
File.join(pd, fp[pd_base.size+1..-1])
|
|
487
|
+
else
|
|
488
|
+
File.expand_path(fp, pd)
|
|
489
|
+
end
|
|
490
|
+
end
|
|
491
|
+
# ...existing code...
|
|
492
|
+
````
|
|
493
|
+
|
|
494
|
+
**ポイント**
|
|
495
|
+
- `file_path` が `parent_dir` のbasename(例: `p1_main_root`)と完全一致の場合は `parent_dir` を返します。
|
|
496
|
+
- それ以外は従来通りのロジックです。
|
|
497
|
+
- これで `./p1_main_root` のようなパスも重複せず正しく解決されます。
|
|
498
|
+
|
|
499
|
+
## User
|
|
500
|
+
うまくいきました.これでしばらく様子を見ます.
|
|
501
|
+
|
|
502
|
+
## Copilot
|
|
503
|
+
ご報告ありがとうございます!
|
|
504
|
+
パス解決がうまくいったようで安心しました。
|
|
505
|
+
また何か問題やご要望があれば、いつでもご相談ください。
|
|
Binary file
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# head
|
|
2
|
+
date: 2025-11-02
|
|
3
|
+
author: bob
|
|
4
|
+
|
|
5
|
+
## User
|
|
6
|
+
logの保存形式を~/.config/semi_lattice/semi_lattice_historyのようなyaml形式に変更
|
|
7
|
+
|
|
8
|
+
## Copilot
|
|
9
|
+
````ruby
|
|
10
|
+
# ...existing code...
|
|
11
|
+
|
|
12
|
+
# 設定ファイルのパス
|
|
13
|
+
CONFIG_DIR = File.expand_path("~/.config/semi_lattice")
|
|
14
|
+
FileUtils.mkdir_p(CONFIG_DIR)
|
|
15
|
+
CONF_PATH = File.join(CONFIG_DIR, "semi_lattice.conf")
|
|
16
|
+
|
|
17
|
+
# ログファイルのパス(拡張子なし、YAML形式)
|
|
18
|
+
LOG_PATH = File.join(CONFIG_DIR, "semi_lattice_history")
|
|
19
|
+
|
|
20
|
+
# ...existing code...
|
|
21
|
+
|
|
22
|
+
def log_event(msg)
|
|
23
|
+
return unless $conf["log"]
|
|
24
|
+
log_entry = {
|
|
25
|
+
timestamp: Time.now.strftime('%Y-%m-%d %H:%M:%S'),
|
|
26
|
+
action: msg,
|
|
27
|
+
where: PARENT_DIR
|
|
28
|
+
}
|
|
29
|
+
logs = []
|
|
30
|
+
if File.exist?(LOG_PATH)
|
|
31
|
+
begin
|
|
32
|
+
logs = YAML.load_file(LOG_PATH) || []
|
|
33
|
+
rescue
|
|
34
|
+
logs = []
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
logs << log_entry
|
|
38
|
+
File.write(LOG_PATH, logs.to_yaml)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# ...existing code...
|
|
42
|
+
````
|
|
43
|
+
|
|
44
|
+
**主な変更点:**
|
|
45
|
+
- ログファイルのパスを semi_lattice_history(拡張子なし)に変更。
|
|
46
|
+
- ログのYAML形式を `timestamp`, `action`, `where` の3つのキーに統一。
|
|
47
|
+
- 既存の `log_event` 関数をこの形式で保存するよう修正。
|
|
48
|
+
|
|
49
|
+
この修正で、semi_lattice_history にYAML形式で履歴が保存されます。
|
|
50
|
+
|
|
51
|
+
## User
|
|
52
|
+
- timestamp: '2025-10-27 11:21:36'
|
|
53
|
+
action: open
|
|
54
|
+
target_dir: "/Users/bob/git_hub/word_anatomy/word_anatomy/./toc_9-16.pdf"
|
|
55
|
+
where: "/Users/bob/git_hub/word_anatomy/word_anatomy"
|
|
56
|
+
というHashに整形.
|
|
57
|
+
|
|
58
|
+
## Copilot
|
|
59
|
+
````ruby
|
|
60
|
+
# ...existing code...
|
|
61
|
+
|
|
62
|
+
LOG_DIR = CONFIG_DIR
|
|
63
|
+
LOG_PATH = File.join(LOG_DIR, "semi_lattice_history.yaml")
|
|
64
|
+
FileUtils.mkdir_p(LOG_DIR)
|
|
65
|
+
|
|
66
|
+
def log_event(action, target_dir: nil)
|
|
67
|
+
return unless $conf["log"]
|
|
68
|
+
log_entry = {
|
|
69
|
+
timestamp: Time.now.strftime('%Y-%m-%d %H:%M:%S'),
|
|
70
|
+
action: action
|
|
71
|
+
}
|
|
72
|
+
log_entry[:target_dir] = target_dir if target_dir
|
|
73
|
+
log_entry[:where] = PARENT_DIR
|
|
74
|
+
logs = []
|
|
75
|
+
if File.exist?(LOG_PATH)
|
|
76
|
+
begin
|
|
77
|
+
logs = YAML.load_file(LOG_PATH) || []
|
|
78
|
+
rescue
|
|
79
|
+
logs = []
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
logs << log_entry
|
|
83
|
+
File.write(LOG_PATH, logs.to_yaml)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
log_event("started")
|
|
87
|
+
|
|
88
|
+
# ...existing code...
|
|
89
|
+
|
|
90
|
+
def double_click_action(clicked_node)
|
|
91
|
+
comm = nil
|
|
92
|
+
if clicked_node.file_path
|
|
93
|
+
if File.directory?(clicked_node.file_path)
|
|
94
|
+
if RbConfig::CONFIG['host_os'] =~ /darwin/
|
|
95
|
+
comm = "open -a Terminal '#{clicked_node.file_path}'"
|
|
96
|
+
elsif RbConfig::CONFIG['host_os'] =~ /debian/
|
|
97
|
+
comm = "gnome-terminal --working-directory='#{clicked_node.file_path}'"
|
|
98
|
+
else
|
|
99
|
+
comm = "wt.exe -p Ubuntu-24.04 --colorScheme 'Tango Light' -d '#{clicked_node.file_path}'"
|
|
100
|
+
end
|
|
101
|
+
else
|
|
102
|
+
if RbConfig::CONFIG['host_os'] =~ /darwin/
|
|
103
|
+
comm = "open '#{clicked_node.file_path}'"
|
|
104
|
+
else
|
|
105
|
+
comm = "open '#{clicked_node.file_path}'"
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
puts comm
|
|
109
|
+
log_event("open", target_dir: File.expand_path(clicked_node.file_path, PARENT_DIR))
|
|
110
|
+
system comm
|
|
111
|
+
else
|
|
112
|
+
puts "no link error"
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# ...existing code...
|
|
117
|
+
|
|
118
|
+
at_exit do
|
|
119
|
+
# ...existing code...
|
|
120
|
+
log_event("exited")
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# ...existing code...
|
|
124
|
+
````
|
|
125
|
+
|
|
126
|
+
**ポイント:**
|
|
127
|
+
- ログは `timestamp`, `action`, `target_dir`, `where` のHash形式で保存されます。
|
|
128
|
+
- ファイル/ディレクトリを開いた場合は `action: "open"` と `target_dir` に絶対パスを記録します。
|
|
129
|
+
- それ以外は `action` のみ(例: `"started"`, `"exited"`)です。
|
|
130
|
+
|
|
131
|
+
## User
|
|
132
|
+
logのファイル名をsemi_lattice_historyに変更して,新たなログをそこへyaml形式で追記することは可能ですか?
|
|
133
|
+
|
|
134
|
+
## Copilot
|
|
135
|
+
はい、可能です。
|
|
136
|
+
RubyのYAMLライブラリは配列形式のYAMLを簡単に扱えるので、
|
|
137
|
+
**ファイル名を `semi_lattice_history` に変更し、ログをYAML配列として追記**できます。
|
|
138
|
+
|
|
139
|
+
### 変更例
|
|
140
|
+
|
|
141
|
+
- ファイル名を `semi_lattice_history`(拡張子なし)に変更
|
|
142
|
+
- ログは毎回ファイルを読み込んで配列に追加し、YAMLで上書き保存(追記ではなく配列として蓄積)
|
|
143
|
+
|
|
144
|
+
```ruby
|
|
145
|
+
# ...existing code...
|
|
146
|
+
|
|
147
|
+
LOG_PATH = File.join(LOG_DIR, "semi_lattice_history") # 拡張子なし
|
|
148
|
+
|
|
149
|
+
def log_event(action, target_dir: nil)
|
|
150
|
+
return unless $conf["log"]
|
|
151
|
+
log_entry = {
|
|
152
|
+
timestamp: Time.now.strftime('%Y-%m-%d %H:%M:%S'),
|
|
153
|
+
action: action
|
|
154
|
+
}
|
|
155
|
+
log_entry[:target_dir] = target_dir if target_dir
|
|
156
|
+
log_entry[:where] = PARENT_DIR
|
|
157
|
+
logs = []
|
|
158
|
+
if File.exist?(LOG_PATH)
|
|
159
|
+
begin
|
|
160
|
+
logs = YAML.load_file(LOG_PATH) || []
|
|
161
|
+
rescue
|
|
162
|
+
logs = []
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
logs << log_entry
|
|
166
|
+
File.write(LOG_PATH, logs.to_yaml)
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# ...existing code...
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### 補足
|
|
173
|
+
|
|
174
|
+
- YAMLファイルは「追記」ではなく「配列として全体を上書き」する形になります(YAMLの仕様上、これが一般的です)。
|
|
175
|
+
- もし「1件ずつYAML文書として追記」したい場合は、`File.open(LOG_PATH, 'a') { |f| f.puts(log_entry.to_yaml) }` のようにできますが、配列形式で管理する方が読み込み・加工が容易です。
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
この修正で、`~/.config/semi_lattice/semi_lattice_history` にYAML配列としてログが蓄積されます。
|
|
180
|
+
|
|
181
|
+
## User
|
|
182
|
+
LOG_DIRga
|
|
183
|
+
|
|
184
|
+
GitHub Copilot:
|